ctrl exit to test restart

This commit is contained in:
Kang Yu 2024-09-20 19:44:29 -07:00
parent 665aed45f7
commit 2b0c470ce5
2 changed files with 11 additions and 5 deletions

View file

@ -349,7 +349,7 @@ if not errorlevel 1 goto wait_to_finish";
if (relaunch_delay > 0) if (relaunch_delay > 0)
{ {
RestartHidden(relaunch_delay); Restart(relaunch_delay);
return; return;
} }
@ -428,11 +428,11 @@ if not errorlevel 1 goto wait_to_finish";
Log.Error("taskbar not ready, restart PersistentWindows"); Log.Error("taskbar not ready, restart PersistentWindows");
} }
RestartHidden(1); Restart(1);
return false; return false;
} }
static void RestartHidden(int delay) static public void Restart(int delay, bool hidden = true)
{ {
Process p = new Process(); Process p = new Process();
string batFile = Path.Combine(AppdataFolder, $"pw_restart.bat"); string batFile = Path.Combine(AppdataFolder, $"pw_restart.bat");
@ -441,8 +441,11 @@ if not errorlevel 1 goto wait_to_finish";
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;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; if (hidden)
p.StartInfo.UseShellExecute = true; {
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo.UseShellExecute = true;
}
p.Start(); p.Start();
Log.Error("program restarted"); Log.Error("program restarted");

View file

@ -445,6 +445,9 @@ namespace PersistentWindows.SystrayShell
private void ExitToolStripMenuItemClickHandler(object sender, EventArgs e) private void ExitToolStripMenuItemClickHandler(object sender, EventArgs e)
{ {
bool ctrl_key_pressed = (User32.GetKeyState(0x11) & 0x8000) != 0;
if (ctrl_key_pressed)
Program.Restart(2, hidden:false);
Exit(); Exit();
} }