enhance: secure exit

This commit is contained in:
leo 2024-07-15 09:54:46 +08:00
parent f4eca45754
commit 3aad24a64e
No known key found for this signature in database
4 changed files with 15 additions and 11 deletions

View file

@ -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);
return true;
}

View file

@ -153,7 +153,7 @@ namespace SourceGit.ViewModels
}
else
{
App.Quit();
App.Quit(0);
}
return;

View file

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

View file

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