From e104f9f9b21bd70b210c397774d10edbaf776e55 Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Mon, 18 Aug 2025 20:09:58 +0800 Subject: [PATCH] Rename Manager --- .../HotkeyManager.cs} | 8 +++---- .../Views/GlobalHotkeySettingWindow.axaml.cs | 6 ++--- .../v2rayN.Desktop/Views/MainWindow.axaml.cs | 6 ++--- .../{QRCodeHelper.cs => QRCodeUtils.cs} | 4 ++-- .../HotkeyManager.cs} | 22 +++++++++---------- .../WindowsManager.cs} | 15 +++++++------ .../Views/GlobalHotkeySettingWindow.xaml.cs | 6 ++--- v2rayN/v2rayN/Views/MainWindow.xaml | 1 + v2rayN/v2rayN/Views/MainWindow.xaml.cs | 6 ++--- v2rayN/v2rayN/Views/ProfilesView.xaml.cs | 2 +- v2rayN/v2rayN/Views/StatusBarView.xaml.cs | 6 ++--- v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs | 2 +- 12 files changed, 43 insertions(+), 41 deletions(-) rename v2rayN/v2rayN.Desktop/{Handler/HotkeyHandler.cs => Manager/HotkeyManager.cs} (91%) rename v2rayN/v2rayN/Common/{QRCodeHelper.cs => QRCodeUtils.cs} (94%) rename v2rayN/v2rayN/{Handler/HotkeyHandler.cs => Manager/HotkeyManager.cs} (89%) rename v2rayN/v2rayN/{Handler/WindowsHandler.cs => Manager/WindowsManager.cs} (89%) diff --git a/v2rayN/v2rayN.Desktop/Handler/HotkeyHandler.cs b/v2rayN/v2rayN.Desktop/Manager/HotkeyManager.cs similarity index 91% rename from v2rayN/v2rayN.Desktop/Handler/HotkeyHandler.cs rename to v2rayN/v2rayN.Desktop/Manager/HotkeyManager.cs index a8d257c8..5ce6ff60 100644 --- a/v2rayN/v2rayN.Desktop/Handler/HotkeyHandler.cs +++ b/v2rayN/v2rayN.Desktop/Manager/HotkeyManager.cs @@ -4,12 +4,12 @@ using Avalonia.ReactiveUI; using Avalonia.Win32.Input; using GlobalHotKeys; -namespace v2rayN.Desktop.Handler; +namespace v2rayN.Desktop.Manager; -public sealed class HotkeyHandler +public sealed class HotkeyManager { - private static readonly Lazy _instance = new(() => new()); - public static HotkeyHandler Instance = _instance.Value; + private static readonly Lazy _instance = new(() => new()); + public static HotkeyManager Instance = _instance.Value; private readonly Dictionary _hotkeyTriggerDic = new(); private HotKeyManager? _hotKeyManager; diff --git a/v2rayN/v2rayN.Desktop/Views/GlobalHotkeySettingWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/GlobalHotkeySettingWindow.axaml.cs index a9f79765..f676ccfc 100644 --- a/v2rayN/v2rayN.Desktop/Views/GlobalHotkeySettingWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/GlobalHotkeySettingWindow.axaml.cs @@ -5,7 +5,7 @@ using Avalonia.Input; using Avalonia.Interactivity; using ReactiveUI; using v2rayN.Desktop.Base; -using v2rayN.Desktop.Handler; +using v2rayN.Desktop.Manager; namespace v2rayN.Desktop.Views; @@ -21,8 +21,8 @@ public partial class GlobalHotkeySettingWindow : WindowBase HotkeyHandler.Instance.IsPause = false; + HotkeyManager.Instance.IsPause = true; + this.Closing += (s, e) => HotkeyManager.Instance.IsPause = false; btnCancel.Click += (s, e) => this.Close(); this.WhenActivated(disposables => diff --git a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs index e808e54e..0633e9af 100644 --- a/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs +++ b/v2rayN/v2rayN.Desktop/Views/MainWindow.axaml.cs @@ -13,7 +13,7 @@ using ServiceLib.Manager; using Splat; using v2rayN.Desktop.Base; using v2rayN.Desktop.Common; -using v2rayN.Desktop.Handler; +using v2rayN.Desktop.Manager; namespace v2rayN.Desktop.Views; @@ -143,7 +143,7 @@ public partial class MainWindow : WindowBase this.Title = $"{Utils.GetVersion()} - {(Utils.IsAdministrator() ? ResUI.RunAsAdmin : ResUI.NotRunAsAdmin)}"; ThreadPool.RegisterWaitForSingleObject(Program.ProgramStarted, OnProgramStarted, null, -1, false); - HotkeyHandler.Instance.Init(_config, OnHotkeyHandler); + HotkeyManager.Instance.Init(_config, OnHotkeyHandler); } else { @@ -235,7 +235,7 @@ public partial class MainWindow : WindowBase StorageUI(); if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { - HotkeyHandler.Instance.Dispose(); + HotkeyManager.Instance.Dispose(); desktop.Shutdown(); } break; diff --git a/v2rayN/v2rayN/Common/QRCodeHelper.cs b/v2rayN/v2rayN/Common/QRCodeUtils.cs similarity index 94% rename from v2rayN/v2rayN/Common/QRCodeHelper.cs rename to v2rayN/v2rayN/Common/QRCodeUtils.cs index 6d070972..3013e45f 100644 --- a/v2rayN/v2rayN/Common/QRCodeHelper.cs +++ b/v2rayN/v2rayN/Common/QRCodeUtils.cs @@ -7,7 +7,7 @@ using System.Windows.Media.Imaging; namespace v2rayN; -public class QRCodeHelper +public class QRCodeUtils { public static ImageSource? GetQRCode(string? strContent) { @@ -17,7 +17,7 @@ public class QRCodeHelper } try { - var qrCodeImage = QRCodeUtils.GenQRCode(strContent); + var qrCodeImage = ServiceLib.Common.QRCodeUtils.GenQRCode(strContent); return qrCodeImage is null ? null : ByteToImage(qrCodeImage); } catch diff --git a/v2rayN/v2rayN/Handler/HotkeyHandler.cs b/v2rayN/v2rayN/Manager/HotkeyManager.cs similarity index 89% rename from v2rayN/v2rayN/Handler/HotkeyHandler.cs rename to v2rayN/v2rayN/Manager/HotkeyManager.cs index cfc2d463..9301cfad 100644 --- a/v2rayN/v2rayN/Handler/HotkeyHandler.cs +++ b/v2rayN/v2rayN/Manager/HotkeyManager.cs @@ -6,12 +6,12 @@ using System.Windows.Input; using System.Windows.Interop; using ServiceLib.Manager; -namespace v2rayN.Handler; +namespace v2rayN.Manager; -public sealed class HotkeyHandler +public sealed class HotkeyManager { - private static readonly Lazy _instance = new(() => new()); - public static HotkeyHandler Instance = _instance.Value; + private static readonly Lazy _instance = new(() => new()); + public static HotkeyManager Instance = _instance.Value; private const int WmHotkey = 0x0312; private readonly Dictionary> _hotkeyTriggerDic = new(); @@ -21,7 +21,7 @@ public sealed class HotkeyHandler public event Action? HotkeyTriggerEvent; - public HotkeyHandler() + public HotkeyManager() { ComponentDispatcher.ThreadPreprocessMessage += OnThreadPreProcessMessage; Init(); @@ -51,7 +51,7 @@ public sealed class HotkeyHandler modifiers |= KeyModifiers.Alt; } - key = (key << 16) | (int)modifiers; + key = key << 16 | (int)modifiers; if (!_hotkeyTriggerDic.ContainsKey(key)) { _hotkeyTriggerDic.Add(key, new() { item.EGlobalHotkey }); @@ -77,7 +77,7 @@ public sealed class HotkeyHandler Application.Current?.Dispatcher.Invoke(() => { - isSuccess = RegisterHotKey(IntPtr.Zero, _hotkeyCode, hotkeyInfo.fsModifiers, hotkeyInfo.vKey); + isSuccess = RegisterHotKey(nint.Zero, _hotkeyCode, hotkeyInfo.fsModifiers, hotkeyInfo.vKey); }); foreach (var name in hotkeyInfo.Names) { @@ -101,7 +101,7 @@ public sealed class HotkeyHandler { Application.Current?.Dispatcher.Invoke(() => { - UnregisterHotKey(IntPtr.Zero, hotkey); + UnregisterHotKey(nint.Zero, hotkey); }); } Init(); @@ -111,7 +111,7 @@ public sealed class HotkeyHandler private (int fsModifiers, int vKey, string hotkeyStr, List Names) GetHotkeyInfo(int hotkeyCode) { var fsModifiers = hotkeyCode & 0xffff; - var vKey = (hotkeyCode >> 16) & 0xffff; + var vKey = hotkeyCode >> 16 & 0xffff; var hotkeyStr = new StringBuilder(); var names = new List(); @@ -174,10 +174,10 @@ public sealed class HotkeyHandler } [DllImport("user32.dll", SetLastError = true)] - private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc); + private static extern bool RegisterHotKey(nint hWnd, int id, int fsModifiers, int vlc); [DllImport("user32.dll", SetLastError = true)] - private static extern bool UnregisterHotKey(IntPtr hWnd, int id); + private static extern bool UnregisterHotKey(nint hWnd, int id); [Flags] private enum KeyModifiers diff --git a/v2rayN/v2rayN/Handler/WindowsHandler.cs b/v2rayN/v2rayN/Manager/WindowsManager.cs similarity index 89% rename from v2rayN/v2rayN/Handler/WindowsHandler.cs rename to v2rayN/v2rayN/Manager/WindowsManager.cs index 2e4ba33b..8e8b116d 100644 --- a/v2rayN/v2rayN/Handler/WindowsHandler.cs +++ b/v2rayN/v2rayN/Manager/WindowsManager.cs @@ -1,13 +1,14 @@ using System.Drawing; using System.IO; using System.Windows.Media.Imaging; +using v2rayN.Manager; -namespace v2rayN.Handler; +namespace v2rayN.Manager; -public sealed class WindowsHandler +public sealed class WindowsManager { - private static readonly Lazy instance = new(() => new()); - public static WindowsHandler Instance => instance.Value; + private static readonly Lazy instance = new(() => new()); + public static WindowsManager Instance => instance.Value; private static readonly string _tag = "WindowsHandler"; public async Task GetNotifyIcon(Config config) @@ -97,8 +98,8 @@ public sealed class WindowsHandler public void RegisterGlobalHotkey(Config config, Action handler, Action? update) { - HotkeyHandler.Instance.UpdateViewEvent += update; - HotkeyHandler.Instance.HotkeyTriggerEvent += handler; - HotkeyHandler.Instance.Load(); + HotkeyManager.Instance.UpdateViewEvent += update; + HotkeyManager.Instance.HotkeyTriggerEvent += handler; + HotkeyManager.Instance.Load(); } } diff --git a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs index d6d25445..54dc6c8b 100644 --- a/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/GlobalHotkeySettingWindow.xaml.cs @@ -5,7 +5,7 @@ using System.Windows.Controls; using System.Windows.Input; using ReactiveUI; using ServiceLib.Manager; -using v2rayN.Handler; +using v2rayN.Manager; namespace v2rayN.Views; @@ -23,8 +23,8 @@ public partial class GlobalHotkeySettingWindow btnReset.Click += btnReset_Click; - HotkeyHandler.Instance.IsPause = true; - this.Closing += (s, e) => HotkeyHandler.Instance.IsPause = false; + HotkeyManager.Instance.IsPause = true; + this.Closing += (s, e) => HotkeyManager.Instance.IsPause = false; this.WhenActivated(disposables => { diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml b/v2rayN/v2rayN/Views/MainWindow.xaml index 14fe809a..b12b17ec 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml +++ b/v2rayN/v2rayN/Views/MainWindow.xaml @@ -15,6 +15,7 @@ Height="700" MinWidth="900" x:TypeArguments="vms:MainWindowViewModel" + Icon="/Resources/v2rayN.ico" ResizeMode="CanResizeWithGrip" ShowInTaskbar="True" Style="{StaticResource WindowGlobal}" diff --git a/v2rayN/v2rayN/Views/MainWindow.xaml.cs b/v2rayN/v2rayN/Views/MainWindow.xaml.cs index 95f3b218..37c6bba7 100644 --- a/v2rayN/v2rayN/Views/MainWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/MainWindow.xaml.cs @@ -10,7 +10,7 @@ using MaterialDesignThemes.Wpf; using ReactiveUI; using ServiceLib.Manager; using Splat; -using v2rayN.Handler; +using v2rayN.Manager; namespace v2rayN.Views; @@ -143,7 +143,7 @@ public partial class MainWindow } AddHelpMenuItem(); - WindowsHandler.Instance.RegisterGlobalHotkey(_config, OnHotkeyHandler, null); + WindowsManager.Instance.RegisterGlobalHotkey(_config, OnHotkeyHandler, null); MessageBus.Current.Listen(EMsgCommand.AppExit.ToString()).Subscribe(StorageUI); } @@ -344,7 +344,7 @@ public partial class MainWindow if (Application.Current?.MainWindow is Window window) { - var bytes = QRCodeHelper.CaptureScreen(window); + var bytes = QRCodeUtils.CaptureScreen(window); await ViewModel?.ScanScreenResult(bytes); } diff --git a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs index a17e0585..265325d3 100644 --- a/v2rayN/v2rayN/Views/ProfilesView.xaml.cs +++ b/v2rayN/v2rayN/Views/ProfilesView.xaml.cs @@ -180,7 +180,7 @@ public partial class ProfilesView public async void ShareServer(string url) { - var img = QRCodeHelper.GetQRCode(url); + var img = QRCodeUtils.GetQRCode(url); var dialog = new QrcodeView() { imgQrcode = { Source = img }, diff --git a/v2rayN/v2rayN/Views/StatusBarView.xaml.cs b/v2rayN/v2rayN/Views/StatusBarView.xaml.cs index 683767a7..db92793d 100644 --- a/v2rayN/v2rayN/Views/StatusBarView.xaml.cs +++ b/v2rayN/v2rayN/Views/StatusBarView.xaml.cs @@ -5,7 +5,7 @@ using System.Windows.Threading; using ReactiveUI; using ServiceLib.Manager; using Splat; -using v2rayN.Handler; +using v2rayN.Manager; namespace v2rayN.Views; @@ -96,8 +96,8 @@ public partial class StatusBarView case EViewAction.DispatcherRefreshIcon: Application.Current?.Dispatcher.Invoke((async () => { - tbNotify.Icon = await WindowsHandler.Instance.GetNotifyIcon(_config); - Application.Current.MainWindow.Icon = WindowsHandler.Instance.GetAppIcon(_config); + tbNotify.Icon = await WindowsManager.Instance.GetNotifyIcon(_config); + Application.Current.MainWindow.Icon = WindowsManager.Instance.GetAppIcon(_config); }), DispatcherPriority.Normal); break; diff --git a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs index 797f3cdc..c8e694d4 100644 --- a/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs +++ b/v2rayN/v2rayN/Views/SubSettingWindow.xaml.cs @@ -70,7 +70,7 @@ public partial class SubSettingWindow { return; } - var img = QRCodeHelper.GetQRCode(url); + var img = QRCodeUtils.GetQRCode(url); var dialog = new QrcodeView() { imgQrcode = { Source = img },