Reconnection when signal server is not active and minor changes

This commit is contained in:
2026-03-18 20:45:00 +01:00
parent eb987ac672
commit 141de64767
15 changed files with 229 additions and 27 deletions

View File

@@ -1,5 +1,8 @@
const { spawn } = require('child_process');
const DEV_SINGLE_INSTANCE_EXIT_CODE = 23;
const DEV_SINGLE_INSTANCE_EXIT_CODE_ENV = 'METOYOU_SINGLE_INSTANCE_EXIT_CODE';
function isWaylandSession(env) {
const sessionType = String(env.XDG_SESSION_TYPE || '').trim().toLowerCase();
@@ -44,11 +47,40 @@ function buildElectronArgs(argv) {
return args;
}
function isDevelopmentLaunch(env) {
return String(env.NODE_ENV || '').trim().toLowerCase() === 'development';
}
function buildChildEnv(env) {
const nextEnv = { ...env };
if (isDevelopmentLaunch(env)) {
nextEnv[DEV_SINGLE_INSTANCE_EXIT_CODE_ENV] = String(DEV_SINGLE_INSTANCE_EXIT_CODE);
}
return nextEnv;
}
function keepProcessAliveForExistingInstance() {
console.log(
'Electron is already running; keeping the dev services alive and routing links to the open window.'
);
const intervalId = setInterval(() => {}, 60_000);
const shutdown = () => {
clearInterval(intervalId);
process.exit(0);
};
process.once('SIGINT', shutdown);
process.once('SIGTERM', shutdown);
}
function main() {
const electronBinary = resolveElectronBinary();
const args = buildElectronArgs(process.argv.slice(2));
const child = spawn(electronBinary, args, {
env: process.env,
env: buildChildEnv(process.env),
stdio: 'inherit'
});
@@ -58,6 +90,11 @@ function main() {
});
child.on('exit', (code, signal) => {
if (code === DEV_SINGLE_INSTANCE_EXIT_CODE) {
keepProcessAliveForExistingInstance();
return;
}
if (signal) {
process.kill(process.pid, signal);
return;