mirror of
https://fastgit.cc/github.com/sourcegit-scm/sourcegit
synced 2026-04-20 21:01:06 +08:00
refactor: rewrite the way to quit app
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace SourceGit.ViewModels
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Quit()
|
||||
public void CloseAll()
|
||||
{
|
||||
_ignoreIndexChange = true;
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user