This commit is contained in:
Serge
2024-02-17 12:03:29 +01:00
parent 03bff51850
commit 8d38e8b29c
2 changed files with 12 additions and 7 deletions

View File

@@ -223,6 +223,8 @@ public class AsusACPI
return _connected; return _connected;
} }
private static ManagementEventWatcher? watcher;
public AsusACPI() public AsusACPI()
{ {
try try
@@ -747,10 +749,14 @@ public class AsusACPI
{ {
try try
{ {
ManagementEventWatcher watcher = new ManagementEventWatcher(); if (watcher is null)
{
watcher = new ManagementEventWatcher();
watcher.EventArrived += new EventArrivedEventHandler(EventHandler); watcher.EventArrived += new EventArrivedEventHandler(EventHandler);
watcher.Scope = new ManagementScope("root\\wmi"); watcher.Scope = new ManagementScope("root\\wmi");
watcher.Query = new WqlEventQuery("SELECT * FROM AsusAtkWmiEvent"); watcher.Query = new WqlEventQuery("SELECT * FROM AsusAtkWmiEvent");
}
watcher.Start(); watcher.Start();
} }
catch catch

View File

@@ -32,9 +32,6 @@ namespace GHelper.Input
byte[] result = Program.acpi.DeviceInit(); byte[] result = Program.acpi.DeviceInit();
Debug.WriteLine($"Init: {BitConverter.ToString(result)}"); Debug.WriteLine($"Init: {BitConverter.ToString(result)}");
Program.acpi.SubscribeToEvents(WatcherEventArrived);
//Task.Run(Program.acpi.RunListener);
hook.KeyPressed += new EventHandler<KeyPressedEventArgs>(KeyPressed); hook.KeyPressed += new EventHandler<KeyPressedEventArgs>(KeyPressed);
RegisterKeys(); RegisterKeys();
@@ -83,6 +80,8 @@ namespace GHelper.Input
else else
Logger.WriteLine("Optimization service is running"); Logger.WriteLine("Optimization service is running");
Program.acpi.SubscribeToEvents(WatcherEventArrived);
InitBacklightTimer(); InitBacklightTimer();
if (AppConfig.ContainsModel("VivoBook")) Program.acpi.DeviceSet(AsusACPI.FnLock, AppConfig.Is("fn_lock") ? 1 : 0, "FnLock"); if (AppConfig.ContainsModel("VivoBook")) Program.acpi.DeviceSet(AsusACPI.FnLock, AppConfig.Is("fn_lock") ? 1 : 0, "FnLock");