From f2d3ba712f8e961f7a9e639f1b8aefb69a6d1617 Mon Sep 17 00:00:00 2001
From: Jack251970 <1160210343@qq.com>
Date: Fri, 13 Jun 2025 17:58:05 +0800
Subject: [PATCH] Combine restart functions to one function
---
Flow.Launcher/App.xaml.cs | 25 +++++++++++--------------
1 file changed, 11 insertions(+), 14 deletions(-)
diff --git a/Flow.Launcher/App.xaml.cs b/Flow.Launcher/App.xaml.cs
index e9ccbca22..ef8d52e22 100644
--- a/Flow.Launcher/App.xaml.cs
+++ b/Flow.Launcher/App.xaml.cs
@@ -26,7 +26,6 @@ using Flow.Launcher.ViewModel;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.VisualStudio.Threading;
-using Squirrel;
namespace Flow.Launcher
{
@@ -258,7 +257,7 @@ namespace Flow.Launcher
API.GetTranslation("runAsAdministratorChange"),
MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
- RestartAppAsAdministrator();
+ RestartApp(true);
}
}
catch (Exception e)
@@ -347,28 +346,26 @@ namespace Flow.Launcher
///
/// Restart the application without changing the user privileges.
///
+ ///
+ /// Since Squirrel does not provide a way to restart the app as administrator,
+ /// we need to do it manually by starting the update.exe with the runas verb
+ ///
+ ///
+ /// If true, the application will be restarted as administrator.
+ /// If false, it will be restarted with the same privileges as the current user.
+ ///
+ /// Thrown when the Update.exe is not found in the expected location
public static void RestartApp(bool forceAdmin = false)
{
// Restart requires Squirrel's Update.exe to be present in the parent folder,
// it is only published from the project's release pipeline. When debugging without it,
// the project may not restart or just terminates. This is expected.
- RestartAppAsAdministrator(Win32Helper.IsAdministrator() || forceAdmin);
- }
-
- ///
- /// Since Squirrel does not provide a way to restart the app as administrator,
- /// we need to do it manually by starting the update.exe with the runas verb
- ///
- /// Whether to run the application as administrator or not
- /// Thrown when the Update.exe is not found in the expected location
- private static void RestartAppAsAdministrator(bool runAsAdmin)
- {
var startInfo = new ProcessStartInfo
{
FileName = getUpdateExe(),
Arguments = $"--processStartAndWait \"{Constant.ExecutablePath}\"",
UseShellExecute = true,
- Verb = runAsAdmin ? "runas" : ""
+ Verb = Win32Helper.IsAdministrator() || forceAdmin ? "runas" : ""
};
Process.Start(startInfo);
Thread.Sleep(500);