From 8bdba69cb4876c2a8413b0a1e2ac991f3fc6332a Mon Sep 17 00:00:00 2001 From: leo Date: Thu, 16 Apr 2026 11:47:16 +0800 Subject: [PATCH] refactor: rewrite the way to quit app Signed-off-by: leo --- src/App.axaml.cs | 15 ++++++--------- src/ViewModels/Launcher.cs | 2 +- src/Views/Launcher.axaml.cs | 13 ++++++++++--- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/App.axaml.cs b/src/App.axaml.cs index 8d6bafb7..234b7d97 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -230,15 +230,9 @@ namespace SourceGit public static void Quit(int exitCode) { if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) - { - desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown; - desktop.MainWindow?.Close(); desktop.Shutdown(exitCode); - } else - { Environment.Exit(exitCode); - } } #endregion @@ -478,7 +472,12 @@ namespace SourceGit _launcher = new ViewModels.Launcher(startupRepo); desktop.MainWindow = new Views.Launcher() { DataContext = _launcher }; - desktop.ShutdownMode = ShutdownMode.OnMainWindowClose; + desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown; + desktop.Exit += (_, _) => + { + _ipcChannel?.Dispose(); + _ipcChannel = null; + }; _ipcChannel.MessageReceived += repo => { @@ -490,8 +489,6 @@ namespace SourceGit }); }; - desktop.Exit += (_, _) => _ipcChannel.Dispose(); - #if !DISABLE_UPDATE_DETECTION if (pref.ShouldCheck4UpdateOnStartup()) Check4Update(); diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index 4287cb9b..5beb3f13 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -117,7 +117,7 @@ namespace SourceGit.ViewModels return false; } - public void Quit() + public void CloseAll() { _ignoreIndexChange = true; diff --git a/src/Views/Launcher.axaml.cs b/src/Views/Launcher.axaml.cs index 20d5617a..e19b9ec2 100644 --- a/src/Views/Launcher.axaml.cs +++ b/src/Views/Launcher.axaml.cs @@ -338,10 +338,17 @@ namespace SourceGit.Views base.OnClosing(e); if (!Design.IsDesignMode && DataContext is ViewModels.Launcher launcher) - { + launcher.CloseAll(); + } + + protected override void OnClosed(EventArgs e) + { + base.OnClosed(e); + + if (!Design.IsDesignMode) ViewModels.Preferences.Instance.Save(); - launcher.Quit(); - } + + App.Quit(0); } private void OnPositionChanged(object sender, PixelPointEventArgs e)