Add scanning QR code from image

This commit is contained in:
2dust
2024-10-18 17:35:32 +08:00
parent b74ddc0b43
commit 5c0fba8744
16 changed files with 208 additions and 89 deletions
+2 -4
View File
@@ -32,10 +32,8 @@
</StackPanel>
</MenuItem.Header>
<MenuItem x:Name="menuAddServerViaClipboard" Header="{x:Static resx:ResUI.menuAddServerViaClipboard}" />
<MenuItem
x:Name="menuAddServerViaScan"
Header="{x:Static resx:ResUI.menuAddServerViaScan}"
IsVisible="False" />
<MenuItem x:Name="menuAddServerViaScan" Header="{x:Static resx:ResUI.menuAddServerViaScan}" />
<MenuItem x:Name="menuAddServerViaImage" Header="{x:Static resx:ResUI.menuAddServerViaImage}" />
<MenuItem x:Name="menuAddCustomServer" Header="{x:Static resx:ResUI.menuAddCustomServer}" />
<Separator />
<MenuItem x:Name="menuAddVmessServer" Header="{x:Static resx:ResUI.menuAddVmessServer}" />
@@ -4,6 +4,7 @@ using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Controls.Notifications;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Platform.Storage;
using Avalonia.ReactiveUI;
using Avalonia.Threading;
using DialogHostAvalonia;
@@ -60,6 +61,7 @@ namespace v2rayN.Desktop.Views
this.BindCommand(ViewModel, vm => vm.AddCustomServerCmd, v => v.menuAddCustomServer).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.AddServerViaClipboardCmd, v => v.menuAddServerViaClipboard).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.AddServerViaScanCmd, v => v.menuAddServerViaScan).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.AddServerViaImageCmd, v => v.menuAddServerViaImage).DisposeWith(disposables);
//sub
this.BindCommand(ViewModel, vm => vm.SubSettingCmd, v => v.menuSubSetting).DisposeWith(disposables);
@@ -224,6 +226,10 @@ namespace v2rayN.Desktop.Views
await ScanScreenTaskAsync();
break;
case EViewAction.ScanImageTask:
await ScanImageTaskAsync();
break;
case EViewAction.AddServerViaClipboard:
var clipboardData = await AvaUtils.GetClipboardData(this);
ViewModel?.AddServerViaClipboardAsync(clipboardData);
@@ -324,7 +330,16 @@ namespace v2rayN.Desktop.Views
ShowHideWindow(true);
//ViewModel?.ScanScreenTaskAsync(result);
//ViewModel?.ScanScreenResult(result);
}
private async Task ScanImageTaskAsync()
{
var fileName = await UI.OpenFileDialog(this,null );
if (fileName.IsNullOrEmpty())
{
return;
}
await ViewModel?.ScanImageResult(fileName);
}
private void MenuCheckUpdate_Click(object? sender, RoutedEventArgs e)
+2 -3
View File
@@ -17,8 +17,7 @@
<Image
Name="imgQrcode"
Width="300"
Height="300"
Source="/Assets/close.png" />
Height="300" />
<TextBox
x:Name="txtContent"
@@ -29,6 +28,6 @@
IsReadOnly="True"
MaxLines="1" />
</Grid>
</UserControl>