mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -08:00
refactor: extract cli command runtime wiring
This commit is contained in:
21
src/main.ts
21
src/main.ts
@@ -243,9 +243,8 @@ import {
|
||||
createBuildStartJellyfinRemoteSessionMainDepsHandler,
|
||||
createBuildStopJellyfinRemoteSessionMainDepsHandler,
|
||||
} from './main/runtime/jellyfin-remote-session-main-deps';
|
||||
import { createCliCommandRuntimeHandler } from './main/runtime/cli-command-runtime-handler';
|
||||
import { createInitialArgsRuntimeHandler } from './main/runtime/initial-args-runtime-handler';
|
||||
import { createHandleTexthookerOnlyModeTransitionHandler } from './main/runtime/cli-command-prechecks';
|
||||
import { createBuildHandleTexthookerOnlyModeTransitionMainDepsHandler } from './main/runtime/cli-command-prechecks-main-deps';
|
||||
import {
|
||||
createGetFieldGroupingResolverHandler,
|
||||
createSetFieldGroupingResolverHandler,
|
||||
@@ -2190,8 +2189,8 @@ runAndApplyStartupState();
|
||||
void refreshAnilistClientSecretState({ force: true });
|
||||
anilistStateRuntime.refreshRetryQueueState();
|
||||
|
||||
const handleTexthookerOnlyModeTransitionHandler = createHandleTexthookerOnlyModeTransitionHandler(
|
||||
createBuildHandleTexthookerOnlyModeTransitionMainDepsHandler({
|
||||
const handleCliCommand = createCliCommandRuntimeHandler({
|
||||
handleTexthookerOnlyModeTransitionMainDeps: {
|
||||
isTexthookerOnlyMode: () => appState.texthookerOnlyMode,
|
||||
setTexthookerOnlyMode: (enabled) => {
|
||||
appState.texthookerOnlyMode = enabled;
|
||||
@@ -2199,15 +2198,11 @@ const handleTexthookerOnlyModeTransitionHandler = createHandleTexthookerOnlyMode
|
||||
commandNeedsOverlayRuntime: (inputArgs) => commandNeedsOverlayRuntime(inputArgs),
|
||||
startBackgroundWarmups: () => startBackgroundWarmups(),
|
||||
logInfo: (message: string) => logger.info(message),
|
||||
})(),
|
||||
);
|
||||
|
||||
function handleCliCommand(args: CliArgs, source: CliCommandSource = 'initial'): void {
|
||||
handleTexthookerOnlyModeTransitionHandler(args);
|
||||
|
||||
const cliContext = createCliCommandContextHandler();
|
||||
handleCliCommandRuntimeServiceWithContext(args, source, cliContext);
|
||||
}
|
||||
},
|
||||
createCliCommandContext: () => createCliCommandContextHandler(),
|
||||
handleCliCommandRuntimeServiceWithContext: (args, source, cliContext) =>
|
||||
handleCliCommandRuntimeServiceWithContext(args, source, cliContext),
|
||||
});
|
||||
|
||||
const handleInitialArgsRuntimeHandler = createInitialArgsRuntimeHandler({
|
||||
getInitialArgs: () => appState.initialArgs,
|
||||
|
||||
33
src/main/runtime/cli-command-runtime-handler.test.ts
Normal file
33
src/main/runtime/cli-command-runtime-handler.test.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createCliCommandRuntimeHandler } from './cli-command-runtime-handler';
|
||||
|
||||
test('cli command runtime handler applies precheck and forwards command with context', () => {
|
||||
const calls: string[] = [];
|
||||
const handler = createCliCommandRuntimeHandler({
|
||||
handleTexthookerOnlyModeTransitionMainDeps: {
|
||||
isTexthookerOnlyMode: () => true,
|
||||
setTexthookerOnlyMode: () => calls.push('set-mode'),
|
||||
commandNeedsOverlayRuntime: () => true,
|
||||
startBackgroundWarmups: () => calls.push('warmups'),
|
||||
logInfo: (message) => calls.push(`log:${message}`),
|
||||
},
|
||||
createCliCommandContext: () => {
|
||||
calls.push('context');
|
||||
return { id: 'ctx' };
|
||||
},
|
||||
handleCliCommandRuntimeServiceWithContext: (_args, source, context) => {
|
||||
calls.push(`cli:${source}:${context.id}`);
|
||||
},
|
||||
});
|
||||
|
||||
handler({ start: true } as never);
|
||||
|
||||
assert.deepEqual(calls, [
|
||||
'set-mode',
|
||||
'log:Disabling texthooker-only mode after overlay/start command.',
|
||||
'warmups',
|
||||
'context',
|
||||
'cli:initial:ctx',
|
||||
]);
|
||||
});
|
||||
30
src/main/runtime/cli-command-runtime-handler.ts
Normal file
30
src/main/runtime/cli-command-runtime-handler.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { CliArgs, CliCommandSource } from '../../cli/args';
|
||||
import { createHandleTexthookerOnlyModeTransitionHandler } from './cli-command-prechecks';
|
||||
import { createBuildHandleTexthookerOnlyModeTransitionMainDepsHandler } from './cli-command-prechecks-main-deps';
|
||||
|
||||
type HandleTexthookerOnlyModeTransitionMainDeps = Parameters<
|
||||
typeof createBuildHandleTexthookerOnlyModeTransitionMainDepsHandler
|
||||
>[0];
|
||||
|
||||
export function createCliCommandRuntimeHandler<TCliContext>(deps: {
|
||||
handleTexthookerOnlyModeTransitionMainDeps: HandleTexthookerOnlyModeTransitionMainDeps;
|
||||
createCliCommandContext: () => TCliContext;
|
||||
handleCliCommandRuntimeServiceWithContext: (
|
||||
args: CliArgs,
|
||||
source: CliCommandSource,
|
||||
cliContext: TCliContext,
|
||||
) => void;
|
||||
}) {
|
||||
const handleTexthookerOnlyModeTransitionHandler =
|
||||
createHandleTexthookerOnlyModeTransitionHandler(
|
||||
createBuildHandleTexthookerOnlyModeTransitionMainDepsHandler(
|
||||
deps.handleTexthookerOnlyModeTransitionMainDeps,
|
||||
)(),
|
||||
);
|
||||
|
||||
return (args: CliArgs, source: CliCommandSource = 'initial'): void => {
|
||||
handleTexthookerOnlyModeTransitionHandler(args);
|
||||
const cliContext = deps.createCliCommandContext();
|
||||
deps.handleCliCommandRuntimeServiceWithContext(args, source, cliContext);
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user