show current service version in ui

pull/56/head
Sleevezipper 4 years ago
parent 1fd6e14115
commit d0125dc947

@ -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;
}
}
}

@ -7,6 +7,7 @@
<StackPanel Margin="30">
<StackPanel Margin="0 0 0 20" HorizontalAlignment="Left">
<ContentControl FontSize="18" FontWeight="Bold" >Info</ContentControl>
<TextBlock Text="{Binding ServiceVersion}" Margin="0 0 0 20"></TextBlock >
<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>

@ -23,7 +23,7 @@ namespace UserInterface.Views
this.InitializeComponent();
// register IPC clients
ServiceProvider serviceProvider = new ServiceCollection()
.AddNamedPipeIpcClient<ServiceContractInterfaces>("broker", pipeName: "pipeinternal")
.AddNamedPipeIpcClient<ServiceContractInterfaces>("info", pipeName: "pipeinternal")
.BuildServiceProvider();
// resolve IPC client factory
@ -31,36 +31,25 @@ namespace UserInterface.Views
.GetRequiredService<IIpcClientFactory<ServiceContractInterfaces>>();
// 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 @@ namespace UserInterface.Views
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);

@ -12,24 +12,15 @@
<Design.DataContext>
<vm:MainWindowViewModel/>
</Design.DataContext>
<ScrollViewer Height="700">
<Grid ColumnDefinitions="Auto,1*,Auto" RowDefinitions="Auto,Auto" Margin="30" VerticalAlignment="Stretch">
<ScrollViewer Height="700" VerticalScrollBarVisibility="Visible">
<Grid ColumnDefinitions="Auto,1*,Auto" RowDefinitions="Auto,Auto,Auto" Margin="30" VerticalAlignment="Stretch">
<views:BrokerSettings Grid.Column="0" Grid.Row="0" Margin="10 0" Grid.RowSpan="2" Background="#2D2D30"/>
<views:SensorSettings Grid.Column="1" Grid.Row="0" Margin="10 0" Background="#2D2D30"/>
<views:CommandSettings Grid.Column="1" Grid.Row="1" Margin="0 10 0 0" Background="#2D2D30"/>
<views:BackgroundServiceSettings Grid.Column="2" Grid.Row="0" Margin="10 0" Background="#2D2D30"/>
<views:AppInfo Grid.Column="2" Grid.Row="1" Margin="10 10 10 0" Background="#2D2D30"/>
<!--<views:BrokerSettings Grid.Column="1" Grid.Row="0"/>
<views:BrokerSettings Grid.Column="2" Grid.Row="0"/>-->
<!--<TextBlock Text="Col0Row0:" Grid.Row="0" Grid.Column="0"/>
<TextBlock Text="Col0Row1:" Grid.Row="1" Grid.Column="0"/>
<TextBlock Text="Col0Row2:" Grid.Row="2" Grid.Column="0"/>
<CheckBox Content="Col2Row0" Grid.Row="0" Grid.Column="2"/>
<Button Content="SpansCol1-2Row1-2" Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" Grid.ColumnSpan="2"/>-->
</Grid>
</ScrollViewer>
<!--<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center"/>-->
</Window>

@ -225,5 +225,10 @@ namespace hass_workstation_service.Communication.InterProcesCommunication
this._configurationService.AddConfiguredCommand(commandToCreate);
}
}
public string GetCurrentVersion()
{
return Program.GetVersion();
}
}
}

@ -20,5 +20,6 @@ namespace hass_workstation_service.Communication.NamedPipe
void RemoveCommandById(Guid id);
List<ConfiguredCommandModel> GetConfiguredCommands();
void AddCommand(AvailableCommands commandType, string json);
string GetCurrentVersion();
}
}

Loading…
Cancel
Save