From d554a269359695068587d1e9325866c31247ca92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henri=20Hyyryl=C3=A4inen?= Date: Thu, 21 Mar 2024 11:21:11 +0200 Subject: [PATCH] Made launcher quit request also quit the background watcher loop fixes #503 --- ThriveLauncher/Program.cs | 17 +++++++++++++++++ ThriveLauncher/Views/MainWindow.axaml.cs | 7 +++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/ThriveLauncher/Program.cs b/ThriveLauncher/Program.cs index 6b80837d..ee8b23af 100644 --- a/ThriveLauncher/Program.cs +++ b/ThriveLauncher/Program.cs @@ -38,6 +38,8 @@ internal class Program private static bool reActivationRequested; + private static bool launcherQuitRequested; + // Initialization code. Don't use any Avalonia, third-party APIs or any // SynchronizationContext-reliant code before AppMain is called: things aren't initialized // yet and stuff might break. @@ -95,6 +97,14 @@ public static int Main(string[] args) } } + /// + /// Signals the main loop that the launcher should quit now + /// + public static void OnLauncherWantsToCloseNow() + { + launcherQuitRequested = true; + } + // Avalonia configuration, don't remove; also used by visual designer. // Can't be made private without breaking the designer // ReSharper disable once MemberCanBePrivate.Global @@ -319,6 +329,13 @@ private static async Task RunCustomShutdownWatcher(AppBuilder avaloniaBuilder, S { await Task.Delay(runInterval); + if (launcherQuitRequested) + { + programLogger.LogInformation("Launcher quit requested, exiting shutdown watcher loop"); + lifetime.Shutdown(); + break; + } + try { // If there are Avalonia windows open, we don't need to do anything diff --git a/ThriveLauncher/Views/MainWindow.axaml.cs b/ThriveLauncher/Views/MainWindow.axaml.cs index c815cd65..22bf2ecc 100644 --- a/ThriveLauncher/Views/MainWindow.axaml.cs +++ b/ThriveLauncher/Views/MainWindow.axaml.cs @@ -1007,10 +1007,13 @@ private void OnWantedWindowHiddenStateChanged(bool hidden) private void OnLauncherWantsToClose(bool close) { - // TODO: should this close all windows always (or signal to the main loop that quit is wanted)? - // Especially on mac: https://github.com/Revolutionary-Games/Thrive-Launcher/issues/503 if (close) + { Close(); + + // Signal main loop to also quit immediately to not hang around on mac or if there are other windows open + Program.OnLauncherWantsToCloseNow(); + } } private async void CopyLogsToClipboard(object? sender, RoutedEventArgs e)