livedesk 0.1.278 → 0.1.280
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 +42 -17
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { randomUUID } from 'node:crypto';
|
|
2
2
|
|
|
3
3
|
export const LIVE_DESK_UPDATE_COMMAND = 'livedesk.client-update';
|
|
4
|
-
export const LIVE_DESK_DEDICATED_CLIENT_UPDATE_MIN_VERSION = '0.1.
|
|
4
|
+
export const LIVE_DESK_DEDICATED_CLIENT_UPDATE_MIN_VERSION = '0.1.141';
|
|
5
5
|
export const LIVE_DESK_UPDATE_TIMEOUT_MS = 120_000;
|
|
6
6
|
export const LIVE_DESK_UPDATE_CHECK_INTERVAL_MS = 60_000;
|
|
7
7
|
|
|
@@ -54,19 +54,43 @@ function buildWindowsLegacyUpdateCommand({ manager, pair, name, slot, targetVers
|
|
|
54
54
|
`$env:LIVEDESK_CLIENT_NAME = ${quotePowerShell(name)}`,
|
|
55
55
|
`$env:LIVEDESK_CLIENT_SLOT = ${quotePowerShell(slot || '')}`,
|
|
56
56
|
`$env:LIVEDESK_CLIENT_UPDATE_TARGET_VERSION = ${quotePowerShell(targetVersion)}`,
|
|
57
|
-
'$
|
|
58
|
-
'if ($
|
|
59
|
-
'if (-not $
|
|
60
|
-
'if (-not $
|
|
61
|
-
|
|
62
|
-
'
|
|
63
|
-
'
|
|
57
|
+
'$node = [string]$env:LIVEDESK_NODE_EXECUTABLE',
|
|
58
|
+
'if ($node -and -not (Test-Path -LiteralPath $node -PathType Leaf)) { $node = "" }',
|
|
59
|
+
'if (-not $node) { $node = (Get-Command node.exe -ErrorAction SilentlyContinue).Source }',
|
|
60
|
+
'if (-not $node) { throw "LiveDesk node executable was not found." }',
|
|
61
|
+
`$env:LIVEDESK_UPDATE_BOOTSTRAP_BASE64 = ${quotePowerShell(Buffer.from(buildUnixClientUpdateBootstrapScript(), 'utf8').toString('base64'))}`,
|
|
62
|
+
'$env:LIVEDESK_UPDATE_WAIT_PID = [string]$launcherPid',
|
|
63
|
+
'$env:LIVEDESK_UPDATE_AGENT_PID = "0"',
|
|
64
|
+
'$bootstrapRunner = "eval(Buffer.from(process.env.LIVEDESK_UPDATE_BOOTSTRAP_BASE64, \'base64\').toString(\'utf8\'))"',
|
|
65
|
+
'Start-Process -FilePath $node -ArgumentList @("-e", $bootstrapRunner) -WindowStyle Hidden',
|
|
66
|
+
'Start-Sleep -Milliseconds 750',
|
|
64
67
|
'Start-Process -FilePath "taskkill.exe" -ArgumentList @("/PID", [string]$launcherPid, "/T", "/F") -WindowStyle Hidden',
|
|
65
68
|
''
|
|
66
69
|
].join('\r\n');
|
|
67
70
|
return `powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand ${encodePowerShell(script)}`;
|
|
68
71
|
}
|
|
69
72
|
|
|
73
|
+
function buildUnixClientUpdateBootstrapScript() {
|
|
74
|
+
return [
|
|
75
|
+
'const { spawn } = require("node:child_process");',
|
|
76
|
+
'const fs = require("node:fs");',
|
|
77
|
+
'const path = require("node:path");',
|
|
78
|
+
'const waitPid = Number(process.env.LIVEDESK_UPDATE_WAIT_PID || 0);',
|
|
79
|
+
'const agentPid = Number(process.env.LIVEDESK_UPDATE_AGENT_PID || 0);',
|
|
80
|
+
'const isAlive = pid => { try { process.kill(pid, 0); return true; } catch (error) { return error?.code !== "ESRCH"; } };',
|
|
81
|
+
'const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));',
|
|
82
|
+
'const waitForExit = async pid => { for (let attempt = 0; attempt < 360 && pid > 1; attempt += 1) { if (!isAlive(pid)) return; await sleep(500); } if (pid > 1 && isAlive(pid)) throw new Error("LiveDesk client process did not exit before update installation."); };',
|
|
83
|
+
'const nodeDir = path.dirname(process.execPath);',
|
|
84
|
+
'const npxCandidates = process.platform === "win32" ? [process.env.LIVEDESK_NPX_EXECUTABLE, path.join(nodeDir, "npx.cmd"), path.join(nodeDir, "npx.exe"), "npx.cmd"] : [process.env.LIVEDESK_NPX_EXECUTABLE, path.join(nodeDir, "npx"), "npx"];',
|
|
85
|
+
'const npx = npxCandidates.find(candidate => !path.isAbsolute(candidate) || fs.existsSync(candidate)) || npxCandidates[npxCandidates.length - 1];',
|
|
86
|
+
'const npxArgs = ["-y", "--prefer-online", "livedesk@latest", "client", "--no-login"];',
|
|
87
|
+
'const command = process.platform === "win32" ? (process.env.ComSpec || "cmd.exe") : npx;',
|
|
88
|
+
'const commandArgs = process.platform === "win32" ? ["/d", "/s", "/c", "call \\"" + npx + "\\" " + npxArgs.join(" ")] : npxArgs;',
|
|
89
|
+
'(async () => { await waitForExit(waitPid); await waitForExit(agentPid); const updater = spawn(command, commandArgs, { detached: true, stdio: "ignore", windowsHide: true, env: process.env }); updater.once("error", error => { console.error("LiveDesk updater failed to start: " + error.message); process.exitCode = 1; }); updater.once("spawn", () => updater.unref()); })().catch(error => { console.error("LiveDesk updater failed: " + error.message); process.exitCode = 1; });',
|
|
90
|
+
''
|
|
91
|
+
].join('\n');
|
|
92
|
+
}
|
|
93
|
+
|
|
70
94
|
function buildUnixLegacyUpdateCommand({ manager, pair, name, slot, targetVersion }) {
|
|
71
95
|
const script = [
|
|
72
96
|
'const { execFileSync, spawn } = require("node:child_process");',
|
|
@@ -77,24 +101,25 @@ function buildUnixLegacyUpdateCommand({ manager, pair, name, slot, targetVersion
|
|
|
77
101
|
'const isAlive = pid => { try { process.kill(pid, 0); return true; } catch { return false; } };',
|
|
78
102
|
'const configuredLauncherPid = Number(process.env.LIVEDESK_CLIENT_PARENT_PID || 0);',
|
|
79
103
|
'let launcherPid = Number.isInteger(configuredLauncherPid) && configuredLauncherPid > 1 && isAlive(configuredLauncherPid) ? configuredLauncherPid : 0;',
|
|
104
|
+
'let agentPid = Number(process.env.LIVEDESK_CLIENT_AGENT_PID || 0);',
|
|
80
105
|
'let cursor = parentOf(process.pid);',
|
|
81
|
-
'for (let depth = 0; depth < 12 && cursor; depth++) { const command = commandOf(cursor); if (/livedesk-client\\.js|livedesk\\.
|
|
82
|
-
'
|
|
106
|
+
'for (let depth = 0; depth < 12 && cursor; depth++) { const command = commandOf(cursor); if (!agentPid && /livedesk-client-node\\.js|livedesk-client-fast|RemoteAgent\\.Fast/i.test(command)) agentPid = cursor; if (!launcherPid && /livedesk-client\\.js|livedesk\\.js/i.test(command)) launcherPid = cursor; cursor = parentOf(cursor); }',
|
|
107
|
+
'if (launcherPid <= 1) throw new Error("LiveDesk client launcher process was not found.");',
|
|
108
|
+
'const waitPid = launcherPid;',
|
|
83
109
|
`process.env.LIVEDESK_CLIENT_MANAGER = ${JSON.stringify(String(manager || ''))};`,
|
|
84
110
|
`process.env.LIVEDESK_CLIENT_PAIR_TOKEN = ${JSON.stringify(String(pair || ''))};`,
|
|
85
111
|
`process.env.LIVEDESK_CLIENT_NAME = ${JSON.stringify(String(name || ''))};`,
|
|
86
112
|
`process.env.LIVEDESK_CLIENT_SLOT = ${JSON.stringify(String(slot || ''))};`,
|
|
87
113
|
`process.env.LIVEDESK_CLIENT_UPDATE_TARGET_VERSION = ${JSON.stringify(String(targetVersion || ''))};`,
|
|
88
|
-
|
|
89
|
-
'const
|
|
90
|
-
'const
|
|
91
|
-
'
|
|
92
|
-
'updater.once("
|
|
93
|
-
'updater.once("spawn", () => { updater.unref(); if (waitPid !== process.pid) setTimeout(() => { try { process.kill(waitPid, "SIGTERM"); } catch {} }, 500); });',
|
|
114
|
+
`const bootstrapScript = ${JSON.stringify(buildUnixClientUpdateBootstrapScript())};`,
|
|
115
|
+
'const bootstrapEnv = { ...process.env, LIVEDESK_UPDATE_WAIT_PID: String(waitPid), LIVEDESK_UPDATE_AGENT_PID: String(agentPid) };',
|
|
116
|
+
'const updater = spawn(process.execPath, ["-e", bootstrapScript], { detached: true, stdio: "ignore", env: bootstrapEnv });',
|
|
117
|
+
'updater.once("error", error => { console.error("LiveDesk updater bootstrap failed to start: " + error.message); process.exitCode = 1; });',
|
|
118
|
+
'updater.once("spawn", () => { updater.unref(); setTimeout(() => { try { process.kill(waitPid, "SIGTERM"); } catch {} if (agentPid > 1 && agentPid !== process.pid) setTimeout(() => { try { process.kill(agentPid, "SIGTERM"); } catch {} }, 500); }, 750); });',
|
|
94
119
|
''
|
|
95
120
|
].join('\n');
|
|
96
121
|
return [
|
|
97
|
-
'if [ -n "$LIVEDESK_NODE_EXECUTABLE" ]; then node_bin="$LIVEDESK_NODE_EXECUTABLE"; else node_bin="node"; fi',
|
|
122
|
+
'if [ -n "$LIVEDESK_NODE_EXECUTABLE" ]; then node_bin="$LIVEDESK_NODE_EXECUTABLE"; else node_bin="$(ps -p "$LIVEDESK_CLIENT_PARENT_PID" -o comm= 2>/dev/null | sed "s/^ *//")"; if [ -z "$node_bin" ]; then node_bin="node"; fi; fi',
|
|
98
123
|
`"$node_bin" -e ${JSON.stringify(script)}`
|
|
99
124
|
].join('\n');
|
|
100
125
|
}
|