using XFEExtension.NetCore.WinUIHelper.Interface.Services;
using XFEExtension.NetCore.WinUIHelper.Utilities;
using XFEExtension.NetCore.WinUIHelper.Utilities.Helper;
using XFEExtension.NetCore.XFEConsole;
using XFEWorkflow.Profiles.CacheProfiles;
using XFEWorkflow.Profiles.CrossVersionProfiles;
using XFEWorkflow.Utilities;
namespace XFEWorkflow
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
/// <summary>
/// 主页窗口
/// </summary>
public static MainWindow MainWindow { get; private set; } = null!;
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
XFEConsole.UseXFEConsoleLog();
XFEConsole.Log.LogPath = $@"{AppPath.LogDictionary}\{DateTime.Now:yyyy-M-d_HH-mm-ss}.log";
Console.WriteLine("正在启动应用程序...");
this.InitializeComponent();
AppThemeHelper.Theme = SystemProfile.Theme;
PageManager.RegisterPage(typeof(AppShellPage));
PageManager.RegisterPage(typeof(MainPage));
PageManager.RegisterPage(typeof(WorkflowListPage)); PageManager.RegisterPage(typeof(WorkflowEditorPage));
PageManager.RegisterPage(typeof(PluginPageHostPage));
PageManager.RegisterPage(typeof(LogViewPage));
PageManager.RegisterPage(typeof(SettingPage));
foreach (var page in new[] { typeof(BrowserPage), typeof(PluginsPage), typeof(SpacePage), typeof(RunsPage), typeof(CredentialsPage), typeof(AccountPage) }) PageManager.RegisterPage(page);
UnhandledException += App_UnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
private static void CurrentDomain_UnhandledException(object sender, System.UnhandledExceptionEventArgs e)
{
if (e.ExceptionObject is not Exception ex) return;
Console.WriteLine($"[ERROR]应用程序发生错误:{ex.Message}");
Console.WriteLine($"[TRACE]{ex.StackTrace}");
if (ServiceManager.GetService<IMessageService>() is not { } messageService) return;
messageService.ShowMessage(ex.Message, "发生错误", InfoBarSeverity.Error);
}
private static void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
{
Console.WriteLine($"[ERROR]应用程序发生错误:{e.Message}");
Console.WriteLine($"[TRACE]{e.Exception.StackTrace}");
if (ServiceManager.GetService<IMessageService>() is not { } messageService) return;
messageService.ShowMessage(e.Message, "发生错误", InfoBarSeverity.Error);
e.Handled = true;
}
/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
MainWindow = new();
MainWindow.Closed += (_, _) =>
{
SystemProfile.SaveProfile();
CacheProfile.SaveProfile();
};
MainWindow.Content = new AppShellPage();
if (Environment.GetCommandLineArgs().Contains("--ui-background") && Environment.GetCommandLineArgs().Any(x => x.StartsWith("--ui-test=", StringComparison.Ordinal))) MainWindow.AppWindow.Show(false);
else MainWindow.Activate();
MainWindow.InitializeTray();
var uiTest = Environment.GetCommandLineArgs().FirstOrDefault(x => x.StartsWith("--ui-test=", StringComparison.Ordinal));
if (uiTest is not null) MainWindow.DispatcherQueue.TryEnqueue(async () =>
{
try { await Services.UiSmokeTest.RunAsync(Path.GetFullPath(uiTest["--ui-test=".Length..])); }
catch (Exception ex) { await Infrastructure.Storage.AtomicJson.WriteAsync(Path.Combine(Path.GetFullPath(uiTest["--ui-test=".Length..]), "ui-fatal.json"), new { error = ex.ToString() }); }
finally { await MainWindow.Tray!.ExitAsync(); }
});
AppThemeHelper.MainWindow = MainWindow;
Console.WriteLine("应用程序已启动");
}
}
}
using XFEExtension.NetCore.WinUIHelper.Interface.Services;
using XFEExtension.NetCore.WinUIHelper.Utilities;
using XFEExtension.NetCore.WinUIHelper.Utilities.Helper;
using XFEExtension.NetCore.XFEConsole;
using XFEWorkflow.Profiles.CacheProfiles;
using XFEWorkflow.Profiles.CrossVersionProfiles;
using XFEWorkflow.Utilities;
namespace XFEWorkflow
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
/// <summary>
/// 主页窗口
/// </summary>
public static MainWindow MainWindow { get; private set; } = null!;
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
XFEConsole.UseXFEConsoleLog();
XFEConsole.Log.LogPath = $@"{AppPath.LogDictionary}\{DateTime.Now:yyyy-M-d_HH-mm-ss}.log";
Console.WriteLine("正在启动应用程序...");
this.InitializeComponent();
AppThemeHelper.Theme = SystemProfile.Theme;
PageManager.RegisterPage(typeof(AppShellPage));
PageManager.RegisterPage(typeof(MainPage));
PageManager.RegisterPage(typeof(WorkflowListPage)); PageManager.RegisterPage(typeof(WorkflowEditorPage));
PageManager.RegisterPage(typeof(PluginPageHostPage));
PageManager.RegisterPage(typeof(LogViewPage));
PageManager.RegisterPage(typeof(SettingPage));
foreach (var page in new[] { typeof(BrowserPage), typeof(PluginsPage), typeof(SpacePage), typeof(RunsPage), typeof(CredentialsPage), typeof(AccountPage) }) PageManager.RegisterPage(page);
UnhandledException += App_UnhandledException;
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
private static void CurrentDomain_UnhandledException(object sender, System.UnhandledExceptionEventArgs e)
{
if (e.ExceptionObject is not Exception ex) return;
Console.WriteLine($"[ERROR]应用程序发生错误:{ex.Message}");
Console.WriteLine($"[TRACE]{ex.StackTrace}");
if (ServiceManager.GetService<IMessageService>() is not { } messageService) return;
messageService.ShowMessage(ex.Message, "发生错误", InfoBarSeverity.Error);
}
private static void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
{
Console.WriteLine($"[ERROR]应用程序发生错误:{e.Message}");
Console.WriteLine($"[TRACE]{e.Exception.StackTrace}");
if (ServiceManager.GetService<IMessageService>() is not { } messageService) return;
messageService.ShowMessage(e.Message, "发生错误", InfoBarSeverity.Error);
e.Handled = true;
}
/// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
MainWindow = new();
MainWindow.Closed += (_, _) =>
{
SystemProfile.SaveProfile();
CacheProfile.SaveProfile();
};
MainWindow.Content = new AppShellPage();
if (Environment.GetCommandLineArgs().Contains("--ui-background") && Environment.GetCommandLineArgs().Any(x => x.StartsWith("--ui-test=", StringComparison.Ordinal))) MainWindow.AppWindow.Show(false);
else MainWindow.Activate();
MainWindow.InitializeTray();
var uiTest = Environment.GetCommandLineArgs().FirstOrDefault(x => x.StartsWith("--ui-test=", StringComparison.Ordinal));
if (uiTest is not null) MainWindow.DispatcherQueue.TryEnqueue(async () =>
{
try { await Services.UiSmokeTest.RunAsync(Path.GetFullPath(uiTest["--ui-test=".Length..])); }
catch (Exception ex) { await Infrastructure.Storage.AtomicJson.WriteAsync(Path.Combine(Path.GetFullPath(uiTest["--ui-test=".Length..]), "ui-fatal.json"), new { error = ex.ToString() }); }
finally { await MainWindow.Tray!.ExitAsync(); }
});
AppThemeHelper.MainWindow = MainWindow;
Console.WriteLine("应用程序已启动");
}
}
}