refactor UndoCapture(DateTime)

This commit is contained in:
Kang Yu 2024-08-12 10:38:34 -07:00
parent b13bcf0b58
commit eade031052

View file

@ -719,21 +719,8 @@ namespace PersistentWindows.Common
string displayKey = GetDisplayKey();
Log.Event("Display settings changed {0}", displayKey);
// undo disqualified capture time
if (snapshotTakenTime.ContainsKey(curDisplayKey) && snapshotTakenTime[curDisplayKey].ContainsKey(MaxSnapshots))
{
var lastCaptureTime = snapshotTakenTime[curDisplayKey][MaxSnapshots];
var diff = lastDisplayChangeTime - lastCaptureTime;
if (diff.TotalMilliseconds < CaptureLatency)
{
if (snapshotTakenTime[curDisplayKey].ContainsKey(MaxSnapshots + 1))
{
snapshotTakenTime[curDisplayKey][MaxSnapshots] = snapshotTakenTime[curDisplayKey][MaxSnapshots + 1];
Log.Error("undo capture of {0} at {1}", curDisplayKey, lastCaptureTime);
}
}
}
// rewind disqualified capture time
UndoCapture(lastDisplayChangeTime);
{
EndDisplaySession();
@ -2499,6 +2486,24 @@ namespace PersistentWindows.Common
return null;
}
private void UndoCapture(DateTime ref_time)
{
// rewind disqualified capture time
if (snapshotTakenTime.ContainsKey(curDisplayKey) && snapshotTakenTime[curDisplayKey].ContainsKey(MaxSnapshots))
{
var lastCaptureTime = snapshotTakenTime[curDisplayKey][MaxSnapshots];
var diff = ref_time - lastCaptureTime;
if (diff.TotalMilliseconds < CaptureLatency)
{
if (snapshotTakenTime[curDisplayKey].ContainsKey(MaxSnapshots + 1))
{
snapshotTakenTime[curDisplayKey][MaxSnapshots] = snapshotTakenTime[curDisplayKey][MaxSnapshots + 1];
Log.Error("undo capture of {0} at {1}", curDisplayKey, lastCaptureTime);
}
}
}
}
private void CaptureApplicationsOnCurrentDisplays(string displayKey, bool saveToDB = false, bool immediateCapture = false)
{
User32.SetThreadDpiAwarenessContextSafe(User32.DPI_AWARENESS_CONTEXT_UNAWARE);