Browse Source

use cliwrap for windows wrapper (#710)

pull/711/head
Jason Dove 4 years ago committed by GitHub
parent
commit
d32f881c4e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      ErsatzTV-Windows/ErsatzTV-Windows.csproj
  2. 16
      ErsatzTV-Windows/TrayApplicationContext.cs

2
ErsatzTV-Windows/ErsatzTV-Windows.csproj

@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Asmichi.ChildProcess" Version="0.11.0" />
<PackageReference Include="CliWrap" Version="3.4.2" />
</ItemGroup>
<ItemGroup>

16
ErsatzTV-Windows/TrayApplicationContext.cs

@ -1,14 +1,13 @@ @@ -1,14 +1,13 @@
using ErsatzTV.Core;
using System.Diagnostics;
using Asmichi.ProcessManagement;
using System.Reflection;
using CliWrap;
namespace ErsatzTV_Windows;
public class TrayApplicationContext : ApplicationContext
{
private readonly NotifyIcon _trayIcon;
private readonly IChildProcess? _childProcess;
private readonly CancellationTokenSource _tokenSource;
public TrayApplicationContext()
{
@ -19,6 +18,8 @@ public class TrayApplicationContext : ApplicationContext @@ -19,6 +18,8 @@ public class TrayApplicationContext : ApplicationContext
Visible = true
};
_tokenSource = new CancellationTokenSource();
AddMenuItem("Launch Web UI", LaunchWebUI);
AddMenuItem("Show Logs", ShowLogs);
_trayIcon.ContextMenuStrip.Items.Add(new ToolStripSeparator());
@ -29,8 +30,11 @@ public class TrayApplicationContext : ApplicationContext @@ -29,8 +30,11 @@ public class TrayApplicationContext : ApplicationContext
if (File.Exists(exe))
{
var si = new ChildProcessStartInfo(exe);
_childProcess = ChildProcess.Start(si);
Cli.Wrap(exe)
.WithWorkingDirectory(folder)
.WithValidation(CommandResultValidation.None)
.ExecuteAsync(_tokenSource.Token);
}
}
@ -64,7 +68,7 @@ public class TrayApplicationContext : ApplicationContext @@ -64,7 +68,7 @@ public class TrayApplicationContext : ApplicationContext
protected override void Dispose(bool disposing)
{
_childProcess?.Dispose();
_tokenSource?.Cancel();
base.Dispose(disposing);
}

Loading…
Cancel
Save