From 83401c510fe2fca4ab207fdcf67ebf13c7dd5a41 Mon Sep 17 00:00:00 2001 From: Lesueur Benjamin Date: Mon, 17 Apr 2023 08:49:25 +0200 Subject: [PATCH] Fix an issue caused by threaded calls from PowerManager (#486) * rollback PowerManager modifications Threaded call from raised event was affecting Keyboard hook * implement Default Device F1-F4 OEM key support helpful for debugging... --- ControllerCommon/Devices/DefaultDevice.cs | 29 ++++++++++++++++++++++- ControllerCommon/Managers/PowerManager.cs | 17 ++++--------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/ControllerCommon/Devices/DefaultDevice.cs b/ControllerCommon/Devices/DefaultDevice.cs index 243d0bede..6f00137ae 100644 --- a/ControllerCommon/Devices/DefaultDevice.cs +++ b/ControllerCommon/Devices/DefaultDevice.cs @@ -1,9 +1,36 @@ -namespace ControllerCommon.Devices +using ControllerCommon.Inputs; +using System.Collections.Generic; +using WindowsInput.Events; + +namespace ControllerCommon.Devices { public class DefaultDevice : IDevice { public DefaultDevice() : base() { + OEMChords.Add(new DeviceChord("F1", + new List() { KeyCode.F1 }, + new List() { KeyCode.F1 }, + false, ButtonFlags.OEM1 + )); + + OEMChords.Add(new DeviceChord("F2", + new List() { KeyCode.F2 }, + new List() { KeyCode.F2 }, + false, ButtonFlags.OEM2 + )); + + OEMChords.Add(new DeviceChord("F3", + new List() { KeyCode.F3 }, + new List() { KeyCode.F3 }, + false, ButtonFlags.OEM3 + )); + + OEMChords.Add(new DeviceChord("F4", + new List() { KeyCode.F4 }, + new List() { KeyCode.F4 }, + false, ButtonFlags.OEM4 + )); } } } diff --git a/ControllerCommon/Managers/PowerManager.cs b/ControllerCommon/Managers/PowerManager.cs index 8a8926093..1f4160814 100644 --- a/ControllerCommon/Managers/PowerManager.cs +++ b/ControllerCommon/Managers/PowerManager.cs @@ -2,10 +2,8 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; -using System.Timers; using System.Windows.Forms; using SystemPowerManager = Windows.System.Power.PowerManager; -using Timer = System.Timers.Timer; namespace ControllerCommon.Managers { @@ -33,8 +31,6 @@ public static class PowerManager private static SystemStatus currentSystemStatus = SystemStatus.SystemBooting; private static SystemStatus previousSystemStatus = SystemStatus.SystemBooting; - private static Timer updateTimer = new(250) { AutoReset = false }; - public static bool IsInitialized; public static readonly SortedDictionary PowerStatusIcon = new() @@ -115,8 +111,7 @@ public static void Start(bool service = false) IsSessionLocked = false; } - updateTimer.Elapsed += UpdateTimer_Elapsed; - updateTimer.Start(); + SystemRoutine(); IsInitialized = true; Initialized?.Invoke(); @@ -156,9 +151,7 @@ private static void OnPowerChange(object s, PowerModeChangedEventArgs e) LogManager.LogDebug("Device power mode set to {0}", e.Mode); - // reset timer - updateTimer.Stop(); - updateTimer.Start(); + SystemRoutine(); } private static void OnSessionSwitch(object sender, SessionSwitchEventArgs e) @@ -177,12 +170,10 @@ private static void OnSessionSwitch(object sender, SessionSwitchEventArgs e) LogManager.LogDebug("Session switched to {0}", e.Reason); - // reset timer - updateTimer.Stop(); - updateTimer.Start(); + SystemRoutine(); } - private static void UpdateTimer_Elapsed(object sender, ElapsedEventArgs e) + private static void SystemRoutine() { if (!IsPowerSuspended && !IsSessionLocked) currentSystemStatus = SystemStatus.SystemReady;