livedesk 0.1.272 → 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/bin/livedesk.js CHANGED
@@ -578,6 +578,10 @@ async function runManager(args) {
578
578
  try {
579
579
  const request = JSON.parse(readFileSync(updateRequestPath, 'utf8'));
580
580
  rmSync(updateRequestPath, { force: true });
581
+ if (request?.continueClientUpdate === true) {
582
+ process.env.LIVEDESK_UPDATE_CONTINUE = '1';
583
+ process.env.LIVEDESK_UPDATE_CONTINUE_TARGET_VERSION = String(request.latestClientVersion || '');
584
+ }
581
585
  if (request?.pid && Number(request.pid) !== Number(activeChild?.pid || 0)) {
582
586
  restartRequested = true;
583
587
  console.log(`[LiveDesk Hub] Restart requested for update ${request.operationId || 'unknown'}.`);
@@ -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
- 'let cursor = parentOf(self); let launcherPid = 0;',
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
- 'if (!launcherPid) throw new Error("LiveDesk client launcher process was not found.");',
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 updater = spawn("npx", ["-y", "--prefer-online", "livedesk@latest", "client", "--no-login", "--update-wait-pid", String(launcherPid)], { detached: true, stdio: "ignore" });',
81
- 'updater.unref();',
82
- 'setTimeout(() => { try { process.kill(launcherPid, "SIGTERM"); } catch {} }, 500);',
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)}`;
package/hub/src/server.js CHANGED
@@ -285,6 +285,7 @@ function requestHubRestart(request = {}) {
285
285
  const temporaryPath = `${requestPath}.${process.pid}.tmp`;
286
286
  writeFileSync(temporaryPath, JSON.stringify({
287
287
  ...request,
288
+ continueClientUpdate: true,
288
289
  pid: process.pid,
289
290
  requestedAt: new Date().toISOString()
290
291
  }), 'utf8');
@@ -302,7 +303,45 @@ liveDeskUpdateManager = createLiveDeskUpdateManager({
302
303
  restartSupported: !!String(process.env.LIVEDESK_HUB_UPDATE_REQUEST_PATH || '').trim(),
303
304
  requestHubRestart
304
305
  });
305
- const agentMcpSessions = new Map();
306
+
307
+ if (process.env.LIVEDESK_UPDATE_CONTINUE === '1') {
308
+ let continueUpdateInFlight = false;
309
+ let continueUpdateAttempts = 0;
310
+ const continueUpdateTimer = setInterval(async () => {
311
+ if (continueUpdateInFlight || continueUpdateAttempts >= 90) {
312
+ if (continueUpdateAttempts >= 90) clearInterval(continueUpdateTimer);
313
+ return;
314
+ }
315
+ const connectedDevices = remoteHub.listDevices({ includeDataUrl: false })
316
+ .filter(device => device.connected === true && device.synthetic !== true);
317
+ if (connectedDevices.length === 0) return;
318
+ continueUpdateAttempts += 1;
319
+ continueUpdateInFlight = true;
320
+ try {
321
+ await liveDeskUpdateManager.checkLatest();
322
+ const updateStatus = liveDeskUpdateManager.getStatus();
323
+ if (!updateStatus.updateAvailable) {
324
+ clearInterval(continueUpdateTimer);
325
+ return;
326
+ }
327
+ if (updateStatus.outdatedClientCount <= 0 && !updateStatus.clientPackageUpdateAvailable) {
328
+ clearInterval(continueUpdateTimer);
329
+ return;
330
+ }
331
+ const result = await liveDeskUpdateManager.startUpdate();
332
+ if (result?.ok === false || ['waiting-for-clients', 'clients-updated', 'hub-restart-requested'].includes(String(result?.state || ''))) {
333
+ clearInterval(continueUpdateTimer);
334
+ }
335
+ } catch (error) {
336
+ console.warn(`[LiveDesk Hub] automatic client update continuation failed: ${error instanceof Error ? error.message : String(error)}`);
337
+ clearInterval(continueUpdateTimer);
338
+ } finally {
339
+ continueUpdateInFlight = false;
340
+ }
341
+ }, 1000);
342
+ continueUpdateTimer.unref?.();
343
+ }
344
+ const agentMcpSessions = new Map();
306
345
  const agentMcpRunBatches = new Map();
307
346
  const agentMcpRunCleanupTimers = new Map();
308
347
  const AGENT_MCP_RUN_TTL_MS = 60 * 60 * 1000;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livedesk",
3
- "version": "0.1.272",
3
+ "version": "0.1.274",
4
4
  "description": "LiveDesk Hub and client launcher",
5
5
  "type": "module",
6
6
  "bin": {