mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -08:00
refactor: extract mpv osd and secondary-sub runtime wiring
This commit is contained in:
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