From 4011a9adfff89d17c479d936c751e7793d7dd07b Mon Sep 17 00:00:00 2001 From: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com> Date: Fri, 12 Apr 2024 04:15:13 +0300 Subject: [PATCH] Fix default dark mode resolution --- YoutubeDownloader/App.axaml.cs | 7 +++---- YoutubeDownloader/Services/SettingsService.cs | 15 ++++++++++++--- YoutubeDownloader/ViewModels/MainViewModel.cs | 3 +++ 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/YoutubeDownloader/App.axaml.cs b/YoutubeDownloader/App.axaml.cs index 9f336bf84..bbd87ea6b 100644 --- a/YoutubeDownloader/App.axaml.cs +++ b/YoutubeDownloader/App.axaml.cs @@ -119,11 +119,10 @@ public static void SetDefaultTheme() if (Current is null) return; - var isDark = Current.RequestedThemeVariant is not null - ? Current.RequestedThemeVariant == ThemeVariant.Dark - : Current.PlatformSettings?.GetColorValues().ThemeVariant == PlatformThemeVariant.Dark; + var isDarkModeEnabledByDefault = + Current.PlatformSettings?.GetColorValues().ThemeVariant == PlatformThemeVariant.Dark; - if (isDark) + if (isDarkModeEnabledByDefault) SetDarkTheme(); else SetLightTheme(); diff --git a/YoutubeDownloader/Services/SettingsService.cs b/YoutubeDownloader/Services/SettingsService.cs index 2b8d24c3b..6c726436b 100644 --- a/YoutubeDownloader/Services/SettingsService.cs +++ b/YoutubeDownloader/Services/SettingsService.cs @@ -24,9 +24,7 @@ public partial class SettingsService() private bool _isAutoUpdateEnabled = true; [ObservableProperty] - private bool _isDarkModeEnabled = - Application.Current?.PlatformSettings?.GetColorValues().ThemeVariant - == PlatformThemeVariant.Dark; + private bool _isDarkModeEnabled; [ObservableProperty] private bool _isAuthPersisted = true; @@ -59,6 +57,17 @@ public partial class SettingsService() [ObservableProperty] private VideoQualityPreference _lastVideoQualityPreference = VideoQualityPreference.Highest; + public override void Reset() + { + base.Reset(); + + // Reset the dark mode setting separately because its default value is evaluated dynamically + // and cannot be set in the field initializer. + IsDarkModeEnabled = + Application.Current?.PlatformSettings?.GetColorValues().ThemeVariant + == PlatformThemeVariant.Dark; + } + public override void Save() { // Clear the cookies if they are not supposed to be persisted diff --git a/YoutubeDownloader/ViewModels/MainViewModel.cs b/YoutubeDownloader/ViewModels/MainViewModel.cs index 9c1d1f760..81198eea4 100644 --- a/YoutubeDownloader/ViewModels/MainViewModel.cs +++ b/YoutubeDownloader/ViewModels/MainViewModel.cs @@ -76,6 +76,9 @@ private async Task CheckForUpdatesAsync() [RelayCommand] private async Task InitializeAsync() { + // Reset settings (needed to resolve the default dark mode setting) + settingsService.Reset(); + // Load settings settingsService.Load();