Skip to content

Commit ed231cf

Browse files
committed
fix: add guard for theme applying
1 parent 4263660 commit ed231cf

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Nagi.WinUI/MainPage.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ public sealed partial class MainPage : UserControl, ICustomTitleBarProvider
7878
// A flag to track if the page has been unloaded, to prevent dispatcher callbacks from updating UI.
7979
private bool _isUnloaded;
8080

81+
private ElementTheme _lastKnownTheme;
82+
8183
public MainPage()
8284
{
8385
InitializeComponent();
@@ -288,6 +290,7 @@ private async void OnMainPageLoaded(object sender, RoutedEventArgs e)
288290
try
289291
{
290292
// 1. Hook up event handlers first to avoid missing any updates during the async initialization phase.
293+
_lastKnownTheme = ActualTheme;
291294
ActualThemeChanged += OnActualThemeChanged;
292295
ContentFrame.Navigated += OnContentFrameNavigated;
293296
ViewModel.PropertyChanged += OnViewModelPropertyChanged;
@@ -423,6 +426,8 @@ private void OnNavigationSettingsChanged()
423426
// Reapplies the dynamic theme when the system or app theme changes.
424427
private void OnActualThemeChanged(FrameworkElement sender, object args)
425428
{
429+
if (ActualTheme == _lastKnownTheme) return;
430+
_lastKnownTheme = ActualTheme;
426431
_ = _themeService.ReapplyCurrentDynamicThemeAsync();
427432
}
428433

0 commit comments

Comments
 (0)