added sending closing event message to settings windows (#7)
Release / release (push) Successful in 5m7s
Release / release (push) Successful in 5m7s
Reviewed-on: #7 Co-authored-by: Aleksandr Neychev <alexnejchev73@gmail.com>
This commit was merged in pull request #7.
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user