|
|
|
@ -4,11 +4,14 @@ using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Runtime.Versioning;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
namespace hass_workstation_service.Domain.Sensors
|
|
|
|
|
{
|
|
|
|
|
public class MicrophoneProcessSensor : AbstractSensor
|
|
|
|
|
{
|
|
|
|
|
private List<string> processes = new List<string>();
|
|
|
|
|
|
|
|
|
|
public MicrophoneProcessSensor(MqttPublisher publisher, int? updateInterval = null, string name = "MicrophoneProcess", Guid id = default) : base(publisher, name ?? "MicrophoneProcess", updateInterval ?? 10, id)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
@ -38,9 +41,7 @@ namespace hass_workstation_service.Domain.Sensors
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
|
|
|
private string IsMicrophoneInUseRegistry()
|
|
|
|
|
{
|
|
|
|
|
using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\microphone"))
|
|
|
|
|
private void CheckLastUsed(RegistryKey key)
|
|
|
|
|
{
|
|
|
|
|
foreach (var subKeyName in key.GetSubKeyNames())
|
|
|
|
|
{
|
|
|
|
@ -49,20 +50,7 @@ namespace hass_workstation_service.Domain.Sensors
|
|
|
|
|
{
|
|
|
|
|
using (var nonpackagedkey = key.OpenSubKey(subKeyName))
|
|
|
|
|
{
|
|
|
|
|
foreach (var nonpackagedSubKeyName in nonpackagedkey.GetSubKeyNames())
|
|
|
|
|
{
|
|
|
|
|
using (var subKey = nonpackagedkey.OpenSubKey(nonpackagedSubKeyName))
|
|
|
|
|
{
|
|
|
|
|
if (subKey.GetValueNames().Contains("LastUsedTimeStop"))
|
|
|
|
|
{
|
|
|
|
|
var endTime = subKey.GetValue("LastUsedTimeStop") is long ? (long)subKey.GetValue("LastUsedTimeStop") : -1;
|
|
|
|
|
if (endTime <= 0)
|
|
|
|
|
{
|
|
|
|
|
return nonpackagedSubKeyName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CheckLastUsed(nonpackagedkey);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
@ -74,7 +62,7 @@ namespace hass_workstation_service.Domain.Sensors
|
|
|
|
|
var endTime = subKey.GetValue("LastUsedTimeStop") is long ? (long)subKey.GetValue("LastUsedTimeStop") : -1;
|
|
|
|
|
if (endTime <= 0)
|
|
|
|
|
{
|
|
|
|
|
return subKeyName;
|
|
|
|
|
this.processes.Add(subKeyName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -82,48 +70,23 @@ namespace hass_workstation_service.Domain.Sensors
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (var key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\microphone"))
|
|
|
|
|
{
|
|
|
|
|
foreach (var subKeyName in key.GetSubKeyNames())
|
|
|
|
|
{
|
|
|
|
|
// NonPackaged has multiple subkeys
|
|
|
|
|
if (subKeyName == "NonPackaged")
|
|
|
|
|
{
|
|
|
|
|
using (var nonpackagedkey = key.OpenSubKey(subKeyName))
|
|
|
|
|
{
|
|
|
|
|
foreach (var nonpackagedSubKeyName in nonpackagedkey.GetSubKeyNames())
|
|
|
|
|
{
|
|
|
|
|
using (var subKey = nonpackagedkey.OpenSubKey(nonpackagedSubKeyName))
|
|
|
|
|
{
|
|
|
|
|
if (subKey.GetValueNames().Contains("LastUsedTimeStop"))
|
|
|
|
|
[SupportedOSPlatform("windows")]
|
|
|
|
|
private string IsMicrophoneInUseRegistry()
|
|
|
|
|
{
|
|
|
|
|
var endTime = subKey.GetValue("LastUsedTimeStop") is long ? (long)subKey.GetValue("LastUsedTimeStop") : -1;
|
|
|
|
|
if (endTime <= 0)
|
|
|
|
|
using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\microphone"))
|
|
|
|
|
{
|
|
|
|
|
return nonpackagedSubKeyName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CheckLastUsed(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
using (var subKey = key.OpenSubKey(subKeyName))
|
|
|
|
|
{
|
|
|
|
|
if (subKey.GetValueNames().Contains("LastUsedTimeStop"))
|
|
|
|
|
{
|
|
|
|
|
var endTime = subKey.GetValue("LastUsedTimeStop") is long ? (long)subKey.GetValue("LastUsedTimeStop") : -1;
|
|
|
|
|
if (endTime <= 0)
|
|
|
|
|
|
|
|
|
|
using (var key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\microphone"))
|
|
|
|
|
{
|
|
|
|
|
return subKeyName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CheckLastUsed(key);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.processes.Count() > 0)
|
|
|
|
|
{
|
|
|
|
|
return String.Join(",", this.processes.ToArray());
|
|
|
|
|
}
|
|
|
|
|
return "off";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|