diff --git a/src/App.axaml.cs b/src/App.axaml.cs index 45830ad0..67bd3aad 100644 --- a/src/App.axaml.cs +++ b/src/App.axaml.cs @@ -122,7 +122,7 @@ namespace SourceGit Check4Update(true); }); - public static readonly SimpleCommand QuitCommand = new SimpleCommand(Quit); + public static readonly SimpleCommand QuitCommand = new SimpleCommand(() => Quit(0)); public static void RaiseException(string context, string message) { @@ -315,12 +315,16 @@ namespace SourceGit return null; } - public static void Quit() + public static void Quit(int exitCode) { if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { desktop.MainWindow?.Close(); - desktop.Shutdown(); + desktop.Shutdown(exitCode); + } + else + { + Environment.Exit(exitCode); } } @@ -485,9 +489,10 @@ namespace SourceGit var file = args[1]; if (!File.Exists(file)) - Environment.Exit(-1); + desktop.Shutdown(-1); + else + desktop.MainWindow = new Views.StandaloneCommitMessageEditor(file); - desktop.MainWindow = new Views.StandaloneCommitMessageEditor(file); return true; } diff --git a/src/ViewModels/Launcher.cs b/src/ViewModels/Launcher.cs index d99020b9..bdc94a8d 100644 --- a/src/ViewModels/Launcher.cs +++ b/src/ViewModels/Launcher.cs @@ -153,7 +153,7 @@ namespace SourceGit.ViewModels } else { - App.Quit(); + App.Quit(0); } return; diff --git a/src/Views/Askpass.axaml.cs b/src/Views/Askpass.axaml.cs index 0f87b4c0..305e9843 100644 --- a/src/Views/Askpass.axaml.cs +++ b/src/Views/Askpass.axaml.cs @@ -50,13 +50,13 @@ namespace SourceGit.Views private void CloseWindow(object _1, RoutedEventArgs _2) { Console.Out.WriteLine("No passphrase entered."); - Environment.Exit(-1); + App.Quit(-1); } private void EnterPassword(object _1, RoutedEventArgs _2) { Console.Out.Write($"{Passphrase}\n"); - Environment.Exit(0); + App.Quit(0); } } } diff --git a/src/Views/StandaloneCommitMessageEditor.axaml.cs b/src/Views/StandaloneCommitMessageEditor.axaml.cs index b5100a40..dd4c0fcf 100644 --- a/src/Views/StandaloneCommitMessageEditor.axaml.cs +++ b/src/Views/StandaloneCommitMessageEditor.axaml.cs @@ -1,4 +1,3 @@ -using System; using System.IO; using Avalonia.Input; @@ -41,13 +40,13 @@ namespace SourceGit.Views private void CloseWindow(object _1, RoutedEventArgs _2) { - Environment.Exit(-1); + App.Quit(-1); } private void SaveAndClose(object _1, RoutedEventArgs _2) { File.WriteAllText(_file, Editor.Text); - Environment.Exit(0); + App.Quit(0); } private readonly string _file;