livedesk 0.1.286 → 0.1.288

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
@@ -518,6 +518,20 @@ function quoteWindowsCommandArg(value) {
518
518
  return `"${text.replaceAll('"', '\\"')}"`;
519
519
  }
520
520
 
521
+ function buildHubRestartBootstrapScript() {
522
+ return [
523
+ 'const { spawn } = require("node:child_process");',
524
+ 'const waitPid = Number(process.env.LIVEDESK_RESTART_WAIT_PID || 0);',
525
+ 'const isAlive = pid => { try { process.kill(pid, 0); return true; } catch (error) { return error?.code !== "ESRCH"; } };',
526
+ 'const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));',
527
+ 'const waitForExit = async pid => { for (let attempt = 0; attempt < 240 && pid > 1; attempt += 1) { if (!isAlive(pid)) return; await sleep(250); } if (pid > 1 && isAlive(pid)) throw new Error("Previous LiveDesk Hub launcher did not exit before restart."); };',
528
+ 'const command = process.env.LIVEDESK_RESTART_COMMAND || "";',
529
+ 'const args = JSON.parse(Buffer.from(process.env.LIVEDESK_RESTART_ARGS_BASE64 || "", "base64").toString("utf8"));',
530
+ '(async () => { await waitForExit(waitPid); if (!command || !Array.isArray(args)) throw new Error("LiveDesk Hub restart command is unavailable."); const next = spawn(command, args, { cwd: process.env.LIVEDESK_RESTART_CWD || process.cwd(), env: process.env, detached: true, stdio: "ignore", windowsHide: true }); next.once("error", error => { console.error("LiveDesk Hub restart failed to start: " + error.message); process.exitCode = 1; }); next.once("spawn", () => next.unref()); })().catch(error => { console.error("LiveDesk Hub restart bootstrap failed: " + error.message); process.exitCode = 1; });',
531
+ ''
532
+ ].join('\n');
533
+ }
534
+
521
535
  async function runManager(args) {
522
536
  const options = parseManagerArgs(args);
523
537
  const httpPort = normalizePort(
@@ -572,21 +586,23 @@ async function runManager(args) {
572
586
  const commandArgs = process.platform === 'win32'
573
587
  ? ['/d', '/s', '/c', `call ${quoteWindowsCommandArg(npxCommand)} ${nextArgs.map(quoteWindowsCommandArg).join(' ')}`]
574
588
  : nextArgs;
575
- const next = spawn(command, commandArgs, {
589
+ const restartBootstrap = spawn(process.execPath, ['-e', buildHubRestartBootstrapScript()], {
576
590
  env: {
577
591
  ...process.env,
578
- LIVEDESK_NODE_EXECUTABLE: process.execPath,
579
- LIVEDESK_NPX_EXECUTABLE: npxCommand
592
+ LIVEDESK_RESTART_WAIT_PID: String(process.pid),
593
+ LIVEDESK_RESTART_COMMAND: command,
594
+ LIVEDESK_RESTART_ARGS_BASE64: Buffer.from(JSON.stringify(commandArgs), 'utf8').toString('base64'),
595
+ LIVEDESK_RESTART_CWD: process.cwd()
580
596
  },
581
- stdio: 'inherit',
597
+ stdio: 'ignore',
582
598
  detached: true,
583
- windowsHide: false
599
+ windowsHide: true
584
600
  });
585
- next.once('error', error => {
586
- console.error(`Failed to relaunch LiveDesk Hub from npm: ${error.message}`);
601
+ restartBootstrap.once('error', error => {
602
+ console.error(`Failed to prepare LiveDesk Hub restart: ${error.message}`);
587
603
  });
588
- next.unref();
589
- console.log('[LiveDesk Hub] Update approved. The latest Hub launcher is starting.');
604
+ restartBootstrap.once('spawn', () => restartBootstrap.unref());
605
+ console.log('[LiveDesk Hub] Update approved. The current Hub launcher is exiting and the latest Hub will start automatically.');
590
606
  setTimeout(() => process.exit(0), 100);
591
607
  };
592
608
 
@@ -1,8 +1,10 @@
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.141';
5
- export const LIVE_DESK_UPDATE_TIMEOUT_MS = 120_000;
4
+ // 0.1.143 contains the launcher-PID-aware updater. Older clients use the
5
+ // Hub-generated legacy command so they can still be upgraded safely.
6
+ export const LIVE_DESK_DEDICATED_CLIENT_UPDATE_MIN_VERSION = '0.1.143';
7
+ export const LIVE_DESK_UPDATE_TIMEOUT_MS = 60_000;
6
8
  export const LIVE_DESK_UPDATE_CHECK_INTERVAL_MS = 60_000;
7
9
 
8
10
  function cleanVersion(value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "livedesk",
3
- "version": "0.1.286",
3
+ "version": "0.1.288",
4
4
  "description": "LiveDesk Hub and client launcher",
5
5
  "type": "module",
6
6
  "bin": {