mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -08:00
refactor: extract overlay bootstrap runtime wiring
This commit is contained in:
66
src/main/runtime/overlay-runtime-bootstrap-handlers.test.ts
Normal file
66
src/main/runtime/overlay-runtime-bootstrap-handlers.test.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createOverlayRuntimeBootstrapHandlers } from './overlay-runtime-bootstrap-handlers';
|
||||
|
||||
test('overlay runtime bootstrap handlers compose options builder and bootstrap handler', () => {
|
||||
const appState = {
|
||||
backendOverride: null as string | null,
|
||||
windowTracker: null as unknown,
|
||||
subtitleTimingTracker: null as unknown,
|
||||
mpvClient: null as unknown,
|
||||
mpvSocketPath: '/tmp/mpv.sock',
|
||||
runtimeOptionsManager: null as unknown,
|
||||
ankiIntegration: null as unknown,
|
||||
};
|
||||
let initialized = false;
|
||||
let invisibleOverlayVisible = false;
|
||||
let warmupsStarted = 0;
|
||||
|
||||
const { initializeOverlayRuntime } = createOverlayRuntimeBootstrapHandlers({
|
||||
initializeOverlayRuntimeMainDeps: {
|
||||
appState,
|
||||
overlayManager: {
|
||||
getVisibleOverlayVisible: () => true,
|
||||
getInvisibleOverlayVisible: () => false,
|
||||
},
|
||||
overlayVisibilityRuntime: {
|
||||
updateVisibleOverlayVisibility: () => {},
|
||||
updateInvisibleOverlayVisibility: () => {},
|
||||
},
|
||||
overlayShortcutsRuntime: {
|
||||
syncOverlayShortcuts: () => {},
|
||||
},
|
||||
getInitialInvisibleOverlayVisibility: () => false,
|
||||
createMainWindow: () => {},
|
||||
createInvisibleWindow: () => {},
|
||||
registerGlobalShortcuts: () => {},
|
||||
updateVisibleOverlayBounds: () => {},
|
||||
updateInvisibleOverlayBounds: () => {},
|
||||
getOverlayWindows: () => [],
|
||||
getResolvedConfig: () => ({}),
|
||||
showDesktopNotification: () => {},
|
||||
createFieldGroupingCallback: () => (async () => 'combined' as never),
|
||||
getKnownWordCacheStatePath: () => '/tmp/known.json',
|
||||
},
|
||||
initializeOverlayRuntimeBootstrapDeps: {
|
||||
isOverlayRuntimeInitialized: () => initialized,
|
||||
initializeOverlayRuntimeCore: () => ({ invisibleOverlayVisible: true }),
|
||||
setInvisibleOverlayVisible: (visible) => {
|
||||
invisibleOverlayVisible = visible;
|
||||
},
|
||||
setOverlayRuntimeInitialized: (next) => {
|
||||
initialized = next;
|
||||
},
|
||||
startBackgroundWarmups: () => {
|
||||
warmupsStarted += 1;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
initializeOverlayRuntime();
|
||||
initializeOverlayRuntime();
|
||||
|
||||
assert.equal(invisibleOverlayVisible, true);
|
||||
assert.equal(initialized, true);
|
||||
assert.equal(warmupsStarted, 1);
|
||||
});
|
||||
30
src/main/runtime/overlay-runtime-bootstrap-handlers.ts
Normal file
30
src/main/runtime/overlay-runtime-bootstrap-handlers.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { createBuildInitializeOverlayRuntimeBootstrapMainDepsHandler } from './app-runtime-main-deps';
|
||||
import { createInitializeOverlayRuntimeHandler } from './overlay-runtime-bootstrap';
|
||||
import { createBuildInitializeOverlayRuntimeOptionsHandler } from './overlay-runtime-options';
|
||||
import { createBuildInitializeOverlayRuntimeMainDepsHandler } from './overlay-runtime-options-main-deps';
|
||||
|
||||
type InitializeOverlayRuntimeMainDeps = Parameters<
|
||||
typeof createBuildInitializeOverlayRuntimeMainDepsHandler
|
||||
>[0];
|
||||
type InitializeOverlayRuntimeBootstrapMainDeps = Parameters<
|
||||
typeof createBuildInitializeOverlayRuntimeBootstrapMainDepsHandler
|
||||
>[0];
|
||||
|
||||
export function createOverlayRuntimeBootstrapHandlers(deps: {
|
||||
initializeOverlayRuntimeMainDeps: InitializeOverlayRuntimeMainDeps;
|
||||
initializeOverlayRuntimeBootstrapDeps: Omit<InitializeOverlayRuntimeBootstrapMainDeps, 'buildOptions'>;
|
||||
}) {
|
||||
const buildInitializeOverlayRuntimeOptionsHandler = createBuildInitializeOverlayRuntimeOptionsHandler(
|
||||
createBuildInitializeOverlayRuntimeMainDepsHandler(deps.initializeOverlayRuntimeMainDeps)(),
|
||||
);
|
||||
const initializeOverlayRuntime = createInitializeOverlayRuntimeHandler(
|
||||
createBuildInitializeOverlayRuntimeBootstrapMainDepsHandler({
|
||||
...deps.initializeOverlayRuntimeBootstrapDeps,
|
||||
buildOptions: () => buildInitializeOverlayRuntimeOptionsHandler(),
|
||||
})(),
|
||||
);
|
||||
|
||||
return {
|
||||
initializeOverlayRuntime,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user