mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -08:00
refactor: split startup lifecycle and Anki service architecture
This commit is contained in:
@@ -87,3 +87,11 @@ export function createAppReadyRuntimeDeps(
|
||||
handleInitialArgs: params.handleInitialArgs,
|
||||
};
|
||||
}
|
||||
|
||||
export function createAppReadyRuntimeRunner(
|
||||
params: AppReadyRuntimeDepsFactoryInput,
|
||||
): () => Promise<void> {
|
||||
return async () => {
|
||||
await runAppReadyRuntimeService(createAppReadyRuntimeDeps(params));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ export interface AnkiJimakuIpcRuntimeServiceDepsParams {
|
||||
getMpvClient: AnkiJimakuIpcRuntimeOptions["getMpvClient"];
|
||||
getAnkiIntegration: AnkiJimakuIpcRuntimeOptions["getAnkiIntegration"];
|
||||
setAnkiIntegration: AnkiJimakuIpcRuntimeOptions["setAnkiIntegration"];
|
||||
getKnownWordCacheStatePath: AnkiJimakuIpcRuntimeOptions["getKnownWordCacheStatePath"];
|
||||
showDesktopNotification: AnkiJimakuIpcRuntimeOptions["showDesktopNotification"];
|
||||
createFieldGroupingCallback: AnkiJimakuIpcRuntimeOptions["createFieldGroupingCallback"];
|
||||
broadcastRuntimeOptionsChanged: AnkiJimakuIpcRuntimeOptions["broadcastRuntimeOptionsChanged"];
|
||||
@@ -224,6 +225,7 @@ export function createAnkiJimakuIpcRuntimeServiceDeps(
|
||||
getMpvClient: params.getMpvClient,
|
||||
getAnkiIntegration: params.getAnkiIntegration,
|
||||
setAnkiIntegration: params.setAnkiIntegration,
|
||||
getKnownWordCacheStatePath: params.getKnownWordCacheStatePath,
|
||||
showDesktopNotification: params.showDesktopNotification,
|
||||
createFieldGroupingCallback: params.createFieldGroupingCallback,
|
||||
broadcastRuntimeOptionsChanged: params.broadcastRuntimeOptionsChanged,
|
||||
|
||||
44
src/main/startup-lifecycle.ts
Normal file
44
src/main/startup-lifecycle.ts
Normal 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,
|
||||
}),
|
||||
),
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -13,6 +13,28 @@ export interface SubsyncRuntimeServiceInput {
|
||||
openManualPicker: (payload: SubsyncManualPayload) => void;
|
||||
}
|
||||
|
||||
export interface SubsyncRuntimeServiceStateInput {
|
||||
getMpvClient: SubsyncRuntimeServiceInput["getMpvClient"];
|
||||
getResolvedSubsyncConfig: SubsyncRuntimeServiceInput["getResolvedSubsyncConfig"];
|
||||
getSubsyncInProgress: () => boolean;
|
||||
setSubsyncInProgress: SubsyncRuntimeServiceInput["setSubsyncInProgress"];
|
||||
showMpvOsd: SubsyncRuntimeServiceInput["showMpvOsd"];
|
||||
openManualPicker: SubsyncRuntimeServiceInput["openManualPicker"];
|
||||
}
|
||||
|
||||
export function createSubsyncRuntimeServiceInputFromState(
|
||||
input: SubsyncRuntimeServiceStateInput,
|
||||
): SubsyncRuntimeServiceInput {
|
||||
return {
|
||||
getMpvClient: input.getMpvClient,
|
||||
getResolvedSubsyncConfig: input.getResolvedSubsyncConfig,
|
||||
isSubsyncInProgress: input.getSubsyncInProgress,
|
||||
setSubsyncInProgress: input.setSubsyncInProgress,
|
||||
showMpvOsd: input.showMpvOsd,
|
||||
openManualPicker: input.openManualPicker,
|
||||
};
|
||||
}
|
||||
|
||||
export function createSubsyncRuntimeServiceDeps(
|
||||
params: SubsyncRuntimeServiceInput,
|
||||
): SubsyncRuntimeDeps {
|
||||
|
||||
Reference in New Issue
Block a user