You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hass-workstation-service/UserInterface/Views/AppInfo.axaml.cs

86 lines
2.7 KiB

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;
using System;
using System.IO;
using System.Diagnostics;
namespace UserInterface.Views
{
public class AppInfo : UserControl
{
private readonly IIpcClient<IServiceContractInterfaces> client;
private readonly string _basePath;
public AppInfo()
{
this.InitializeComponent();
// register IPC clients
ServiceProvider serviceProvider = new ServiceCollection()
.AddNamedPipeIpcClient<IServiceContractInterfaces>("info", pipeName: "pipeinternal")
.BuildServiceProvider();
// resolve IPC client factory
IIpcClientFactory<IServiceContractInterfaces> clientFactory = serviceProvider
.GetRequiredService<IIpcClientFactory<IServiceContractInterfaces>>();
// create client
this.client = clientFactory.CreateClient("info");
this._basePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Hass Workstation Service");
DataContext = new InfoViewModel();
UpdateVersion();
}
public async void UpdateVersion() {
try
{
var result = await this.client.InvokeAsync(x => x.GetCurrentVersion());
((InfoViewModel)this.DataContext).UpdateServiceVersion(result);
}
catch (System.Exception)
{
}
}
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 OpenLogDirectory(object sender, RoutedEventArgs args)
{
string path = Path.Combine(this._basePath, "logs");
Process.Start("explorer.exe", path);
}
public void OpenConfigDirectory(object sender, RoutedEventArgs args)
{
Process.Start("explorer.exe", this._basePath);
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}