mirror of
https://github.com/SourMesen/Mesen2.git
synced 2025-04-02 10:21:44 -04:00
60 lines
1.6 KiB
C#
60 lines
1.6 KiB
C#
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Controls.ApplicationLifetimes;
|
|
using Avalonia.Controls.Platform;
|
|
using Avalonia.Markup.Xaml;
|
|
using Avalonia.Styling;
|
|
using Avalonia.Threading;
|
|
using Mesen.Config;
|
|
using Mesen.Interop;
|
|
using Mesen.Localization;
|
|
using Mesen.Utilities;
|
|
using Mesen.ViewModels;
|
|
using Mesen.Windows;
|
|
using System.IO;
|
|
using System.Reflection;
|
|
|
|
namespace Mesen
|
|
{
|
|
public class App : Application
|
|
{
|
|
public static bool ShowConfigWindow { get; set; }
|
|
|
|
public override void Initialize()
|
|
{
|
|
if(Design.IsDesignMode || ShowConfigWindow) {
|
|
RequestedThemeVariant = ThemeVariant.Light;
|
|
} else {
|
|
RequestedThemeVariant = ConfigManager.Config.Preferences.Theme == MesenTheme.Dark ? ThemeVariant.Dark : ThemeVariant.Light;
|
|
}
|
|
|
|
Dispatcher.UIThread.UnhandledException += (s, e) => {
|
|
MesenMsgBox.ShowException(e.Exception);
|
|
e.Handled = true;
|
|
};
|
|
|
|
AvaloniaXamlLoader.Load(this);
|
|
ResourceHelper.LoadResources();
|
|
}
|
|
|
|
public override void OnFrameworkInitializationCompleted()
|
|
{
|
|
if(ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) {
|
|
if(ShowConfigWindow) {
|
|
new PreferencesConfig().InitializeFontDefaults();
|
|
desktop.MainWindow = new SetupWizardWindow();
|
|
} else {
|
|
try {
|
|
desktop.MainWindow = new MainWindow();
|
|
} catch {
|
|
//Something broke when trying to load the main window, the settings file might be invalid/broken, try to reset them
|
|
Configuration.BackupSettings(ConfigManager.ConfigFile);
|
|
ConfigManager.ResetSettings(false);
|
|
desktop.MainWindow = new MainWindow();
|
|
}
|
|
}
|
|
}
|
|
base.OnFrameworkInitializationCompleted();
|
|
}
|
|
}
|
|
}
|