mirror of
https://github.com/2dust/v2rayN.git
synced 2026-01-11 08:32:47 +00:00
fix: Fix failure to follow system theme changes (#8584)
Fix the issue where the application failed to sync with system dark/light mode changes in specific scenarios such as triggering system theme switching via scheduled tasks while waking from hibernation, caused by the unreliable HWND hook implementation that missed critical events.
This commit is contained in:
parent
68583e20bc
commit
cbdfe2e15a
1 changed files with 8 additions and 17 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using MaterialDesignColors;
|
||||
using MaterialDesignColors.ColorManipulation;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Microsoft.Win32;
|
||||
|
||||
namespace v2rayN.ViewModels;
|
||||
|
||||
|
|
@ -24,7 +25,7 @@ public class ThemeSettingViewModel : MyReactiveObject
|
|||
{
|
||||
_config = AppManager.Instance.Config;
|
||||
|
||||
RegisterSystemColorSet(_config, Application.Current.MainWindow, ModifyTheme);
|
||||
RegisterSystemColorSet(_config, ModifyTheme);
|
||||
|
||||
BindingUI();
|
||||
RestoreUI();
|
||||
|
|
@ -158,25 +159,15 @@ public class ThemeSettingViewModel : MyReactiveObject
|
|||
_paletteHelper.SetTheme(theme);
|
||||
}
|
||||
|
||||
public void RegisterSystemColorSet(Config config, Window window, Action updateFunc)
|
||||
public static void RegisterSystemColorSet(Config config, Action updateFunc)
|
||||
{
|
||||
var helper = new WindowInteropHelper(window);
|
||||
var hwndSource = HwndSource.FromHwnd(helper.EnsureHandle());
|
||||
hwndSource.AddHook((IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) =>
|
||||
SystemEvents.UserPreferenceChanged += (s, e) =>
|
||||
{
|
||||
if (config.UiItem.CurrentTheme == nameof(ETheme.FollowSystem))
|
||||
if ((e.Category == UserPreferenceCategory.Color || e.Category == UserPreferenceCategory.General)
|
||||
&& config.UiItem.CurrentTheme == nameof(ETheme.FollowSystem))
|
||||
{
|
||||
const int WM_SETTINGCHANGE = 0x001A;
|
||||
if (msg == WM_SETTINGCHANGE)
|
||||
{
|
||||
if (wParam == IntPtr.Zero && Marshal.PtrToStringUni(lParam) == "ImmersiveColorSet")
|
||||
{
|
||||
updateFunc?.Invoke();
|
||||
}
|
||||
}
|
||||
updateFunc?.Invoke();
|
||||
}
|
||||
|
||||
return IntPtr.Zero;
|
||||
});
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue