diff --git a/UserInterface/Views/BackgroundServiceSettings.axaml.cs b/UserInterface/Views/BackgroundServiceSettings.axaml.cs index 1789bae..23588c9 100644 --- a/UserInterface/Views/BackgroundServiceSettings.axaml.cs +++ b/UserInterface/Views/BackgroundServiceSettings.axaml.cs @@ -1,88 +1,88 @@ -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; - -namespace UserInterface.Views -{ - public class BackgroundServiceSettings : UserControl - { - private readonly IIpcClient _client; - - public BackgroundServiceSettings() - { - this.InitializeComponent(); - // register IPC clients - ServiceProvider serviceProvider = new ServiceCollection() - .AddNamedPipeIpcClient("broker", pipeName: "pipeinternal") - .BuildServiceProvider(); - - // resolve IPC client factory - IIpcClientFactory clientFactory = serviceProvider - .GetRequiredService>(); - - // create client - this._client = clientFactory.CreateClient("broker"); - - DataContext = new BackgroundServiceSettingsViewModel(); - Ping(); - } - - public async void Ping() - { - while (true) - { - if (DataContext is not BackgroundServiceSettingsViewModel viewModel) - throw new System.Exception("Wrong viewmodel class!"); - - try - { - var result = await this._client.InvokeAsync(x => x.Ping("ping")); - - if (result == "pong") - viewModel.UpdateStatus(true, "All good"); - else - viewModel.UpdateStatus(false, "Not running"); - } - catch (System.Exception) - { - viewModel.UpdateStatus(false, "Not running"); - } - - var autostartresult = await this._client.InvokeAsync(x => x.IsAutoStartEnabled()); - viewModel.UpdateAutostartStatus(autostartresult); - - await Task.Delay(1000); - } - } - - public void Start(object sender, RoutedEventArgs args) - { - //TODO: fix the path. This will depend on the deployment structure. - System.Diagnostics.Process.Start("hass-worstation-service.exe"); - } - - 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); - } - } +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; + +namespace UserInterface.Views +{ + public class BackgroundServiceSettings : UserControl + { + private readonly IIpcClient _client; + + public BackgroundServiceSettings() + { + this.InitializeComponent(); + // register IPC clients + ServiceProvider serviceProvider = new ServiceCollection() + .AddNamedPipeIpcClient("broker", pipeName: "pipeinternal") + .BuildServiceProvider(); + + // resolve IPC client factory + IIpcClientFactory clientFactory = serviceProvider + .GetRequiredService>(); + + // create client + this._client = clientFactory.CreateClient("broker"); + + DataContext = new BackgroundServiceSettingsViewModel(); + Ping(); + } + + public async void Ping() + { + while (true) + { + if (DataContext is not BackgroundServiceSettingsViewModel viewModel) + throw new System.Exception("Wrong viewmodel class!"); + + try + { + var result = await this._client.InvokeAsync(x => x.Ping("ping")); + + if (result == "pong") + viewModel.UpdateStatus(true, "All good"); + else + viewModel.UpdateStatus(false, "Not running"); + } + catch (System.Exception) + { + viewModel.UpdateStatus(false, "Not running"); + } + + var autostartresult = await this._client.InvokeAsync(x => x.IsAutoStartEnabled()); + viewModel.UpdateAutostartStatus(autostartresult); + + await Task.Delay(1000); + } + } + + public void Start(object sender, RoutedEventArgs args) + { + //TODO: fix the path. This will depend on the deployment structure. + System.Diagnostics.Process.Start("hass-worstation-service.exe"); + } + + 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); + } + } } \ No newline at end of file diff --git a/UserInterface/Views/CommandSettings.axaml b/UserInterface/Views/CommandSettings.axaml index dea407b..6998808 100644 --- a/UserInterface/Views/CommandSettings.axaml +++ b/UserInterface/Views/CommandSettings.axaml @@ -5,25 +5,25 @@ mc:Ignorable="d" d:DesignWidth="500" d:DesignHeight="450" x:Class="UserInterface.Views.CommandSettings"> - - - - - - - - - - -