mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-08-13 01:55:50 -07:00
refactor(launcher): move detached app spawning into runtime utilities
This commit is contained in:
@@ -25,8 +25,21 @@ import {
|
|||||||
applyBackgroundBootstrapCommandLineSwitches,
|
applyBackgroundBootstrapCommandLineSwitches,
|
||||||
applyEarlyLinuxCommandLineSwitches,
|
applyEarlyLinuxCommandLineSwitches,
|
||||||
resolveLinuxPasswordStoreValue,
|
resolveLinuxPasswordStoreValue,
|
||||||
|
spawnDetachedApp,
|
||||||
} from './main-entry-runtime';
|
} from './main-entry-runtime';
|
||||||
|
|
||||||
|
test('detached app launch policy stays in the startup runtime utilities', () => {
|
||||||
|
const entrySource = fs.readFileSync(path.join(process.cwd(), 'src/main-entry.ts'), 'utf8');
|
||||||
|
const runtimeSource = fs.readFileSync(
|
||||||
|
path.join(process.cwd(), 'src/main-entry-runtime.ts'),
|
||||||
|
'utf8',
|
||||||
|
);
|
||||||
|
|
||||||
|
assert.equal(typeof spawnDetachedApp, 'function');
|
||||||
|
assert.doesNotMatch(entrySource, /function spawnDetachedApp/);
|
||||||
|
assert.match(runtimeSource, /child\.unref\(\)/);
|
||||||
|
});
|
||||||
|
|
||||||
test('background bootstrap exits through Electron so Chromium children shut down', () => {
|
test('background bootstrap exits through Electron so Chromium children shut down', () => {
|
||||||
const exitCodes: number[] = [];
|
const exitCodes: number[] = [];
|
||||||
exitBackgroundBootstrap({ exit: (code) => exitCodes.push(code) });
|
exitBackgroundBootstrap({ exit: (code) => exitCodes.push(code) });
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
|
import { spawn } from 'node:child_process';
|
||||||
import { CliArgs, hasExplicitCommand, parseArgs, shouldStartApp } from './cli/args';
|
import { CliArgs, hasExplicitCommand, parseArgs, shouldStartApp } from './cli/args';
|
||||||
import { resolveConfigDir } from './config/path-resolution';
|
import { resolveConfigDir } from './config/path-resolution';
|
||||||
|
import { resolveAppImageMountKeepaliveInvocation } from './main/appimage-mount-keepalive';
|
||||||
|
|
||||||
const BACKGROUND_ARG = '--background';
|
const BACKGROUND_ARG = '--background';
|
||||||
const START_ARG = '--start';
|
const START_ARG = '--start';
|
||||||
@@ -265,6 +267,22 @@ export function exitBackgroundBootstrap(app: BackgroundBootstrapAppLike): void {
|
|||||||
app.exit(0);
|
app.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function spawnDetachedApp(childArgs: string[], env: NodeJS.ProcessEnv): void {
|
||||||
|
const keepalive = resolveAppImageMountKeepaliveInvocation(env);
|
||||||
|
const child = keepalive
|
||||||
|
? spawn(keepalive.command, [...keepalive.args, ...childArgs], {
|
||||||
|
detached: true,
|
||||||
|
stdio: 'ignore',
|
||||||
|
env,
|
||||||
|
})
|
||||||
|
: spawn(process.execPath, childArgs, {
|
||||||
|
detached: true,
|
||||||
|
stdio: 'ignore',
|
||||||
|
env,
|
||||||
|
});
|
||||||
|
child.unref();
|
||||||
|
}
|
||||||
|
|
||||||
export function shouldHandleHelpOnlyAtEntry(argv: string[], env: NodeJS.ProcessEnv): boolean {
|
export function shouldHandleHelpOnlyAtEntry(argv: string[], env: NodeJS.ProcessEnv): boolean {
|
||||||
if (env.ELECTRON_RUN_AS_NODE === '1') return false;
|
if (env.ELECTRON_RUN_AS_NODE === '1') return false;
|
||||||
const args = parseCliArgs(argv);
|
const args = parseCliArgs(argv);
|
||||||
|
|||||||
+1
-18
@@ -1,5 +1,4 @@
|
|||||||
import os from 'node:os';
|
import os from 'node:os';
|
||||||
import { spawn } from 'node:child_process';
|
|
||||||
import { app, dialog, shell } from 'electron';
|
import { app, dialog, shell } from 'electron';
|
||||||
import { printHelp } from './cli/help';
|
import { printHelp } from './cli/help';
|
||||||
import {
|
import {
|
||||||
@@ -20,9 +19,9 @@ import {
|
|||||||
shouldHandleHelpOnlyAtEntry,
|
shouldHandleHelpOnlyAtEntry,
|
||||||
shouldHandleLaunchMpvAtEntry,
|
shouldHandleLaunchMpvAtEntry,
|
||||||
shouldHandleStatsDaemonCommandAtEntry,
|
shouldHandleStatsDaemonCommandAtEntry,
|
||||||
|
spawnDetachedApp,
|
||||||
} from './main-entry-runtime';
|
} from './main-entry-runtime';
|
||||||
import { requestSingleInstanceLockEarly } from './main/early-single-instance';
|
import { requestSingleInstanceLockEarly } from './main/early-single-instance';
|
||||||
import { resolveAppImageMountKeepaliveInvocation } from './main/appimage-mount-keepalive';
|
|
||||||
import { readConfiguredWindowsMpvLaunch } from './main-entry-launch-config';
|
import { readConfiguredWindowsMpvLaunch } from './main-entry-launch-config';
|
||||||
import { isAppControlServerAvailable, sendAppControlCommand } from './shared/app-control-client';
|
import { isAppControlServerAvailable, sendAppControlCommand } from './shared/app-control-client';
|
||||||
import {
|
import {
|
||||||
@@ -75,22 +74,6 @@ function applySanitizedEnv(sanitizedEnv: NodeJS.ProcessEnv): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function spawnDetachedApp(childArgs: string[], env: NodeJS.ProcessEnv): void {
|
|
||||||
const keepalive = resolveAppImageMountKeepaliveInvocation(env);
|
|
||||||
const child = keepalive
|
|
||||||
? spawn(keepalive.command, [...keepalive.args, ...childArgs], {
|
|
||||||
detached: true,
|
|
||||||
stdio: 'ignore',
|
|
||||||
env,
|
|
||||||
})
|
|
||||||
: spawn(process.execPath, childArgs, {
|
|
||||||
detached: true,
|
|
||||||
stdio: 'ignore',
|
|
||||||
env,
|
|
||||||
});
|
|
||||||
child.unref();
|
|
||||||
}
|
|
||||||
|
|
||||||
function resolveBundledWindowsMpvPluginEntrypoint(): string | undefined {
|
function resolveBundledWindowsMpvPluginEntrypoint(): string | undefined {
|
||||||
return (
|
return (
|
||||||
resolvePackagedRuntimePluginPath({
|
resolvePackagedRuntimePluginPath({
|
||||||
|
|||||||
Reference in New Issue
Block a user