Skip to content

Commit

Permalink
Fix an issue caused by threaded calls from PowerManager (#486)
Browse files Browse the repository at this point in the history
* rollback PowerManager modifications

Threaded call from raised event was affecting Keyboard hook

* implement Default Device F1-F4 OEM key support

helpful for debugging...
  • Loading branch information
Valkirie authored Apr 17, 2023
1 parent 9be9c31 commit 83401c5
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
29 changes: 28 additions & 1 deletion ControllerCommon/Devices/DefaultDevice.cs
Original file line number Diff line number Diff line change
@@ -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>() { KeyCode.F1 },
new List<KeyCode>() { KeyCode.F1 },
false, ButtonFlags.OEM1
));

OEMChords.Add(new DeviceChord("F2",
new List<KeyCode>() { KeyCode.F2 },
new List<KeyCode>() { KeyCode.F2 },
false, ButtonFlags.OEM2
));

OEMChords.Add(new DeviceChord("F3",
new List<KeyCode>() { KeyCode.F3 },
new List<KeyCode>() { KeyCode.F3 },
false, ButtonFlags.OEM3
));

OEMChords.Add(new DeviceChord("F4",
new List<KeyCode>() { KeyCode.F4 },
new List<KeyCode>() { KeyCode.F4 },
false, ButtonFlags.OEM4
));
}
}
}
17 changes: 4 additions & 13 deletions ControllerCommon/Managers/PowerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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<string, string> PowerStatusIcon = new()
Expand Down Expand Up @@ -115,8 +111,7 @@ public static void Start(bool service = false)
IsSessionLocked = false;
}

updateTimer.Elapsed += UpdateTimer_Elapsed;
updateTimer.Start();
SystemRoutine();

IsInitialized = true;
Initialized?.Invoke();
Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand Down

0 comments on commit 83401c5

Please sign in to comment.