af014d9829
A workspace could not be created on Windows: "cwd must be an absolute path" for D:\…, because createLane/canonicalCwd tested for a leading "/". - lanes.js: path.isAbsolute/path.resolve; canonicalCwd stops at any root (a missing drive looped forever); resolveLaneByCwd and /ensure accept "\" too - native-dialog.js: the Windows picker gets an invisible TopMost owner form, shown first — an ownerless dialog from the background server opened behind the browser, or hidden - windows-hide.js: every child process on Windows starts with windowsHide, required first by the server and the detached scripts (a console window flashed per git/npm call) - Confirm/update/clear-data modals and the quota panel scroll instead of overflowing a short window
48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* @file Detached helper spawned by `server/lib/self-restart.js`. Polls the
|
|
* old dashboard PID until it exits (server/index.js's own SIGTERM handler
|
|
* has a 5s force-exit backstop, so this never waits forever), then starts a
|
|
* fresh server from the same entry point and exits itself.
|
|
* @author Nguyễn Ngọc Trí Vĩ <vinnt@smartgift.vn>
|
|
*/
|
|
|
|
require("../server/lib/windows-hide").install(); // before child_process is read
|
|
const { spawn } = require("child_process");
|
|
|
|
const [, , pidArg, entry] = process.argv;
|
|
const pid = parseInt(pidArg, 10);
|
|
|
|
// ponytail: fixed poll cadence/cap, not configurable — this script has one caller.
|
|
const POLL_MS = 200;
|
|
const MAX_WAIT_MS = 20_000;
|
|
|
|
function isAlive(p) {
|
|
try {
|
|
process.kill(p, 0);
|
|
return true;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function restart() {
|
|
const child = spawn(process.execPath, [entry], {
|
|
detached: true,
|
|
stdio: "ignore",
|
|
env: process.env,
|
|
});
|
|
child.unref();
|
|
process.exit(0);
|
|
}
|
|
|
|
function waitAndRestart(waited = 0) {
|
|
if (isAlive(pid) && waited < MAX_WAIT_MS) {
|
|
setTimeout(() => waitAndRestart(waited + POLL_MS), POLL_MS);
|
|
return;
|
|
}
|
|
restart();
|
|
}
|
|
|
|
waitAndRestart();
|