From 1fa5e8b0e5f5bceb0dd60b494d62bbbb144e08aa Mon Sep 17 00:00:00 2001 From: elgegeto <341694139+elgegeto@users.noreply.github.com> Date: Tue, 10 Nov 2026 16:12:29 -0300 Subject: [PATCH 1/2] fix: let Windows shutdown and sign-out proceed (#58) Persist the current session synchronously for WM_QUERYENDSESSION without cancelling it. Bypass close-to-tray interception during the Windows session-ending path, preserving the normal application quit behavior on other platforms. --- src/RatioMaster.App/App.axaml.cs | 16 ++++++++++++++++ .../ViewModels/MainWindowViewModel.cs | 11 +++++++++-- src/RatioMaster.App/Views/MainWindow.axaml.cs | 4 +++- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/RatioMaster.App/App.axaml.cs b/src/RatioMaster.App/App.axaml.cs index d8f1ddb..dc7c79d 100644 --- a/src/RatioMaster.App/App.axaml.cs +++ b/src/RatioMaster.App/App.axaml.cs @@ -67,6 +67,22 @@ public override void OnFrameworkInitializationCompleted() viewModel.RestoreRequested += (_, _) => window.RestoreFromTray(); desktop.ShutdownRequested += async (_, e) => { + if (OperatingSystem.IsWindows()) + { + // WM_QUERYENDSESSION must not be cancelled for shutdown or sign-out. + window.WindowsSessionEnding = true; + try + { + viewModel.SaveForSystemShutdown(); + } + catch (Exception) + { + // A failed save must not prevent Windows from ending the session. + } + + return; + } + e.Cancel = true; await this.ShutdownAsync(desktop); }; diff --git a/src/RatioMaster.App/ViewModels/MainWindowViewModel.cs b/src/RatioMaster.App/ViewModels/MainWindowViewModel.cs index f371d88..df2f84e 100644 --- a/src/RatioMaster.App/ViewModels/MainWindowViewModel.cs +++ b/src/RatioMaster.App/ViewModels/MainWindowViewModel.cs @@ -266,6 +266,13 @@ public async Task HandleDroppedFilesAsync(IReadOnlyList paths) } } + /// Saves immediately without waiting for tracker announces during a system shutdown. + public void SaveForSystemShutdown() + { + this.SaveLastSession(force: true); + this.settingsStore.Save(this.settings); + } + /// Stops every torrent (sending the stopped announce) and persists state. Called when quitting. public async Task ShutdownAsync(TimeSpan timeout) { @@ -852,9 +859,9 @@ private async Task RestoreSessionAsync(string path, bool startImmediately, bool } } - private void SaveLastSession() + private void SaveLastSession(bool force = false) { - if (this.deferredListChanges > 0) + if (!force && this.deferredListChanges > 0) { return; } diff --git a/src/RatioMaster.App/Views/MainWindow.axaml.cs b/src/RatioMaster.App/Views/MainWindow.axaml.cs index 941be8e..1458d5b 100644 --- a/src/RatioMaster.App/Views/MainWindow.axaml.cs +++ b/src/RatioMaster.App/Views/MainWindow.axaml.cs @@ -66,6 +66,8 @@ public MainWindow() this.BuildColumnsMenu(); } + internal bool WindowsSessionEnding { get; set; } + private MainWindowViewModel? ViewModel => this.viewModel; private RowDefinition DetailsRow => this.ContentGrid.RowDefinitions[2]; @@ -85,7 +87,7 @@ protected override void OnClosing(WindowClosingEventArgs e) { this.SavePlacement(); - if (!e.IsProgrammatic && this.ViewModel is { } viewModel) + if (!e.IsProgrammatic && !this.WindowsSessionEnding && this.ViewModel is { } viewModel) { // Close to tray keeps the torrents announcing; quitting happens through File > Exit or the tray menu. // Otherwise closing the window quits as File > Exit does, which stops the torrents and then closes it: From 819dea171b270db84771547dcbe3959d55bcf6b9 Mon Sep 17 00:00:00 2001 From: elgegeto <341694139+elgegeto@users.noreply.github.com> Date: Tue, 10 Nov 2026 16:13:42 -0300 Subject: [PATCH 2/2] fix: keep Windows session end resilient to layout save errors --- src/RatioMaster.App/Views/MainWindow.axaml.cs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/RatioMaster.App/Views/MainWindow.axaml.cs b/src/RatioMaster.App/Views/MainWindow.axaml.cs index 1458d5b..636df4b 100644 --- a/src/RatioMaster.App/Views/MainWindow.axaml.cs +++ b/src/RatioMaster.App/Views/MainWindow.axaml.cs @@ -85,7 +85,21 @@ public void RestoreFromTray() protected override void OnClosing(WindowClosingEventArgs e) { - this.SavePlacement(); + if (this.WindowsSessionEnding) + { + try + { + this.SavePlacement(); + } + catch (Exception) + { + // A layout save failure must not interrupt Windows sign-out. + } + } + else + { + this.SavePlacement(); + } if (!e.IsProgrammatic && !this.WindowsSessionEnding && this.ViewModel is { } viewModel) {