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 else
{ {
SetDefaultServer(indexId); await SetDefaultServer(indexId);
} }
} }

View File

@ -33,6 +33,10 @@
ToolTipText="v2rayN Desktop"> ToolTipText="v2rayN Desktop">
<TrayIcon.Menu> <TrayIcon.Menu>
<NativeMenu> <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 Command="{Binding AddServerViaClipboardCmd}" Header="{x:Static resx:ResUI.menuAddServerViaClipboard}" />
<NativeMenuItem Header="{x:Static resx:ResUI.menuAddServerViaScan}" IsVisible="False" /> <NativeMenuItem Header="{x:Static resx:ResUI.menuAddServerViaScan}" IsVisible="False" />
<NativeMenuItem Command="{Binding SubUpdateCmd}" Header="{x:Static resx:ResUI.menuSubUpdate}" /> <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 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> AddServerViaClipboardCmd { get; }
public ReactiveCommand<Unit, Unit> SubUpdateCmd { get; } public ReactiveCommand<Unit, Unit> SubUpdateCmd { get; }
public ReactiveCommand<Unit, Unit> SubUpdateViaProxyCmd { get; } public ReactiveCommand<Unit, Unit> SubUpdateViaProxyCmd { get; }
@ -18,33 +21,78 @@ namespace v2rayN.Desktop.ViewModels
{ {
_config = AppHandler.Instance.Config; _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 () =>
{ {
var clipboardData = AvaUtils.GetClipboardData(desktop.MainWindow).Result; await SetListenerType(ESysProxyType.ForcedChange);
Locator.Current.GetService<MainWindowViewModel>()?.AddServerViaClipboardAsync(clipboardData); });
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();
});
} }
});
SubUpdateCmd = ReactiveCommand.Create(() => private async Task SetListenerType(ESysProxyType type)
{ {
Locator.Current.GetService<MainWindowViewModel>()?.UpdateSubscriptionProcess("", false); if (_config.systemProxyItem.sysProxyType == type)
});
SubUpdateViaProxyCmd = ReactiveCommand.Create(() =>
{ {
Locator.Current.GetService<MainWindowViewModel>()?.UpdateSubscriptionProcess("", true); return;
}); }
ExitCmd = ReactiveCommand.Create(() => 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 (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{ {
Locator.Current.GetService<MainWindowViewModel>()?.MyAppExitAsync(false); if (desktop.MainWindow != null)
{
var clipboardData = await AvaUtils.GetClipboardData(desktop.MainWindow);
var service = Locator.Current.GetService<MainWindowViewModel>();
if (service != null) await service.AddServerViaClipboardAsync(clipboardData);
}
}
}
private async Task UpdateSubscriptionProcess(bool blProxy)
{
var service = Locator.Current.GetService<MainWindowViewModel>();
if (service != null) await service.UpdateSubscriptionProcess("", blProxy);
}
private async Task Exit()
{
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
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" HeadersVisibility="Column"
IsReadOnly="True" IsReadOnly="True"
ItemsSource="{Binding RoutingItems}"> ItemsSource="{Binding RoutingItems}">
<DataGrid.KeyBindings>
<KeyBinding Command="{Binding RoutingAdvancedSetDefaultCmd}" Gesture="Enter" />
</DataGrid.KeyBindings>
<DataGrid.ContextMenu> <DataGrid.ContextMenu>
<ContextMenu> <ContextMenu>
<MenuItem x:Name="menuRoutingAdvancedAdd" Header="{x:Static resx:ResUI.menuRoutingAdvancedAdd}" /> <MenuItem x:Name="menuRoutingAdvancedAdd" Header="{x:Static resx:ResUI.menuRoutingAdvancedAdd}" />

View File

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