From 4010fc1b0429b5ab85ae0e300b686b1ae54c3f6d Mon Sep 17 00:00:00 2001 From: sudacode Date: Fri, 20 Feb 2026 01:32:37 -0800 Subject: [PATCH] refactor: normalize additional main dependency construction --- .../codex-task85-20260219T233711Z-46hc.md | 2 + src/main.ts | 62 +++++++++++-------- 2 files changed, 38 insertions(+), 26 deletions(-) diff --git a/docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md b/docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md index caed325..d42ed3a 100644 --- a/docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md +++ b/docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md @@ -407,3 +407,5 @@ - [2026-02-20T09:30:02Z] progress: applied 5-block safe normalization in `main.ts` by prebuilding deps handlers for global shortcuts (`getConfiguredShortcuts`, `registerGlobalShortcuts`, `refreshGlobalAndOverlayShortcuts`) and MPV logging/OSD (`appendToMpvLog`, `showMpvOsd`). - [2026-02-20T09:30:02Z] progress: earlier in this batch also extracted `jellyfin-playback-launch-main-deps`, `immersion-startup-main-deps`, `numeric-shortcut-runtime-main-deps`, and `mpv-subtitle-render-metrics-main-deps`; extended `config-hot-reload-main-deps` with watcher/message builders. - [2026-02-20T09:30:02Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + targeted suites pass for `global-shortcuts*`, `mpv-osd-log*`, `jellyfin-playback-launch*`, `immersion-startup*`, `config-hot-reload-main-deps*`, `mpv-subtitle-render-metrics*`, `numeric-shortcut-runtime-main-deps*`, `initial-args*`. +- [2026-02-20T09:32:11Z] progress: completed 5-block safe normalization in `main.ts`: prebuilt deps handlers for CLI context main deps, MPV main-event bind deps, MPV runtime service factory deps, MeCab initializer deps, and subtitle dictionary prewarm deps. +- [2026-02-20T09:32:11Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + targeted suites pass: `cli-command-context-main-deps`, `mpv-main-event-main-deps`, `mpv-main-event-bindings`, `mpv-client-runtime-service-main-deps`, `subtitle-tokenization-main-deps`. diff --git a/src/main.ts b/src/main.ts index de139ca..5e0269b 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2189,7 +2189,7 @@ function handleInitialArgs(): void { handleInitialArgsRuntimeHandler(); } -const bindMpvClientEventHandlers = createBindMpvMainEventHandlersHandler( +const buildBindMpvMainEventHandlersMainDepsHandler = createBuildBindMpvMainEventHandlersMainDepsHandler({ appState, getQuitOnDisconnectArmed: () => jellyfinPlayQuitOnDisconnectArmed, @@ -2236,27 +2236,30 @@ const bindMpvClientEventHandlers = createBindMpvMainEventHandlersHandler( updateSubtitleRenderMetrics: (patch) => { updateMpvSubtitleRenderMetrics(patch as Partial); }, - })(), + }); +const bindMpvClientEventHandlers = createBindMpvMainEventHandlersHandler( + buildBindMpvMainEventHandlersMainDepsHandler(), ); +const buildMpvClientRuntimeServiceFactoryMainDepsHandler = + createBuildMpvClientRuntimeServiceFactoryDepsHandler({ + createClient: MpvIpcClient, + getSocketPath: () => appState.mpvSocketPath, + getResolvedConfig: () => getResolvedConfig(), + isAutoStartOverlayEnabled: () => appState.autoStartOverlay, + setOverlayVisible: (visible: boolean) => setOverlayVisible(visible), + shouldBindVisibleOverlayToMpvSubVisibility: () => + configDerivedRuntime.shouldBindVisibleOverlayToMpvSubVisibility(), + isVisibleOverlayVisible: () => overlayManager.getVisibleOverlayVisible(), + getReconnectTimer: () => appState.reconnectTimer, + setReconnectTimer: (timer: ReturnType | null) => { + appState.reconnectTimer = timer; + }, + bindEventHandlers: (client) => bindMpvClientEventHandlers(client), + }); + function createMpvClientRuntimeService(): MpvIpcClient { - return createMpvClientRuntimeServiceFactory( - createBuildMpvClientRuntimeServiceFactoryDepsHandler({ - createClient: MpvIpcClient, - getSocketPath: () => appState.mpvSocketPath, - getResolvedConfig: () => getResolvedConfig(), - isAutoStartOverlayEnabled: () => appState.autoStartOverlay, - setOverlayVisible: (visible: boolean) => setOverlayVisible(visible), - shouldBindVisibleOverlayToMpvSubVisibility: () => - configDerivedRuntime.shouldBindVisibleOverlayToMpvSubVisibility(), - isVisibleOverlayVisible: () => overlayManager.getVisibleOverlayVisible(), - getReconnectTimer: () => appState.reconnectTimer, - setReconnectTimer: (timer: ReturnType | null) => { - appState.reconnectTimer = timer; - }, - bindEventHandlers: (client) => bindMpvClientEventHandlers(client), - })(), - )(); + return createMpvClientRuntimeServiceFactory(buildMpvClientRuntimeServiceFactoryMainDepsHandler())(); } const buildUpdateMpvSubtitleRenderMetricsMainDepsHandler = @@ -2308,19 +2311,25 @@ const buildTokenizerDepsHandler = createBuildTokenizerDepsMainHandler({ getMecabTokenizer: () => appState.mecabTokenizer, }); -const createMecabTokenizerAndCheckHandler = createCreateMecabTokenizerAndCheckMainHandler({ +const buildCreateMecabTokenizerAndCheckMainDepsHandler = createCreateMecabTokenizerAndCheckMainHandler( + { getMecabTokenizer: () => appState.mecabTokenizer, setMecabTokenizer: (tokenizer) => { appState.mecabTokenizer = tokenizer; }, createMecabTokenizer: () => new MecabTokenizer(), checkAvailability: async (tokenizer) => tokenizer.checkAvailability(), -}); +}, +); +const createMecabTokenizerAndCheckHandler = buildCreateMecabTokenizerAndCheckMainDepsHandler; -const prewarmSubtitleDictionariesHandler = createPrewarmSubtitleDictionariesMainHandler({ +const buildPrewarmSubtitleDictionariesMainDepsHandler = createPrewarmSubtitleDictionariesMainHandler( + { ensureJlptDictionaryLookup: () => jlptDictionaryRuntime.ensureJlptDictionaryLookup(), ensureFrequencyDictionaryLookup: () => frequencyDictionaryRuntime.ensureFrequencyDictionaryLookup(), -}); +}, +); +const prewarmSubtitleDictionariesHandler = buildPrewarmSubtitleDictionariesMainDepsHandler; async function tokenizeSubtitle(text: string): Promise { await jlptDictionaryRuntime.ensureJlptDictionaryLookup(); @@ -2864,8 +2873,7 @@ const buildRunSubsyncManualFromIpcMainDepsHandler = const runSubsyncManualFromIpcHandler = createRunSubsyncManualFromIpcHandler( buildRunSubsyncManualFromIpcMainDepsHandler(), ); -const buildCliCommandContextDepsHandler = createBuildCliCommandContextDepsHandler( - createBuildCliCommandContextMainDepsHandler({ +const buildCliCommandContextMainDepsHandler = createBuildCliCommandContextMainDepsHandler({ appState, texthookerService, getResolvedConfig: () => getResolvedConfig(), @@ -2906,7 +2914,9 @@ const buildCliCommandContextDepsHandler = createBuildCliCommandContextDepsHandle logInfo: (message: string) => logger.info(message), logWarn: (message: string) => logger.warn(message), logError: (message: string, err: unknown) => logger.error(message, err), - })(), + }); +const buildCliCommandContextDepsHandler = createBuildCliCommandContextDepsHandler( + buildCliCommandContextMainDepsHandler(), ); const createOverlayWindowHandler = createCreateOverlayWindowHandler( createBuildCreateOverlayWindowMainDepsHandler({