Skip to content

Commit

Permalink
Improved UI for Desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Oct 11, 2024
1 parent a556bf9 commit b172b03
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 23 deletions.
2 changes: 1 addition & 1 deletion v2rayN/ServiceLib/ViewModels/ProfilesViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ private async Task SetDefaultMultipleServer(ECoreType coreType)
}
else
{
SetDefaultServer(indexId);
await SetDefaultServer(indexId);
}
}

Expand Down
4 changes: 4 additions & 0 deletions v2rayN/v2rayN.Desktop/App.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}" />
Expand Down
80 changes: 64 additions & 16 deletions v2rayN/v2rayN.Desktop/ViewModels/AppViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand All @@ -18,33 +21,78 @@ public AppViewModel()
{
_config = AppHandler.Instance.Config;

AddServerViaClipboardCmd = ReactiveCommand.Create(() =>
SystemProxyClearCmd = ReactiveCommand.CreateFromTask(async () =>
{
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
var clipboardData = AvaUtils.GetClipboardData(desktop.MainWindow).Result;
Locator.Current.GetService<MainWindowViewModel>()?.AddServerViaClipboardAsync(clipboardData);
}
await SetListenerType(ESysProxyType.ForcedClear);
});
SystemProxySetCmd = ReactiveCommand.CreateFromTask(async () =>
{
await SetListenerType(ESysProxyType.ForcedChange);
});
SystemProxyNothingCmd = ReactiveCommand.CreateFromTask(async () =>
{
await SetListenerType(ESysProxyType.Unchanged);
});

SubUpdateCmd = ReactiveCommand.Create(() =>
AddServerViaClipboardCmd = ReactiveCommand.CreateFromTask(async () =>
{
Locator.Current.GetService<MainWindowViewModel>()?.UpdateSubscriptionProcess("", false);
await AddServerViaClipboard();
});
SubUpdateViaProxyCmd = ReactiveCommand.Create(() =>

SubUpdateCmd = ReactiveCommand.CreateFromTask(async () =>
{
Locator.Current.GetService<MainWindowViewModel>()?.UpdateSubscriptionProcess("", true);
await UpdateSubscriptionProcess(false);
});
SubUpdateViaProxyCmd = ReactiveCommand.CreateFromTask(async () =>
{
await UpdateSubscriptionProcess(true);
});

ExitCmd = ReactiveCommand.Create(() =>
ExitCmd = ReactiveCommand.CreateFromTask(async () =>
{
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
Locator.Current.GetService<MainWindowViewModel>()?.MyAppExitAsync(false);
await Exit();
});
}

private async Task SetListenerType(ESysProxyType type)
{
if (_config.systemProxyItem.sysProxyType == type)
{
return;
}

desktop.Shutdown();
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 = 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();
}
}
}
}
3 changes: 3 additions & 0 deletions v2rayN/v2rayN.Desktop/Views/RoutingSettingWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -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}" />
Expand Down
7 changes: 1 addition & 6 deletions v2rayN/v2rayN.Desktop/Views/RoutingSettingWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,7 @@ private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
}

private void RoutingSettingWindow_KeyDown(object? sender, KeyEventArgs e)
{
if (ViewModel?.enableRoutingBasic ?? false)
{
return;
}

{
if (e.KeyModifiers == KeyModifiers.Control)
{
if (e.Key == Key.A)
Expand Down

0 comments on commit b172b03

Please sign in to comment.