-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
1,323 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using hass_workstation_service.Communication.InterProcesCommunication.Models; | ||
using ReactiveUI; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace UserInterface.ViewModels | ||
{ | ||
public class AddCommandViewModel : ViewModelBase | ||
{ | ||
private AvailableCommands selectedType; | ||
private string description; | ||
|
||
public string Description { get => description; set => this.RaiseAndSetIfChanged(ref description, value); } | ||
public bool ShowCommandInput { get => showCommandInput; set => this.RaiseAndSetIfChanged(ref showCommandInput, value); } | ||
|
||
private string moreInfoLink; | ||
private bool showCommandInput; | ||
|
||
public string MoreInfoLink | ||
{ | ||
get { return moreInfoLink; } | ||
set { this.RaiseAndSetIfChanged(ref moreInfoLink, value); } | ||
} | ||
|
||
public AvailableCommands SelectedType { get => selectedType; set => this.RaiseAndSetIfChanged(ref selectedType, value); } | ||
|
||
public string Name { get; set; } | ||
public string Command { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using ReactiveUI; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace UserInterface.ViewModels | ||
{ | ||
public class CommandSettingsViewModel : ViewModelBase | ||
{ | ||
private ICollection<CommandViewModel> configuredCommands; | ||
|
||
public ICollection<CommandViewModel> ConfiguredCommands { get => configuredCommands; set => this.RaiseAndSetIfChanged(ref configuredCommands, value); } | ||
public void TriggerUpdate() | ||
{ | ||
this.RaisePropertyChanged(); | ||
} | ||
} | ||
|
||
public class CommandViewModel : ViewModelBase | ||
{ | ||
public Guid Id { get; set; } | ||
public string Type { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<Window xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:Class="UserInterface.Views.AddCommandDialog" | ||
SizeToContent="WidthAndHeight" | ||
Title="Add sensor"> | ||
<StackPanel Margin="40" MinWidth="200"> | ||
<ContentControl Margin="0 20 0 10">Sensor type</ContentControl> | ||
|
||
<ComboBox x:Name="ComboBox" SelectionChanged="ComboBoxClosed" SelectedItem="{Binding SelectedType}" MinHeight="27"></ComboBox> | ||
<TextBlock Margin="0 10 0 10" MaxWidth="300" TextWrapping="Wrap" TextAlignment="Left" Text="{Binding Description}"></TextBlock> | ||
<Button IsVisible="{Binding MoreInfoLink, Converter={x:Static StringConverters.IsNotNullOrEmpty}}" Click="OpenInfo" Margin="0 10 0 10">Click for more information.</Button> | ||
<ContentControl Margin="0 20 0 10">Name</ContentControl> | ||
<TextBox Text="{Binding Name}" HorizontalAlignment="Left" MinWidth="150"/> | ||
|
||
|
||
|
||
<TextBlock Text="{Binding UpdateInterval, StringFormat= Update every {0} seconds}" HorizontalAlignment="Left" MinWidth="150"/> | ||
<ContentControl IsVisible="{Binding ShowCommandInput}" Margin="0 20 0 10">Command</ContentControl> | ||
<TextBox IsVisible="{Binding ShowCommandInput}" Text="{Binding Command}" Watermark="Rundll32.exe user32.dll,LockWorkStation" HorizontalAlignment="Left" MinWidth="300"/> | ||
<Button IsVisible="{Binding ShowCommandInput}" Width="75" HorizontalAlignment="Right" Margin="0 40 0 10" Click="Test">Test</Button> | ||
<Button Width="75" HorizontalAlignment="Right" Margin="0 40 0 10" Click="Save">Save</Button> | ||
</StackPanel> | ||
</Window> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Interactivity; | ||
using Avalonia.Markup.Xaml; | ||
using hass_workstation_service.Communication.InterProcesCommunication.Models; | ||
using hass_workstation_service.Communication.NamedPipe; | ||
using JKang.IpcServiceFramework.Client; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using System; | ||
using System.Dynamic; | ||
using System.Linq; | ||
using System.Text.Json; | ||
using UserInterface.Util; | ||
using UserInterface.ViewModels; | ||
|
||
namespace UserInterface.Views | ||
{ | ||
public class AddCommandDialog : Window | ||
{ | ||
private readonly IIpcClient<ServiceContractInterfaces> client; | ||
public ComboBox comboBox { get; set; } | ||
public ComboBox detectionModecomboBox { get; set; } | ||
public AddCommandDialog() | ||
{ | ||
this.InitializeComponent(); | ||
#if DEBUG | ||
this.AttachDevTools(); | ||
#endif | ||
DataContext = new AddCommandViewModel(); | ||
this.comboBox = this.FindControl<ComboBox>("ComboBox"); | ||
this.comboBox.Items = Enum.GetValues(typeof(AvailableCommands)).Cast<AvailableCommands>().OrderBy(v => v.ToString()); | ||
this.comboBox.SelectedIndex = 0; | ||
|
||
// register IPC clients | ||
ServiceProvider serviceProvider = new ServiceCollection() | ||
.AddNamedPipeIpcClient<ServiceContractInterfaces>("addCommand", pipeName: "pipeinternal") | ||
.BuildServiceProvider(); | ||
|
||
// resolve IPC client factory | ||
IIpcClientFactory<ServiceContractInterfaces> clientFactory = serviceProvider | ||
.GetRequiredService<IIpcClientFactory<ServiceContractInterfaces>>(); | ||
|
||
// create client | ||
this.client = clientFactory.CreateClient("addCommand"); | ||
} | ||
|
||
public async void Save(object sender, RoutedEventArgs args) | ||
{ | ||
var item = ((AddCommandViewModel)this.DataContext); | ||
dynamic model = new { item.Name, item.Command}; | ||
string json = JsonSerializer.Serialize(model); | ||
await this.client.InvokeAsync(x => x.AddCommand(item.SelectedType, json)); | ||
Close(); | ||
} | ||
|
||
public void ComboBoxClosed(object sender, SelectionChangedEventArgs args) | ||
{ | ||
var item = ((AddCommandViewModel)this.DataContext); | ||
switch (item.SelectedType) | ||
{ | ||
case AvailableCommands.CustomCommand: | ||
item.Description = "This command lets you execute any command you want. It will run in a Windows Command Prompt silently. "; | ||
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#customcommand"; | ||
item.ShowCommandInput = true; | ||
break; | ||
case AvailableCommands.ShutdownCommand: | ||
item.Description = "This command shuts down the PC immediately. "; | ||
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#shutdowncommand"; | ||
item.ShowCommandInput = false; | ||
break; | ||
case AvailableCommands.RestartCommand: | ||
item.Description = "This command restarts the PC immediately. "; | ||
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#restartcommand"; | ||
item.ShowCommandInput = false; | ||
break; | ||
case AvailableCommands.LogOffCommand: | ||
item.Description = "This command logs the current user off immediately. "; | ||
item.MoreInfoLink = "https://github.com/sleevezipper/hass-workstation-service#logoffcommand"; | ||
item.ShowCommandInput = false; | ||
break; | ||
default: | ||
item.Description = null; | ||
item.MoreInfoLink = null; | ||
item.ShowCommandInput = false; | ||
break; | ||
} | ||
} | ||
public void OpenInfo(object sender, RoutedEventArgs args) | ||
{ | ||
var item = ((AddSensorViewModel)this.DataContext); | ||
BrowserUtil.OpenBrowser(item.MoreInfoLink); | ||
} | ||
|
||
public void Test(object sender, RoutedEventArgs args) | ||
{ | ||
var item = ((AddCommandViewModel)this.DataContext); | ||
|
||
System.Diagnostics.Process process = new System.Diagnostics.Process(); | ||
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); | ||
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; | ||
startInfo.FileName = "cmd.exe"; | ||
startInfo.Arguments = $"/k {"echo You won't see this window normally. &&" + item.Command}"; | ||
process.StartInfo = startInfo; | ||
process.Start(); | ||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<UserControl xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450" | ||
x:Class="UserInterface.Views.AppInfo"> | ||
<StackPanel Margin="30"> | ||
<StackPanel Margin="0 0 0 20" HorizontalAlignment="Left"> | ||
<ContentControl FontSize="18" FontWeight="Bold" >Info</ContentControl> | ||
<TextBlock Text="Need some help?" Margin="0 0 0 20"></TextBlock > | ||
<StackPanel Margin="0 0 0 20" HorizontalAlignment="Left" Orientation="Horizontal"> | ||
<Button Width="75" HorizontalAlignment="Right" Margin="10 10" Click="Github">Github</Button> | ||
<Button Width="75" HorizontalAlignment="Left" Margin="10 10" Click="Discord">Discord</Button> | ||
</StackPanel> | ||
</StackPanel> | ||
</StackPanel> | ||
</UserControl> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Markup.Xaml; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using hass_workstation_service.Communication.NamedPipe; | ||
using JKang.IpcServiceFramework.Client; | ||
using System.Threading.Tasks; | ||
using Avalonia.Interactivity; | ||
using System.Reactive.Linq; | ||
using UserInterface.ViewModels; | ||
using System.Security; | ||
using hass_workstation_service.Communication.InterProcesCommunication.Models; | ||
using UserInterface.Util; | ||
|
||
namespace UserInterface.Views | ||
{ | ||
public class AppInfo : UserControl | ||
{ | ||
private readonly IIpcClient<ServiceContractInterfaces> client; | ||
|
||
public AppInfo() | ||
{ | ||
this.InitializeComponent(); | ||
// register IPC clients | ||
ServiceProvider serviceProvider = new ServiceCollection() | ||
.AddNamedPipeIpcClient<ServiceContractInterfaces>("broker", pipeName: "pipeinternal") | ||
.BuildServiceProvider(); | ||
|
||
// resolve IPC client factory | ||
IIpcClientFactory<ServiceContractInterfaces> clientFactory = serviceProvider | ||
.GetRequiredService<IIpcClientFactory<ServiceContractInterfaces>>(); | ||
|
||
// create client | ||
this.client = clientFactory.CreateClient("broker"); | ||
|
||
|
||
DataContext = new BackgroundServiceSettingsViewModel(); | ||
Ping(); | ||
} | ||
public async void Ping() { | ||
while (true) | ||
{ | ||
try | ||
{ | ||
var result = await this.client.InvokeAsync(x => x.Ping("ping")); | ||
if (result == "pong") | ||
{ | ||
((BackgroundServiceSettingsViewModel)this.DataContext).UpdateStatus(true, "All good"); | ||
} | ||
else | ||
{ | ||
((BackgroundServiceSettingsViewModel)this.DataContext).UpdateStatus(false, "Not running"); | ||
} | ||
} | ||
catch (System.Exception) | ||
{ | ||
((BackgroundServiceSettingsViewModel)this.DataContext).UpdateStatus(false, "Not running"); | ||
} | ||
|
||
var autostartresult = await this.client.InvokeAsync(x => x.IsAutoStartEnabled()); | ||
((BackgroundServiceSettingsViewModel)this.DataContext).UpdateAutostartStatus(autostartresult); | ||
|
||
await Task.Delay(1000); | ||
} | ||
} | ||
|
||
public void Github(object sender, RoutedEventArgs args) | ||
{ | ||
BrowserUtil.OpenBrowser("https://github.com/sleevezipper/hass-workstation-service"); | ||
} | ||
|
||
public void Discord(object sender, RoutedEventArgs args) | ||
{ | ||
BrowserUtil.OpenBrowser("https://discord.gg/VraYT2N3wd"); | ||
} | ||
|
||
public void EnableAutostart(object sender, RoutedEventArgs args) | ||
{ | ||
this.client.InvokeAsync(x => x.EnableAutostart(true)); | ||
} | ||
public void DisableAutostart(object sender, RoutedEventArgs args) | ||
{ | ||
this.client.InvokeAsync(x => x.EnableAutostart(false)); | ||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
} | ||
} |
Oops, something went wrong.