livedesk 0.1.273 → 0.1.274
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/hub/src/live-desk-update.js +11 -7
- package/package.json +1 -1
|
@@ -64,22 +64,26 @@ function buildUnixLegacyUpdateCommand({ manager, pair, name, slot, targetVersion
|
|
|
64
64
|
const script = [
|
|
65
65
|
'const { execFileSync, spawn } = require("node:child_process");',
|
|
66
66
|
'const fs = require("node:fs");',
|
|
67
|
-
'const os = require("node:os");',
|
|
68
67
|
'const path = require("node:path");',
|
|
69
|
-
'const self = process.pid;',
|
|
70
68
|
'const parentOf = pid => { try { return Number(execFileSync("ps", ["-o", "ppid=", "-p", String(pid)], { encoding: "utf8" }).trim()) || 0; } catch { return 0; } };',
|
|
71
69
|
'const commandOf = pid => { try { return execFileSync("ps", ["-o", "command=", "-p", String(pid)], { encoding: "utf8" }); } catch { return ""; } };',
|
|
72
|
-
'
|
|
70
|
+
'const isAlive = pid => { try { process.kill(pid, 0); return true; } catch { return false; } };',
|
|
71
|
+
'const configuredLauncherPid = Number(process.env.LIVEDESK_CLIENT_PARENT_PID || 0);',
|
|
72
|
+
'let launcherPid = Number.isInteger(configuredLauncherPid) && configuredLauncherPid > 1 && isAlive(configuredLauncherPid) ? configuredLauncherPid : 0;',
|
|
73
|
+
'let cursor = parentOf(process.pid);',
|
|
73
74
|
'for (let depth = 0; depth < 12 && cursor; depth++) { const command = commandOf(cursor); if (/livedesk-client\\.js|livedesk\\.js/i.test(command)) { launcherPid = cursor; break; } cursor = parentOf(cursor); }',
|
|
74
|
-
'
|
|
75
|
+
'const waitPid = launcherPid > 1 ? launcherPid : process.pid;',
|
|
75
76
|
`process.env.LIVEDESK_CLIENT_MANAGER = ${JSON.stringify(String(manager || ''))};`,
|
|
76
77
|
`process.env.LIVEDESK_CLIENT_PAIR_TOKEN = ${JSON.stringify(String(pair || ''))};`,
|
|
77
78
|
`process.env.LIVEDESK_CLIENT_NAME = ${JSON.stringify(String(name || ''))};`,
|
|
78
79
|
`process.env.LIVEDESK_CLIENT_SLOT = ${JSON.stringify(String(slot || ''))};`,
|
|
79
80
|
`process.env.LIVEDESK_CLIENT_UPDATE_TARGET_VERSION = ${JSON.stringify(String(targetVersion || ''))};`,
|
|
80
|
-
'const
|
|
81
|
-
'
|
|
82
|
-
'
|
|
81
|
+
'const nodeDir = path.dirname(process.execPath);',
|
|
82
|
+
'const npxCandidates = [process.env.LIVEDESK_NPX_EXECUTABLE, path.join(nodeDir, process.platform === "win32" ? "npx.cmd" : "npx"), process.platform === "win32" ? "npx.cmd" : "npx"].filter(Boolean);',
|
|
83
|
+
'const npx = npxCandidates.find(candidate => !path.isAbsolute(candidate) || fs.existsSync(candidate)) || npxCandidates[npxCandidates.length - 1];',
|
|
84
|
+
'const updater = spawn(npx, ["-y", "--prefer-online", "livedesk@latest", "client", "--no-login", "--update-wait-pid", String(waitPid)], { detached: true, stdio: "ignore", env: process.env });',
|
|
85
|
+
'updater.once("error", error => { console.error(`LiveDesk updater failed to start: ${error.message}`); process.exitCode = 1; });',
|
|
86
|
+
'updater.once("spawn", () => { updater.unref(); if (waitPid !== process.pid) setTimeout(() => { try { process.kill(waitPid, "SIGTERM"); } catch {} }, 500); });',
|
|
83
87
|
''
|
|
84
88
|
].join('\n');
|
|
85
89
|
return `node -e ${JSON.stringify(script)}`;
|