using Microsoft.UI.Xaml;
using XFEExtension.NetCore.WinUIHelper.Utilities;
using XFEExtension.NetCore.WinUIHelper.Utilities.Helper;
using XFEWarframe.Player.Interface.Services;
using XFEWarframe.Player.Profiles.CrossVersionProfiles;
using XFEWarframe.Player.Utilities;
using XFEWarframe.Player.Views;
namespace XFEWarframe.Player;
public partial class App : Application
{
private static readonly CancellationTokenSource lifetime = new();
public static CancellationToken Lifetime => lifetime.Token;
public static MainWindow MainWindow { get; private set; } = null!;
public static IPlayerService Service { get; private set; } = null!;
public static IPlayerAccountService Accounts { get; private set; } = null!;
public App()
{
AppPath.TraceVerification("App constructor");
if (AppPath.Argument("verify-ui") is not null)
{
DebugSettings.IsBindingTracingEnabled = true;
DebugSettings.BindingFailed += (_, args) => Utilities.Diagnostics.DesktopVerification.BindingErrors.Add(args.Message);
}
XFEWarframe.Desktop.Editing.UiText.Language = AppPath.Argument("ui-language") ?? SystemProfile.UiLanguage;
InitializeComponent();
AppPath.TraceVerification("App resources initialized");
PageManager.RegisterPage(typeof(AppShellPage));
PageManager.RegisterPage(typeof(MainPage));
PageManager.RegisterPage(typeof(AccountPage));
PageManager.RegisterPage(typeof(InventoryPage));
PageManager.RegisterPage(typeof(EditorPage));
PageManager.RegisterPage(typeof(EquipmentPage));
PageManager.RegisterPage(typeof(RivenPage));
PageManager.RegisterPage(typeof(RuntimePage));
PageManager.RegisterPage(typeof(InstallPage));
PageManager.RegisterPage(typeof(LogViewPage));
PageManager.RegisterPage(typeof(ItemCatalogPage));
PageManager.RegisterPage(typeof(SettingPage));
UnhandledException += (_, args) => AppPath.LogException(args.Exception);
TaskScheduler.UnobservedTaskException += (_, args) => { AppPath.LogException(args.Exception); args.SetObserved(); };
}
protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
AppPath.TraceVerification("OnLaunched");
MainWindow = new MainWindow();
AppPath.TraceVerification("MainWindow created");
AppThemeHelper.MainWindow = MainWindow;
XFEWarframe.Desktop.Editing.FormDialogButton.ShowDialogAsync = ServiceManager.GetService<IInteractionService>().ShowAsync;
Service = ServiceManager.GetService<IPlayerService>();
Accounts = ServiceManager.GetService<IPlayerAccountService>();
MainWindow.Content = new AppShellPage();
AppPath.TraceVerification("AppShellPage attached");
AppThemeHelper.Theme = SystemProfile.Theme;
AppThemeHelper.ChangeTheme(SystemProfile.Theme);
AppPath.TraceVerification("Theme applied");
if (AppPath.Argument("verify-ui") is string report)
{
if (AppPath.Argument("verify-dialogs") == "true") { MainWindow.Activate(); MainWindow.AppWindow.Show(); for (var attempt = 0; attempt < 100 && ((FrameworkElement)MainWindow.Content).XamlRoot is null; attempt++) await Task.Delay(20); }
await Utilities.Diagnostics.DesktopVerification.RunAsync(report);
if (AppPath.Argument("verify-visible") == "true") { MainWindow.Activate(); return; }
await ShutdownAsync();
MainWindow.Close();
Exit();
}
else MainWindow.Activate();
}
public static async Task ShutdownAsync()
{
lifetime.Cancel();
try
{
await Service.StopAsync();
Accounts.Stop();
SystemProfile.SaveProfile();
}
catch (Exception ex) { AppPath.LogException(ex); }
}
}
using Microsoft.UI.Xaml;
using XFEExtension.NetCore.WinUIHelper.Utilities;
using XFEExtension.NetCore.WinUIHelper.Utilities.Helper;
using XFEWarframe.Player.Interface.Services;
using XFEWarframe.Player.Profiles.CrossVersionProfiles;
using XFEWarframe.Player.Utilities;
using XFEWarframe.Player.Views;
namespace XFEWarframe.Player;
public partial class App : Application
{
private static readonly CancellationTokenSource lifetime = new();
public static CancellationToken Lifetime => lifetime.Token;
public static MainWindow MainWindow { get; private set; } = null!;
public static IPlayerService Service { get; private set; } = null!;
public static IPlayerAccountService Accounts { get; private set; } = null!;
public App()
{
AppPath.TraceVerification("App constructor");
if (AppPath.Argument("verify-ui") is not null)
{
DebugSettings.IsBindingTracingEnabled = true;
DebugSettings.BindingFailed += (_, args) => Utilities.Diagnostics.DesktopVerification.BindingErrors.Add(args.Message);
}
XFEWarframe.Desktop.Editing.UiText.Language = AppPath.Argument("ui-language") ?? SystemProfile.UiLanguage;
InitializeComponent();
AppPath.TraceVerification("App resources initialized");
PageManager.RegisterPage(typeof(AppShellPage));
PageManager.RegisterPage(typeof(MainPage));
PageManager.RegisterPage(typeof(AccountPage));
PageManager.RegisterPage(typeof(InventoryPage));
PageManager.RegisterPage(typeof(EditorPage));
PageManager.RegisterPage(typeof(EquipmentPage));
PageManager.RegisterPage(typeof(RivenPage));
PageManager.RegisterPage(typeof(RuntimePage));
PageManager.RegisterPage(typeof(InstallPage));
PageManager.RegisterPage(typeof(LogViewPage));
PageManager.RegisterPage(typeof(ItemCatalogPage));
PageManager.RegisterPage(typeof(SettingPage));
UnhandledException += (_, args) => AppPath.LogException(args.Exception);
TaskScheduler.UnobservedTaskException += (_, args) => { AppPath.LogException(args.Exception); args.SetObserved(); };
}
protected override async void OnLaunched(LaunchActivatedEventArgs args)
{
AppPath.TraceVerification("OnLaunched");
MainWindow = new MainWindow();
AppPath.TraceVerification("MainWindow created");
AppThemeHelper.MainWindow = MainWindow;
XFEWarframe.Desktop.Editing.FormDialogButton.ShowDialogAsync = ServiceManager.GetService<IInteractionService>().ShowAsync;
Service = ServiceManager.GetService<IPlayerService>();
Accounts = ServiceManager.GetService<IPlayerAccountService>();
MainWindow.Content = new AppShellPage();
AppPath.TraceVerification("AppShellPage attached");
AppThemeHelper.Theme = SystemProfile.Theme;
AppThemeHelper.ChangeTheme(SystemProfile.Theme);
AppPath.TraceVerification("Theme applied");
if (AppPath.Argument("verify-ui") is string report)
{
if (AppPath.Argument("verify-dialogs") == "true") { MainWindow.Activate(); MainWindow.AppWindow.Show(); for (var attempt = 0; attempt < 100 && ((FrameworkElement)MainWindow.Content).XamlRoot is null; attempt++) await Task.Delay(20); }
await Utilities.Diagnostics.DesktopVerification.RunAsync(report);
if (AppPath.Argument("verify-visible") == "true") { MainWindow.Activate(); return; }
await ShutdownAsync();
MainWindow.Close();
Exit();
}
else MainWindow.Activate();
}
public static async Task ShutdownAsync()
{
lifetime.Cancel();
try
{
await Service.StopAsync();
Accounts.Stop();
SystemProfile.SaveProfile();
}
catch (Exception ex) { AppPath.LogException(ex); }
}
}