Improved UI for Desktop

pull/5829/head
2dust 2024-10-11 09:24:15 +08:00
parent a556bf9487
commit b172b03927
5 changed files with 77 additions and 27 deletions

View File

@ -582,7 +582,7 @@ namespace ServiceLib.ViewModels
}
else
{
SetDefaultServer(indexId);
await SetDefaultServer(indexId);
}
}

View File

@ -33,6 +33,10 @@
ToolTipText="v2rayN Desktop">
<TrayIcon.Menu>
<NativeMenu>
<NativeMenuItem Command="{Binding SystemProxyClearCmd}" Header="{x:Static resx:ResUI.menuSystemProxyClear}" />
<NativeMenuItem Command="{Binding SystemProxySetCmd}" Header="{x:Static resx:ResUI.menuSystemProxySet}" />
<NativeMenuItem Command="{Binding SystemProxyNothingCmd}" Header="{x:Static resx:ResUI.menuSystemProxyNothing}" />
<NativeMenuItemSeparator />
<NativeMenuItem Command="{Binding AddServerViaClipboardCmd}" Header="{x:Static resx:ResUI.menuAddServerViaClipboard}" />
<NativeMenuItem Header="{x:Static resx:ResUI.menuAddServerViaScan}" IsVisible="False" />
<NativeMenuItem Command="{Binding SubUpdateCmd}" Header="{x:Static resx:ResUI.menuSubUpdate}" />

View File

@ -9,6 +9,9 @@ namespace v2rayN.Desktop.ViewModels
{
public class AppViewModel : MyReactiveObject
{
public ReactiveCommand<Unit, Unit> SystemProxyClearCmd { get; }
public ReactiveCommand<Unit, Unit> SystemProxySetCmd { get; }
public ReactiveCommand<Unit, Unit> SystemProxyNothingCmd { get; }
public ReactiveCommand<Unit, Unit> AddServerViaClipboardCmd { get; }
public ReactiveCommand<Unit, Unit> SubUpdateCmd { get; }
public ReactiveCommand<Unit, Unit> SubUpdateViaProxyCmd { get; }
@ -18,33 +21,78 @@ namespace v2rayN.Desktop.ViewModels
{
_config = AppHandler.Instance.Config;
AddServerViaClipboardCmd = ReactiveCommand.Create(() =>
SystemProxyClearCmd = ReactiveCommand.CreateFromTask(async () =>
{
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
await SetListenerType(ESysProxyType.ForcedClear);
});
SystemProxySetCmd = ReactiveCommand.CreateFromTask(async () =>
{
await SetListenerType(ESysProxyType.ForcedChange);
});
SystemProxyNothingCmd = ReactiveCommand.CreateFromTask(async () =>
{
await SetListenerType(ESysProxyType.Unchanged);
});
AddServerViaClipboardCmd = ReactiveCommand.CreateFromTask(async () =>
{
await AddServerViaClipboard();
});
SubUpdateCmd = ReactiveCommand.CreateFromTask(async () =>
{
await UpdateSubscriptionProcess(false);
});
SubUpdateViaProxyCmd = ReactiveCommand.CreateFromTask(async () =>
{
await UpdateSubscriptionProcess(true);
});
ExitCmd = ReactiveCommand.CreateFromTask(async () =>
{
await Exit();
});
}
private async Task SetListenerType(ESysProxyType type)
{
if (_config.systemProxyItem.sysProxyType == type)
{
return;
}
var service = Locator.Current.GetService<MainWindowViewModel>();
if (service != null) await service.SetListenerType(type);
}
private async Task AddServerViaClipboard()
{
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
if (desktop.MainWindow != null)
{
var clipboardData = AvaUtils.GetClipboardData(desktop.MainWindow).Result;
Locator.Current.GetService<MainWindowViewModel>()?.AddServerViaClipboardAsync(clipboardData);
var clipboardData = await AvaUtils.GetClipboardData(desktop.MainWindow);
var service = Locator.Current.GetService<MainWindowViewModel>();
if (service != null) await service.AddServerViaClipboardAsync(clipboardData);
}
});
}
}
SubUpdateCmd = ReactiveCommand.Create(() =>
{
Locator.Current.GetService<MainWindowViewModel>()?.UpdateSubscriptionProcess("", false);
});
SubUpdateViaProxyCmd = ReactiveCommand.Create(() =>
{
Locator.Current.GetService<MainWindowViewModel>()?.UpdateSubscriptionProcess("", true);
});
private async Task UpdateSubscriptionProcess(bool blProxy)
{
var service = Locator.Current.GetService<MainWindowViewModel>();
if (service != null) await service.UpdateSubscriptionProcess("", blProxy);
}
ExitCmd = ReactiveCommand.Create(() =>
private async Task Exit()
{
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
Locator.Current.GetService<MainWindowViewModel>()?.MyAppExitAsync(false);
var service = Locator.Current.GetService<MainWindowViewModel>();
if (service != null) await service.MyAppExitAsync(false);
desktop.Shutdown();
}
});
desktop.Shutdown();
}
}
}
}

View File

@ -92,6 +92,9 @@
HeadersVisibility="Column"
IsReadOnly="True"
ItemsSource="{Binding RoutingItems}">
<DataGrid.KeyBindings>
<KeyBinding Command="{Binding RoutingAdvancedSetDefaultCmd}" Gesture="Enter" />
</DataGrid.KeyBindings>
<DataGrid.ContextMenu>
<ContextMenu>
<MenuItem x:Name="menuRoutingAdvancedAdd" Header="{x:Static resx:ResUI.menuRoutingAdvancedAdd}" />

View File

@ -82,12 +82,7 @@ namespace v2rayN.Desktop.Views
}
private void RoutingSettingWindow_KeyDown(object? sender, KeyEventArgs e)
{
if (ViewModel?.enableRoutingBasic ?? false)
{
return;
}
{
if (e.KeyModifiers == KeyModifiers.Control)
{
if (e.Key == Key.A)