mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-10 04:46:07 -08:00
refactor(main): move plugins, session actions and subtitle generation into assemblies (#327)
* 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
This commit is contained in:
1 parent
14ef7e823c
commit
f89f78b861
28 files changed
+2005
-1147
No files matched your search
@@ -0,0 +1,132 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test, { type TestContext } from 'node:test';
|
||||
import type { BrowserWindow } from 'electron';
|
||||
import { stopLinuxOverlayPointerInteractionLoop } from './linux-overlay-pointer-interaction';
|
||||
import { stopLinuxOverlayZOrderKeepAliveLoop } from './linux-overlay-zorder-keepalive';
|
||||
import {
|
||||
createVisibleOverlayInteractionRuntime,
|
||||
type VisibleOverlayInteractionRuntimeDeps,
|
||||
} from './visible-overlay-interaction-runtime';
|
||||
|
||||
type MouseEventsCall = { ignore: boolean; options?: { forward?: boolean } };
|
||||
|
||||
/** Builds the runtime with `process.platform` set, a visible overlay and a fake main window. */
|
||||
function setup(t: TestContext, platform: NodeJS.Platform) {
|
||||
const originalPlatform = process.platform;
|
||||
Object.defineProperty(process, 'platform', { value: platform, configurable: true });
|
||||
t.after(() => {
|
||||
Object.defineProperty(process, 'platform', { value: originalPlatform });
|
||||
// Construction on Linux starts the shared pointer poll and z-order keep-alive loops.
|
||||
stopLinuxOverlayPointerInteractionLoop();
|
||||
stopLinuxOverlayZOrderKeepAliveLoop();
|
||||
});
|
||||
|
||||
const mouseEvents: MouseEventsCall[] = [];
|
||||
const clearedLayers: string[] = [];
|
||||
const mainWindow = {
|
||||
isDestroyed: () => false,
|
||||
isVisible: () => true,
|
||||
isFocused: () => true,
|
||||
getBounds: () => ({ x: 0, y: 0, width: 1920, height: 1080 }),
|
||||
setShape: () => {},
|
||||
setIgnoreMouseEvents: (ignore: boolean, options?: { forward?: boolean }) => {
|
||||
mouseEvents.push({ ignore, options });
|
||||
},
|
||||
} as unknown as BrowserWindow;
|
||||
const noop = () => {};
|
||||
const deps: VisibleOverlayInteractionRuntimeDeps = {
|
||||
screen: {
|
||||
getCursorScreenPoint: () => ({ x: 5, y: 5 }),
|
||||
screenToDipPoint: (point) => point,
|
||||
},
|
||||
overlayManager: {
|
||||
getMainWindow: () => mainWindow,
|
||||
getVisibleOverlayVisible: () => true,
|
||||
},
|
||||
overlayContentMeasurementStore: {
|
||||
clear: (layer) => {
|
||||
clearedLayers.push(layer);
|
||||
},
|
||||
getLatestByLayer: () => null,
|
||||
},
|
||||
logger: { info: noop, warn: noop, debug: noop },
|
||||
updateVisibleOverlayVisibility: noop,
|
||||
getModalInputExclusive: () => false,
|
||||
getStatsOverlayVisible: () => false,
|
||||
setStatsOverlayVisible: noop,
|
||||
getWindowTracker: () => null,
|
||||
setWindowTracker: noop,
|
||||
setTrackerNotReadyWarningShown: noop,
|
||||
getMpvSocketPath: () => '/tmp/subminer-interaction-test.sock',
|
||||
getBackendOverride: () => null,
|
||||
getInitialArgs: () => null,
|
||||
getOverlayRuntimeInitialized: () => true,
|
||||
getLinuxVisibleOverlayWindowMode: () => 'managed',
|
||||
setLinuxVisibleOverlayOwnerBindingKey: noop,
|
||||
bindVisibleOverlayToTrackedX11Window: noop,
|
||||
updateVisibleOverlayBounds: noop,
|
||||
refreshCurrentSubtitle: noop,
|
||||
getOverlayWindows: () => [mainWindow],
|
||||
syncOverlayShortcuts: noop,
|
||||
resetLastOverlayWindowGeometry: noop,
|
||||
enforceOverlayLayerOrder: noop,
|
||||
getOverlayForegroundSeparateWindows: () => [],
|
||||
};
|
||||
const runtime = createVisibleOverlayInteractionRuntime(deps);
|
||||
return { runtime, mouseEvents, clearedLayers };
|
||||
}
|
||||
|
||||
test('resetting visible overlay input clears the visible content measurement', (t) => {
|
||||
const { runtime, clearedLayers } = setup(t, 'darwin');
|
||||
|
||||
runtime.resetVisibleOverlayInputState();
|
||||
|
||||
assert.deepEqual(clearedLayers, ['visible']);
|
||||
});
|
||||
|
||||
// With no subtitle under the cursor the poll wants passthrough. An input reset leaves the
|
||||
// window's real state unknown, so the next poll must reapply it even though the desired state
|
||||
// matches the remembered one. Hiding resets all input; showing resets only the startup primer.
|
||||
for (const reset of [
|
||||
'resetVisibleOverlayInputState',
|
||||
'resetLinuxVisibleOverlayStartupInputPrimer',
|
||||
] as const) {
|
||||
test(`the Linux pointer poll reapplies passive passthrough after ${reset}`, (t) => {
|
||||
const { runtime, mouseEvents } = setup(t, 'linux');
|
||||
const passthrough: MouseEventsCall = { ignore: true, options: { forward: true } };
|
||||
|
||||
runtime.tickLinuxOverlayPointerInteractionNow();
|
||||
runtime.tickLinuxOverlayPointerInteractionNow();
|
||||
assert.deepEqual(mouseEvents, [passthrough]);
|
||||
|
||||
runtime[reset]();
|
||||
runtime.tickLinuxOverlayPointerInteractionNow();
|
||||
runtime.tickLinuxOverlayPointerInteractionNow();
|
||||
assert.deepEqual(mouseEvents, [passthrough, passthrough]);
|
||||
});
|
||||
}
|
||||
|
||||
test('the Linux startup input grace makes the overlay interactive on the next poll', (t) => {
|
||||
const { runtime, mouseEvents } = setup(t, 'linux');
|
||||
runtime.tickLinuxOverlayPointerInteractionNow();
|
||||
|
||||
runtime.startLinuxVisibleOverlayStartupInputGrace();
|
||||
runtime.tickLinuxOverlayPointerInteractionNow();
|
||||
|
||||
assert.deepEqual(mouseEvents.at(-1), { ignore: false, options: undefined });
|
||||
assert.equal(runtime.getVisibleOverlayInteractionActive(), true);
|
||||
});
|
||||
|
||||
test('the Linux startup input grace reasserts input on an overlay that is already interactive', (t) => {
|
||||
const { runtime, mouseEvents } = setup(t, 'linux');
|
||||
const interactive: MouseEventsCall = { ignore: false, options: undefined };
|
||||
runtime.setLinuxOverlayInteractiveHint(true);
|
||||
runtime.tickLinuxOverlayPointerInteractionNow();
|
||||
runtime.tickLinuxOverlayPointerInteractionNow();
|
||||
assert.deepEqual(mouseEvents, [interactive]);
|
||||
|
||||
runtime.startLinuxVisibleOverlayStartupInputGrace();
|
||||
runtime.tickLinuxOverlayPointerInteractionNow();
|
||||
|
||||
assert.deepEqual(mouseEvents, [interactive, interactive]);
|
||||
});
|
||||
Reference in new issue
Block a user