diff --git a/src/Ryujinx/App.axaml.cs b/src/Ryujinx/App.axaml.cs index 387a6dc145..77ec36eca8 100644 --- a/src/Ryujinx/App.axaml.cs +++ b/src/Ryujinx/App.axaml.cs @@ -84,7 +84,7 @@ namespace Ryujinx.Ava ApplyConfiguredTheme(); } - private void ApplyConfiguredTheme() + public void ApplyConfiguredTheme() { try { @@ -92,13 +92,16 @@ namespace Ryujinx.Ava if (string.IsNullOrWhiteSpace(baseStyle)) { - ConfigurationState.Instance.UI.BaseStyle.Value = "Dark"; + ConfigurationState.Instance.UI.BaseStyle.Value = "Auto"; baseStyle = ConfigurationState.Instance.UI.BaseStyle; } + ThemeVariant systemTheme = DetectSystemTheme(); + RequestedThemeVariant = baseStyle switch { + "Auto" => systemTheme, "Light" => ThemeVariant.Light, "Dark" => ThemeVariant.Dark, _ => ThemeVariant.Default, @@ -111,5 +114,29 @@ namespace Ryujinx.Ava ShowRestartDialog(); } } + + // Convert Avalonia.Platform.PlatformThemeVariant to the expected ThemeVariant type + private Avalonia.Styling.ThemeVariant ConvertThemeVariant(Avalonia.Platform.PlatformThemeVariant platformThemeVariant) + { + switch (platformThemeVariant) + { + case Avalonia.Platform.PlatformThemeVariant.Dark: + return Avalonia.Styling.ThemeVariant.Dark; + + case Avalonia.Platform.PlatformThemeVariant.Light: + return Avalonia.Styling.ThemeVariant.Light; + + default: + return Avalonia.Styling.ThemeVariant.Default; + } + } + + private ThemeVariant DetectSystemTheme() + { + var platformSettings = this.PlatformSettings; + var colorValues = platformSettings.GetColorValues(); + + return ConvertThemeVariant(colorValues.ThemeVariant); + } } } diff --git a/src/Ryujinx/Assets/Locales/en_US.json b/src/Ryujinx/Assets/Locales/en_US.json index ef40fd5b2e..48b3af76f1 100644 --- a/src/Ryujinx/Assets/Locales/en_US.json +++ b/src/Ryujinx/Assets/Locales/en_US.json @@ -298,6 +298,7 @@ "GameListContextMenuToggleFavorite": "Toggle Favorite", "GameListContextMenuToggleFavoriteToolTip": "Toggle Favorite status of Game", "SettingsTabGeneralTheme": "Theme:", + "SettingsTabGeneralThemeAuto": "Follow OS theme", "SettingsTabGeneralThemeDark": "Dark", "SettingsTabGeneralThemeLight": "Light", "ControllerSettingsConfigureGeneral": "Configure", diff --git a/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs b/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs index fde8f74ae4..fed13e165e 100644 --- a/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs +++ b/src/Ryujinx/UI/ViewModels/SettingsViewModel.cs @@ -405,7 +405,13 @@ namespace Ryujinx.Ava.UI.ViewModels GameDirectories.Clear(); GameDirectories.AddRange(config.UI.GameDirs.Value); - BaseStyleIndex = config.UI.BaseStyle == "Light" ? 0 : 1; + BaseStyleIndex = config.UI.BaseStyle.Value switch + { + "Auto" => 0, + "Light" => 1, + "Dark" => 2, + _ => 0 + }; // Input EnableDockedMode = config.System.EnableDockedMode; @@ -492,7 +498,13 @@ namespace Ryujinx.Ava.UI.ViewModels config.UI.GameDirs.Value = gameDirs; } - config.UI.BaseStyle.Value = BaseStyleIndex == 0 ? "Light" : "Dark"; + config.UI.BaseStyle.Value = BaseStyleIndex switch + { + 0 => "Auto", + 1 => "Light", + 2 => "Dark", + _ => "Auto" + }; // Input config.System.EnableDockedMode.Value = EnableDockedMode; diff --git a/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml b/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml index 6504637e6c..7787fb30b3 100644 --- a/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml +++ b/src/Ryujinx/UI/Views/Settings/SettingsUIView.axaml @@ -62,6 +62,9 @@ + + + diff --git a/src/Ryujinx/UI/Windows/MainWindow.axaml.cs b/src/Ryujinx/UI/Windows/MainWindow.axaml.cs index 37e2e71a8c..dfd8b8a39f 100644 --- a/src/Ryujinx/UI/Windows/MainWindow.axaml.cs +++ b/src/Ryujinx/UI/Windows/MainWindow.axaml.cs @@ -2,6 +2,7 @@ using Avalonia; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Interactivity; +using Avalonia.Platform; using Avalonia.Threading; using FluentAvalonia.UI.Controls; using Ryujinx.Ava.Common; @@ -87,6 +88,25 @@ namespace Ryujinx.Ava.UI.Windows } } + // Event handler for detecting OS theme change when using "Follow OS theme" option + private void OnPlatformColorValuesChanged(object? sender, PlatformColorValues e) + { + if (Application.Current is App app) + { + app.ApplyConfiguredTheme(); + } + } + + protected override void OnClosed(EventArgs e) + { + base.OnClosed(e); + if (this.PlatformSettings != null) + { + // Unsubscribe to the ColorValuesChanged event + this.PlatformSettings.ColorValuesChanged -= OnPlatformColorValuesChanged; + } + } + protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { base.OnApplyTemplate(e); @@ -370,6 +390,9 @@ namespace Ryujinx.Ava.UI.Windows Initialize(); + // Subscribe to the ColorValuesChanged event + this.PlatformSettings.ColorValuesChanged += OnPlatformColorValuesChanged; + ViewModel.Initialize( ContentManager, StorageProvider,