diff --git a/UserInterface/ViewModels/InfoViewModel.cs b/UserInterface/ViewModels/InfoViewModel.cs new file mode 100644 index 0000000..77bc347 --- /dev/null +++ b/UserInterface/ViewModels/InfoViewModel.cs @@ -0,0 +1,22 @@ +using hass_workstation_service.Communication.InterProcesCommunication.Models; +using ReactiveUI; +using System; +using System.Collections.Generic; +using System.Text; + +namespace UserInterface.ViewModels +{ + public class InfoViewModel : ViewModelBase + { + private string serviceVersion; + + + public string ServiceVersion { get => "Service version: " + serviceVersion; private set => this.RaiseAndSetIfChanged(ref serviceVersion, value); } + + public void UpdateServiceVersion(string version) + { + this.ServiceVersion = version; + } + + } +} diff --git a/UserInterface/Views/AddCommandDialog.axaml.cs b/UserInterface/Views/AddCommandDialog.axaml.cs index b8590d6..a1ed877 100644 --- a/UserInterface/Views/AddCommandDialog.axaml.cs +++ b/UserInterface/Views/AddCommandDialog.axaml.cs @@ -53,7 +53,7 @@ public async void Save(object sender, RoutedEventArgs args) public void ComboBoxClosed(object sender, SelectionChangedEventArgs args) { var item = ((AddCommandViewModel)this.DataContext); - switch (item.SelectedType) + switch (this.comboBox.SelectedItem) { case AvailableCommands.CustomCommand: item.Description = "This command lets you execute any command you want. It will run in a Windows Command Prompt silently. "; diff --git a/UserInterface/Views/AddSensorDialog.axaml.cs b/UserInterface/Views/AddSensorDialog.axaml.cs index c1543d1..8c12a81 100644 --- a/UserInterface/Views/AddSensorDialog.axaml.cs +++ b/UserInterface/Views/AddSensorDialog.axaml.cs @@ -53,7 +53,7 @@ public async void Save(object sender, RoutedEventArgs args) public void ComboBoxClosed(object sender, SelectionChangedEventArgs args) { var item = ((AddSensorViewModel)this.DataContext); - switch (item.SelectedType) + switch (this.comboBox.SelectedItem) { case AvailableSensors.UserNotificationStateSensor: item.Description = "This sensor watches the UserNotificationState. This is normally used in applications to determine if it is appropriate to send a notification but we can use it to expose this state. \n "; diff --git a/UserInterface/Views/AppInfo.axaml b/UserInterface/Views/AppInfo.axaml index 33e766f..afab0c5 100644 --- a/UserInterface/Views/AppInfo.axaml +++ b/UserInterface/Views/AppInfo.axaml @@ -7,6 +7,7 @@ Info + diff --git a/UserInterface/Views/AppInfo.axaml.cs b/UserInterface/Views/AppInfo.axaml.cs index 0fda95c..388d13c 100644 --- a/UserInterface/Views/AppInfo.axaml.cs +++ b/UserInterface/Views/AppInfo.axaml.cs @@ -23,7 +23,7 @@ public AppInfo() this.InitializeComponent(); // register IPC clients ServiceProvider serviceProvider = new ServiceCollection() - .AddNamedPipeIpcClient("broker", pipeName: "pipeinternal") + .AddNamedPipeIpcClient("info", pipeName: "pipeinternal") .BuildServiceProvider(); // resolve IPC client factory @@ -31,36 +31,25 @@ public AppInfo() .GetRequiredService>(); // create client - this.client = clientFactory.CreateClient("broker"); + this.client = clientFactory.CreateClient("info"); - DataContext = new BackgroundServiceSettingsViewModel(); - Ping(); + + + DataContext = new InfoViewModel(); + UpdateVersion(); } - public async void Ping() { - while (true) + public async void UpdateVersion() { + + try { - 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 result = await this.client.InvokeAsync(x => x.GetCurrentVersion()); + ((InfoViewModel)this.DataContext).UpdateServiceVersion(result); - var autostartresult = await this.client.InvokeAsync(x => x.IsAutoStartEnabled()); - ((BackgroundServiceSettingsViewModel)this.DataContext).UpdateAutostartStatus(autostartresult); + } + catch (System.Exception) + { - await Task.Delay(1000); } } @@ -74,15 +63,6 @@ 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); diff --git a/UserInterface/Views/MainWindow.axaml b/UserInterface/Views/MainWindow.axaml index c8f2cc3..1da7f05 100644 --- a/UserInterface/Views/MainWindow.axaml +++ b/UserInterface/Views/MainWindow.axaml @@ -12,23 +12,15 @@ - - + + - - - - + diff --git a/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs b/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs index e78985b..2846115 100644 --- a/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs +++ b/hass-workstation-service/Communication/InterProcesCommunication/InterProcessApi.cs @@ -225,5 +225,10 @@ public void AddCommand(AvailableCommands commandType, string json) this._configurationService.AddConfiguredCommand(commandToCreate); } } + + public string GetCurrentVersion() + { + return Program.GetVersion(); + } } } diff --git a/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractInterfaces.cs b/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractInterfaces.cs index b7f9dc3..57c29f6 100644 --- a/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractInterfaces.cs +++ b/hass-workstation-service/Communication/InterProcesCommunication/ServiceContractInterfaces.cs @@ -20,5 +20,6 @@ public interface ServiceContractInterfaces void RemoveCommandById(Guid id); List GetConfiguredCommands(); void AddCommand(AvailableCommands commandType, string json); + string GetCurrentVersion(); } } diff --git a/hass-workstation-service/Communication/MQTT/MqttPublisher.cs b/hass-workstation-service/Communication/MQTT/MqttPublisher.cs index 93f82a5..bcdd12f 100644 --- a/hass-workstation-service/Communication/MQTT/MqttPublisher.cs +++ b/hass-workstation-service/Communication/MQTT/MqttPublisher.cs @@ -80,7 +80,7 @@ public MqttPublisher( // configure what happens on disconnect this._mqttClient.UseDisconnectedHandler(e => { - this._mqttClientMessage = e.Reason.ToString(); + this._mqttClientMessage = e.ReasonCode.ToString(); }); } diff --git a/hass-workstation-service/Data/ConfigurationService.cs b/hass-workstation-service/Data/ConfigurationService.cs index 208f252..db11c32 100644 --- a/hass-workstation-service/Data/ConfigurationService.cs +++ b/hass-workstation-service/Data/ConfigurationService.cs @@ -226,7 +226,6 @@ public async Task GetMqttClientOptionsAsync() .WithTls(new MqttClientOptionsBuilderTlsParameters() { UseTls = configuredBroker.UseTLS, - SslProtocol = System.Security.Authentication.SslProtocols.Tls12, AllowUntrustedCertificates = true }) .WithCredentials(configuredBroker.Username, configuredBroker.Password.ToString()) diff --git a/hass-workstation-service/Properties/PublishProfiles/AzureHosted.pubxml b/hass-workstation-service/Properties/PublishProfiles/AzureHosted.pubxml index 4bf6060..f64505d 100644 --- a/hass-workstation-service/Properties/PublishProfiles/AzureHosted.pubxml +++ b/hass-workstation-service/Properties/PublishProfiles/AzureHosted.pubxml @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121. --> - 39 + 40 1.0.0.* True Release diff --git a/hass-workstation-service/UserInterface.exe b/hass-workstation-service/UserInterface.exe index 7ef0348..cf168c1 100644 Binary files a/hass-workstation-service/UserInterface.exe and b/hass-workstation-service/UserInterface.exe differ diff --git a/hass-workstation-service/hass-workstation-service.csproj b/hass-workstation-service/hass-workstation-service.csproj index cf89a3f..6a31982 100644 --- a/hass-workstation-service/hass-workstation-service.csproj +++ b/hass-workstation-service/hass-workstation-service.csproj @@ -24,6 +24,7 @@ + @@ -32,14 +33,17 @@ - - Always + + PreserveNewest - Always + PreserveNewest + + + PreserveNewest - Always + PreserveNewest @@ -54,8 +58,8 @@ - - + + @@ -67,8 +71,4 @@ ..\lib\CoreAudio.dll - - - - diff --git a/hass-workstation-service/hass-workstation-service.exe b/hass-workstation-service/hass-workstation-service.exe index 387fa26..1f4de5b 100644 Binary files a/hass-workstation-service/hass-workstation-service.exe and b/hass-workstation-service/hass-workstation-service.exe differ