From 6b5c5259722397f6fa97d74a0bcef4ba1976d843 Mon Sep 17 00:00:00 2001 From: Aytackydln Date: Mon, 30 Dec 2024 09:08:52 +0100 Subject: [PATCH] added Events + Polling process detection option, increase polling to 2 seconds --- .../Modules/ProcessMonitor/ActiveProcessMonitor.cs | 13 +++++++------ .../Project-Aurora/Profiles/LightingStateManager.cs | 6 +++--- .../Project-Aurora/Settings/SettingEnums.cs | 3 +++ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Project-Aurora/Project-Aurora/Modules/ProcessMonitor/ActiveProcessMonitor.cs b/Project-Aurora/Project-Aurora/Modules/ProcessMonitor/ActiveProcessMonitor.cs index 7d21d01b1..51d58a6de 100644 --- a/Project-Aurora/Project-Aurora/Modules/ProcessMonitor/ActiveProcessMonitor.cs +++ b/Project-Aurora/Project-Aurora/Modules/ProcessMonitor/ActiveProcessMonitor.cs @@ -31,13 +31,11 @@ private set internal ActiveProcessMonitor() { _dele = WinEventProc; - if (Global.Configuration.DetectionMode != ApplicationDetectionMode.WindowsEvents) + if (Global.Configuration.DetectionMode is ApplicationDetectionMode.WindowsEvents or ApplicationDetectionMode.EventsAndForeground) { - return; + _setWinEventHook = User32.SetWinEventHook(EventSystemForeground, EventSystemForeground, + IntPtr.Zero, _dele, 0, 0, WinEventOutOfContext); } - - _setWinEventHook = User32.SetWinEventHook(EventSystemForeground, EventSystemForeground, - IntPtr.Zero, _dele, 0, 0, WinEventOutOfContext); } private void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr windowHandle, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime) @@ -77,6 +75,9 @@ private void SetActiveWindowProperties(IntPtr windowHandle) public void Dispose() { - User32.UnhookWinEvent(_setWinEventHook); + if (_setWinEventHook != IntPtr.Zero) + { + User32.UnhookWinEvent(_setWinEventHook); + } } } \ No newline at end of file diff --git a/Project-Aurora/Project-Aurora/Profiles/LightingStateManager.cs b/Project-Aurora/Project-Aurora/Profiles/LightingStateManager.cs index 1fb2f5d7b..14357d04a 100755 --- a/Project-Aurora/Project-Aurora/Profiles/LightingStateManager.cs +++ b/Project-Aurora/Project-Aurora/Profiles/LightingStateManager.cs @@ -418,10 +418,10 @@ private void TimerUpdate() private void UpdateProcess() { - if (Global.Configuration.DetectionMode != ApplicationDetectionMode.ForegroundApp || - _currentTick < _nextProcessNameUpdate) return; + var pollingEnabled = Global.Configuration.DetectionMode is ApplicationDetectionMode.ForegroundApp or ApplicationDetectionMode.EventsAndForeground; + if (!pollingEnabled || _currentTick < _nextProcessNameUpdate) return; _activeProcessMonitor.Result.UpdateActiveProcessPolling(); - _nextProcessNameUpdate = _currentTick + 1000L; + _nextProcessNameUpdate = _currentTick + 2000L; } private void UpdateIdleEffects(EffectFrame newFrame) diff --git a/Project-Aurora/Project-Aurora/Settings/SettingEnums.cs b/Project-Aurora/Project-Aurora/Settings/SettingEnums.cs index 0d3d8520e..a3a343fdc 100644 --- a/Project-Aurora/Project-Aurora/Settings/SettingEnums.cs +++ b/Project-Aurora/Project-Aurora/Settings/SettingEnums.cs @@ -584,6 +584,9 @@ public enum ApplicationDetectionMode [Description("Foreground App Scan")] ForegroundApp = 1, + [Description("Windows Events and Foreground App Scan")] + EventsAndForeground = 2, + [Description("None")] [UsedImplicitly] None = -1,