Skip to content

Commit

Permalink
Fix default dark mode resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyrrrz committed Apr 12, 2024
1 parent c300391 commit 4011a9a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
7 changes: 3 additions & 4 deletions YoutubeDownloader/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
15 changes: 12 additions & 3 deletions YoutubeDownloader/Services/SettingsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions YoutubeDownloader/ViewModels/MainViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 4011a9a

Please sign in to comment.