refactor: rewrite the way to quit app

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2026-04-16 11:47:16 +08:00
parent 538001a72f
commit 8bdba69cb4
3 changed files with 17 additions and 13 deletions

View File

@@ -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();

View File

@@ -117,7 +117,7 @@ namespace SourceGit.ViewModels
return false;
}
public void Quit()
public void CloseAll()
{
_ignoreIndexChange = true;

View File

@@ -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)