fix: replace SystemEvents with DispatcherTimer to avoid missing package crash

This commit is contained in:
SuperDooper
2026-05-08 14:04:32 +02:00
parent 37939b84ac
commit 01f28cf044
+8 -10
View File
@@ -2,6 +2,7 @@ using Microsoft.Win32;
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Threading;
namespace ClaudeCheckerWindows; namespace ClaudeCheckerWindows;
@@ -14,20 +15,17 @@ public static class ThemeManager
{ {
IsDark = ReadIsDark(); IsDark = ReadIsDark();
Apply(); Apply();
SystemEvents.UserPreferenceChanged += OnPreferenceChanged;
}
private static void OnPreferenceChanged(object sender, UserPreferenceChangedEventArgs e) var timer = new DispatcherTimer { Interval = TimeSpan.FromSeconds(5) };
{ timer.Tick += (_, _) =>
if (e.Category != UserPreferenceCategory.General) return;
var nowDark = ReadIsDark();
if (nowDark == IsDark) return;
IsDark = nowDark;
Application.Current.Dispatcher.Invoke(() =>
{ {
var nowDark = ReadIsDark();
if (nowDark == IsDark) return;
IsDark = nowDark;
Apply(); Apply();
ThemeChanged?.Invoke(); ThemeChanged?.Invoke();
}); };
timer.Start();
} }
private static bool ReadIsDark() private static bool ReadIsDark()