From d12297909c18ed1906c5ff3fb6c02e66d54b4c41 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:04:03 +0800 Subject: [PATCH 1/2] Improve the code for WPF Global Window --- v2rayN/v2rayN/App.xaml | 11 ++++++++++- v2rayN/v2rayN/Views/AddServer2Window.xaml | 6 ------ v2rayN/v2rayN/Views/AddServerWindow.xaml | 5 ----- v2rayN/v2rayN/Views/ClashConnectionsView.xaml | 6 +++--- v2rayN/v2rayN/Views/ClashProxiesView.xaml | 8 ++++---- v2rayN/v2rayN/Views/DNSSettingWindow.xaml | 6 ------ v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml | 6 ------ v2rayN/v2rayN/Views/MainWindow.xaml | 5 ----- v2rayN/v2rayN/Views/OptionSettingWindow.xaml | 6 ------ v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml | 12 +++--------- v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml | 12 +++--------- v2rayN/v2rayN/Views/RoutingSettingWindow.xaml | 6 ------ v2rayN/v2rayN/Views/SubEditWindow.xaml | 7 ------- v2rayN/v2rayN/Views/SubSettingWindow.xaml | 6 ------ 14 files changed, 23 insertions(+), 79 deletions(-) diff --git a/v2rayN/v2rayN/App.xaml b/v2rayN/v2rayN/App.xaml index 5327b705..b22ea83b 100644 --- a/v2rayN/v2rayN/App.xaml +++ b/v2rayN/v2rayN/App.xaml @@ -1,9 +1,9 @@  @@ -211,6 +211,11 @@ + + + + + diff --git a/v2rayN/v2rayN/Views/AddServer2Window.xaml b/v2rayN/v2rayN/Views/AddServer2Window.xaml index 5c12a951..36b0c9cc 100644 --- a/v2rayN/v2rayN/Views/AddServer2Window.xaml +++ b/v2rayN/v2rayN/Views/AddServer2Window.xaml @@ -2,7 +2,6 @@ x:Class="v2rayN.Views.AddServer2Window" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:conv="clr-namespace:v2rayN.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" @@ -13,13 +12,8 @@ Width="700" Height="500" x:TypeArguments="vms:AddServer2ViewModel" - Background="{DynamicResource MaterialDesignPaper}" - FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" - ResizeMode="NoResize" ShowInTaskbar="False" Style="{StaticResource WindowGlobal}" - TextElement.FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" - TextElement.Foreground="{DynamicResource MaterialDesignBody}" WindowStartupLocation="CenterScreen" mc:Ignorable="d"> diff --git a/v2rayN/v2rayN/Views/AddServerWindow.xaml b/v2rayN/v2rayN/Views/AddServerWindow.xaml index 760650ea..bbec6703 100644 --- a/v2rayN/v2rayN/Views/AddServerWindow.xaml +++ b/v2rayN/v2rayN/Views/AddServerWindow.xaml @@ -2,7 +2,6 @@ x:Class="v2rayN.Views.AddServerWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:conv="clr-namespace:v2rayN.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" @@ -13,13 +12,9 @@ Width="900" Height="700" x:TypeArguments="vms:AddServerViewModel" - Background="{DynamicResource MaterialDesignPaper}" - FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" ResizeMode="CanResize" ShowInTaskbar="False" Style="{StaticResource WindowGlobal}" - TextElement.FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" - TextElement.Foreground="{DynamicResource MaterialDesignBody}" WindowStartupLocation="CenterScreen" mc:Ignorable="d"> diff --git a/v2rayN/v2rayN/Views/ClashConnectionsView.xaml b/v2rayN/v2rayN/Views/ClashConnectionsView.xaml index 8ea9ca0b..e5781abe 100644 --- a/v2rayN/v2rayN/Views/ClashConnectionsView.xaml +++ b/v2rayN/v2rayN/Views/ClashConnectionsView.xaml @@ -1,11 +1,11 @@ diff --git a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml index 08669761..629bc6ae 100644 --- a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml +++ b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml @@ -2,7 +2,6 @@ x:Class="v2rayN.Views.GlobalHotkeySettingWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:conv="clr-namespace:v2rayN.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" @@ -13,14 +12,9 @@ Width="700" Height="500" x:TypeArguments="vms:SubEditViewModel" - Background="{DynamicResource MaterialDesignPaper}" - FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" KeyDown="GlobalHotkeySettingWindow_KeyDown" - ResizeMode="NoResize" ShowInTaskbar="False" Style="{StaticResource WindowGlobal}" - TextElement.FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" - TextElement.Foreground="{DynamicResource MaterialDesignBody}" WindowStartupLocation="CenterScreen" mc:Ignorable="d"> diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml b/v2rayN/v2rayN/Views/MainWindow.xaml index 79d2ffbe..14ae889a 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml +++ b/v2rayN/v2rayN/Views/MainWindow.xaml @@ -2,7 +2,6 @@ x:Class="v2rayN.Views.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:conv="clr-namespace:v2rayN.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" @@ -15,12 +14,8 @@ Height="700" MinWidth="900" x:TypeArguments="vms:MainWindowViewModel" - Background="{DynamicResource MaterialDesignPaper}" - FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" ShowInTaskbar="True" Style="{StaticResource WindowGlobal}" - TextElement.FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" - TextElement.Foreground="{DynamicResource MaterialDesignBody}" WindowStartupLocation="CenterScreen" mc:Ignorable="d"> diff --git a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml index 61ce6d2c..2303d8f6 100644 --- a/v2rayN/v2rayN/Views/OptionSettingWindow.xaml +++ b/v2rayN/v2rayN/Views/OptionSettingWindow.xaml @@ -2,7 +2,6 @@ x:Class="v2rayN.Views.OptionSettingWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:conv="clr-namespace:v2rayN.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" @@ -13,13 +12,8 @@ Width="1000" Height="700" x:TypeArguments="vms:OptionSettingViewModel" - Background="{DynamicResource MaterialDesignPaper}" - FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" - ResizeMode="NoResize" ShowInTaskbar="False" Style="{StaticResource WindowGlobal}" - TextElement.FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" - TextElement.Foreground="{DynamicResource MaterialDesignBody}" WindowStartupLocation="CenterScreen" mc:Ignorable="d"> diff --git a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml index f3c86a74..758b203c 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml +++ b/v2rayN/v2rayN/Views/RoutingRuleDetailsWindow.xaml @@ -1,25 +1,19 @@  diff --git a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml index 581bb805..08bef17c 100644 --- a/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml +++ b/v2rayN/v2rayN/Views/RoutingRuleSettingWindow.xaml @@ -1,25 +1,19 @@  diff --git a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml index a140a4f8..70621361 100644 --- a/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml +++ b/v2rayN/v2rayN/Views/RoutingSettingWindow.xaml @@ -2,7 +2,6 @@ x:Class="v2rayN.Views.RoutingSettingWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:conv="clr-namespace:v2rayN.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" @@ -13,13 +12,8 @@ Width="990" Height="700" x:TypeArguments="vms:RoutingSettingViewModel" - Background="{DynamicResource MaterialDesignPaper}" - FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" - ResizeMode="NoResize" ShowInTaskbar="False" Style="{StaticResource WindowGlobal}" - TextElement.FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" - TextElement.Foreground="{DynamicResource MaterialDesignBody}" WindowStartupLocation="CenterScreen" mc:Ignorable="d"> diff --git a/v2rayN/v2rayN/Views/SubEditWindow.xaml b/v2rayN/v2rayN/Views/SubEditWindow.xaml index 3853afd8..6f39e9c1 100644 --- a/v2rayN/v2rayN/Views/SubEditWindow.xaml +++ b/v2rayN/v2rayN/Views/SubEditWindow.xaml @@ -2,7 +2,6 @@ x:Class="v2rayN.Views.SubEditWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" - xmlns:conv="clr-namespace:v2rayN.Converters" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" @@ -13,13 +12,8 @@ Width="700" Height="600" x:TypeArguments="vms:SubEditViewModel" - Background="{DynamicResource MaterialDesignPaper}" - FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" - ResizeMode="NoResize" ShowInTaskbar="False" Style="{StaticResource WindowGlobal}" - TextElement.FontFamily="{x:Static conv:MaterialDesignFonts.MyFont}" - TextElement.Foreground="{DynamicResource MaterialDesignBody}" WindowStartupLocation="CenterScreen" mc:Ignorable="d"> @@ -302,7 +296,6 @@ Style="{StaticResource MyOutlinedTextBox}" ToolTip="{x:Static resx:ResUI.TipPreSocksPort}" /> - Date: Fri, 8 Nov 2024 11:11:06 +0800 Subject: [PATCH 2/2] Improve the code for Desktop Exit --- .../ViewModels/MainWindowViewModel.cs | 17 --------------- .../v2rayN.Desktop/Views/MainWindow.axaml.cs | 21 +++++++++++-------- 2 files changed, 12 insertions(+), 26 deletions(-) diff --git a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs index 79f2d29f..90293b54 100644 --- a/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/ServiceLib/ViewModels/MainWindowViewModel.cs @@ -52,8 +52,6 @@ namespace ServiceLib.ViewModels public ReactiveCommand ReloadCmd { get; } - public ReactiveCommand ExitCmd { get; } - [Reactive] public bool BlReloadEnabled { get; set; } @@ -189,11 +187,6 @@ namespace ServiceLib.ViewModels await Reload(); }); - ExitCmd = ReactiveCommand.CreateFromTask(async () => - { - await Exit(); - }); - RegionalPresetDefaultCmd = ReactiveCommand.CreateFromTask(async () => { await ApplyRegionalPreset(EPresetType.Default); @@ -595,16 +588,6 @@ namespace ServiceLib.ViewModels } } - private async Task Exit() - { - if (await _updateView?.Invoke(EViewAction.ShowYesNo, null) == false) - { - return; - } - - await MyAppExitAsync(false); - } - #endregion core job #region Presets diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index d8e7867e..0825faff 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -36,6 +36,7 @@ namespace v2rayN.Desktop.Views menuPromotion.Click += menuPromotion_Click; menuCheckUpdate.Click += MenuCheckUpdate_Click; menuBackupAndRestore.Click += MenuBackupAndRestore_Click; + menuClose.Click += MenuClose_Click; MessageBus.Current.Listen(EMsgCommand.SendSnackMsg.ToString()).Subscribe(DelegateSnackMsg); ViewModel = new MainWindowViewModel(UpdateViewHandler); @@ -80,7 +81,6 @@ namespace v2rayN.Desktop.Views this.BindCommand(ViewModel, vm => vm.ReloadCmd, v => v.menuReload).DisposeWith(disposables); this.OneWayBind(ViewModel, vm => vm.BlReloadEnabled, v => v.menuReload.IsEnabled).DisposeWith(disposables); - this.BindCommand(ViewModel, vm => vm.ExitCmd, v => v.menuClose).DisposeWith(disposables); switch (_config.UiItem.MainGirdOrientation) { @@ -243,14 +243,6 @@ namespace v2rayN.Desktop.Views Locator.Current.GetService()?.AutofitColumnWidthAsync(), DispatcherPriority.Default); break; - - case EViewAction.ShowYesNo: - if (await UI.ShowYesNo(this, ResUI.menuExitTips) == ButtonResult.No) - { - return false; - } - StorageUI(); - break; } return await Task.FromResult(true); @@ -360,6 +352,17 @@ namespace v2rayN.Desktop.Views DialogHost.Show(_backupAndRestoreView); } + private async void MenuClose_Click(object? sender, RoutedEventArgs e) + { + if (await UI.ShowYesNo(this, ResUI.menuExitTips) == ButtonResult.No) + { + return; + } + StorageUI(); + + await ViewModel?.MyAppExitAsync(false); + } + #endregion Event #region UI