From bae81d20d5c9952cd865ec9b7076a3745884655c Mon Sep 17 00:00:00 2001 From: Vladimir Eremeev Date: Tue, 24 Dec 2024 20:15:40 +0300 Subject: [PATCH] Handle window closing event --- src/App.axaml.cs | 8 ++++++-- src/Views/Launcher.axaml.cs | 8 +++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/App.axaml.cs b/src/App.axaml.cs index 7ee837a0..94455df7 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -210,7 +210,7 @@ namespace SourceGit ] } }; - + icons[0].Clicked += (_, _) => ShowWindow(); TrayIcon.SetIcons(Current, icons); } } @@ -576,11 +576,15 @@ namespace SourceGit if (desktop.Args != null && desktop.Args.Length == 1 && Directory.Exists(desktop.Args[0])) startupRepo = desktop.Args[0]; + var pref = ViewModels.Preference.Instance; + if (pref.SystemTrayIcon) { + desktop.ShutdownMode = ShutdownMode.OnExplicitShutdown; + } + _launcher = new ViewModels.Launcher(startupRepo); desktop.MainWindow = new Views.Launcher() { DataContext = _launcher }; #if !DISABLE_UPDATE_DETECTION - var pref = ViewModels.Preference.Instance; if (pref.ShouldCheck4UpdateOnStartup()) Check4Update(); #endif diff --git a/src/Views/Launcher.axaml.cs b/src/Views/Launcher.axaml.cs index a3a3af8b..c5d6289c 100644 --- a/src/Views/Launcher.axaml.cs +++ b/src/Views/Launcher.axaml.cs @@ -255,7 +255,13 @@ namespace SourceGit.Views protected override void OnClosing(WindowClosingEventArgs e) { - (DataContext as ViewModels.Launcher)?.Quit(Width, Height); + var pref = ViewModels.Preference.Instance; + if (pref.SystemTrayIcon) { + e.Cancel = true; + Hide(); + } else { + (DataContext as ViewModels.Launcher)?.Quit(Width, Height); + } base.OnClosing(e); }