wip burnt toast

burnt-toast
Sleevezipper 3 years ago
parent 92aa9ca10e
commit 69dd3ba5c1

@ -0,0 +1 @@
Install-Module -Name BurntToast

@ -7,8 +7,17 @@
<ItemGroup> <ItemGroup>
<AvaloniaResource Include="Assets\**" /> <AvaloniaResource Include="Assets\**" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<AvaloniaResource Remove="Assets\InstallBurntToast.ps1" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<None Remove="Assets\hass-workstation-logo.ico" /> <None Remove="Assets\hass-workstation-logo.ico" />
<None Remove="Assets\InstallBurntToast.ps1" />
</ItemGroup>
<ItemGroup>
<Content Include="Assets\InstallBurntToast.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Avalonia" Version="0.10.8" /> <PackageReference Include="Avalonia" Version="0.10.8" />

@ -100,6 +100,12 @@ namespace UserInterface.Views
item.ShowCommandInput = true; item.ShowCommandInput = true;
item.ShowKeyInput = false; item.ShowKeyInput = false;
break; break;
case AvailableCommands.CustomPowerShellCommand:
item.Description = "This command lets you execute any command you want. It will run in a Powershell window silently. ";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service/blob/master/documentation/Commands.md#custompowershellcommand";
item.ShowCommandInput = true;
item.ShowKeyInput = false;
break;
case AvailableCommands.ShutdownCommand: case AvailableCommands.ShutdownCommand:
item.Description = "This command shuts down the PC immediately. "; item.Description = "This command shuts down the PC immediately. ";
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service/blob/master/documentation/Commands.md#shutdowncommand"; item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service/blob/master/documentation/Commands.md#shutdowncommand";

@ -23,5 +23,8 @@ If a sensor is called "ActiveWindow" and the name prefix is set to "laptop", the
</StackPanel> </StackPanel>
<TextBox Text="{Binding NamePrefix}" HorizontalAlignment="Left" Width="100"/> <TextBox Text="{Binding NamePrefix}" HorizontalAlignment="Left" Width="100"/>
<Button Width="75" HorizontalAlignment="Right" Margin="0 40 0 10" Click="Configure">Save</Button> <Button Width="75" HorizontalAlignment="Right" Margin="0 40 0 10" Click="Configure">Save</Button>
<StackPanel Margin="0 20 0 10" HorizontalAlignment="Left" Orientation="Horizontal">
<Button Width="75" HorizontalAlignment="Right" Margin="0 40 0 10" Click="InstallBurntToast">Install BurntToast</Button>
</StackPanel>
</StackPanel> </StackPanel>
</UserControl> </UserControl>

@ -57,6 +57,19 @@ namespace UserInterface.Views
((GeneralSettingsViewModel)this.DataContext).Update(settings); ((GeneralSettingsViewModel)this.DataContext).Update(settings);
} }
public void InstallBurntToast(object sender, RoutedEventArgs args)
{
var process = new System.Diagnostics.Process();
var startInfo = new System.Diagnostics.ProcessStartInfo
{
WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal,
FileName = "powershell.exe",
Arguments = $"-NoExit Start-Process 'powershell InstallBurntToast.ps1' -Verb runAs"
};
process.StartInfo = startInfo;
process.Start();
}
private void InitializeComponent() private void InitializeComponent()
{ {

@ -183,8 +183,8 @@ namespace hass_workstation_service.Communication.InterProcesCommunication
AvailableSensors.LastBootSensor => new LastBootSensor(_publisher, (int)model.UpdateInterval, model.Name), AvailableSensors.LastBootSensor => new LastBootSensor(_publisher, (int)model.UpdateInterval, model.Name),
AvailableSensors.SessionStateSensor => new SessionStateSensor(_publisher, (int)model.UpdateInterval, model.Name), AvailableSensors.SessionStateSensor => new SessionStateSensor(_publisher, (int)model.UpdateInterval, model.Name),
AvailableSensors.CurrentVolumeSensor => new CurrentVolumeSensor(_publisher, (int)model.UpdateInterval, model.Name), AvailableSensors.CurrentVolumeSensor => new CurrentVolumeSensor(_publisher, (int)model.UpdateInterval, model.Name),
AvailableSensors.GPUTemperatureSensor => new GpuTemperatureSensor(_publisher, (int)model.UpdateInterval, model.Name), AvailableSensors.GPUTemperatureSensor => new GPUTemperatureSensor(_publisher, (int)model.UpdateInterval, model.Name),
AvailableSensors.GPULoadSensor => new GpuLoadSensor(_publisher, (int)model.UpdateInterval, model.Name), AvailableSensors.GPULoadSensor => new GPULoadSensor(_publisher, (int)model.UpdateInterval, model.Name),
_ => null _ => null
}; };
} }
@ -203,6 +203,7 @@ namespace hass_workstation_service.Communication.InterProcesCommunication
AvailableCommands.RestartCommand => new RestartCommand(_publisher, model.Name), AvailableCommands.RestartCommand => new RestartCommand(_publisher, model.Name),
AvailableCommands.LogOffCommand => new LogOffCommand(_publisher, model.Name), AvailableCommands.LogOffCommand => new LogOffCommand(_publisher, model.Name),
AvailableCommands.CustomCommand => new CustomCommand(_publisher, model.Command, model.Name), AvailableCommands.CustomCommand => new CustomCommand(_publisher, model.Command, model.Name),
AvailableCommands.CustomPowerShellCommand => new CustomPowerShellCommand(_publisher, model.Command, model.Name),
AvailableCommands.PlayPauseCommand => new PlayPauseCommand(_publisher, model.Name), AvailableCommands.PlayPauseCommand => new PlayPauseCommand(_publisher, model.Name),
AvailableCommands.NextCommand => new NextCommand(_publisher, model.Name), AvailableCommands.NextCommand => new NextCommand(_publisher, model.Name),
AvailableCommands.PreviousCommand => new PreviousCommand(_publisher, model.Name), AvailableCommands.PreviousCommand => new PreviousCommand(_publisher, model.Name),

@ -116,6 +116,7 @@ namespace hass_workstation_service.Communication.InterProcesCommunication.Models
PreviousCommand, PreviousCommand,
VolumeUpCommand, VolumeUpCommand,
VolumeDownCommand, VolumeDownCommand,
MuteCommand MuteCommand,
CustomPowerShellCommand
} }
} }

@ -138,11 +138,11 @@ namespace hass_workstation_service.Data
case "CurrentVolumeSensor": case "CurrentVolumeSensor":
sensor = new CurrentVolumeSensor(publisher, configuredSensor.UpdateInterval, configuredSensor.Name, configuredSensor.Id); sensor = new CurrentVolumeSensor(publisher, configuredSensor.UpdateInterval, configuredSensor.Name, configuredSensor.Id);
break; break;
case "GpuTemperatureSensor": case "GPUTemperatureSensor":
sensor = new GpuTemperatureSensor(publisher, configuredSensor.UpdateInterval, configuredSensor.Name, configuredSensor.Id); sensor = new GPUTemperatureSensor(publisher, configuredSensor.UpdateInterval, configuredSensor.Name, configuredSensor.Id);
break; break;
case "GpuLoadSensor": case "GPULoadSensor":
sensor = new GpuLoadSensor(publisher, configuredSensor.UpdateInterval, configuredSensor.Name, configuredSensor.Id); sensor = new GPULoadSensor(publisher, configuredSensor.UpdateInterval, configuredSensor.Name, configuredSensor.Id);
break; break;
// keep this one last! // keep this one last!
case "WMIQuerySensor": case "WMIQuerySensor":
@ -196,6 +196,9 @@ namespace hass_workstation_service.Data
case "CustomCommand": case "CustomCommand":
command = new CustomCommand(publisher, configuredCommand.Command, configuredCommand.Name, configuredCommand.Id); command = new CustomCommand(publisher, configuredCommand.Command, configuredCommand.Name, configuredCommand.Id);
break; break;
case "CustomPowerShellCommand":
command = new CustomPowerShellCommand(publisher, configuredCommand.Command, configuredCommand.Name, configuredCommand.Id);
break;
case "MediaPlayPauseCommand": case "MediaPlayPauseCommand":
command = new PlayPauseCommand(publisher, configuredCommand.Name, configuredCommand.Id); command = new PlayPauseCommand(publisher, configuredCommand.Name, configuredCommand.Id);
break; break;

@ -46,9 +46,6 @@ namespace hass_workstation_service.Domain.Commands
} }
this.State = "OFF"; this.State = "OFF";
} }
public override CommandDiscoveryConfigModel GetAutoDiscoveryConfig() public override CommandDiscoveryConfigModel GetAutoDiscoveryConfig()
{ {
return new CommandDiscoveryConfigModel() return new CommandDiscoveryConfigModel()

@ -0,0 +1,73 @@
using hass_workstation_service.Communication;
using Serilog;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace hass_workstation_service.Domain.Commands
{
public class CustomPowerShellCommand : AbstractCommand
{
public string Command { get; protected set; }
public string State { get; protected set; }
public Process Process { get; private set; }
public CustomPowerShellCommand(MqttPublisher publisher, string command, string name = "CustomPowerShell", Guid id = default(Guid)) : base(publisher, name ?? "CustomPowerShell", id)
{
this.Command = command;
this.State = "OFF";
}
public override async void TurnOn()
{
this.State = "ON";
this.Process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
startInfo.CreateNoWindow = true;
startInfo.FileName = @"powershell.exe";
startInfo.Arguments = $"\"&' { this.Command } '\"";
this.Process.StartInfo = startInfo;
try
{
this.Process.Start();
}
catch (Exception e)
{
Log.Logger.Error($"Sensor {this.Name} failed", e);
this.State = "FAILED";
}
while (!this.Process.HasExited)
{
await Task.Delay(1000);
}
this.State = "OFF";
}
public override CommandDiscoveryConfigModel GetAutoDiscoveryConfig()
{
return new CommandDiscoveryConfigModel()
{
Name = this.Name,
NamePrefix = Publisher.NamePrefix,
Unique_id = this.Id.ToString(),
Availability_topic = $"homeassistant/sensor/{Publisher.DeviceConfigModel.Name}/availability",
Command_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/{Publisher.NamePrefix}{this.ObjectId}/set",
State_topic = $"homeassistant/{this.Domain}/{Publisher.DeviceConfigModel.Name}/{DiscoveryConfigModel.GetNameWithPrefix(Publisher.NamePrefix, this.ObjectId)}/state",
Device = this.Publisher.DeviceConfigModel,
};
}
public override string GetState()
{
return this.State;
}
public override void TurnOff()
{
this.Process.Kill();
}
}
}

@ -9,11 +9,11 @@ using LibreHardwareMonitor.Hardware;
namespace hass_workstation_service.Domain.Sensors namespace hass_workstation_service.Domain.Sensors
{ {
public class GpuLoadSensor : AbstractSensor public class GPULoadSensor : AbstractSensor
{ {
private Computer _computer; private Computer _computer;
private IHardware _gpu; private IHardware _gpu;
public GpuLoadSensor(MqttPublisher publisher, int? updateInterval = null, string name = "GPULoad", Guid id = default(Guid)) : base(publisher, name ?? "GPULoad", updateInterval ?? 10, id) public GPULoadSensor(MqttPublisher publisher, int? updateInterval = null, string name = "GPULoad", Guid id = default(Guid)) : base(publisher, name ?? "GPULoad", updateInterval ?? 10, id)
{ {
_computer = new Computer _computer = new Computer
{ {

@ -9,11 +9,11 @@ using LibreHardwareMonitor.Hardware;
namespace hass_workstation_service.Domain.Sensors namespace hass_workstation_service.Domain.Sensors
{ {
public class GpuTemperatureSensor : AbstractSensor public class GPUTemperatureSensor : AbstractSensor
{ {
private Computer _computer; private Computer _computer;
private IHardware _gpu; private IHardware _gpu;
public GpuTemperatureSensor(MqttPublisher publisher, int? updateInterval = null, string name = "GPUTemperature", Guid id = default(Guid)) : base(publisher, name ?? "GPUTemperature", updateInterval ?? 10, id) public GPUTemperatureSensor(MqttPublisher publisher, int? updateInterval = null, string name = "GPUTemperature", Guid id = default(Guid)) : base(publisher, name ?? "GPUTemperature", updateInterval ?? 10, id)
{ {
_computer = new Computer _computer = new Computer
{ {

@ -0,0 +1 @@
Install-Module -Name BurntToast

@ -26,6 +26,7 @@
<ItemGroup> <ItemGroup>
<None Remove="hass-workstation-service.exe" /> <None Remove="hass-workstation-service.exe" />
<None Remove="hass-workstation-service.pdb" /> <None Remove="hass-workstation-service.pdb" />
<None Remove="InstallBurntToast.ps1" />
<None Remove="libHarfBuzzSharp.dll" /> <None Remove="libHarfBuzzSharp.dll" />
<None Remove="libSkiaSharp.dll" /> <None Remove="libSkiaSharp.dll" />
<None Remove="UserInterface.exe" /> <None Remove="UserInterface.exe" />
@ -33,6 +34,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="InstallBurntToast.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="libHarfBuzzSharp.dll"> <Content Include="libHarfBuzzSharp.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content> </Content>

Loading…
Cancel
Save