diff --git a/GSS2.Test/App.axaml.cs b/GSS2.Test/App.axaml.cs index 03ba3e7..85a98a2 100644 --- a/GSS2.Test/App.axaml.cs +++ b/GSS2.Test/App.axaml.cs @@ -1,6 +1,7 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Markup.Xaml; +using Avalonia.Threading; using GSS2.Test.ViewModels; using GSS2.Test.Views; @@ -29,6 +30,7 @@ public partial class App : Application { DataContext = Program.ApplicationHost.Services.GetRequiredService() }; + Program.ShutdownRequested += (_, _) => Dispatcher.UIThread.Invoke(() => desktop.MainWindow.Close()); } else if (ApplicationLifetime is ISingleViewApplicationLifetime singleView) { diff --git a/GSS2.Test/Program.cs b/GSS2.Test/Program.cs index 485a3c1..46e20f6 100644 --- a/GSS2.Test/Program.cs +++ b/GSS2.Test/Program.cs @@ -1,11 +1,15 @@ using System.Reflection; + using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging.Console; + using Avalonia; using Avalonia.OpenGL.Egl; + using GSS2.Core; using GSS2.Core.Logging; using GSS2.Core.Analysis.AmineContent.Database; + using ConsoleFormatter = GSS2.Core.Logging.ConsoleFormatter; namespace GSS2.Test; @@ -13,6 +17,7 @@ namespace GSS2.Test; public class Program { public static IHost ApplicationHost { get; } = BuildHostApp(); + public static event ConsoleCancelEventHandler? ShutdownRequested; [STAThread] public static int Main(string[] args) @@ -33,9 +38,19 @@ public class Program Console.WriteLine($"\t--console - in DRM rendering mode do not suppress console output"); return 0; } + + Console.CancelKeyPress += new ConsoleCancelEventHandler(OnProgramShutdown); + Console.WriteLine("Press Ctrl+C to shut down."); + return builder.StartWithClassicDesktopLifetime(args); } + private static void OnProgramShutdown(object? sender, ConsoleCancelEventArgs ea) + { + ShutdownRequested?.Invoke(sender, ea); + ea.Cancel = true; + } + private static void SilenceConsole() { new Thread(() =>