From 000162b9894cdf1476ddad428e464c02863f9dc5 Mon Sep 17 00:00:00 2001 From: yinyue200 Date: Mon, 11 Nov 2024 02:35:43 +0800 Subject: [PATCH] Add support for CameraShutter (#3358) --- app/AppConfig.cs | 5 ++++ app/AsusACPI.cs | 1 + app/Input/InputDispatcher.cs | 54 +++++++++++++++++++++++------------- 3 files changed, 41 insertions(+), 19 deletions(-) diff --git a/app/AppConfig.cs b/app/AppConfig.cs index 164144bb..a1612566 100644 --- a/app/AppConfig.cs +++ b/app/AppConfig.cs @@ -698,10 +698,15 @@ public static bool IsForceMiniled() { return ContainsModel("G834JYR") || ContainsModel("G834JZR") || Is("force_miniled"); } + public static bool IsCameraShutter() + { + return ContainsModel("UX5401") || ContainsModel("UX5406"); + } public static bool SaveDimming() { return Is("save_dimming"); } + } diff --git a/app/AsusACPI.cs b/app/AsusACPI.cs index 8a52e686..8b42c0d2 100644 --- a/app/AsusACPI.cs +++ b/app/AsusACPI.cs @@ -129,6 +129,7 @@ public class AsusACPI public const int ScreenPadToggle = 0x00050031; public const int ScreenPadBrightness = 0x00050032; + public const int CameraShutter = 0x00060078; public const int CameraLed = 0x00060079; public const int StatusLed = 0x000600C2; diff --git a/app/Input/InputDispatcher.cs b/app/Input/InputDispatcher.cs index 39cbe955..4db0fc4d 100644 --- a/app/Input/InputDispatcher.cs +++ b/app/Input/InputDispatcher.cs @@ -944,33 +944,49 @@ public static void ToggleScreenRate() public static void ToggleCamera() { - if (!ProcessHelper.IsUserAdministrator()) return; - - string CameraRegistryKeyPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam"; - string CameraRegistryValueName = "Value"; - - try + if(AppConfig.IsCameraShutter()) { - var status = (string?)Registry.GetValue(CameraRegistryKeyPath, CameraRegistryValueName, ""); + if(Program.acpi.DeviceGet(AsusACPI.CameraShutter)==0) + { + Program.acpi.DeviceSet(AsusACPI.CameraShutter, 1, "CameraShutterOn"); + Program.toast.RunToast($"Camera Off"); - if (status == "Allow") status = "Deny"; - else if (status == "Deny") status = "Allow"; + } else { - Logger.WriteLine("Unknown camera status"); - return; + Program.acpi.DeviceSet(AsusACPI.CameraShutter, 0, "CameraShutterOff"); + Program.toast.RunToast($"Camera On"); } - - Registry.SetValue(CameraRegistryKeyPath, CameraRegistryValueName, status, RegistryValueKind.String); - Program.acpi.DeviceSet(AsusACPI.CameraLed, (status == "Deny" ? 1 : 0), "Camera"); - Program.toast.RunToast($"Camera " + (status == "Deny" ? "Off" : "On")); - } - catch (Exception ex) + else { - Logger.WriteLine(ex.ToString()); - } + if (!ProcessHelper.IsUserAdministrator()) return; + + string CameraRegistryKeyPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam"; + string CameraRegistryValueName = "Value"; + try + { + var status = (string?)Registry.GetValue(CameraRegistryKeyPath, CameraRegistryValueName, ""); + + if (status == "Allow") status = "Deny"; + else if (status == "Deny") status = "Allow"; + else + { + Logger.WriteLine("Unknown camera status"); + return; + } + + Registry.SetValue(CameraRegistryKeyPath, CameraRegistryValueName, status, RegistryValueKind.String); + Program.acpi.DeviceSet(AsusACPI.CameraLed, (status == "Deny" ? 1 : 0), "Camera"); + Program.toast.RunToast($"Camera " + (status == "Deny" ? "Off" : "On")); + + } + catch (Exception ex) + { + Logger.WriteLine(ex.ToString()); + } + } } private static System.Threading.Timer screenpadActionTimer;