core: improve windows tray launcher code. resolves #10094 (#10125)

This commit is contained in:
Diego Heras 2020-11-07 03:08:35 +01:00 committed by GitHub
parent 2abbdc409f
commit 3050f7bc95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 7 deletions

View File

@ -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'))

19
jackett_launcher.bat Executable file
View File

@ -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

View File

@ -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);
}