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>
<AvaloniaResource Include="Assets\**" />
</ItemGroup>
<ItemGroup>
<AvaloniaResource Remove="Assets\InstallBurntToast.ps1" />
</ItemGroup>
<ItemGroup>
<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>
<PackageReference Include="Avalonia" Version="0.10.8" />

@ -100,6 +100,12 @@ namespace UserInterface.Views
item.ShowCommandInput = true;
item.ShowKeyInput = false;
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:
item.Description = "This command shuts down the PC immediately. ";
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>
<TextBox Text="{Binding NamePrefix}" HorizontalAlignment="Left" Width="100"/>
<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>
</UserControl>

@ -57,6 +57,19 @@ namespace UserInterface.Views
((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()
{

@ -183,8 +183,8 @@ namespace hass_workstation_service.Communication.InterProcesCommunication
AvailableSensors.LastBootSensor => new LastBootSensor(_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.GPUTemperatureSensor => new GpuTemperatureSensor(_publisher, (int)model.UpdateInterval, model.Name),
AvailableSensors.GPULoadSensor => new GpuLoadSensor(_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),
_ => null
};
}
@ -203,6 +203,7 @@ namespace hass_workstation_service.Communication.InterProcesCommunication
AvailableCommands.RestartCommand => new RestartCommand(_publisher, model.Name),
AvailableCommands.LogOffCommand => new LogOffCommand(_publisher, 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.NextCommand => new NextCommand(_publisher, model.Name),
AvailableCommands.PreviousCommand => new PreviousCommand(_publisher, model.Name),

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

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

@ -46,9 +46,6 @@ namespace hass_workstation_service.Domain.Commands
}
this.State = "OFF";
}
public override CommandDiscoveryConfigModel GetAutoDiscoveryConfig()
{
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
{
public class GpuLoadSensor : AbstractSensor
public class GPULoadSensor : AbstractSensor
{
private Computer _computer;
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
{

@ -9,11 +9,11 @@ using LibreHardwareMonitor.Hardware;
namespace hass_workstation_service.Domain.Sensors
{
public class GpuTemperatureSensor : AbstractSensor
public class GPUTemperatureSensor : AbstractSensor
{
private Computer _computer;
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
{

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

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

Loading…
Cancel
Save