mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-06-18 15:13:31 -07:00
refactor(main): split main.ts into focused runtime modules (#123)
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import type { BackgroundStatsServerState } from './main/runtime/stats-daemon';
|
||||
import { verifyBackgroundStatsServerIdentity } from './main/runtime/stats-daemon';
|
||||
import type { StatsCliCommandResponse } from './main/runtime/stats-cli-command';
|
||||
|
||||
export type StatsDaemonControlAction = 'start' | 'stop';
|
||||
@@ -22,6 +23,7 @@ export function createRunStatsDaemonControlHandler(deps: {
|
||||
readState: () => BackgroundStatsServerState | null;
|
||||
removeState: () => void;
|
||||
isProcessAlive: (pid: number) => boolean;
|
||||
verifyProcessIdentity?: (pid: number, startedAtMs: number) => boolean;
|
||||
resolveUrl: (state: Pick<BackgroundStatsServerState, 'port'>) => string;
|
||||
spawnDaemon: (options: SpawnStatsDaemonOptions) => Promise<number> | number;
|
||||
waitForDaemonResponse: (responsePath: string) => Promise<StatsCliCommandResponse>;
|
||||
@@ -81,6 +83,12 @@ export function createRunStatsDaemonControlHandler(deps: {
|
||||
writeResponseSafe(args.responsePath, { ok: true });
|
||||
return 0;
|
||||
}
|
||||
const verifyProcessIdentity = deps.verifyProcessIdentity ?? verifyBackgroundStatsServerIdentity;
|
||||
if (!verifyProcessIdentity(state.pid, state.startedAtMs)) {
|
||||
deps.removeState();
|
||||
writeResponseSafe(args.responsePath, { ok: true });
|
||||
return 0;
|
||||
}
|
||||
|
||||
deps.killProcess(state.pid, 'SIGTERM');
|
||||
const deadline = Date.now() + 2_000;
|
||||
|
||||
Reference in New Issue
Block a user