From eef8a7eb41ef935327ca0ca4724d1c98827d5ac1 Mon Sep 17 00:00:00 2001 From: sudacode Date: Fri, 20 Feb 2026 03:33:06 -0800 Subject: [PATCH] refactor: extract mpv osd and secondary-sub runtime wiring --- docs/subagents/INDEX.md | 2 +- .../codex-task85-20260219T233711Z-46hc.md | 5 ++ src/main.ts | 62 +++++++------------ .../runtime/mpv-osd-runtime-handlers.test.ts | 33 ++++++++++ src/main/runtime/mpv-osd-runtime-handlers.ts | 29 +++++++++ ...secondary-sub-mode-runtime-handler.test.ts | 29 +++++++++ .../secondary-sub-mode-runtime-handler.ts | 17 +++++ 7 files changed, 136 insertions(+), 41 deletions(-) create mode 100644 src/main/runtime/mpv-osd-runtime-handlers.test.ts create mode 100644 src/main/runtime/mpv-osd-runtime-handlers.ts create mode 100644 src/main/runtime/secondary-sub-mode-runtime-handler.test.ts create mode 100644 src/main/runtime/secondary-sub-mode-runtime-handler.ts diff --git a/docs/subagents/INDEX.md b/docs/subagents/INDEX.md index 5417c32..99b07a3 100644 --- a/docs/subagents/INDEX.md +++ b/docs/subagents/INDEX.md @@ -6,7 +6,7 @@ Read first. Keep concise. | ------------ | -------------- | ---------------------------------------------------- | --------- | ------------------------------------- | ---------------------- | | `codex-generate-minecard-image-20260220T112900Z-vsxr` | `codex-generate-minecard-image` | `Generate media fallbacks (GIF) from assets/minecard.webm and wire README/docs fallback markup` | `done` | `docs/subagents/agents/codex-generate-minecard-image-20260220T112900Z-vsxr.md` | `2026-02-20T11:35:30Z` | | `codex-main` | `planner-exec` | `Fix frequency/N+1 regression in plugin --start flow` | `in_progress` | `docs/subagents/agents/codex-main.md` | `2026-02-19T19:36:46Z` | -| `codex-task85-20260219T233711Z-46hc` | `codex-task85` | `Resume TASK-85 maintainability refactor from latest handoff point` | `in_progress` | `docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md` | `2026-02-20T11:18:02Z` | +| `codex-task85-20260219T233711Z-46hc` | `codex-task85` | `Resume TASK-85 maintainability refactor from latest handoff point` | `in_progress` | `docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md` | `2026-02-20T11:32:45Z` | | `codex-config-validation-20260219T172015Z-iiyf` | `codex-config-validation` | `Find root cause of config validation error for ~/.config/SubMiner/config.jsonc` | `completed` | `docs/subagents/agents/codex-config-validation-20260219T172015Z-iiyf.md` | `2026-02-19T17:26:17Z` | | `codex-task85-20260219T233711Z-46hc` | `codex-task85` | `Resume TASK-85 maintainability refactor from latest handoff point` | `in_progress` | `docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md` | `2026-02-20T02:56:34Z` | | `codex-anilist-deeplink-20260219T233926Z` | `anilist-deeplink` | `Fix external subminer:// AniList callback handling from browser` | `done` | `docs/subagents/agents/codex-anilist-deeplink-20260219T233926Z.md` | `2026-02-19T23:59:21Z` | diff --git a/docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md b/docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md index 4c6002b..13a556c 100644 --- a/docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md +++ b/docs/subagents/agents/codex-task85-20260219T233711Z-46hc.md @@ -9,6 +9,11 @@ ## Current Work (newest first) +- [2026-02-20T11:32:45Z] progress: extracted MPV OSD composition from `src/main.ts` into `src/main/runtime/mpv-osd-runtime-handlers.ts`; `main.ts` now receives `appendToMpvLog` and `showMpvOsd` from one runtime factory. +- [2026-02-20T11:32:45Z] progress: extracted secondary subtitle mode composition from `src/main.ts` into `src/main/runtime/secondary-sub-mode-runtime-handler.ts`; `main.ts` now builds `cycleSecondarySubMode` via one runtime handler factory. +- [2026-02-20T11:32:45Z] progress: added parity tests `src/main/runtime/mpv-osd-runtime-handlers.test.ts` and `src/main/runtime/secondary-sub-mode-runtime-handler.test.ts`. +- [2026-02-20T11:32:45Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + focused suites pass for `mpv-osd-runtime-handlers*`, `secondary-sub-mode-runtime-handler*`, `mpv-osd-log*`, `secondary-sub-mode-main-deps*`, and `global-shortcuts-runtime-handlers*` (7/7). +- [2026-02-20T11:32:45Z] scope: staging `src/main.ts`, new mpv-osd/secondary-sub runtime handler modules/tests, and subagent bookkeeping only. - [2026-02-20T11:18:02Z] progress: extracted global shortcuts composition from `src/main.ts` into `src/main/runtime/global-shortcuts-runtime-handlers.ts`; `main.ts` now obtains `getConfiguredShortcuts`/`registerGlobalShortcuts`/`refreshGlobalAndOverlayShortcuts` from one runtime factory. - [2026-02-20T11:18:02Z] progress: added parity coverage in `src/main/runtime/global-shortcuts-runtime-handlers.test.ts` for get/register/refresh wiring. - [2026-02-20T11:18:02Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + focused suites pass for `global-shortcuts-runtime-handlers*`, `global-shortcuts*`, `global-shortcuts-main-deps*`, `cli-command-runtime-handler*`, and `startup-runtime-handlers*` (9/9). diff --git a/src/main.ts b/src/main.ts index 09deea7..e0527c6 100644 --- a/src/main.ts +++ b/src/main.ts @@ -288,12 +288,8 @@ import { } from './main/runtime/overlay-window-layout-main-deps'; import { buildTrayMenuTemplateRuntime, resolveTrayIconPathRuntime } from './main/runtime/tray-runtime'; import { createGlobalShortcutsRuntimeHandlers } from './main/runtime/global-shortcuts-runtime-handlers'; -import { createAppendToMpvLogHandler, createShowMpvOsdHandler } from './main/runtime/mpv-osd-log'; -import { - createBuildAppendToMpvLogMainDepsHandler, - createBuildShowMpvOsdMainDepsHandler, -} from './main/runtime/mpv-osd-log-main-deps'; -import { createBuildCycleSecondarySubModeMainDepsHandler } from './main/runtime/secondary-sub-mode-main-deps'; +import { createMpvOsdRuntimeHandlers } from './main/runtime/mpv-osd-runtime-handlers'; +import { createCycleSecondarySubModeRuntimeHandler } from './main/runtime/secondary-sub-mode-runtime-handler'; import { createCancelNumericShortcutSessionHandler, createStartNumericShortcutSessionHandler, @@ -2522,8 +2518,25 @@ const { }), }); -const buildCycleSecondarySubModeMainDepsHandler = createBuildCycleSecondarySubModeMainDepsHandler( - { +const { appendToMpvLog, showMpvOsd } = createMpvOsdRuntimeHandlers({ + appendToMpvLogMainDeps: { + logPath: DEFAULT_MPV_LOG_PATH, + dirname: (targetPath) => path.dirname(targetPath), + mkdirSync: (targetPath, options) => fs.mkdirSync(targetPath, options), + appendFileSync: (targetPath, data, options) => fs.appendFileSync(targetPath, data, options), + now: () => new Date(), + }, + buildShowMpvOsdMainDeps: (appendToMpvLogHandler) => ({ + appendToMpvLog: (message) => appendToMpvLogHandler(message), + showMpvOsdRuntime: (mpvClient, text, fallbackLog) => + showMpvOsdRuntime(mpvClient as never, text, fallbackLog), + getMpvClient: () => appState.mpvClient, + logInfo: (line) => logger.info(line), + }), +}); + +const cycleSecondarySubMode = createCycleSecondarySubModeRuntimeHandler({ + cycleSecondarySubModeMainDeps: { getSecondarySubMode: () => appState.secondarySubMode, setSecondarySubMode: (mode: SecondarySubMode) => { appState.secondarySubMode = mode; @@ -2537,39 +2550,8 @@ const buildCycleSecondarySubModeMainDepsHandler = createBuildCycleSecondarySubMo }, showMpvOsd: (text: string) => showMpvOsd(text), }, -); - -function cycleSecondarySubMode(): void { - cycleSecondarySubModeCore(buildCycleSecondarySubModeMainDepsHandler()); -} - -const buildAppendToMpvLogMainDepsHandler = createBuildAppendToMpvLogMainDepsHandler({ - logPath: DEFAULT_MPV_LOG_PATH, - dirname: (targetPath) => path.dirname(targetPath), - mkdirSync: (targetPath, options) => fs.mkdirSync(targetPath, options), - appendFileSync: (targetPath, data, options) => fs.appendFileSync(targetPath, data, options), - now: () => new Date(), + cycleSecondarySubMode: (deps) => cycleSecondarySubModeCore(deps), }); -const appendToMpvLogMainDeps = buildAppendToMpvLogMainDepsHandler(); -const appendToMpvLogHandler = createAppendToMpvLogHandler(appendToMpvLogMainDeps); - -const buildShowMpvOsdMainDepsHandler = createBuildShowMpvOsdMainDepsHandler({ - appendToMpvLog: (message) => appendToMpvLog(message), - showMpvOsdRuntime: (mpvClient, text, fallbackLog) => - showMpvOsdRuntime(mpvClient as never, text, fallbackLog), - getMpvClient: () => appState.mpvClient, - logInfo: (line) => logger.info(line), -}); -const showMpvOsdMainDeps = buildShowMpvOsdMainDepsHandler(); -const showMpvOsdHandler = createShowMpvOsdHandler(showMpvOsdMainDeps); - -function showMpvOsd(text: string): void { - showMpvOsdHandler(text); -} - -function appendToMpvLog(message: string): void { - appendToMpvLogHandler(message); -} const buildNumericShortcutRuntimeMainDepsHandler = createBuildNumericShortcutRuntimeMainDepsHandler({ globalShortcut, diff --git a/src/main/runtime/mpv-osd-runtime-handlers.test.ts b/src/main/runtime/mpv-osd-runtime-handlers.test.ts new file mode 100644 index 0000000..cf27e21 --- /dev/null +++ b/src/main/runtime/mpv-osd-runtime-handlers.test.ts @@ -0,0 +1,33 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { createMpvOsdRuntimeHandlers } from './mpv-osd-runtime-handlers'; + +test('mpv osd runtime handlers compose append and osd logging flow', () => { + const calls: string[] = []; + const runtime = createMpvOsdRuntimeHandlers({ + appendToMpvLogMainDeps: { + logPath: '/tmp/subminer/mpv.log', + dirname: () => '/tmp/subminer', + mkdirSync: () => {}, + appendFileSync: (_targetPath, data) => calls.push(`append:${data.trimEnd()}`), + now: () => new Date('2026-02-20T00:00:00.000Z'), + }, + buildShowMpvOsdMainDeps: (appendToMpvLog) => ({ + appendToMpvLog, + showMpvOsdRuntime: (_client, text, fallbackLog) => { + calls.push(`show:${text}`); + fallbackLog('fallback'); + }, + getMpvClient: () => null, + logInfo: (line) => calls.push(`info:${line}`), + }), + }); + + runtime.showMpvOsd('hello'); + + assert.deepEqual(calls, [ + 'append:[2026-02-20T00:00:00.000Z] [OSD] hello', + 'show:hello', + 'info:fallback', + ]); +}); diff --git a/src/main/runtime/mpv-osd-runtime-handlers.ts b/src/main/runtime/mpv-osd-runtime-handlers.ts new file mode 100644 index 0000000..f7c8deb --- /dev/null +++ b/src/main/runtime/mpv-osd-runtime-handlers.ts @@ -0,0 +1,29 @@ +import { createAppendToMpvLogHandler, createShowMpvOsdHandler } from './mpv-osd-log'; +import { + createBuildAppendToMpvLogMainDepsHandler, + createBuildShowMpvOsdMainDepsHandler, +} from './mpv-osd-log-main-deps'; + +type AppendToMpvLogMainDeps = Parameters[0]; +type ShowMpvOsdMainDeps = Parameters[0]; + +export function createMpvOsdRuntimeHandlers(deps: { + appendToMpvLogMainDeps: AppendToMpvLogMainDeps; + buildShowMpvOsdMainDeps: (appendToMpvLog: (message: string) => void) => ShowMpvOsdMainDeps; +}) { + const appendToMpvLogMainDeps = + createBuildAppendToMpvLogMainDepsHandler(deps.appendToMpvLogMainDeps)(); + const appendToMpvLogHandler = createAppendToMpvLogHandler(appendToMpvLogMainDeps); + const appendToMpvLog = (message: string) => appendToMpvLogHandler(message); + + const showMpvOsdMainDeps = createBuildShowMpvOsdMainDepsHandler( + deps.buildShowMpvOsdMainDeps(appendToMpvLog), + )(); + const showMpvOsdHandler = createShowMpvOsdHandler(showMpvOsdMainDeps); + const showMpvOsd = (text: string) => showMpvOsdHandler(text); + + return { + appendToMpvLog, + showMpvOsd, + }; +} diff --git a/src/main/runtime/secondary-sub-mode-runtime-handler.test.ts b/src/main/runtime/secondary-sub-mode-runtime-handler.test.ts new file mode 100644 index 0000000..a3c25d8 --- /dev/null +++ b/src/main/runtime/secondary-sub-mode-runtime-handler.test.ts @@ -0,0 +1,29 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { createCycleSecondarySubModeRuntimeHandler } from './secondary-sub-mode-runtime-handler'; + +test('secondary sub mode runtime handler composes deps for runtime call', () => { + const calls: string[] = []; + const handleCycleSecondarySubMode = createCycleSecondarySubModeRuntimeHandler({ + cycleSecondarySubModeMainDeps: { + getSecondarySubMode: () => 'hidden', + setSecondarySubMode: () => calls.push('set-mode'), + getLastSecondarySubToggleAtMs: () => 10, + setLastSecondarySubToggleAtMs: () => calls.push('set-ts'), + broadcastToOverlayWindows: (channel, mode) => calls.push(`broadcast:${channel}:${mode}`), + showMpvOsd: (text) => calls.push(`osd:${text}`), + }, + cycleSecondarySubMode: (deps) => { + deps.setSecondarySubMode('romaji' as never); + deps.broadcastSecondarySubMode('romaji' as never); + deps.showMpvOsd('romaji'); + }, + }); + + handleCycleSecondarySubMode(); + assert.deepEqual(calls, [ + 'set-mode', + 'broadcast:secondary-subtitle:mode:romaji', + 'osd:romaji', + ]); +}); diff --git a/src/main/runtime/secondary-sub-mode-runtime-handler.ts b/src/main/runtime/secondary-sub-mode-runtime-handler.ts new file mode 100644 index 0000000..201e8ec --- /dev/null +++ b/src/main/runtime/secondary-sub-mode-runtime-handler.ts @@ -0,0 +1,17 @@ +import { createBuildCycleSecondarySubModeMainDepsHandler } from './secondary-sub-mode-main-deps'; + +type CycleSecondarySubModeMainDeps = Parameters< + typeof createBuildCycleSecondarySubModeMainDepsHandler +>[0]; +type CycleSecondarySubModeDeps = ReturnType< + ReturnType +>; + +export function createCycleSecondarySubModeRuntimeHandler(deps: { + cycleSecondarySubModeMainDeps: CycleSecondarySubModeMainDeps; + cycleSecondarySubMode: (deps: CycleSecondarySubModeDeps) => void; +}) { + const buildCycleSecondarySubModeMainDepsHandler = + createBuildCycleSecondarySubModeMainDepsHandler(deps.cycleSecondarySubModeMainDeps); + return () => deps.cycleSecondarySubMode(buildCycleSecondarySubModeMainDepsHandler()); +}