mirror of
https://github.com/kangyu-california/PersistentWindows.git
synced 2025-05-11 13:05:38 +02:00
refactor pw restart script
This commit is contained in:
parent
2b73c3c2bc
commit
b575920805
2 changed files with 8 additions and 17 deletions
|
@ -26,6 +26,10 @@ namespace PersistentWindows.SystrayShell
|
||||||
public static bool Gui = true;
|
public static bool Gui = true;
|
||||||
public static bool hotkey_window = true;
|
public static bool hotkey_window = true;
|
||||||
public static uint hotkey = 'W'; //Alt + W
|
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
|
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");
|
Log.Error("taskbar not ready, restart PersistentWindows");
|
||||||
}
|
}
|
||||||
|
|
||||||
Restart(10);
|
RestartHidden(1);
|
||||||
return false;
|
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)
|
static void RestartHidden(int delay)
|
||||||
{
|
{
|
||||||
Process p = new Process();
|
Process p = new Process();
|
||||||
string batFile = Path.Combine(AppdataFolder, $"pw_restart.bat");
|
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;
|
content += "\nstart \"\" /B \"" + Path.Combine(Application.StartupPath, Application.ProductName) + ".exe\" " + "-wait_taskbar " + Program.CmdArgs;
|
||||||
File.WriteAllText(batFile, content);
|
File.WriteAllText(batFile, content);
|
||||||
p.StartInfo.FileName = batFile;
|
p.StartInfo.FileName = batFile;
|
||||||
|
|
|
@ -266,10 +266,7 @@ namespace PersistentWindows.SystrayShell
|
||||||
upgradeDownloaded[latestVersion] = true;
|
upgradeDownloaded[latestVersion] = true;
|
||||||
|
|
||||||
string batFile = Path.Combine(Program.AppdataFolder, $"pw_upgrade.bat");
|
string batFile = Path.Combine(Program.AppdataFolder, $"pw_upgrade.bat");
|
||||||
string content = ":wait_to_finish";
|
string content = Program.WaitPwFinish;
|
||||||
content += "\ntimeout /t 2 /nobreak >nul";
|
|
||||||
content += "\ntasklist | find \"PersistentWindows\" >nul";
|
|
||||||
content += "\nif not errorlevel 1 goto wait_to_finish";
|
|
||||||
content += $"\ncopy /Y \"{dst_dir}\\*.*\" \"{install_dir}\"";
|
content += $"\ncopy /Y \"{dst_dir}\\*.*\" \"{install_dir}\"";
|
||||||
content += "\nstart \"\" /B \"" + Path.Combine(install_dir, Application.ProductName) + ".exe\" " + Program.CmdArgs;
|
content += "\nstart \"\" /B \"" + Path.Combine(install_dir, Application.ProductName) + ".exe\" " + Program.CmdArgs;
|
||||||
File.WriteAllText(batFile, content);
|
File.WriteAllText(batFile, content);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue