added sending closing event message to settings windows
Pull request / build (pull_request) Successful in 39s

This commit is contained in:
2026-08-14 02:18:47 +05:00
parent 70b83a5fec
commit 81587988f2
7 changed files with 303 additions and 8 deletions
+32
View File
@@ -26,6 +26,7 @@ public partial class App : Application
{
private ServiceProvider? _services;
private SingleInstanceGate? _instanceGate;
private SettingsCloseSignal? _closeSignal;
protected override void OnStartup(StartupEventArgs e)
{
@@ -42,6 +43,10 @@ public partial class App : Application
_instanceGate = gate;
_instanceGate.ActivationRequested += OnActivationRequested;
_closeSignal = new SettingsCloseSignal();
_closeSignal.CloseRequested += OnCloseRequested;
_closeSignal.Listen();
var services = new ServiceCollection();
ConfigureServices(services);
_services = services.BuildServiceProvider();
@@ -61,6 +66,12 @@ public partial class App : Application
{
_services?.Dispose();
if (_closeSignal is not null)
{
_closeSignal.CloseRequested -= OnCloseRequested;
_closeSignal.Dispose();
}
if (_instanceGate is not null)
{
_instanceGate.ActivationRequested -= OnActivationRequested;
@@ -95,6 +106,27 @@ public partial class App : Application
private void OnActivationRequested(object? sender, EventArgs e) =>
Dispatcher.BeginInvoke(ShowMainWindow);
// The agent is quitting. Answered on a thread pool thread, and the window is closed
// on its own one
private void OnCloseRequested(object? sender, EventArgs e) =>
Dispatcher.BeginInvoke(CloseMainWindow);
/// <summary>
/// Closes the window the way the title bar button does, so that everything hanging
/// off closing happens; <see cref="ShutdownMode.OnMainWindowClose"/> ends the process
/// after it. Without a window there is nothing to close and the process simply ends.
/// </summary>
private void CloseMainWindow()
{
if (MainWindow is { } window)
{
window.Close();
return;
}
Shutdown();
}
private void ShowMainWindow()
{
if (MainWindow is not { } window)