mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Fix restart as administrator issue
This commit is contained in:
parent
52c36ff8d4
commit
35f4fd5b18
1 changed files with 36 additions and 9 deletions
|
|
@ -1,7 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Forms;
|
||||
|
|
@ -168,19 +171,43 @@ public partial class SettingsPaneGeneralViewModel : BaseModel
|
|||
await ImageLoader.WaitSaveAsync();
|
||||
|
||||
// Restart the app as administrator
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
UseShellExecute = true,
|
||||
WorkingDirectory = Environment.CurrentDirectory,
|
||||
FileName = Constant.ExecutablePath,
|
||||
Verb = "runas"
|
||||
};
|
||||
Process.Start(startInfo);
|
||||
Environment.Exit(0);
|
||||
RestartAppAsAdministrator(Constant.ExecutablePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void RestartAppAsAdministrator(string exeToStart)
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = getUpdateExe(),
|
||||
Arguments = $"--processStartAndWait {exeToStart}",
|
||||
UseShellExecute = true,
|
||||
Verb = "runas",
|
||||
};
|
||||
Process.Start(startInfo);
|
||||
Thread.Sleep(500);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
|
||||
private static string getUpdateExe()
|
||||
{
|
||||
Assembly entryAssembly = Assembly.GetEntryAssembly();
|
||||
if (entryAssembly != null && Path.GetFileName(entryAssembly.Location).Equals("update.exe", StringComparison.OrdinalIgnoreCase) && entryAssembly.Location.IndexOf("app-", StringComparison.OrdinalIgnoreCase) == -1 && entryAssembly.Location.IndexOf("SquirrelTemp", StringComparison.OrdinalIgnoreCase) == -1)
|
||||
{
|
||||
return Path.GetFullPath(entryAssembly.Location);
|
||||
}
|
||||
|
||||
entryAssembly = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
|
||||
FileInfo fileInfo = new FileInfo(Path.Combine(Path.GetDirectoryName(entryAssembly.Location), "..\\Update.exe"));
|
||||
if (!fileInfo.Exists)
|
||||
{
|
||||
throw new Exception("Update.exe not found, not a Squirrel-installed app?");
|
||||
}
|
||||
|
||||
return fileInfo.FullName;
|
||||
}
|
||||
|
||||
public List<SearchWindowScreenData> SearchWindowScreens { get; } =
|
||||
DropdownDataGeneric<SearchWindowScreens>.GetValues<SearchWindowScreenData>("SearchWindowScreen");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue