Skip to content

Commit b2edea4

Browse files
committed
Improve code quality
1 parent ba1ada7 commit b2edea4

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

Flow.Launcher/App.xaml.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
using Microsoft.Extensions.DependencyInjection;
2727
using Microsoft.Extensions.Hosting;
2828
using Microsoft.VisualStudio.Threading;
29+
using Squirrel;
2930

3031
namespace Flow.Launcher
3132
{
@@ -334,9 +335,27 @@ private static void RegisterTaskSchedulerUnhandledException()
334335

335336
#region Restart
336337

338+
/// <summary>
339+
/// Restart the application without changing the user privileges.
340+
/// </summary>
341+
public static void RestartApp(bool forceAdmin = false)
342+
{
343+
if (Win32Helper.IsAdministrator() || forceAdmin)
344+
{
345+
RestartAppAsAdministrator();
346+
}
347+
else
348+
{
349+
// Restart requires Squirrel's Update.exe to be present in the parent folder,
350+
// it is only published from the project's release pipeline. When debugging without it,
351+
// the project may not restart or just terminates. This is expected.
352+
UpdateManager.RestartApp(Constant.ApplicationFileName);
353+
}
354+
}
355+
337356
// Since Squirrel does not provide a way to restart the app as administrator,
338357
// we need to do it manually by starting the update.exe with the runas verb
339-
public static void RestartAppAsAdministrator()
358+
private static void RestartAppAsAdministrator()
340359
{
341360
var startInfo = new ProcessStartInfo
342361
{

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
using Flow.Launcher.Plugin.SharedCommands;
3232
using Flow.Launcher.ViewModel;
3333
using JetBrains.Annotations;
34-
using Squirrel;
3534
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
3635

3736
namespace Flow.Launcher
@@ -85,18 +84,10 @@ public async void RestartApp()
8584
// Wait for all image caches to be saved before restarting
8685
await ImageLoader.WaitSaveAsync();
8786

88-
// If app is run as administrator already, we continue to restart app as administrator
89-
if (Win32Helper.IsAdministrator())
90-
{
91-
App.RestartAppAsAdministrator();
92-
}
93-
else
94-
{
95-
// Restart requires Squirrel's Update.exe to be present in the parent folder,
96-
// it is only published from the project's release pipeline. When debugging without it,
97-
// the project may not restart or just terminates. This is expected.
98-
UpdateManager.RestartApp(Constant.ApplicationFileName);
99-
}
87+
// Restart requires Squirrel's Update.exe to be present in the parent folder,
88+
// it is only published from the project's release pipeline. When debugging without it,
89+
// the project may not restart or just terminates. This is expected.
90+
App.RestartApp();
10091
}
10192

10293
public void ShowMainWindow() => _mainVM.Show();

0 commit comments

Comments
 (0)