Fix icons in About dialog do not response to "auto" theme
The theme icons seemingly use Dark variant event when the OS theme is light. In addition, I added ThemeManager common to make it accessible for both App and AboutWindow
This commit is contained in:
parent
7c0f261f44
commit
9808450e4c
3 changed files with 59 additions and 22 deletions
|
@ -4,6 +4,7 @@ using Avalonia.Markup.Xaml;
|
||||||
using Avalonia.Platform;
|
using Avalonia.Platform;
|
||||||
using Avalonia.Styling;
|
using Avalonia.Styling;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
|
using Ryujinx.Ava.Common;
|
||||||
using Ryujinx.Ava.Common.Locale;
|
using Ryujinx.Ava.Common.Locale;
|
||||||
using Ryujinx.Ava.UI.Helpers;
|
using Ryujinx.Ava.UI.Helpers;
|
||||||
using Ryujinx.Ava.UI.Windows;
|
using Ryujinx.Ava.UI.Windows;
|
||||||
|
@ -114,12 +115,14 @@ namespace Ryujinx.Ava
|
||||||
|
|
||||||
ShowRestartDialog();
|
ShowRestartDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ThemeManager.OnThemeChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts a PlatformThemeVariant value to the corresponding ThemeVariant value.
|
/// Converts a PlatformThemeVariant value to the corresponding ThemeVariant value.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private ThemeVariant ConvertThemeVariant(PlatformThemeVariant platformThemeVariant) =>
|
public static ThemeVariant ConvertThemeVariant(PlatformThemeVariant platformThemeVariant) =>
|
||||||
platformThemeVariant switch
|
platformThemeVariant switch
|
||||||
{
|
{
|
||||||
PlatformThemeVariant.Dark => ThemeVariant.Dark,
|
PlatformThemeVariant.Dark => ThemeVariant.Dark,
|
||||||
|
@ -127,11 +130,15 @@ namespace Ryujinx.Ava
|
||||||
_ => ThemeVariant.Default,
|
_ => ThemeVariant.Default,
|
||||||
};
|
};
|
||||||
|
|
||||||
private ThemeVariant DetectSystemTheme()
|
public static ThemeVariant DetectSystemTheme()
|
||||||
{
|
{
|
||||||
var colorValues = PlatformSettings.GetColorValues();
|
if (Application.Current is App app)
|
||||||
|
{
|
||||||
|
var colorValues = app.PlatformSettings.GetColorValues();
|
||||||
|
|
||||||
return ConvertThemeVariant(colorValues.ThemeVariant);
|
return ConvertThemeVariant(colorValues.ThemeVariant);
|
||||||
}
|
}
|
||||||
|
return ThemeVariant.Default;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
14
src/Ryujinx/Common/ThemeManager.cs
Normal file
14
src/Ryujinx/Common/ThemeManager.cs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Ryujinx.Ava.Common
|
||||||
|
{
|
||||||
|
public static class ThemeManager
|
||||||
|
{
|
||||||
|
public static event EventHandler ThemeChanged;
|
||||||
|
|
||||||
|
public static void OnThemeChanged()
|
||||||
|
{
|
||||||
|
ThemeChanged?.Invoke(null, EventArgs.Empty);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,8 @@
|
||||||
using Avalonia.Media.Imaging;
|
using Avalonia.Media.Imaging;
|
||||||
using Avalonia.Platform;
|
using Avalonia.Platform;
|
||||||
|
using Avalonia.Styling;
|
||||||
using Avalonia.Threading;
|
using Avalonia.Threading;
|
||||||
|
using Ryujinx.Ava.Common;
|
||||||
using Ryujinx.Ava.Common.Locale;
|
using Ryujinx.Ava.Common.Locale;
|
||||||
using Ryujinx.Common.Utilities;
|
using Ryujinx.Common.Utilities;
|
||||||
using Ryujinx.UI.Common.Configuration;
|
using Ryujinx.UI.Common.Configuration;
|
||||||
|
@ -11,7 +13,7 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Ryujinx.Ava.UI.ViewModels
|
namespace Ryujinx.Ava.UI.ViewModels
|
||||||
{
|
{
|
||||||
public class AboutWindowViewModel : BaseModel
|
public class AboutWindowViewModel : BaseModel, IDisposable
|
||||||
{
|
{
|
||||||
private Bitmap _githubLogo;
|
private Bitmap _githubLogo;
|
||||||
private Bitmap _discordLogo;
|
private Bitmap _discordLogo;
|
||||||
|
@ -85,24 +87,38 @@ namespace Ryujinx.Ava.UI.ViewModels
|
||||||
|
|
||||||
public AboutWindowViewModel()
|
public AboutWindowViewModel()
|
||||||
{
|
{
|
||||||
Version = Program.Version;
|
UpdateLogoTheme(ConfigurationState.Instance.UI.BaseStyle.Value);
|
||||||
|
|
||||||
if (ConfigurationState.Instance.UI.BaseStyle.Value == "Light")
|
|
||||||
{
|
|
||||||
GithubLogo = new Bitmap(AssetLoader.Open(new Uri("resm:Ryujinx.UI.Common.Resources.Logo_GitHub_Light.png?assembly=Ryujinx.UI.Common")));
|
|
||||||
DiscordLogo = new Bitmap(AssetLoader.Open(new Uri("resm:Ryujinx.UI.Common.Resources.Logo_Discord_Light.png?assembly=Ryujinx.UI.Common")));
|
|
||||||
PatreonLogo = new Bitmap(AssetLoader.Open(new Uri("resm:Ryujinx.UI.Common.Resources.Logo_Patreon_Light.png?assembly=Ryujinx.UI.Common")));
|
|
||||||
TwitterLogo = new Bitmap(AssetLoader.Open(new Uri("resm:Ryujinx.UI.Common.Resources.Logo_Twitter_Light.png?assembly=Ryujinx.UI.Common")));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
GithubLogo = new Bitmap(AssetLoader.Open(new Uri("resm:Ryujinx.UI.Common.Resources.Logo_GitHub_Dark.png?assembly=Ryujinx.UI.Common")));
|
|
||||||
DiscordLogo = new Bitmap(AssetLoader.Open(new Uri("resm:Ryujinx.UI.Common.Resources.Logo_Discord_Dark.png?assembly=Ryujinx.UI.Common")));
|
|
||||||
PatreonLogo = new Bitmap(AssetLoader.Open(new Uri("resm:Ryujinx.UI.Common.Resources.Logo_Patreon_Dark.png?assembly=Ryujinx.UI.Common")));
|
|
||||||
TwitterLogo = new Bitmap(AssetLoader.Open(new Uri("resm:Ryujinx.UI.Common.Resources.Logo_Twitter_Dark.png?assembly=Ryujinx.UI.Common")));
|
|
||||||
}
|
|
||||||
|
|
||||||
Dispatcher.UIThread.InvokeAsync(DownloadPatronsJson);
|
Dispatcher.UIThread.InvokeAsync(DownloadPatronsJson);
|
||||||
|
|
||||||
|
ThemeManager.ThemeChanged += ThemeManager_ThemeChanged;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ThemeManager_ThemeChanged(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
Dispatcher.UIThread.Post(() => UpdateLogoTheme(ConfigurationState.Instance.UI.BaseStyle.Value));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateLogoTheme(string theme)
|
||||||
|
{
|
||||||
|
bool isDarkTheme = theme == "Dark" || (theme == "Auto" && App.DetectSystemTheme() == ThemeVariant.Dark);
|
||||||
|
|
||||||
|
string basePath = "resm:Ryujinx.UI.Common.Resources.";
|
||||||
|
string themeSuffix = isDarkTheme ? "Dark.png" : "Light.png";
|
||||||
|
|
||||||
|
GithubLogo = LoadBitmap($"{basePath}Logo_GitHub_{themeSuffix}?assembly=Ryujinx.UI.Common");
|
||||||
|
DiscordLogo = LoadBitmap($"{basePath}Logo_Discord_{themeSuffix}?assembly=Ryujinx.UI.Common");
|
||||||
|
PatreonLogo = LoadBitmap($"{basePath}Logo_Patreon_{themeSuffix}?assembly=Ryujinx.UI.Common");
|
||||||
|
TwitterLogo = LoadBitmap($"{basePath}Logo_Twitter_{themeSuffix}?assembly=Ryujinx.UI.Common");
|
||||||
|
}
|
||||||
|
|
||||||
|
private Bitmap LoadBitmap(string uri)
|
||||||
|
{
|
||||||
|
return new Bitmap(Avalonia.Platform.AssetLoader.Open(new Uri(uri)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
ThemeManager.ThemeChanged -= ThemeManager_ThemeChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task DownloadPatronsJson()
|
private async Task DownloadPatronsJson()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue