From d32f881c4e2b046179a4452bc6faf9ee819fb03e Mon Sep 17 00:00:00 2001 From: Jason Dove Date: Fri, 18 Mar 2022 13:36:38 -0500 Subject: [PATCH] use cliwrap for windows wrapper (#710) --- ErsatzTV-Windows/ErsatzTV-Windows.csproj | 2 +- ErsatzTV-Windows/TrayApplicationContext.cs | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/ErsatzTV-Windows/ErsatzTV-Windows.csproj b/ErsatzTV-Windows/ErsatzTV-Windows.csproj index db3d6b6f6..598e68eaa 100644 --- a/ErsatzTV-Windows/ErsatzTV-Windows.csproj +++ b/ErsatzTV-Windows/ErsatzTV-Windows.csproj @@ -17,7 +17,7 @@ - + diff --git a/ErsatzTV-Windows/TrayApplicationContext.cs b/ErsatzTV-Windows/TrayApplicationContext.cs index 18a4e3fa6..8ae26f295 100644 --- a/ErsatzTV-Windows/TrayApplicationContext.cs +++ b/ErsatzTV-Windows/TrayApplicationContext.cs @@ -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 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 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 protected override void Dispose(bool disposing) { - _childProcess?.Dispose(); + _tokenSource?.Cancel(); base.Dispose(disposing); }