livedesk 0.1.277 → 0.1.279

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.
@@ -67,6 +67,25 @@ function buildWindowsLegacyUpdateCommand({ manager, pair, name, slot, targetVers
67
67
  return `powershell.exe -NoProfile -NonInteractive -ExecutionPolicy Bypass -EncodedCommand ${encodePowerShell(script)}`;
68
68
  }
69
69
 
70
+ function buildUnixClientUpdateBootstrapScript() {
71
+ return [
72
+ 'const { spawn } = require("node:child_process");',
73
+ 'const fs = require("node:fs");',
74
+ 'const path = require("node:path");',
75
+ 'const waitPid = Number(process.env.LIVEDESK_UPDATE_WAIT_PID || 0);',
76
+ 'const agentPid = Number(process.env.LIVEDESK_UPDATE_AGENT_PID || 0);',
77
+ 'const isAlive = pid => { try { process.kill(pid, 0); return true; } catch (error) { return error?.code !== "ESRCH"; } };',
78
+ 'const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));',
79
+ '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."); };',
80
+ 'const nodeDir = path.dirname(process.execPath);',
81
+ 'const npxCandidates = [process.env.LIVEDESK_NPX_EXECUTABLE, path.join(nodeDir, "npx"), "npx"].filter(Boolean);',
82
+ 'const npx = npxCandidates.find(candidate => !path.isAbsolute(candidate) || fs.existsSync(candidate)) || npxCandidates[npxCandidates.length - 1];',
83
+ 'const npxArgs = ["-y", "--prefer-online", "livedesk@latest", "client", "--no-login"];',
84
+ '(async () => { await waitForExit(waitPid); await waitForExit(agentPid); const updater = spawn(npx, npxArgs, { detached: true, stdio: "ignore", 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; });',
85
+ ''
86
+ ].join('\n');
87
+ }
88
+
70
89
  function buildUnixLegacyUpdateCommand({ manager, pair, name, slot, targetVersion }) {
71
90
  const script = [
72
91
  'const { execFileSync, spawn } = require("node:child_process");',
@@ -77,24 +96,25 @@ function buildUnixLegacyUpdateCommand({ manager, pair, name, slot, targetVersion
77
96
  'const isAlive = pid => { try { process.kill(pid, 0); return true; } catch { return false; } };',
78
97
  'const configuredLauncherPid = Number(process.env.LIVEDESK_CLIENT_PARENT_PID || 0);',
79
98
  'let launcherPid = Number.isInteger(configuredLauncherPid) && configuredLauncherPid > 1 && isAlive(configuredLauncherPid) ? configuredLauncherPid : 0;',
99
+ 'let agentPid = Number(process.env.LIVEDESK_CLIENT_AGENT_PID || 0);',
80
100
  'let cursor = parentOf(process.pid);',
81
- '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); }',
82
- 'const waitPid = launcherPid > 1 ? launcherPid : process.pid;',
101
+ 'for (let depth = 0; depth < 12 && cursor; depth++) { const command = commandOf(cursor); if (!agentPid && /livedesk-client-node\\.js/i.test(command)) agentPid = cursor; if (!launcherPid && /livedesk-client\\.js|livedesk\\.js/i.test(command)) launcherPid = cursor; cursor = parentOf(cursor); }',
102
+ 'if (launcherPid <= 1) throw new Error("LiveDesk client launcher process was not found.");',
103
+ 'const waitPid = launcherPid;',
83
104
  `process.env.LIVEDESK_CLIENT_MANAGER = ${JSON.stringify(String(manager || ''))};`,
84
105
  `process.env.LIVEDESK_CLIENT_PAIR_TOKEN = ${JSON.stringify(String(pair || ''))};`,
85
106
  `process.env.LIVEDESK_CLIENT_NAME = ${JSON.stringify(String(name || ''))};`,
86
107
  `process.env.LIVEDESK_CLIENT_SLOT = ${JSON.stringify(String(slot || ''))};`,
87
108
  `process.env.LIVEDESK_CLIENT_UPDATE_TARGET_VERSION = ${JSON.stringify(String(targetVersion || ''))};`,
88
- 'const nodeDir = path.dirname(process.execPath);',
89
- 'const npxCandidates = [process.env.LIVEDESK_NPX_EXECUTABLE, path.join(nodeDir, process.platform === "win32" ? "npx.cmd" : "npx"), process.platform === "win32" ? "npx.cmd" : "npx"].filter(Boolean);',
90
- 'const npx = npxCandidates.find(candidate => !path.isAbsolute(candidate) || fs.existsSync(candidate)) || npxCandidates[npxCandidates.length - 1];',
91
- 'const updater = spawn(npx, ["-y", "--prefer-online", "livedesk@latest", "client", "--no-login", "--update-wait-pid", String(waitPid)], { detached: true, stdio: "ignore", env: process.env });',
92
- 'updater.once("error", error => { console.error("LiveDesk updater failed to start: " + error.message); process.exitCode = 1; });',
93
- 'updater.once("spawn", () => { updater.unref(); if (waitPid !== process.pid) setTimeout(() => { try { process.kill(waitPid, "SIGTERM"); } catch {} }, 500); });',
109
+ `const bootstrapScript = ${JSON.stringify(buildUnixClientUpdateBootstrapScript())};`,
110
+ 'const bootstrapEnv = { ...process.env, LIVEDESK_UPDATE_WAIT_PID: String(waitPid), LIVEDESK_UPDATE_AGENT_PID: String(agentPid) };',
111
+ 'const updater = spawn(process.execPath, ["-e", bootstrapScript], { detached: true, stdio: "ignore", env: bootstrapEnv });',
112
+ 'updater.once("error", error => { console.error("LiveDesk updater bootstrap failed to start: " + error.message); process.exitCode = 1; });',
113
+ '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
114
  ''
95
115
  ].join('\n');
96
116
  return [
97
- 'if [ -n "$LIVEDESK_NODE_EXECUTABLE" ]; then node_bin="$LIVEDESK_NODE_EXECUTABLE"; else node_bin="node"; fi',
117
+ '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
118
  `"$node_bin" -e ${JSON.stringify(script)}`
99
119
  ].join('\n');
100
120
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livedesk",
3
- "version": "0.1.277",
3
+ "version": "0.1.279",
4
4
  "description": "LiveDesk Hub and client launcher",
5
5
  "type": "module",
6
6
  "bin": {
@@ -31,7 +31,7 @@
31
31
  },
32
32
  "dependencies": {
33
33
  "@ffmpeg-installer/ffmpeg": "^1.1.0",
34
- "@livedesk/client": "0.1.140",
34
+ "@livedesk/client": "0.1.141",
35
35
  "@openai/codex-sdk": "0.144.5",
36
36
  "cors": "^2.8.5",
37
37
  "express": "^4.21.2",