refactor pw restart script

This commit is contained in:
Kang Yu 2024-09-11 21:19:55 -07:00
parent 2b73c3c2bc
commit b575920805
2 changed files with 8 additions and 17 deletions

View file

@ -26,6 +26,10 @@ namespace PersistentWindows.SystrayShell
public static bool Gui = true;
public static bool hotkey_window = true;
public static uint hotkey = 'W'; //Alt + W
public static string WaitPwFinish = @":wait_to_finish
timeout /t 2 /nobreak >nul
tasklist | find ""PersistentWindows"" >nul
if not errorlevel 1 goto wait_to_finish";
private const int MaxSnapshots = 38; // 0-9, a-z, ` and final one for undo
@ -424,26 +428,16 @@ namespace PersistentWindows.SystrayShell
Log.Error("taskbar not ready, restart PersistentWindows");
}
Restart(10);
RestartHidden(1);
return false;
}
static void Restart(int delay)
{
string batFile = Path.Combine(AppdataFolder, $"pw_restart.bat");
string content = $"timeout /t {delay} /nobreak > NUL";
content += "\nstart \"\" /B \"" + Path.Combine(Application.StartupPath, Application.ProductName) + ".exe\" " + "-wait_taskbar " + Program.CmdArgs;
File.WriteAllText(batFile, content);
Process.Start(batFile);
Log.Error("program restarted");
}
static void RestartHidden(int delay)
{
Process p = new Process();
string batFile = Path.Combine(AppdataFolder, $"pw_restart.bat");
string content = $"timeout /t {delay} /nobreak > NUL";
string content = WaitPwFinish;
content += $"\ntimeout /t {delay} /nobreak > NUL";
content += "\nstart \"\" /B \"" + Path.Combine(Application.StartupPath, Application.ProductName) + ".exe\" " + "-wait_taskbar " + Program.CmdArgs;
File.WriteAllText(batFile, content);
p.StartInfo.FileName = batFile;

View file

@ -266,10 +266,7 @@ namespace PersistentWindows.SystrayShell
upgradeDownloaded[latestVersion] = true;
string batFile = Path.Combine(Program.AppdataFolder, $"pw_upgrade.bat");
string content = ":wait_to_finish";
content += "\ntimeout /t 2 /nobreak >nul";
content += "\ntasklist | find \"PersistentWindows\" >nul";
content += "\nif not errorlevel 1 goto wait_to_finish";
string content = Program.WaitPwFinish;
content += $"\ncopy /Y \"{dst_dir}\\*.*\" \"{install_dir}\"";
content += "\nstart \"\" /B \"" + Path.Combine(install_dir, Application.ProductName) + ".exe\" " + Program.CmdArgs;
File.WriteAllText(batFile, content);