for issue #98: add command option -halt_restore <seconds>

This commit is contained in:
Kang Yu 2021-03-19 22:35:46 -07:00
parent 05aa599836
commit 5fa987a9bf
2 changed files with 9 additions and 22 deletions

View file

@ -95,7 +95,7 @@ namespace Ninjacrab.PersistentWindows.Common
public bool autoRestoreMissingWindows = false;
private int restoreTimes = 0; //multiple passes need to fully restore
private bool restoreHalted = false;
private int restoreHaltTimes = 0; // halt restore due to unstable display setting change
public int haltRestore = 3; //seconds to wait to finish current halted restore and restart next one
private int restoreNestLevel = 0; // nested restore call level
private HashSet<IntPtr> restoredWindows = new HashSet<IntPtr>();
private HashSet<IntPtr> topmostWindowsFixed = new HashSet<IntPtr>();
@ -1703,7 +1703,6 @@ namespace Ninjacrab.PersistentWindows.Common
// end of restore period
//CancelRestoreTimer();
restoreTimes = 0;
restoreHaltTimes = 0;
restoreNestLevel = 0;
restoredWindows.Clear();
@ -2147,20 +2146,9 @@ namespace Ninjacrab.PersistentWindows.Common
string displayKey = GetDisplayKey();
if (restoreHalted || !displayKey.Equals(curDisplayKey))
{
restoreHalted = true;
// display resolution changes during restore
++restoreHaltTimes;
if (restoreHaltTimes > 5)
{
restoreHaltTimes = 0;
// immediately finish restore
StartRestoreFinishedTimer(0);
}
else
{
StartRestoreTimer();
}
restoreHalted = true;
StartRestoreFinishedTimer(haltRestore * 1000);
}
else if (restoreTimes <= MaxRestoreTimes)
{

View file

@ -30,7 +30,7 @@ namespace Ninjacrab.PersistentWindows.SystrayShell
bool dry_run = false; //dry run mode without real restore, for debug purpose only
bool fix_zorder = false;
bool fix_zorder_specified = false;
bool delay_start = false;
int halt_restore = 0; //seconds to halt interrupted restore
bool redraw_desktop = false;
bool redirect_appdata = false; // use "." instead of appdata/local/PersistentWindows to store db file
bool offscreen_fix = true;
@ -42,11 +42,9 @@ namespace Ninjacrab.PersistentWindows.SystrayShell
foreach (var arg in args)
{
if (delay_start)
if (halt_restore != 0)
{
delay_start = false;
int seconds = Int32.Parse(arg);
Thread.Sleep(1000 * seconds);
halt_restore = Int32.Parse(arg);
continue;
}
@ -76,8 +74,8 @@ namespace Ninjacrab.PersistentWindows.SystrayShell
fix_zorder = true;
fix_zorder_specified = true;
break;
case "-delay_start":
delay_start = true;
case "-halt_restore":
halt_restore = 1;
break;
case "-redraw_desktop":
redraw_desktop = true;
@ -182,6 +180,7 @@ namespace Ninjacrab.PersistentWindows.SystrayShell
pwp.enableOffScreenFix = offscreen_fix;
pwp.promptSessionRestore = prompt_session_restore;
pwp.autoRestoreMissingWindows = auto_restore_missing_windows;
pwp.haltRestore = halt_restore;
if (!pwp.Start(auto_restore_from_db_at_startup))
{