mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
refactor: extract mpv osd and secondary-sub runtime wiring
This commit is contained in:
@@ -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-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-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-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-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` |
|
| `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` |
|
||||||
|
|||||||
@@ -9,6 +9,11 @@
|
|||||||
|
|
||||||
## Current Work (newest first)
|
## 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: 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] 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).
|
- [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).
|
||||||
|
|||||||
62
src/main.ts
62
src/main.ts
@@ -288,12 +288,8 @@ import {
|
|||||||
} from './main/runtime/overlay-window-layout-main-deps';
|
} from './main/runtime/overlay-window-layout-main-deps';
|
||||||
import { buildTrayMenuTemplateRuntime, resolveTrayIconPathRuntime } from './main/runtime/tray-runtime';
|
import { buildTrayMenuTemplateRuntime, resolveTrayIconPathRuntime } from './main/runtime/tray-runtime';
|
||||||
import { createGlobalShortcutsRuntimeHandlers } from './main/runtime/global-shortcuts-runtime-handlers';
|
import { createGlobalShortcutsRuntimeHandlers } from './main/runtime/global-shortcuts-runtime-handlers';
|
||||||
import { createAppendToMpvLogHandler, createShowMpvOsdHandler } from './main/runtime/mpv-osd-log';
|
import { createMpvOsdRuntimeHandlers } from './main/runtime/mpv-osd-runtime-handlers';
|
||||||
import {
|
import { createCycleSecondarySubModeRuntimeHandler } from './main/runtime/secondary-sub-mode-runtime-handler';
|
||||||
createBuildAppendToMpvLogMainDepsHandler,
|
|
||||||
createBuildShowMpvOsdMainDepsHandler,
|
|
||||||
} from './main/runtime/mpv-osd-log-main-deps';
|
|
||||||
import { createBuildCycleSecondarySubModeMainDepsHandler } from './main/runtime/secondary-sub-mode-main-deps';
|
|
||||||
import {
|
import {
|
||||||
createCancelNumericShortcutSessionHandler,
|
createCancelNumericShortcutSessionHandler,
|
||||||
createStartNumericShortcutSessionHandler,
|
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,
|
getSecondarySubMode: () => appState.secondarySubMode,
|
||||||
setSecondarySubMode: (mode: SecondarySubMode) => {
|
setSecondarySubMode: (mode: SecondarySubMode) => {
|
||||||
appState.secondarySubMode = mode;
|
appState.secondarySubMode = mode;
|
||||||
@@ -2537,39 +2550,8 @@ const buildCycleSecondarySubModeMainDepsHandler = createBuildCycleSecondarySubMo
|
|||||||
},
|
},
|
||||||
showMpvOsd: (text: string) => showMpvOsd(text),
|
showMpvOsd: (text: string) => showMpvOsd(text),
|
||||||
},
|
},
|
||||||
);
|
cycleSecondarySubMode: (deps) => cycleSecondarySubModeCore(deps),
|
||||||
|
|
||||||
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(),
|
|
||||||
});
|
});
|
||||||
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({
|
const buildNumericShortcutRuntimeMainDepsHandler = createBuildNumericShortcutRuntimeMainDepsHandler({
|
||||||
globalShortcut,
|
globalShortcut,
|
||||||
|
|||||||
33
src/main/runtime/mpv-osd-runtime-handlers.test.ts
Normal file
33
src/main/runtime/mpv-osd-runtime-handlers.test.ts
Normal file
@@ -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',
|
||||||
|
]);
|
||||||
|
});
|
||||||
29
src/main/runtime/mpv-osd-runtime-handlers.ts
Normal file
29
src/main/runtime/mpv-osd-runtime-handlers.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import { createAppendToMpvLogHandler, createShowMpvOsdHandler } from './mpv-osd-log';
|
||||||
|
import {
|
||||||
|
createBuildAppendToMpvLogMainDepsHandler,
|
||||||
|
createBuildShowMpvOsdMainDepsHandler,
|
||||||
|
} from './mpv-osd-log-main-deps';
|
||||||
|
|
||||||
|
type AppendToMpvLogMainDeps = Parameters<typeof createBuildAppendToMpvLogMainDepsHandler>[0];
|
||||||
|
type ShowMpvOsdMainDeps = Parameters<typeof createBuildShowMpvOsdMainDepsHandler>[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,
|
||||||
|
};
|
||||||
|
}
|
||||||
29
src/main/runtime/secondary-sub-mode-runtime-handler.test.ts
Normal file
29
src/main/runtime/secondary-sub-mode-runtime-handler.test.ts
Normal file
@@ -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',
|
||||||
|
]);
|
||||||
|
});
|
||||||
17
src/main/runtime/secondary-sub-mode-runtime-handler.ts
Normal file
17
src/main/runtime/secondary-sub-mode-runtime-handler.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { createBuildCycleSecondarySubModeMainDepsHandler } from './secondary-sub-mode-main-deps';
|
||||||
|
|
||||||
|
type CycleSecondarySubModeMainDeps = Parameters<
|
||||||
|
typeof createBuildCycleSecondarySubModeMainDepsHandler
|
||||||
|
>[0];
|
||||||
|
type CycleSecondarySubModeDeps = ReturnType<
|
||||||
|
ReturnType<typeof createBuildCycleSecondarySubModeMainDepsHandler>
|
||||||
|
>;
|
||||||
|
|
||||||
|
export function createCycleSecondarySubModeRuntimeHandler(deps: {
|
||||||
|
cycleSecondarySubModeMainDeps: CycleSecondarySubModeMainDeps;
|
||||||
|
cycleSecondarySubMode: (deps: CycleSecondarySubModeDeps) => void;
|
||||||
|
}) {
|
||||||
|
const buildCycleSecondarySubModeMainDepsHandler =
|
||||||
|
createBuildCycleSecondarySubModeMainDepsHandler(deps.cycleSecondarySubModeMainDeps);
|
||||||
|
return () => deps.cycleSecondarySubMode(buildCycleSecondarySubModeMainDepsHandler());
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user