Merge branch 'develop'

pull/151/head 1.0.0.29553
Sleevezipper 2 years ago
commit d86513c772

@ -158,6 +158,13 @@ namespace UserInterface.Views
item.UpdateInterval = 10;
break;
case AvailableSensors.WebcamProcessSensor:
item.Description = "This sensor shows which process is using the webcam.";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service/blob/master/documentation/Sensors.md#webcamprocesssensor";
item.ShowQueryInput = false;
item.UpdateInterval = 10;
break;
case AvailableSensors.MicrophoneActiveSensor:
item.Description = "This sensor shows if the microphone is currently in use.";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service/blob/master/documentation/Sensors.md#microphoneactivesensor";

@ -9,10 +9,7 @@
<ContentControl FontSize="18" FontWeight="Bold">Background service</ContentControl>
<TextBlock IsVisible="{Binding IsRunning}" Foreground="Green" Text="{Binding Message}"></TextBlock >
<TextBlock IsVisible="{Binding !IsRunning}" Foreground="Red" Text="{Binding Message}"></TextBlock >
<Button IsVisible="{Binding !IsRunning}" Width="75" HorizontalAlignment="Right" Margin="0 40 0 10" Click="Start">Start</Button>
<TextBlock TextWrapping="Wrap" IsVisible="{Binding !IsRunning}" Text="The UI will crash after a while if the service wasn't started first. Please make sure the service is running. If you used the installer and you are seeing this message, please check if your antivirus might be interfering. "></TextBlock >
</StackPanel>
<StackPanel HorizontalAlignment="Stretch">
<ContentControl FontSize="14" FontWeight="Bold">Autostart</ContentControl>

@ -4,7 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450"
x:Class="UserInterface.Views.BrokerSettings">
<StackPanel Margin="30" HorizontalAlignment="Left">
<StackPanel Margin="30" HorizontalAlignment="Left" ScrollViewer.VerticalScrollBarVisibility="Auto">
<ContentControl FontSize="18" FontWeight="Bold">MQTT Broker</ContentControl>
<TextBlock IsVisible="{Binding IsConnected}" Foreground="Green" Text="{Binding Message}"></TextBlock >
<TextBlock IsVisible="{Binding !IsConnected}" Foreground="Red" Text="{Binding Message}"></TextBlock >

@ -1,4 +1,4 @@
<Window xmlns="https://github.com/avaloniaui"
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vm="clr-namespace:UserInterface.ViewModels;assembly=UserInterface"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
@ -15,13 +15,16 @@
<vm:MainWindowViewModel/>
</Design.DataContext>
<Grid ColumnDefinitions="Auto, *, Auto" RowDefinitions="*, *" Margin="10">
<views:BrokerSettings Grid.Column="0" Grid.Row="0" Margin="10" Grid.RowSpan="2" Background="#2D2D30"/>
<Grid ColumnDefinitions="Auto, *, Auto" Margin="10">
<Grid.RowDefinitions>
<RowDefinition MinHeight="500"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<views:BrokerSettings Grid.Column="0" Grid.Row="0" Margin="10" Grid.RowSpan="2" MinHeight="500" Background="#2D2D30"/>
<views:GeneralSettingsView Grid.Column="0" Grid.Row="1" Margin="10" Grid.RowSpan="2" Background="#2D2D30"/>
<views:SensorSettings Grid.Column="1" Grid.Row="0" Margin="10" Background="#2D2D30"/>
<views:CommandSettings Grid.Column="1" Grid.Row="1" Margin="10" Background="#2D2D30"/>
<views:BackgroundServiceSettings Grid.Column="2" Grid.Row="0" Margin="10" Background="#2D2D30"/>
<views:AppInfo Grid.Column="2" Grid.Row="1" Margin="10" Background="#2D2D30"/>
</Grid>
</Window>

@ -85,6 +85,10 @@ This sensor watches the UserNotificationState. This is normally used in applicat
The webcam active sensor returns the status of the webcam.
### WebcamProcessSensor
The webcam process sensor returns the process which is using the webcam.
### WMIQuerySensor
Please see the specific documentaion page [here](https://github.com/sleevezipper/hass-workstation-service/blob/master/documentation/WMIQuery.md#wmiquerysensor).

@ -177,6 +177,7 @@ namespace hass_workstation_service.Communication.InterProcesCommunication
AvailableSensors.MemoryUsageSensor => new MemoryUsageSensor(_publisher, (int)model.UpdateInterval, model.Name),
AvailableSensors.ActiveWindowSensor => new ActiveWindowSensor(_publisher, (int)model.UpdateInterval, model.Name),
AvailableSensors.WebcamActiveSensor => new WebcamActiveSensor(_publisher, (int)model.UpdateInterval, model.Name),
AvailableSensors.WebcamProcessSensor => new WebcamProcessSensor(_publisher, (int)model.UpdateInterval, model.Name),
AvailableSensors.MicrophoneActiveSensor => new MicrophoneActiveSensor(_publisher, (int)model.UpdateInterval, model.Name),
AvailableSensors.NamedWindowSensor => new NamedWindowSensor(_publisher, model.WindowName, model.Name, (int)model.UpdateInterval),
AvailableSensors.LastActiveSensor => new LastActiveSensor(_publisher, (int)model.UpdateInterval, model.Name),
@ -221,4 +222,4 @@ namespace hass_workstation_service.Communication.InterProcesCommunication
public void WriteGeneralSettings(GeneralSettings settings) => _configurationService.WriteGeneralSettingsAsync(settings);
}
}
}

@ -93,6 +93,7 @@ namespace hass_workstation_service.Communication.InterProcesCommunication.Models
WMIQuerySensor,
MemoryUsageSensor,
WebcamActiveSensor,
WebcamProcessSensor,
MicrophoneActiveSensor,
ActiveWindowSensor,
NamedWindowSensor,
@ -120,4 +121,4 @@ namespace hass_workstation_service.Communication.InterProcesCommunication.Models
VolumeDownCommand,
MuteCommand
}
}
}

@ -129,6 +129,9 @@ namespace hass_workstation_service.Data
case "WebcamActiveSensor":
sensor = new WebcamActiveSensor(publisher, configuredSensor.UpdateInterval, configuredSensor.Name, configuredSensor.Id);
break;
case "WebcamProcessSensor":
sensor = new WebcamProcessSensor(publisher, configuredSensor.UpdateInterval, configuredSensor.Name, configuredSensor.Id);
break;
case "MicrophoneActiveSensor":
sensor = new MicrophoneActiveSensor(publisher, configuredSensor.UpdateInterval, configuredSensor.Name, configuredSensor.Id);
break;
@ -619,4 +622,4 @@ namespace hass_workstation_service.Data
return this.ConfiguredSensors;
}
}
}
}

@ -25,7 +25,7 @@ namespace hass_workstation_service.Domain.Sensors
public override string GetState()
{
return GetLastInputTime().ToString("s");
return GetLastInputTime().ToString("o", System.Globalization.CultureInfo.InvariantCulture);
}

@ -29,10 +29,10 @@ namespace hass_workstation_service.Domain.Sensors
public override string GetState()
{
return (DateTime.Now - TimeSpan.FromMilliseconds(GetTickCount64())).ToString("s");
return (DateTime.Now - TimeSpan.FromMilliseconds(GetTickCount64())).ToString("o", System.Globalization.CultureInfo.InvariantCulture);
}
[DllImport("kernel32")]
extern static UInt64 GetTickCount64();
}
}
}

@ -0,0 +1,130 @@
using hass_workstation_service.Communication;
using Microsoft.Win32;
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace hass_workstation_service.Domain.Sensors
{
public class WebcamProcessSensor : AbstractSensor
{
public WebcamProcessSensor(MqttPublisher publisher, int? updateInterval = null, string name = "WebcamProcess", Guid id = default) : base(publisher, name ?? "WebcamProcess", updateInterval ?? 10, id)
{
}
public override string GetState()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return IsWebCamInUseRegistry();
}
else
{
return "unsupported";
}
}
public override SensorDiscoveryConfigModel GetAutoDiscoveryConfig()
{
return this._autoDiscoveryConfigModel ?? SetAutoDiscoveryConfigModel(new SensorDiscoveryConfigModel()
{
Name = this.Name,
NamePrefix = Publisher.NamePrefix,
Unique_id = this.Id.ToString(),
Device = this.Publisher.DeviceConfigModel,
State_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/{DiscoveryConfigModel.GetNameWithPrefix(Publisher.NamePrefix, this.ObjectId)}/state",
Availability_topic = $"homeassistant/sensor/{Publisher.DeviceConfigModel.Name}/availability"
});
}
[SupportedOSPlatform("windows")]
private string IsWebCamInUseRegistry()
{
using (var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam"))
{
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"))
{
var endTime = subKey.GetValue("LastUsedTimeStop") is long ? (long)subKey.GetValue("LastUsedTimeStop") : -1;
if (endTime <= 0)
{
return nonpackagedSubKeyName;
}
}
}
}
}
}
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)
{
return subKeyName;
}
}
}
}
}
}
using (var key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\CapabilityAccessManager\ConsentStore\webcam"))
{
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"))
{
var endTime = subKey.GetValue("LastUsedTimeStop") is long ? (long)subKey.GetValue("LastUsedTimeStop") : -1;
if (endTime <= 0)
{
return nonpackagedSubKeyName;
}
}
}
}
}
}
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)
{
return subKeyName;
}
}
}
}
}
}
return "off";
}
}
}

@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ApplicationRevision>55</ApplicationRevision>
<ApplicationRevision>57</ApplicationRevision>
<ApplicationVersion>1.0.0.*</ApplicationVersion>
<BootstrapperEnabled>True</BootstrapperEnabled>
<Configuration>Release</Configuration>

Loading…
Cancel
Save