refactor: split startup lifecycle and Anki service architecture

This commit is contained in:
2026-02-14 22:31:21 -08:00
parent 41f7d754cd
commit 162223943d
30 changed files with 1603 additions and 312 deletions

View File

@@ -0,0 +1,44 @@
import { CliArgs, CliCommandSource } from "../cli/args";
import { createAppLifecycleDepsRuntimeService } from "../core/services";
import { startAppLifecycleService } from "../core/services/app-lifecycle-service";
import type { AppLifecycleDepsRuntimeOptions } from "../core/services/app-lifecycle-service";
import { createAppLifecycleRuntimeDeps } from "./app-lifecycle";
export interface AppLifecycleRuntimeRunnerParams {
app: AppLifecycleDepsRuntimeOptions["app"];
platform: NodeJS.Platform;
shouldStartApp: (args: CliArgs) => boolean;
parseArgs: (argv: string[]) => CliArgs;
handleCliCommand: (nextArgs: CliArgs, source: CliCommandSource) => void;
printHelp: () => void;
logNoRunningInstance: () => void;
onReady: () => Promise<void>;
onWillQuitCleanup: () => void;
shouldRestoreWindowsOnActivate: () => boolean;
restoreWindowsOnActivate: () => void;
}
export function createAppLifecycleRuntimeRunner(
params: AppLifecycleRuntimeRunnerParams,
): (args: CliArgs) => void {
return (args: CliArgs): void => {
startAppLifecycleService(
args,
createAppLifecycleDepsRuntimeService(
createAppLifecycleRuntimeDeps({
app: params.app,
platform: params.platform,
shouldStartApp: params.shouldStartApp,
parseArgs: params.parseArgs,
handleCliCommand: params.handleCliCommand,
printHelp: params.printHelp,
logNoRunningInstance: params.logNoRunningInstance,
onReady: params.onReady,
onWillQuitCleanup: params.onWillQuitCleanup,
shouldRestoreWindowsOnActivate: params.shouldRestoreWindowsOnActivate,
restoreWindowsOnActivate: params.restoreWindowsOnActivate,
}),
),
);
};
}