diff --git a/Yosu/App.xaml.cs b/Yosu/App.xaml.cs index 4f5ac3e..14d048f 100644 --- a/Yosu/App.xaml.cs +++ b/Yosu/App.xaml.cs @@ -22,19 +22,30 @@ public partial class App : Application public static IAlertService AlertSvc { get; private set; } = default!; + public static bool IsChangingTheme { get; set; } + public App(IServiceProvider provider) { InitializeComponent(); Services = provider; - AlertSvc = Services.GetService()!; + AlertSvc = Services.GetRequiredService(); ApplyTheme(); } + private Window? CurrentWindow { get; set; } protected override Window CreateWindow(IActivationState? activationState) { - return new(new AppShell()); + if (CurrentWindow is not null && IsChangingTheme) + { + IsChangingTheme = false; + return CurrentWindow; + } + + CurrentWindow = new(new AppShell()); + + return CurrentWindow; } public static bool IsOnline(bool showSnackbar = true) @@ -105,15 +116,11 @@ public static void RefreshCurrentPageBehaviors() if (Current is null) return; - var page = Current.MainPage; - if (page is null) - return; - var gray900Color = Current.Resources["Gray900"]; #if !MACCATALYST #pragma warning disable CA1416 - foreach (var behavior in page.Behaviors.OfType()) + foreach (var behavior in Shell.Current.Behaviors.OfType()) { behavior.SetAppTheme( StatusBarBehavior.StatusBarColorProperty, @@ -129,7 +136,7 @@ public static void RefreshCurrentPageBehaviors() #pragma warning restore CA1416 #endif - foreach (var behavior in page.Behaviors.OfType()) + foreach (var behavior in Shell.Current.Behaviors.OfType()) { behavior.SetAppTheme( NavigationBarBehavior.NavigationBarColorProperty, diff --git a/Yosu/ViewModels/SettingsViewModel.cs b/Yosu/ViewModels/SettingsViewModel.cs index 27403e1..02f1f18 100644 --- a/Yosu/ViewModels/SettingsViewModel.cs +++ b/Yosu/ViewModels/SettingsViewModel.cs @@ -36,6 +36,7 @@ public SettingsViewModel(PreferenceService preferenceService, SettingsService se if (e.PropertyName == nameof(Preference.AppTheme)) { + App.IsChangingTheme = true; App.ApplyTheme(); #if ANDROID @@ -65,6 +66,8 @@ private void ThemeSelected(int index) { Preference.AppTheme = (AppTheme)index; Preference.Save(); + + App.IsChangingTheme = true; App.ApplyTheme(); #if ANDROID