diff --git a/src/desktop/updater-runner.js b/src/desktop/updater-runner.js index c4013e4..567ee2f 100644 --- a/src/desktop/updater-runner.js +++ b/src/desktop/updater-runner.js @@ -129,37 +129,25 @@ const spawnDetachedWindowsRestart = ({ appLaunchPath, parentPid }) => { ) const scriptPath = path.join(updateDir, `restart-${parentPid}.bat`) const appLaunchWin = appLaunchPath.replaceAll('/', '\\') - const scriptWin = scriptPath.replaceAll('/', '\\') + const appDirWin = path.dirname(appLaunchWin) const script = `@echo off setlocal set "PARENT_PID=${parentPid}" set "APP_LAUNCHER=${appLaunchWin}" +set "APP_DIR=${appDirWin}" :waitparent -tasklist /FI "PID eq %PARENT_PID%" 2>NUL | find /I "%PARENT_PID%" >NUL && ( +tasklist /FI "PID eq %PARENT_PID%" 2>NUL | find "%PARENT_PID%" >NUL && ( timeout /t 1 /nobreak >nul goto waitparent ) -:waitprocesses -tasklist /FI "IMAGENAME eq launcher.exe" 2>NUL | find /I /N "launcher.exe">NUL && goto waitsleep -tasklist /FI "IMAGENAME eq bun.exe" 2>NUL | find /I /N "bun.exe">NUL && goto waitsleep -tasklist 2>NUL | find /I "bun Helper">NUL && goto waitsleep -goto waitdone -:waitsleep -timeout /t 1 /nobreak >nul -goto waitprocesses -:waitdone - timeout /t 2 /nobreak >nul +cd /d "%APP_DIR%" start "" "%APP_LAUNCHER%" -for /f "tokens=1" %%t in ('schtasks /query /fo list ^| findstr /i "FarmControlRestart_"') do ( - schtasks /delete /tn "%%t" /f >nul 2>&1 -) - ping -n 2 127.0.0.1 >nul del "%~f0" ` @@ -167,15 +155,12 @@ del "%~f0" mkdirSync(updateDir, { recursive: true }) writeFileSync(scriptPath, script, 'utf8') - const taskName = `FarmControlRestart_${parentPid}_${Date.now()}` - execSync( - `schtasks /create /tn ${quoteBatchArg(taskName)} /tr ${quoteBatchArg(`cmd /c "${scriptWin}"`)} /sc once /st 00:00 /f`, - { stdio: 'ignore', windowsHide: true } - ) - execSync(`schtasks /run /tn ${quoteBatchArg(taskName)}`, { + const child = spawn('cmd.exe', ['/c', scriptPath], { + detached: true, stdio: 'ignore', windowsHide: true }) + child.unref() } export const scheduleAppRestart = ({ parentPid = process.pid } = {}) => {