Skip to content

Commit 3aad24a

Browse files
committed
enhance: secure exit
1 parent f4eca45 commit 3aad24a

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

src/App.axaml.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public static AppBuilder BuildAvaloniaApp()
122122
Check4Update(true);
123123
});
124124

125-
public static readonly SimpleCommand QuitCommand = new SimpleCommand(Quit);
125+
public static readonly SimpleCommand QuitCommand = new SimpleCommand(() => Quit(0));
126126

127127
public static void RaiseException(string context, string message)
128128
{
@@ -315,12 +315,16 @@ public static ViewModels.Repository FindOpenedRepository(string repoPath)
315315
return null;
316316
}
317317

318-
public static void Quit()
318+
public static void Quit(int exitCode)
319319
{
320320
if (Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop)
321321
{
322322
desktop.MainWindow?.Close();
323-
desktop.Shutdown();
323+
desktop.Shutdown(exitCode);
324+
}
325+
else
326+
{
327+
Environment.Exit(exitCode);
324328
}
325329
}
326330

@@ -485,9 +489,10 @@ private bool TryLaunchedAsCoreEditor(IClassicDesktopStyleApplicationLifetime des
485489

486490
var file = args[1];
487491
if (!File.Exists(file))
488-
Environment.Exit(-1);
492+
desktop.Shutdown(-1);
493+
else
494+
desktop.MainWindow = new Views.StandaloneCommitMessageEditor(file);
489495

490-
desktop.MainWindow = new Views.StandaloneCommitMessageEditor(file);
491496
return true;
492497
}
493498

src/ViewModels/Launcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public void CloseTab(LauncherPage page)
153153
}
154154
else
155155
{
156-
App.Quit();
156+
App.Quit(0);
157157
}
158158

159159
return;

src/Views/Askpass.axaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ private void BeginMoveWindow(object _, PointerPressedEventArgs e)
5050
private void CloseWindow(object _1, RoutedEventArgs _2)
5151
{
5252
Console.Out.WriteLine("No passphrase entered.");
53-
Environment.Exit(-1);
53+
App.Quit(-1);
5454
}
5555

5656
private void EnterPassword(object _1, RoutedEventArgs _2)
5757
{
5858
Console.Out.Write($"{Passphrase}\n");
59-
Environment.Exit(0);
59+
App.Quit(0);
6060
}
6161
}
6262
}

src/Views/StandaloneCommitMessageEditor.axaml.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System;
21
using System.IO;
32

43
using Avalonia.Input;
@@ -41,13 +40,13 @@ private void BeginMoveWindow(object _, PointerPressedEventArgs e)
4140

4241
private void CloseWindow(object _1, RoutedEventArgs _2)
4342
{
44-
Environment.Exit(-1);
43+
App.Quit(-1);
4544
}
4645

4746
private void SaveAndClose(object _1, RoutedEventArgs _2)
4847
{
4948
File.WriteAllText(_file, Editor.Text);
50-
Environment.Exit(0);
49+
App.Quit(0);
5150
}
5251

5352
private readonly string _file;

0 commit comments

Comments
 (0)