forked from amkovkov/GranuSightSoftware2
feat: add ui exit on ctrl+c
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.Controls.ApplicationLifetimes;
|
using Avalonia.Controls.ApplicationLifetimes;
|
||||||
using Avalonia.Markup.Xaml;
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Avalonia.Threading;
|
||||||
|
|
||||||
using GSS2.Test.ViewModels;
|
using GSS2.Test.ViewModels;
|
||||||
using GSS2.Test.Views;
|
using GSS2.Test.Views;
|
||||||
@@ -29,6 +30,7 @@ public partial class App : Application
|
|||||||
{
|
{
|
||||||
DataContext = Program.ApplicationHost.Services.GetRequiredService<MainWindowViewModel>()
|
DataContext = Program.ApplicationHost.Services.GetRequiredService<MainWindowViewModel>()
|
||||||
};
|
};
|
||||||
|
Program.ShutdownRequested += (_, _) => Dispatcher.UIThread.Invoke(() => desktop.MainWindow.Close());
|
||||||
}
|
}
|
||||||
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleView)
|
else if (ApplicationLifetime is ISingleViewApplicationLifetime singleView)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging.Console;
|
using Microsoft.Extensions.Logging.Console;
|
||||||
|
|
||||||
using Avalonia;
|
using Avalonia;
|
||||||
using Avalonia.OpenGL.Egl;
|
using Avalonia.OpenGL.Egl;
|
||||||
|
|
||||||
using GSS2.Core;
|
using GSS2.Core;
|
||||||
using GSS2.Core.Logging;
|
using GSS2.Core.Logging;
|
||||||
using GSS2.Core.Analysis.AmineContent.Database;
|
using GSS2.Core.Analysis.AmineContent.Database;
|
||||||
|
|
||||||
using ConsoleFormatter = GSS2.Core.Logging.ConsoleFormatter;
|
using ConsoleFormatter = GSS2.Core.Logging.ConsoleFormatter;
|
||||||
|
|
||||||
namespace GSS2.Test;
|
namespace GSS2.Test;
|
||||||
@@ -13,6 +17,7 @@ namespace GSS2.Test;
|
|||||||
public class Program
|
public class Program
|
||||||
{
|
{
|
||||||
public static IHost ApplicationHost { get; } = BuildHostApp();
|
public static IHost ApplicationHost { get; } = BuildHostApp();
|
||||||
|
public static event ConsoleCancelEventHandler? ShutdownRequested;
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
public static int Main(string[] args)
|
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");
|
Console.WriteLine($"\t--console - in DRM rendering mode do not suppress console output");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Console.CancelKeyPress += new ConsoleCancelEventHandler(OnProgramShutdown);
|
||||||
|
Console.WriteLine("Press Ctrl+C to shut down.");
|
||||||
|
|
||||||
return builder.StartWithClassicDesktopLifetime(args);
|
return builder.StartWithClassicDesktopLifetime(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void OnProgramShutdown(object? sender, ConsoleCancelEventArgs ea)
|
||||||
|
{
|
||||||
|
ShutdownRequested?.Invoke(sender, ea);
|
||||||
|
ea.Cancel = true;
|
||||||
|
}
|
||||||
|
|
||||||
private static void SilenceConsole()
|
private static void SilenceConsole()
|
||||||
{
|
{
|
||||||
new Thread(() =>
|
new Thread(() =>
|
||||||
|
|||||||
Reference in New Issue
Block a user