Improve code quality

This commit is contained in:
Jack251970 2025-06-03 17:21:48 +08:00
parent ba1ada7bf1
commit b2edea4201
2 changed files with 24 additions and 14 deletions

View file

@ -26,6 +26,7 @@ using Flow.Launcher.ViewModel;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.VisualStudio.Threading;
using Squirrel;
namespace Flow.Launcher
{
@ -334,9 +335,27 @@ namespace Flow.Launcher
#region Restart
/// <summary>
/// Restart the application without changing the user privileges.
/// </summary>
public static void RestartApp(bool forceAdmin = false)
{
if (Win32Helper.IsAdministrator() || forceAdmin)
{
RestartAppAsAdministrator();
}
else
{
// 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.
UpdateManager.RestartApp(Constant.ApplicationFileName);
}
}
// 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
public static void RestartAppAsAdministrator()
private static void RestartAppAsAdministrator()
{
var startInfo = new ProcessStartInfo
{

View file

@ -31,7 +31,6 @@ using Flow.Launcher.Plugin.SharedModels;
using Flow.Launcher.Plugin.SharedCommands;
using Flow.Launcher.ViewModel;
using JetBrains.Annotations;
using Squirrel;
using Stopwatch = Flow.Launcher.Infrastructure.Stopwatch;
namespace Flow.Launcher
@ -85,18 +84,10 @@ namespace Flow.Launcher
// Wait for all image caches to be saved before restarting
await ImageLoader.WaitSaveAsync();
// If app is run as administrator already, we continue to restart app as administrator
if (Win32Helper.IsAdministrator())
{
App.RestartAppAsAdministrator();
}
else
{
// 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.
UpdateManager.RestartApp(Constant.ApplicationFileName);
}
// 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.
App.RestartApp();
}
public void ShowMainWindow() => _mainVM.Show();