mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-11-11 00:56:39 +00:00
594246ea47
* add settings windows and children views * Expose hotkeys configuration on the UI * Remove double spacing from locale JSON * simplify button assigner * add cemuhook buttons and title to locale * move common button assigner to own class * cancel button assigner when window is closed * remove unused setting * address review. fix controller profile not loading default when switching devices * fix updater file name * Input cleanup (#37) * addressed review * add device type to controller device checks * change accessibility modifier of public classes to internal * Update Ryujinx.Ava/Ui/ViewModels/ControllerSettingsViewModel.cs Co-authored-by: gdkchan <gab.dark.100@gmail.com> * Update de_DE.json * Update de_DE.json * Update tr_TR.json Translated newly added lines * Update it_IT.json * fix rebase * update avalonia * fix wrong key used for button text * Align settings window elements * Tabs to spaces * Update brazilian portuguese translation * Minor improvement on brazilian portuguese translation * fix turkish translation * remove unused text * change view related classes to public * unsubscribe from deferred event if dialog is closed * Load the default language before loading any other when switching languages * Make controller settings more compact * increase default width of settings window, reduce profile buttons width Co-authored-by: gdk <gab.dark.100@gmail.com> Co-authored-by: MutantAura <44103205+MutantAura@users.noreply.github.com> Co-authored-by: Niwu34 <67392333+Niwu34@users.noreply.github.com> Co-authored-by: aegiff <99728970+aegiff@users.noreply.github.com> Co-authored-by: Antonio Brugnolo <36473846+AntoSkate@users.noreply.github.com>
152 lines
No EOL
5.6 KiB
C#
152 lines
No EOL
5.6 KiB
C#
using Avalonia;
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
using Avalonia.Markup.Xaml;
|
|
using Avalonia.Styling;
|
|
using Avalonia.Threading;
|
|
using FluentAvalonia.Styling;
|
|
using Ryujinx.Ava.Common.Locale;
|
|
using Ryujinx.Ava.Ui.Controls;
|
|
using Ryujinx.Ava.Ui.Windows;
|
|
using Ryujinx.Common;
|
|
using Ryujinx.Common.Logging;
|
|
using Ryujinx.Ui.Common.Configuration;
|
|
using System;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
|
|
namespace Ryujinx.Ava
|
|
{
|
|
public class App : Application
|
|
{
|
|
public override void Initialize()
|
|
{
|
|
AvaloniaXamlLoader.Load(this);
|
|
}
|
|
|
|
public override void OnFrameworkInitializationCompleted()
|
|
{
|
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
|
{
|
|
desktop.MainWindow = new MainWindow();
|
|
}
|
|
|
|
base.OnFrameworkInitializationCompleted();
|
|
|
|
if (Program.PreviewerDetached)
|
|
{
|
|
ApplyConfiguredTheme();
|
|
|
|
ConfigurationState.Instance.Ui.BaseStyle.Event += ThemeChanged_Event;
|
|
ConfigurationState.Instance.Ui.CustomThemePath.Event += ThemeChanged_Event;
|
|
ConfigurationState.Instance.Ui.EnableCustomTheme.Event += CustomThemeChanged_Event;
|
|
}
|
|
}
|
|
|
|
private void CustomThemeChanged_Event(object sender, ReactiveEventArgs<bool> e)
|
|
{
|
|
ApplyConfiguredTheme();
|
|
}
|
|
|
|
private void ShowRestartDialog()
|
|
{
|
|
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
|
Dispatcher.UIThread.InvokeAsync(async () =>
|
|
{
|
|
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
|
|
{
|
|
var result = await ContentDialogHelper.CreateConfirmationDialog(
|
|
(desktop.MainWindow as MainWindow).SettingsWindow,
|
|
LocaleManager.Instance["DialogThemeRestartMessage"],
|
|
LocaleManager.Instance["DialogThemeRestartSubMessage"],
|
|
LocaleManager.Instance["InputDialogYes"],
|
|
LocaleManager.Instance["InputDialogNo"],
|
|
LocaleManager.Instance["DialogRestartRequiredMessage"]);
|
|
|
|
if (result == UserResult.Yes)
|
|
{
|
|
var path = Process.GetCurrentProcess().MainModule.FileName;
|
|
var info = new ProcessStartInfo() { FileName = path, UseShellExecute = false };
|
|
var proc = Process.Start(info);
|
|
desktop.Shutdown();
|
|
Environment.Exit(0);
|
|
}
|
|
}
|
|
});
|
|
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
|
|
}
|
|
|
|
private void ThemeChanged_Event(object sender, ReactiveEventArgs<string> e)
|
|
{
|
|
ApplyConfiguredTheme();
|
|
}
|
|
|
|
private void ApplyConfiguredTheme()
|
|
{
|
|
try
|
|
{
|
|
string baseStyle = ConfigurationState.Instance.Ui.BaseStyle;
|
|
string themePath = ConfigurationState.Instance.Ui.CustomThemePath;
|
|
bool enableCustomTheme = ConfigurationState.Instance.Ui.EnableCustomTheme;
|
|
|
|
const string BaseStyleUrl = "avares://Ryujinx.Ava/Assets/Styles/Base{0}.xaml";
|
|
|
|
if (string.IsNullOrWhiteSpace(baseStyle))
|
|
{
|
|
ConfigurationState.Instance.Ui.BaseStyle.Value = "Dark";
|
|
|
|
baseStyle = ConfigurationState.Instance.Ui.BaseStyle;
|
|
}
|
|
|
|
var theme = AvaloniaLocator.Current.GetService<FluentAvaloniaTheme>();
|
|
|
|
theme.RequestedTheme = baseStyle;
|
|
|
|
var currentStyles = this.Styles;
|
|
|
|
// Remove all styles except the base style.
|
|
if (currentStyles.Count > 1)
|
|
{
|
|
currentStyles.RemoveRange(1, currentStyles.Count - 1);
|
|
}
|
|
|
|
IStyle newStyles = null;
|
|
|
|
// Load requested style, and fallback to Dark theme if loading failed.
|
|
try
|
|
{
|
|
newStyles = (Styles)AvaloniaXamlLoader.Load(new Uri(string.Format(BaseStyleUrl, baseStyle), UriKind.Absolute));
|
|
}
|
|
catch (XamlLoadException)
|
|
{
|
|
newStyles = (Styles)AvaloniaXamlLoader.Load(new Uri(string.Format(BaseStyleUrl, "Dark"), UriKind.Absolute));
|
|
}
|
|
|
|
currentStyles.Add(newStyles);
|
|
|
|
if (enableCustomTheme)
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(themePath))
|
|
{
|
|
try
|
|
{
|
|
var themeContent = File.ReadAllText(themePath);
|
|
var customStyle = AvaloniaRuntimeXamlLoader.Parse<IStyle>(themeContent);
|
|
|
|
currentStyles.Add(customStyle);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Logger.Error?.Print(LogClass.Application, $"Failed to Apply Custom Theme. Error: {ex.Message}");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
Logger.Warning?.Print(LogClass.Application, "Failed to Apply Theme. A restart is needed to apply the selected theme");
|
|
|
|
ShowRestartDialog();
|
|
}
|
|
}
|
|
}
|
|
} |