mirror of
https://github.com/kangyu-california/PersistentWindows.git
synced 2025-05-10 20:45:38 +02:00
#333, add command -delay_restart <seconds> to restart PW in hidden mode
This commit is contained in:
parent
63334fa67c
commit
b782e9b034
1 changed files with 24 additions and 10 deletions
|
@ -51,8 +51,8 @@ namespace PersistentWindows.SystrayShell
|
|||
pwp = new PersistentWindowProcessor();
|
||||
|
||||
bool splash = true;
|
||||
int delay_start = 0;
|
||||
bool relaunch = false;
|
||||
int delay_restart = 0;
|
||||
int relaunch_delay = 0;
|
||||
int delay_manual_capture = 0;
|
||||
int delay_auto_capture = 0;
|
||||
bool redirect_appdata = false; // use "." instead of appdata/local/PersistentWindows to store db file
|
||||
|
@ -86,13 +86,12 @@ namespace PersistentWindows.SystrayShell
|
|||
pwp.haltRestore = (Int32)(float.Parse(arg) * 1000);
|
||||
continue;
|
||||
}
|
||||
else if (delay_start != 0)
|
||||
else if (delay_restart != 0)
|
||||
{
|
||||
delay_start = 0;
|
||||
delay_restart = 0;
|
||||
if (!waiting_taskbar)
|
||||
{
|
||||
Thread.Sleep((Int32)(float.Parse(arg) * 1000));
|
||||
relaunch = true;
|
||||
relaunch_delay = (Int32)(float.Parse(arg));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -153,8 +152,8 @@ namespace PersistentWindows.SystrayShell
|
|||
case "-enable_auto_restore_by_manual_capture":
|
||||
pwp.manualNormalSession = true;
|
||||
break;
|
||||
case "-delay_start":
|
||||
delay_start = 1;
|
||||
case "-delay_restart":
|
||||
delay_restart = 1;
|
||||
break;
|
||||
case "-wait_taskbar":
|
||||
waiting_taskbar = true;
|
||||
|
@ -322,9 +321,9 @@ namespace PersistentWindows.SystrayShell
|
|||
systrayForm = new SystrayForm(check_upgrade);
|
||||
systrayForm.autoUpgrade = auto_upgrade;
|
||||
|
||||
if (relaunch)
|
||||
if (relaunch_delay > 0)
|
||||
{
|
||||
Restart(2);
|
||||
RestartHidden(relaunch_delay);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -418,6 +417,21 @@ namespace PersistentWindows.SystrayShell
|
|||
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";
|
||||
content += "\nstart \"\" /B \"" + Path.Combine(Application.StartupPath, Application.ProductName) + ".exe\" " + "-wait_taskbar " + Program.CmdArgs;
|
||||
File.WriteAllText(batFile, content);
|
||||
p.StartInfo.FileName = batFile;
|
||||
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
|
||||
p.StartInfo.UseShellExecute = true;
|
||||
p.Start();
|
||||
|
||||
Log.Error("program restarted");
|
||||
}
|
||||
|
||||
public static void ShowRestoreTip()
|
||||
{
|
||||
if (systrayForm.contextMenuStripSysTray.InvokeRequired)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue