From a98717ab4e73ece7990efbac024ffa0a9f774d8b Mon Sep 17 00:00:00 2001 From: Kang Yu Date: Sat, 12 Oct 2024 15:04:15 -0700 Subject: [PATCH] dump history xml when display changing --- .../Common/PersistentWindowProcessor.cs | 18 ++++++++++++++---- .../SystrayShell/SystrayForm.cs | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs b/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs index 8f53f19..26a5469 100644 --- a/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs +++ b/Ninjacrab.PersistentWindows.Solution/Common/PersistentWindowProcessor.cs @@ -185,6 +185,7 @@ namespace PersistentWindows.Common private EventHandler displaySettingsChangingHandler; private EventHandler displaySettingsChangedHandler; private SessionSwitchEventHandler sessionSwitchEventHandler; + private SessionEndingEventHandler sessionEndingEventHandler; private readonly List winEventHooks = new List(); private User32.WinEventDelegate winEventsCaptureDelegate; @@ -263,7 +264,7 @@ namespace PersistentWindows.Common { if (monitorApplications[display_key].ContainsKey(hwnd)) continue; - allApps[display_key][hwnd] = deadApps[display_key][hwnd]; + allApps[display_key][hwnd] = new List(deadApps[display_key][hwnd]); } } @@ -679,8 +680,6 @@ namespace PersistentWindows.Common if (!wasRestoringSnapshot && !wasRestoringFromDB) { - WriteDataDump(); - if (!snapshotTakenTime.ContainsKey(curDisplayKey)) snapshotTakenTime[curDisplayKey] = new Dictionary(); if (snapshotTakenTime[curDisplayKey].ContainsKey(MaxSnapshots)) @@ -772,6 +771,14 @@ namespace PersistentWindows.Common 0, (uint)User32Events.WINEVENT_OUTOFCONTEXT)); + this.sessionEndingEventHandler = + (s, e) => + { + WriteDataDump(); + Log.Event("Session ending"); + }; + SystemEvents.SessionEnding += sessionEndingEventHandler; + this.displaySettingsChangingHandler = (s, e) => { @@ -782,6 +789,9 @@ namespace PersistentWindows.Common lastDisplayChangeTime = DateTime.Now; EndDisplaySession(); freezeCapture = true; + + WriteDataDump(); + Log.Event("Session changing"); } }; SystemEvents.DisplaySettingsChanging += this.displaySettingsChangingHandler; @@ -2142,7 +2152,6 @@ namespace PersistentWindows.Common } WriteDataDump(); - return true; } @@ -4543,6 +4552,7 @@ namespace PersistentWindows.Common SystemEvents.DisplaySettingsChanged -= displaySettingsChangedHandler; SystemEvents.PowerModeChanged -= powerModeChangedHandler; SystemEvents.SessionSwitch -= sessionSwitchEventHandler; + SystemEvents.SessionEnding -= sessionEndingEventHandler; foreach (var handle in this.winEventHooks) { diff --git a/Ninjacrab.PersistentWindows.Solution/SystrayShell/SystrayForm.cs b/Ninjacrab.PersistentWindows.Solution/SystrayShell/SystrayForm.cs index 8d8e45f..872ee02 100644 --- a/Ninjacrab.PersistentWindows.Solution/SystrayShell/SystrayForm.cs +++ b/Ninjacrab.PersistentWindows.Solution/SystrayShell/SystrayForm.cs @@ -289,6 +289,7 @@ namespace PersistentWindows.SystrayShell process.PriorityClass = ProcessPriorityClass.High; Program.WriteDataDump(); + Log.Event("Session exit"); this.notifyIconMain.Visible = false; //this.notifyIconMain.Icon = null;