diff --git a/src/Jackett.Common/Services/TrayLockService.cs b/src/Jackett.Common/Services/TrayLockService.cs index a267a3f99..58c46f391 100644 --- a/src/Jackett.Common/Services/TrayLockService.cs +++ b/src/Jackett.Common/Services/TrayLockService.cs @@ -7,7 +7,7 @@ namespace Jackett.Common.Services public class TrayLockService : ITrayLockService { - private readonly string EVENT_HANDLE_NAME = "JACKETT.TRAY"; + private readonly string EVENT_HANDLE_NAME = @"Global\JACKETT.TRAY"; private EventWaitHandle GetEventHandle() { diff --git a/src/Jackett.Common/Services/UpdateService.cs b/src/Jackett.Common/Services/UpdateService.cs index 56f538280..2bde084e1 100644 --- a/src/Jackett.Common/Services/UpdateService.cs +++ b/src/Jackett.Common/Services/UpdateService.cs @@ -268,14 +268,14 @@ namespace Jackett.Common.Services return tempDir; } - private void StartUpdate(string updaterExePath, string installLocation, bool isWindows, bool NoRestart, bool trayWasRunning) + private void StartUpdate(string updaterExePath, string installLocation, bool isWindows, bool NoRestart, bool trayIsRunning) { string appType = "Console"; //DI once off Owin IProcessService processService = new ProcessService(logger); IServiceConfigService windowsService = new WindowsServiceConfigService(processService, logger); - if (isWindows && windowsService.ServiceExists()) + if (isWindows && windowsService.ServiceExists() && windowsService.ServiceRunning()) { appType = "WindowsService"; } @@ -319,18 +319,25 @@ namespace Jackett.Common.Services startInfo.Arguments += " --NoRestart"; } - if (trayWasRunning) + if (trayIsRunning && appType == "Console") { startInfo.Arguments += " --StartTray"; } + if (isWindows) + { + lockService.Signal(); + logger.Info("Signal sent to lock service"); + Thread.Sleep(2000); + } + logger.Info($"Starting updater: {startInfo.FileName} {startInfo.Arguments}"); var procInfo = Process.Start(startInfo); logger.Info($"Updater started process id: {procInfo.Id}"); - if (NoRestart == false) + + if (!NoRestart) { logger.Info("Exiting Jackett.."); - lockService.Signal(); //TODO: Remove once off Owin if (EnvironmentUtil.IsRunningLegacyOwin) { diff --git a/src/Jackett.Tray/Main.cs b/src/Jackett.Tray/Main.cs index c78655344..bf8bda3b1 100644 --- a/src/Jackett.Tray/Main.cs +++ b/src/Jackett.Tray/Main.cs @@ -65,6 +65,8 @@ namespace Jackett.Tray StartConsoleApplication(); } + updatedVersion = updatedVersion.Equals("yes", StringComparison.OrdinalIgnoreCase) ? EnvironmentUtil.JackettVersion : updatedVersion; + if (!string.IsNullOrWhiteSpace(updatedVersion)) { notifyIcon1.BalloonTipTitle = "Jackett"; @@ -81,6 +83,27 @@ namespace Jackett.Tray { trayLockService.WaitForSignal(); logger.Info("Received signal from tray lock service"); + + if (windowsService.ServiceExists() && windowsService.ServiceRunning()) + { + //We won't be able to start the tray app up again from the updater, as when running via a windows service there is no interaction with the desktop + //Fire off a console process that will start the tray 20 seconds later + + string trayExePath = Assembly.GetEntryAssembly().Location; + + var startInfo = new ProcessStartInfo() + { + Arguments = $"/c timeout 20 > NUL & \"{trayExePath}\" --UpdatedVersion yes", + FileName = "cmd.exe", + UseShellExecute = true, + CreateNoWindow = true, + WindowStyle = ProcessWindowStyle.Hidden + }; + + logger.Info("Starting 20 second delay tray launch as Jackett is running as a Windows service: " + startInfo.FileName + " " + startInfo.Arguments); + Process.Start(startInfo); + } + CloseTrayApplication(); } diff --git a/src/Jackett.Updater/Program.cs b/src/Jackett.Updater/Program.cs index f8b29253a..50a55527a 100644 --- a/src/Jackett.Updater/Program.cs +++ b/src/Jackett.Updater/Program.cs @@ -43,9 +43,9 @@ namespace Jackett.Updater { //The updater starts before Jackett closes logger.Info("Pausing for 3 seconds to give Jackett & tray time to shutdown"); - System.Threading.Tasks.Task.Delay(3000); + System.Threading.Thread.Sleep(3000); } - + processService = new ProcessService(logger); windowsService = new WindowsServiceConfigService(processService, logger); @@ -256,7 +256,7 @@ namespace Jackett.Updater if (options.NoRestart == false) { - if (isWindows && (trayRunning || options.StartTray)) + if (isWindows && (trayRunning || options.StartTray) && !string.Equals(options.Type, "WindowsService", StringComparison.OrdinalIgnoreCase)) { var startInfo = new ProcessStartInfo() { @@ -275,7 +275,7 @@ namespace Jackett.Updater } } - if (string.Equals(options.Type, "WindowsService", StringComparison.InvariantCultureIgnoreCase)) + if (string.Equals(options.Type, "WindowsService", StringComparison.OrdinalIgnoreCase)) { logger.Info("Starting Windows service");