From 3050f7bc951dc55834ade9f19c19af74007e11f8 Mon Sep 17 00:00:00 2001 From: Diego Heras Date: Sat, 7 Nov 2020 03:08:35 +0100 Subject: [PATCH] core: improve windows tray launcher code. resolves #10094 (#10125) --- azure-pipelines.yml | 8 ++++++++ jackett_launcher.bat | 19 +++++++++++++++++++ src/Jackett.Tray/Main.cs | 12 +++++------- 3 files changed, 32 insertions(+), 7 deletions(-) create mode 100755 jackett_launcher.bat diff --git a/azure-pipelines.yml b/azure-pipelines.yml index e66405030..8ffaa9391 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -165,6 +165,14 @@ stages: contents: JackettService* targetFolder: $(Build.BinariesDirectory)/Jackett + - task: CopyFiles@2 + displayName: Copy Windows Specific Scripts (Windows only) + condition: and(succeeded(), startsWith(variables['runtime'], 'win')) + inputs: + SourceFolder: $(Build.SourcesDirectory) + contents: jackett_launcher.bat + targetFolder: $(Build.BinariesDirectory)/Jackett + - task: CopyFiles@2 displayName: Copy Mono Specific Scripts condition: and(succeeded(), startsWith(variables['buildDescription'], 'Mono')) diff --git a/jackett_launcher.bat b/jackett_launcher.bat new file mode 100755 index 000000000..79eae9cec --- /dev/null +++ b/jackett_launcher.bat @@ -0,0 +1,19 @@ +:: Helper script to fix +:: https://github.com/Jackett/Jackett/issues/10068 + +@echo off + +:: Wait until the updater ends +:loop +tasklist | find /i "JackettUpdater.exe" > nul 2>&1 +if errorlevel 1 ( + goto continue +) else ( + echo JackettUpdater is still running + ping -n 2 127.0.0.1 > nul + goto loop +) + +:: Start Jackett Tray +:continue +start "" "%0\..\JackettTray.exe" --UpdatedVersion yes diff --git a/src/Jackett.Tray/Main.cs b/src/Jackett.Tray/Main.cs index 0e97f4883..e3263c713 100644 --- a/src/Jackett.Tray/Main.cs +++ b/src/Jackett.Tray/Main.cs @@ -94,22 +94,20 @@ namespace Jackett.Tray 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 30 seconds later - // changed to 120 seconds as a result of https://github.com/Jackett/Jackett/issues/10068 - var trayExePath = Process.GetCurrentProcess().MainModule.FileName; + // 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. + var scriptPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "jackett_launcher.bat"); var startInfo = new ProcessStartInfo() { - Arguments = $"/c timeout 120 > NUL & \"{trayExePath}\" --UpdatedVersion yes", + Arguments = $"/c \"{scriptPath}\"", FileName = "cmd.exe", UseShellExecute = true, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }; - logger.Info($"Starting 120 second delay tray launch as Jackett is running as a Windows service: {startInfo.FileName} {startInfo.Arguments}"); + logger.Info($"Starting launcher script as Jackett is running as a Windows service: {startInfo.FileName} {startInfo.Arguments}"); Process.Start(startInfo); }