From e98cd2f5c1dce3915d3994bc836342117237a61e Mon Sep 17 00:00:00 2001 From: Serge <5920850+seerge@users.noreply.github.com> Date: Wed, 14 Feb 2024 15:40:00 +0100 Subject: [PATCH] Camera toggle for Vivobooks https://github.com/seerge/g-helper/issues/2060 --- app/Input/InputDispatcher.cs | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/Input/InputDispatcher.cs b/app/Input/InputDispatcher.cs index 8eafcb76..eebe9e4d 100644 --- a/app/Input/InputDispatcher.cs +++ b/app/Input/InputDispatcher.cs @@ -794,20 +794,31 @@ namespace GHelper.Input { if (!ProcessHelper.IsUserAdministrator()) return; - int toggle = AppConfig.Is("camera_toggle") ? 0 : 1; - Program.acpi.DeviceSet(AsusACPI.CameraLed, toggle, "Camera"); + string CameraRegistryKeyPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam"; + string CameraRegistryValueName = "Value"; try { - ProcessHelper.RunCMD("powershell", (toggle == 1 ? "Disable" : "Enable") + "-PnpDevice -InstanceId (Get-PnpDevice -FriendlyName *webcam*).InstanceId -Confirm:$false"); + 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()); } - AppConfig.Set("camera_toggle", toggle); - Program.toast.RunToast($"Camera " + (toggle == 1 ? "Off" : "On")); } public static void SetScreenpad(int delta)