mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-10 04:46:07 -08:00
* refactor(main): build overlay geometry and pointer interaction in the overlay assembly Inject Electron's screen (and the stats-window promotion) into the overlay geometry and visible-overlay interaction runtimes so they load under bun test, then construct both in createOverlayAssembly together with the overlay visibility composer and the mpv subtitle suppression handlers. Replace the three regex tests that pinned the moved Linux input and shape code with behaviour tests on the runtimes. * refactor(main): move the autoplay-ready gate into the playback assembly The autoplay-ready gate, its post-warm subtitle prime, the current-media tokenization gate and managed local subtitle selection all read playback state, and playback signals through the gate, so createPlaybackAssembly now builds them. The overlay reaches the gate through a getter. Replace the last four regex guards with behaviour tests: the gate holds the release until the visible overlay has measured the line and ignores untokenized lines during warmup (playback), cached autoplay priming never paints raw first and the sidebar media path is tagged only after prefetch loads (priming runtime), and dashboard mining overrides the Hachidori Anki server only when the proxy is on (stats server runtime). main-wiring.test.ts is now empty and removed. * refactor(main): move the plugin host, panel and windows into a plugins assembly * refactor(main): move session action dispatch and renderer mpv commands into an assembly createSessionActionsAssembly owns the session action dispatcher, the secondary-subtitle mode cycle, queueing the clipboard's video, and the mpv commands the overlay renderer sends. The runtime option cycle both paths used is now one function. * refactor(main): move Whisper subtitle generation into an assembly * refactor(main): resolve subtitle annotation options in a runtime module The runtime-option-over-config resolution that the texthooker page and the MeCab startup decision share moves out of main.ts into createAnnotationOptions. * test(main): cover a non-boolean runtime annotation option value * docs: describe the plugins, session actions and subtitle generation assemblies Update ownership for overlay geometry and pointer interaction, the autoplay-ready gate, and annotation options; point the overlay priming entry points at their new modules; the main-wiring regex debt is gone. * build: export MpvClientEvents so declaration emit can name the plugins assembly's return type
84 lines
2.9 KiB
TypeScript
84 lines
2.9 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
import { createAppState } from '../state';
|
|
import { createPluginsAssembly, type PluginsAssemblyDeps } from './plugins';
|
|
|
|
type MpvClient = NonNullable<ReturnType<typeof createAppState>['mpvClient']>;
|
|
|
|
function lazy(name: string) {
|
|
return (): never => {
|
|
throw new Error(`${name} called unexpectedly`);
|
|
};
|
|
}
|
|
|
|
/** Builds deps whose every function throws, so construction must not call any of them. */
|
|
function makeDeps(): PluginsAssemblyDeps {
|
|
const thrower = <T extends object>(name: string): T =>
|
|
new Proxy({}, { get: (_target, key: string) => lazy(`${name}.${key}`) }) as T;
|
|
return {
|
|
appState: createAppState({ mpvSocketPath: '/tmp/subminer-plugins.sock', texthookerPort: 0 }),
|
|
configService: thrower('configService'),
|
|
overlayManager: thrower('overlayManager'),
|
|
logger: thrower('logger'),
|
|
createLogger: lazy('createLogger'),
|
|
configDir: '/tmp/subminer-plugins-test',
|
|
userDataPath: '/tmp/subminer-plugins-test',
|
|
overlayModalRuntime: thrower('overlayModalRuntime'),
|
|
overlayModals: thrower('overlayModals'),
|
|
getOverlayNotifications: lazy('getOverlayNotifications'),
|
|
createBrowserWindow: lazy('createBrowserWindow'),
|
|
promoteAboveOverlay: lazy('promoteAboveOverlay'),
|
|
ensureMpvRunning: lazy('ensureMpvRunning'),
|
|
dispatchSessionAction: lazy('dispatchSessionAction'),
|
|
};
|
|
}
|
|
|
|
test('createPluginsAssembly does not call its deps while constructing', () => {
|
|
const plugins = createPluginsAssembly(makeDeps());
|
|
assert.equal(typeof plugins.host.loadAll, 'function');
|
|
});
|
|
|
|
test('plugins see the current line with its parsed cue timing', () => {
|
|
const deps = makeDeps();
|
|
deps.appState.currentSubText = '一行目';
|
|
deps.appState.activeParsedSubtitleCues = [{ startTime: 10, endTime: 12, text: '一行目' }];
|
|
deps.appState.mpvClient = {
|
|
currentSubText: '一行目',
|
|
currentTimePos: 11,
|
|
currentSubDelay: 0,
|
|
} as MpvClient;
|
|
|
|
assert.deepEqual(createPluginsAssembly(deps).getCurrentSubtitle(), {
|
|
text: '一行目',
|
|
startTime: 10,
|
|
endTime: 12,
|
|
});
|
|
});
|
|
|
|
test('without parsed cues plugins get the live line, timed only while mpv reports a span', () => {
|
|
const deps = makeDeps();
|
|
const plugins = createPluginsAssembly(deps);
|
|
deps.appState.currentSubText = 'ライブ';
|
|
deps.appState.mpvClient = {
|
|
currentSubText: 'ライブ',
|
|
currentSubStart: 3,
|
|
currentSubEnd: 5,
|
|
} as MpvClient;
|
|
assert.deepEqual(plugins.getCurrentSubtitle(), { text: 'ライブ', startTime: 3, endTime: 5 });
|
|
|
|
// A cleared sub-start reads as zero; a span that does not move forward is not a timing.
|
|
deps.appState.mpvClient = {
|
|
currentSubText: 'ライブ',
|
|
currentSubStart: 0,
|
|
currentSubEnd: 0,
|
|
} as MpvClient;
|
|
assert.deepEqual(plugins.getCurrentSubtitle(), {
|
|
text: 'ライブ',
|
|
startTime: null,
|
|
endTime: null,
|
|
});
|
|
|
|
deps.appState.currentSubText = ' ';
|
|
assert.equal(plugins.getCurrentSubtitle(), null);
|
|
});
|