Add "Follow OS theme" option
This commit is contained in:
parent
12b235700c
commit
6deeba68cc
5 changed files with 70 additions and 4 deletions
|
@ -84,7 +84,7 @@ namespace Ryujinx.Ava
|
||||||
ApplyConfiguredTheme();
|
ApplyConfiguredTheme();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyConfiguredTheme()
|
public void ApplyConfiguredTheme()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -92,13 +92,16 @@ namespace Ryujinx.Ava
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(baseStyle))
|
if (string.IsNullOrWhiteSpace(baseStyle))
|
||||||
{
|
{
|
||||||
ConfigurationState.Instance.UI.BaseStyle.Value = "Dark";
|
ConfigurationState.Instance.UI.BaseStyle.Value = "Auto";
|
||||||
|
|
||||||
baseStyle = ConfigurationState.Instance.UI.BaseStyle;
|
baseStyle = ConfigurationState.Instance.UI.BaseStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ThemeVariant systemTheme = DetectSystemTheme();
|
||||||
|
|
||||||
RequestedThemeVariant = baseStyle switch
|
RequestedThemeVariant = baseStyle switch
|
||||||
{
|
{
|
||||||
|
"Auto" => systemTheme,
|
||||||
"Light" => ThemeVariant.Light,
|
"Light" => ThemeVariant.Light,
|
||||||
"Dark" => ThemeVariant.Dark,
|
"Dark" => ThemeVariant.Dark,
|
||||||
_ => ThemeVariant.Default,
|
_ => ThemeVariant.Default,
|
||||||
|
@ -111,5 +114,29 @@ namespace Ryujinx.Ava
|
||||||
ShowRestartDialog();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -298,6 +298,7 @@
|
||||||
"GameListContextMenuToggleFavorite": "Toggle Favorite",
|
"GameListContextMenuToggleFavorite": "Toggle Favorite",
|
||||||
"GameListContextMenuToggleFavoriteToolTip": "Toggle Favorite status of Game",
|
"GameListContextMenuToggleFavoriteToolTip": "Toggle Favorite status of Game",
|
||||||
"SettingsTabGeneralTheme": "Theme:",
|
"SettingsTabGeneralTheme": "Theme:",
|
||||||
|
"SettingsTabGeneralThemeAuto": "Follow OS theme",
|
||||||
"SettingsTabGeneralThemeDark": "Dark",
|
"SettingsTabGeneralThemeDark": "Dark",
|
||||||
"SettingsTabGeneralThemeLight": "Light",
|
"SettingsTabGeneralThemeLight": "Light",
|
||||||
"ControllerSettingsConfigureGeneral": "Configure",
|
"ControllerSettingsConfigureGeneral": "Configure",
|
||||||
|
|
|
@ -405,7 +405,13 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||||
GameDirectories.Clear();
|
GameDirectories.Clear();
|
||||||
GameDirectories.AddRange(config.UI.GameDirs.Value);
|
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
|
// Input
|
||||||
EnableDockedMode = config.System.EnableDockedMode;
|
EnableDockedMode = config.System.EnableDockedMode;
|
||||||
|
@ -492,7 +498,13 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||||
config.UI.GameDirs.Value = gameDirs;
|
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
|
// Input
|
||||||
config.System.EnableDockedMode.Value = EnableDockedMode;
|
config.System.EnableDockedMode.Value = EnableDockedMode;
|
||||||
|
|
|
@ -62,6 +62,9 @@
|
||||||
<ComboBox SelectedIndex="{Binding BaseStyleIndex}"
|
<ComboBox SelectedIndex="{Binding BaseStyleIndex}"
|
||||||
HorizontalContentAlignment="Left"
|
HorizontalContentAlignment="Left"
|
||||||
MinWidth="100">
|
MinWidth="100">
|
||||||
|
<ComboBoxItem>
|
||||||
|
<TextBlock Text="{locale:Locale SettingsTabGeneralThemeAuto}" />
|
||||||
|
</ComboBoxItem>
|
||||||
<ComboBoxItem>
|
<ComboBoxItem>
|
||||||
<TextBlock Text="{locale:Locale SettingsTabGeneralThemeLight}" />
|
<TextBlock Text="{locale:Locale SettingsTabGeneralThemeLight}" />
|
||||||
</ComboBoxItem>
|
</ComboBoxItem>
|
||||||
|
|
|
@ -2,6 +2,7 @@ using Avalonia;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
using Avalonia.Controls.Primitives;
|
using Avalonia.Controls.Primitives;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
|
using Avalonia.Platform;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
using FluentAvalonia.UI.Controls;
|
using FluentAvalonia.UI.Controls;
|
||||||
using Ryujinx.Ava.Common;
|
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)
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnApplyTemplate(e);
|
base.OnApplyTemplate(e);
|
||||||
|
@ -370,6 +390,9 @@ namespace Ryujinx.Ava.UI.Windows
|
||||||
|
|
||||||
Initialize();
|
Initialize();
|
||||||
|
|
||||||
|
// Subscribe to the ColorValuesChanged event
|
||||||
|
this.PlatformSettings.ColorValuesChanged += OnPlatformColorValuesChanged;
|
||||||
|
|
||||||
ViewModel.Initialize(
|
ViewModel.Initialize(
|
||||||
ContentManager,
|
ContentManager,
|
||||||
StorageProvider,
|
StorageProvider,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue