Skip to content

Commit

Permalink
ActualThemeChanged should always reload all the NavigationView icons
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Feb 21, 2023
1 parent 5c7e2a3 commit fbafe27
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions Amethyst/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ public MainWindow()
// Reload & restart the waiting loop
if (_mainPageLoadedOnce)
Shared.Main.DispatcherQueue.TryEnqueue(
async () => { await MainGrid_LoadedHandler(); });
Shared.Main.DispatcherQueue.TryEnqueue(MainGrid_LoadedHandler);
// Rebuild devices' settings
// (Trick the device into rebuilding its interface)
Expand Down Expand Up @@ -1006,7 +1005,7 @@ static void OnWatcherOnChanged(object o, FileSystemEventArgs fileSystemEventArgs
// MVVM stuff
public event PropertyChangedEventHandler PropertyChanged;

private async void MainGrid_Loaded(object sender, RoutedEventArgs e)
private void MainGrid_Loaded(object sender, RoutedEventArgs e)
{
// Load theme config
Shared.Main.MainNavigationView.XamlRoot.Content.As<Grid>().RequestedTheme =
Expand All @@ -1018,7 +1017,7 @@ private async void MainGrid_Loaded(object sender, RoutedEventArgs e)
};

// Execute the handler
await MainGrid_LoadedHandler();
MainGrid_LoadedHandler();

// Register a theme watchdog
NavView.XamlRoot.Content.As<Grid>().ActualThemeChanged += MainWindow_ActualThemeChanged;
Expand Down Expand Up @@ -1057,37 +1056,15 @@ private void MainWindow_ActualThemeChanged(FrameworkElement sender, object args)

// Request page reloads
Shared.Events.RequestInterfaceReload();

OnPropertyChanged(); // Reload all
ReloadNavigationIcons();
}

private async Task MainGrid_LoadedHandler()
private void MainGrid_LoadedHandler()
{
OnPropertyChanged(); // All
ReloadNavigationIcons();

var oppositeTheme = Interfacing.ActualTheme == ElementTheme.Dark
? ElementTheme.Light
: ElementTheme.Dark;

await Task.Delay(30);
HelpButton.RequestedTheme = oppositeTheme;
NavViewGeneralButtonLabel.RequestedTheme = oppositeTheme;
NavViewSettingsButtonLabel.RequestedTheme = oppositeTheme;
NavViewDevicesButtonLabel.RequestedTheme = oppositeTheme;
NavViewInfoButtonLabel.RequestedTheme = oppositeTheme;
NavViewOkashiButtonLabel.RequestedTheme = oppositeTheme;
UpdateIconText.RequestedTheme = oppositeTheme;
PreviewBadgeLabel.RequestedTheme = oppositeTheme;

await Task.Delay(30);
HelpButton.RequestedTheme = Interfacing.ActualTheme;
NavViewGeneralButtonLabel.RequestedTheme = Interfacing.ActualTheme;
NavViewSettingsButtonLabel.RequestedTheme = Interfacing.ActualTheme;
NavViewDevicesButtonLabel.RequestedTheme = Interfacing.ActualTheme;
NavViewInfoButtonLabel.RequestedTheme = Interfacing.ActualTheme;
NavViewOkashiButtonLabel.RequestedTheme = Interfacing.ActualTheme;
UpdateIconText.RequestedTheme = Interfacing.ActualTheme;
PreviewBadgeLabel.RequestedTheme = Interfacing.ActualTheme;
}

private void ReloadNavigationIcons()
Expand Down

0 comments on commit fbafe27

Please sign in to comment.