Rename Manager
Some checks are pending
release Linux / build (Release) (push) Waiting to run
release macOS / build (Release) (push) Waiting to run
release Windows desktop (Avalonia UI) / build (Release) (push) Waiting to run
release Windows / build (Release) (push) Waiting to run

This commit is contained in:
2dust 2025-08-18 20:09:58 +08:00
parent 876381a7fb
commit e104f9f9b2
12 changed files with 43 additions and 41 deletions

View file

@ -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<HotkeyHandler> _instance = new(() => new());
public static HotkeyHandler Instance = _instance.Value;
private static readonly Lazy<HotkeyManager> _instance = new(() => new());
public static HotkeyManager Instance = _instance.Value;
private readonly Dictionary<int, EGlobalHotkey> _hotkeyTriggerDic = new();
private HotKeyManager? _hotKeyManager;

View file

@ -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<GlobalHotkeySettingV
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;
btnCancel.Click += (s, e) => this.Close();
this.WhenActivated(disposables =>

View file

@ -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<MainWindowViewModel>
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<MainWindowViewModel>
StorageUI();
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
{
HotkeyHandler.Instance.Dispose();
HotkeyManager.Instance.Dispose();
desktop.Shutdown();
}
break;

View file

@ -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

View file

@ -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<HotkeyHandler> _instance = new(() => new());
public static HotkeyHandler Instance = _instance.Value;
private static readonly Lazy<HotkeyManager> _instance = new(() => new());
public static HotkeyManager Instance = _instance.Value;
private const int WmHotkey = 0x0312;
private readonly Dictionary<int, List<EGlobalHotkey>> _hotkeyTriggerDic = new();
@ -21,7 +21,7 @@ public sealed class HotkeyHandler
public event Action<EGlobalHotkey>? 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<string> 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<string>();
@ -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

View file

@ -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<WindowsHandler> instance = new(() => new());
public static WindowsHandler Instance => instance.Value;
private static readonly Lazy<WindowsManager> instance = new(() => new());
public static WindowsManager Instance => instance.Value;
private static readonly string _tag = "WindowsHandler";
public async Task<Icon> GetNotifyIcon(Config config)
@ -97,8 +98,8 @@ public sealed class WindowsHandler
public void RegisterGlobalHotkey(Config config, Action<EGlobalHotkey> handler, Action<bool, string>? update)
{
HotkeyHandler.Instance.UpdateViewEvent += update;
HotkeyHandler.Instance.HotkeyTriggerEvent += handler;
HotkeyHandler.Instance.Load();
HotkeyManager.Instance.UpdateViewEvent += update;
HotkeyManager.Instance.HotkeyTriggerEvent += handler;
HotkeyManager.Instance.Load();
}
}

View file

@ -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 =>
{

View file

@ -15,6 +15,7 @@
Height="700"
MinWidth="900"
x:TypeArguments="vms:MainWindowViewModel"
Icon="/Resources/v2rayN.ico"
ResizeMode="CanResizeWithGrip"
ShowInTaskbar="True"
Style="{StaticResource WindowGlobal}"

View file

@ -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<string>(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);
}

View file

@ -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 },

View file

@ -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;

View file

@ -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 },