mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
refactor: remove unused runtime adapter services
This commit is contained in:
@@ -61,12 +61,6 @@ export {
|
||||
setVisibleOverlayVisibleService,
|
||||
syncInvisibleOverlayMousePassthroughService,
|
||||
} from "./overlay-visibility-runtime-service";
|
||||
export {
|
||||
setInvisibleOverlayVisibleRuntimeFacadeService,
|
||||
setVisibleOverlayVisibleRuntimeFacadeService,
|
||||
toggleInvisibleOverlayRuntimeFacadeService,
|
||||
toggleVisibleOverlayRuntimeFacadeService,
|
||||
} from "./overlay-visibility-facade-service";
|
||||
export { MpvIpcClient, MPV_REQUEST_ID_SECONDARY_SUB_VISIBILITY } from "./mpv-service";
|
||||
export { applyMpvSubtitleRenderMetricsPatchService } from "./mpv-render-metrics-service";
|
||||
export { handleMpvCommandFromIpcService } from "./ipc-command-service";
|
||||
@@ -81,19 +75,9 @@ export { createAppLifecycleDepsRuntimeService } from "./app-lifecycle-deps-runti
|
||||
export { createCliCommandDepsRuntimeService } from "./cli-command-deps-runtime-service";
|
||||
export { createIpcDepsRuntimeService } from "./ipc-deps-runtime-service";
|
||||
export { createFieldGroupingOverlayRuntimeService } from "./field-grouping-overlay-runtime-service";
|
||||
export { createSubsyncRuntimeDepsService } from "./subsync-deps-runtime-service";
|
||||
export { createNumericShortcutRuntimeService } from "./numeric-shortcut-runtime-service";
|
||||
export { createMpvCommandIpcDepsRuntimeService } from "./mpv-command-ipc-deps-runtime-service";
|
||||
export { createRuntimeOptionsIpcDepsRuntimeService } from "./runtime-options-ipc-deps-runtime-service";
|
||||
export { createTokenizerDepsRuntimeService } from "./tokenizer-deps-runtime-service";
|
||||
export {
|
||||
createInitializeOverlayRuntimeDepsService,
|
||||
createInvisibleOverlayVisibilityDepsRuntimeService,
|
||||
createOverlayWindowRuntimeDepsService,
|
||||
createVisibleOverlayVisibilityDepsRuntimeService,
|
||||
} from "./overlay-deps-runtime-service";
|
||||
export { runOverlayShortcutLocalFallbackRuntimeService } from "./shortcut-ui-deps-runtime-service";
|
||||
export { createStartupLifecycleHooksRuntimeService } from "./startup-lifecycle-hooks-runtime-service";
|
||||
export { createRuntimeOptionsManagerRuntimeService } from "./runtime-options-manager-runtime-service";
|
||||
export { createAppLoggingRuntimeService } from "./app-logging-runtime-service";
|
||||
export {
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { SPECIAL_COMMANDS } from "../../config";
|
||||
import { createMpvCommandIpcDepsRuntimeService } from "./mpv-command-ipc-deps-runtime-service";
|
||||
|
||||
test("createMpvCommandIpcDepsRuntimeService wires runtime-options cycle and manager availability", () => {
|
||||
const osd: string[] = [];
|
||||
const deps = createMpvCommandIpcDepsRuntimeService({
|
||||
specialCommands: SPECIAL_COMMANDS,
|
||||
triggerSubsyncFromConfig: () => {},
|
||||
openRuntimeOptionsPalette: () => {},
|
||||
getRuntimeOptionsManager: () => ({
|
||||
cycleOption: () => ({ ok: true, osdMessage: "cycled" }),
|
||||
}),
|
||||
showMpvOsd: (text) => {
|
||||
osd.push(text);
|
||||
},
|
||||
mpvReplaySubtitle: () => {},
|
||||
mpvPlayNextSubtitle: () => {},
|
||||
mpvSendCommand: () => {},
|
||||
isMpvConnected: () => true,
|
||||
});
|
||||
|
||||
const result = deps.runtimeOptionsCycle("subtitles.secondaryMode" as never, 1);
|
||||
assert.equal(result.ok, true);
|
||||
assert.equal(deps.hasRuntimeOptionsManager(), true);
|
||||
assert.ok(osd.includes("cycled"));
|
||||
});
|
||||
@@ -1,53 +0,0 @@
|
||||
import {
|
||||
RuntimeOptionApplyResult,
|
||||
RuntimeOptionId,
|
||||
} from "../../types";
|
||||
import {
|
||||
HandleMpvCommandFromIpcOptions,
|
||||
} from "./ipc-command-service";
|
||||
import { applyRuntimeOptionResultRuntimeService } from "./runtime-options-runtime-service";
|
||||
|
||||
interface RuntimeOptionsManagerLike {
|
||||
cycleOption: (
|
||||
id: RuntimeOptionId,
|
||||
direction: 1 | -1,
|
||||
) => RuntimeOptionApplyResult;
|
||||
}
|
||||
|
||||
export interface MpvCommandIpcDepsRuntimeOptions {
|
||||
specialCommands: HandleMpvCommandFromIpcOptions["specialCommands"];
|
||||
triggerSubsyncFromConfig: () => void;
|
||||
openRuntimeOptionsPalette: () => void;
|
||||
getRuntimeOptionsManager: () => RuntimeOptionsManagerLike | null;
|
||||
showMpvOsd: (text: string) => void;
|
||||
mpvReplaySubtitle: () => void;
|
||||
mpvPlayNextSubtitle: () => void;
|
||||
mpvSendCommand: (command: (string | number)[]) => void;
|
||||
isMpvConnected: () => boolean;
|
||||
}
|
||||
|
||||
export function createMpvCommandIpcDepsRuntimeService(
|
||||
options: MpvCommandIpcDepsRuntimeOptions,
|
||||
): HandleMpvCommandFromIpcOptions {
|
||||
return {
|
||||
specialCommands: options.specialCommands,
|
||||
triggerSubsyncFromConfig: options.triggerSubsyncFromConfig,
|
||||
openRuntimeOptionsPalette: options.openRuntimeOptionsPalette,
|
||||
runtimeOptionsCycle: (id, direction) => {
|
||||
const manager = options.getRuntimeOptionsManager();
|
||||
if (!manager) {
|
||||
return { ok: false, error: "Runtime options manager unavailable" };
|
||||
}
|
||||
return applyRuntimeOptionResultRuntimeService(
|
||||
manager.cycleOption(id, direction),
|
||||
options.showMpvOsd,
|
||||
);
|
||||
},
|
||||
showMpvOsd: options.showMpvOsd,
|
||||
mpvReplaySubtitle: options.mpvReplaySubtitle,
|
||||
mpvPlayNextSubtitle: options.mpvPlayNextSubtitle,
|
||||
mpvSendCommand: options.mpvSendCommand,
|
||||
isMpvConnected: options.isMpvConnected,
|
||||
hasRuntimeOptionsManager: () => options.getRuntimeOptionsManager() !== null,
|
||||
};
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
createInitializeOverlayRuntimeDepsService,
|
||||
createInvisibleOverlayVisibilityDepsRuntimeService,
|
||||
createOverlayWindowRuntimeDepsService,
|
||||
createVisibleOverlayVisibilityDepsRuntimeService,
|
||||
} from "./overlay-deps-runtime-service";
|
||||
|
||||
test("createOverlayWindowRuntimeDepsService maps runtime state providers", () => {
|
||||
let visible = true;
|
||||
let invisible = false;
|
||||
const deps = createOverlayWindowRuntimeDepsService({
|
||||
isDev: false,
|
||||
getOverlayDebugVisualizationEnabled: () => true,
|
||||
ensureOverlayWindowLevel: () => {},
|
||||
onRuntimeOptionsChanged: () => {},
|
||||
setOverlayDebugVisualizationEnabled: () => {},
|
||||
getVisibleOverlayVisible: () => visible,
|
||||
getInvisibleOverlayVisible: () => invisible,
|
||||
tryHandleOverlayShortcutLocalFallback: () => false,
|
||||
onWindowClosed: () => {},
|
||||
});
|
||||
|
||||
assert.equal(deps.isOverlayVisible("visible"), true);
|
||||
assert.equal(deps.isOverlayVisible("invisible"), false);
|
||||
visible = false;
|
||||
invisible = true;
|
||||
assert.equal(deps.isOverlayVisible("visible"), false);
|
||||
assert.equal(deps.isOverlayVisible("invisible"), true);
|
||||
});
|
||||
|
||||
test("createInitializeOverlayRuntimeDepsService passes through overlay init deps", () => {
|
||||
const windows: any[] = [];
|
||||
const deps = createInitializeOverlayRuntimeDepsService({
|
||||
backendOverride: null,
|
||||
getInitialInvisibleOverlayVisibility: () => true,
|
||||
createMainWindow: () => {},
|
||||
createInvisibleWindow: () => {},
|
||||
registerGlobalShortcuts: () => {},
|
||||
updateOverlayBounds: () => {},
|
||||
isVisibleOverlayVisible: () => false,
|
||||
isInvisibleOverlayVisible: () => true,
|
||||
updateVisibleOverlayVisibility: () => {},
|
||||
updateInvisibleOverlayVisibility: () => {},
|
||||
getOverlayWindows: () => windows as never,
|
||||
syncOverlayShortcuts: () => {},
|
||||
setWindowTracker: () => {},
|
||||
getResolvedConfig: () => ({ ankiConnect: undefined }),
|
||||
getSubtitleTimingTracker: () => null,
|
||||
getMpvClient: () => null,
|
||||
getRuntimeOptionsManager: () => null,
|
||||
setAnkiIntegration: () => {},
|
||||
showDesktopNotification: () => {},
|
||||
createFieldGroupingCallback: () => async () => ({
|
||||
keepNoteId: 0,
|
||||
deleteNoteId: 0,
|
||||
deleteDuplicate: true,
|
||||
cancelled: true,
|
||||
}),
|
||||
});
|
||||
|
||||
assert.equal(deps.getInitialInvisibleOverlayVisibility(), true);
|
||||
assert.equal(deps.getOverlayWindows().length, 0);
|
||||
});
|
||||
|
||||
test("createVisibleOverlayVisibilityDepsRuntimeService snapshots runtime values", () => {
|
||||
const deps = createVisibleOverlayVisibilityDepsRuntimeService({
|
||||
getVisibleOverlayVisible: () => true,
|
||||
getMainWindow: () => null,
|
||||
getWindowTracker: () => null,
|
||||
getTrackerNotReadyWarningShown: () => false,
|
||||
setTrackerNotReadyWarningShown: () => {},
|
||||
shouldBindVisibleOverlayToMpvSubVisibility: () => true,
|
||||
getPreviousSecondarySubVisibility: () => null,
|
||||
setPreviousSecondarySubVisibility: () => {},
|
||||
isMpvConnected: () => false,
|
||||
mpvSend: () => {},
|
||||
secondarySubVisibilityRequestId: 123,
|
||||
updateOverlayBounds: () => {},
|
||||
ensureOverlayWindowLevel: () => {},
|
||||
enforceOverlayLayerOrder: () => {},
|
||||
syncOverlayShortcuts: () => {},
|
||||
});
|
||||
|
||||
assert.equal(deps.visibleOverlayVisible, true);
|
||||
assert.equal(deps.secondarySubVisibilityRequestId, 123);
|
||||
assert.equal(deps.mpvConnected, false);
|
||||
});
|
||||
|
||||
test("createInvisibleOverlayVisibilityDepsRuntimeService snapshots runtime values", () => {
|
||||
const deps = createInvisibleOverlayVisibilityDepsRuntimeService({
|
||||
getInvisibleWindow: () => null,
|
||||
getVisibleOverlayVisible: () => true,
|
||||
getInvisibleOverlayVisible: () => false,
|
||||
getWindowTracker: () => null,
|
||||
updateOverlayBounds: () => {},
|
||||
ensureOverlayWindowLevel: () => {},
|
||||
enforceOverlayLayerOrder: () => {},
|
||||
syncOverlayShortcuts: () => {},
|
||||
});
|
||||
|
||||
assert.equal(deps.visibleOverlayVisible, true);
|
||||
assert.equal(deps.invisibleOverlayVisible, false);
|
||||
});
|
||||
@@ -1,174 +0,0 @@
|
||||
import { BrowserWindow } from "electron";
|
||||
import { BaseWindowTracker } from "../../window-trackers";
|
||||
import {
|
||||
AnkiConnectConfig,
|
||||
KikuFieldGroupingChoice,
|
||||
KikuFieldGroupingRequestData,
|
||||
WindowGeometry,
|
||||
} from "../../types";
|
||||
import { createOverlayWindowService } from "./overlay-window-service";
|
||||
import { initializeOverlayRuntimeService } from "./overlay-runtime-init-service";
|
||||
import {
|
||||
updateInvisibleOverlayVisibilityService,
|
||||
updateVisibleOverlayVisibilityService,
|
||||
} from "./overlay-visibility-service";
|
||||
|
||||
interface MpvCommandSender {
|
||||
command: Array<string | number>;
|
||||
request_id?: number;
|
||||
}
|
||||
|
||||
export interface OverlayWindowRuntimeDepsOptions {
|
||||
isDev: boolean;
|
||||
getOverlayDebugVisualizationEnabled: () => boolean;
|
||||
ensureOverlayWindowLevel: (window: BrowserWindow) => void;
|
||||
onRuntimeOptionsChanged: () => void;
|
||||
setOverlayDebugVisualizationEnabled: (enabled: boolean) => void;
|
||||
getVisibleOverlayVisible: () => boolean;
|
||||
getInvisibleOverlayVisible: () => boolean;
|
||||
tryHandleOverlayShortcutLocalFallback: (input: Electron.Input) => boolean;
|
||||
onWindowClosed: (kind: "visible" | "invisible") => void;
|
||||
}
|
||||
|
||||
export interface InitializeOverlayRuntimeDepsOptions {
|
||||
backendOverride: string | null;
|
||||
getInitialInvisibleOverlayVisibility: () => boolean;
|
||||
createMainWindow: () => void;
|
||||
createInvisibleWindow: () => void;
|
||||
registerGlobalShortcuts: () => void;
|
||||
updateOverlayBounds: (geometry: WindowGeometry) => void;
|
||||
isVisibleOverlayVisible: () => boolean;
|
||||
isInvisibleOverlayVisible: () => boolean;
|
||||
updateVisibleOverlayVisibility: () => void;
|
||||
updateInvisibleOverlayVisibility: () => void;
|
||||
getOverlayWindows: () => BrowserWindow[];
|
||||
syncOverlayShortcuts: () => void;
|
||||
setWindowTracker: (tracker: BaseWindowTracker | null) => void;
|
||||
getResolvedConfig: () => { ankiConnect?: AnkiConnectConfig };
|
||||
getSubtitleTimingTracker: () => unknown | null;
|
||||
getMpvClient: () => { send?: (payload: { command: string[] }) => void } | null;
|
||||
getRuntimeOptionsManager: () => {
|
||||
getEffectiveAnkiConnectConfig: (config?: AnkiConnectConfig) => AnkiConnectConfig;
|
||||
} | null;
|
||||
setAnkiIntegration: (integration: unknown | null) => void;
|
||||
showDesktopNotification: (title: string, options: { body?: string; icon?: string }) => void;
|
||||
createFieldGroupingCallback: () => (
|
||||
data: KikuFieldGroupingRequestData,
|
||||
) => Promise<KikuFieldGroupingChoice>;
|
||||
}
|
||||
|
||||
export interface VisibleOverlayVisibilityDepsRuntimeOptions {
|
||||
getVisibleOverlayVisible: () => boolean;
|
||||
getMainWindow: () => BrowserWindow | null;
|
||||
getWindowTracker: () => BaseWindowTracker | null;
|
||||
getTrackerNotReadyWarningShown: () => boolean;
|
||||
setTrackerNotReadyWarningShown: (shown: boolean) => void;
|
||||
shouldBindVisibleOverlayToMpvSubVisibility: () => boolean;
|
||||
getPreviousSecondarySubVisibility: () => boolean | null;
|
||||
setPreviousSecondarySubVisibility: (value: boolean | null) => void;
|
||||
isMpvConnected: () => boolean;
|
||||
mpvSend: (payload: MpvCommandSender) => void;
|
||||
secondarySubVisibilityRequestId: number;
|
||||
updateOverlayBounds: (geometry: WindowGeometry) => void;
|
||||
ensureOverlayWindowLevel: (window: BrowserWindow) => void;
|
||||
enforceOverlayLayerOrder: () => void;
|
||||
syncOverlayShortcuts: () => void;
|
||||
}
|
||||
|
||||
export interface InvisibleOverlayVisibilityDepsRuntimeOptions {
|
||||
getInvisibleWindow: () => BrowserWindow | null;
|
||||
getVisibleOverlayVisible: () => boolean;
|
||||
getInvisibleOverlayVisible: () => boolean;
|
||||
getWindowTracker: () => BaseWindowTracker | null;
|
||||
updateOverlayBounds: (geometry: WindowGeometry) => void;
|
||||
ensureOverlayWindowLevel: (window: BrowserWindow) => void;
|
||||
enforceOverlayLayerOrder: () => void;
|
||||
syncOverlayShortcuts: () => void;
|
||||
}
|
||||
|
||||
export function createOverlayWindowRuntimeDepsService(
|
||||
options: OverlayWindowRuntimeDepsOptions,
|
||||
): Parameters<typeof createOverlayWindowService>[1] {
|
||||
return {
|
||||
isDev: options.isDev,
|
||||
overlayDebugVisualizationEnabled:
|
||||
options.getOverlayDebugVisualizationEnabled(),
|
||||
ensureOverlayWindowLevel: options.ensureOverlayWindowLevel,
|
||||
onRuntimeOptionsChanged: options.onRuntimeOptionsChanged,
|
||||
setOverlayDebugVisualizationEnabled:
|
||||
options.setOverlayDebugVisualizationEnabled,
|
||||
isOverlayVisible: (kind) =>
|
||||
kind === "visible"
|
||||
? options.getVisibleOverlayVisible()
|
||||
: options.getInvisibleOverlayVisible(),
|
||||
tryHandleOverlayShortcutLocalFallback:
|
||||
options.tryHandleOverlayShortcutLocalFallback,
|
||||
onWindowClosed: options.onWindowClosed,
|
||||
};
|
||||
}
|
||||
|
||||
export function createInitializeOverlayRuntimeDepsService(
|
||||
options: InitializeOverlayRuntimeDepsOptions,
|
||||
): Parameters<typeof initializeOverlayRuntimeService>[0] {
|
||||
return {
|
||||
backendOverride: options.backendOverride,
|
||||
getInitialInvisibleOverlayVisibility:
|
||||
options.getInitialInvisibleOverlayVisibility,
|
||||
createMainWindow: options.createMainWindow,
|
||||
createInvisibleWindow: options.createInvisibleWindow,
|
||||
registerGlobalShortcuts: options.registerGlobalShortcuts,
|
||||
updateOverlayBounds: options.updateOverlayBounds,
|
||||
isVisibleOverlayVisible: options.isVisibleOverlayVisible,
|
||||
isInvisibleOverlayVisible: options.isInvisibleOverlayVisible,
|
||||
updateVisibleOverlayVisibility: options.updateVisibleOverlayVisibility,
|
||||
updateInvisibleOverlayVisibility: options.updateInvisibleOverlayVisibility,
|
||||
getOverlayWindows: options.getOverlayWindows,
|
||||
syncOverlayShortcuts: options.syncOverlayShortcuts,
|
||||
setWindowTracker: options.setWindowTracker,
|
||||
getResolvedConfig: options.getResolvedConfig,
|
||||
getSubtitleTimingTracker: options.getSubtitleTimingTracker,
|
||||
getMpvClient: options.getMpvClient,
|
||||
getRuntimeOptionsManager: options.getRuntimeOptionsManager,
|
||||
setAnkiIntegration: options.setAnkiIntegration,
|
||||
showDesktopNotification: options.showDesktopNotification,
|
||||
createFieldGroupingCallback: options.createFieldGroupingCallback,
|
||||
};
|
||||
}
|
||||
|
||||
export function createVisibleOverlayVisibilityDepsRuntimeService(
|
||||
options: VisibleOverlayVisibilityDepsRuntimeOptions,
|
||||
): Parameters<typeof updateVisibleOverlayVisibilityService>[0] {
|
||||
return {
|
||||
visibleOverlayVisible: options.getVisibleOverlayVisible(),
|
||||
mainWindow: options.getMainWindow(),
|
||||
windowTracker: options.getWindowTracker(),
|
||||
trackerNotReadyWarningShown: options.getTrackerNotReadyWarningShown(),
|
||||
setTrackerNotReadyWarningShown: options.setTrackerNotReadyWarningShown,
|
||||
shouldBindVisibleOverlayToMpvSubVisibility:
|
||||
options.shouldBindVisibleOverlayToMpvSubVisibility(),
|
||||
previousSecondarySubVisibility: options.getPreviousSecondarySubVisibility(),
|
||||
setPreviousSecondarySubVisibility: options.setPreviousSecondarySubVisibility,
|
||||
mpvConnected: options.isMpvConnected(),
|
||||
mpvSend: options.mpvSend,
|
||||
secondarySubVisibilityRequestId: options.secondarySubVisibilityRequestId,
|
||||
updateOverlayBounds: options.updateOverlayBounds,
|
||||
ensureOverlayWindowLevel: options.ensureOverlayWindowLevel,
|
||||
enforceOverlayLayerOrder: options.enforceOverlayLayerOrder,
|
||||
syncOverlayShortcuts: options.syncOverlayShortcuts,
|
||||
};
|
||||
}
|
||||
|
||||
export function createInvisibleOverlayVisibilityDepsRuntimeService(
|
||||
options: InvisibleOverlayVisibilityDepsRuntimeOptions,
|
||||
): Parameters<typeof updateInvisibleOverlayVisibilityService>[0] {
|
||||
return {
|
||||
invisibleWindow: options.getInvisibleWindow(),
|
||||
visibleOverlayVisible: options.getVisibleOverlayVisible(),
|
||||
invisibleOverlayVisible: options.getInvisibleOverlayVisible(),
|
||||
windowTracker: options.getWindowTracker(),
|
||||
updateOverlayBounds: options.updateOverlayBounds,
|
||||
ensureOverlayWindowLevel: options.ensureOverlayWindowLevel,
|
||||
enforceOverlayLayerOrder: options.enforceOverlayLayerOrder,
|
||||
syncOverlayShortcuts: options.syncOverlayShortcuts,
|
||||
};
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
OverlayVisibilityFacadeDeps,
|
||||
setVisibleOverlayVisibleRuntimeFacadeService,
|
||||
toggleInvisibleOverlayRuntimeFacadeService,
|
||||
toggleVisibleOverlayRuntimeFacadeService,
|
||||
} from "./overlay-visibility-facade-service";
|
||||
|
||||
function makeDeps(initialVisible = false, initialInvisible = false): {
|
||||
deps: OverlayVisibilityFacadeDeps;
|
||||
getState: () => { visible: boolean; invisible: boolean; mpvSubVisible: boolean | null };
|
||||
} {
|
||||
let visible = initialVisible;
|
||||
let invisible = initialInvisible;
|
||||
let mpvSubVisible: boolean | null = null;
|
||||
|
||||
const deps: OverlayVisibilityFacadeDeps = {
|
||||
getVisibleOverlayVisible: () => visible,
|
||||
getInvisibleOverlayVisible: () => invisible,
|
||||
setVisibleOverlayVisibleState: (value) => {
|
||||
visible = value;
|
||||
},
|
||||
setInvisibleOverlayVisibleState: (value) => {
|
||||
invisible = value;
|
||||
},
|
||||
updateVisibleOverlayVisibility: () => {},
|
||||
updateInvisibleOverlayVisibility: () => {},
|
||||
syncInvisibleOverlayMousePassthrough: () => {},
|
||||
shouldBindVisibleOverlayToMpvSubVisibility: () => true,
|
||||
isMpvConnected: () => true,
|
||||
setMpvSubVisibility: (value) => {
|
||||
mpvSubVisible = value;
|
||||
},
|
||||
};
|
||||
|
||||
return {
|
||||
deps,
|
||||
getState: () => ({ visible, invisible, mpvSubVisible }),
|
||||
};
|
||||
}
|
||||
|
||||
test("setVisibleOverlayVisibleRuntimeFacadeService updates visible state and mpv subtitle visibility", () => {
|
||||
const { deps, getState } = makeDeps(false, true);
|
||||
setVisibleOverlayVisibleRuntimeFacadeService(true, deps);
|
||||
assert.deepEqual(getState(), {
|
||||
visible: true,
|
||||
invisible: true,
|
||||
mpvSubVisible: false,
|
||||
});
|
||||
});
|
||||
|
||||
test("toggleVisibleOverlayRuntimeFacadeService flips visible overlay state", () => {
|
||||
const { deps, getState } = makeDeps(false, false);
|
||||
toggleVisibleOverlayRuntimeFacadeService(deps);
|
||||
assert.equal(getState().visible, true);
|
||||
});
|
||||
|
||||
test("toggleInvisibleOverlayRuntimeFacadeService flips invisible overlay state", () => {
|
||||
const { deps, getState } = makeDeps(false, false);
|
||||
toggleInvisibleOverlayRuntimeFacadeService(deps);
|
||||
assert.equal(getState().invisible, true);
|
||||
});
|
||||
@@ -1,64 +0,0 @@
|
||||
import {
|
||||
setInvisibleOverlayVisibleService,
|
||||
setVisibleOverlayVisibleService,
|
||||
} from "./overlay-visibility-runtime-service";
|
||||
|
||||
export interface OverlayVisibilityFacadeDeps {
|
||||
getVisibleOverlayVisible: () => boolean;
|
||||
getInvisibleOverlayVisible: () => boolean;
|
||||
setVisibleOverlayVisibleState: (visible: boolean) => void;
|
||||
setInvisibleOverlayVisibleState: (visible: boolean) => void;
|
||||
updateVisibleOverlayVisibility: () => void;
|
||||
updateInvisibleOverlayVisibility: () => void;
|
||||
syncInvisibleOverlayMousePassthrough: () => void;
|
||||
shouldBindVisibleOverlayToMpvSubVisibility: () => boolean;
|
||||
isMpvConnected: () => boolean;
|
||||
setMpvSubVisibility: (visible: boolean) => void;
|
||||
}
|
||||
|
||||
export function setVisibleOverlayVisibleRuntimeFacadeService(
|
||||
visible: boolean,
|
||||
deps: OverlayVisibilityFacadeDeps,
|
||||
): void {
|
||||
setVisibleOverlayVisibleService({
|
||||
visible,
|
||||
setVisibleOverlayVisibleState: deps.setVisibleOverlayVisibleState,
|
||||
updateVisibleOverlayVisibility: deps.updateVisibleOverlayVisibility,
|
||||
updateInvisibleOverlayVisibility: deps.updateInvisibleOverlayVisibility,
|
||||
syncInvisibleOverlayMousePassthrough: deps.syncInvisibleOverlayMousePassthrough,
|
||||
shouldBindVisibleOverlayToMpvSubVisibility:
|
||||
deps.shouldBindVisibleOverlayToMpvSubVisibility,
|
||||
isMpvConnected: deps.isMpvConnected,
|
||||
setMpvSubVisibility: deps.setMpvSubVisibility,
|
||||
});
|
||||
}
|
||||
|
||||
export function setInvisibleOverlayVisibleRuntimeFacadeService(
|
||||
visible: boolean,
|
||||
deps: OverlayVisibilityFacadeDeps,
|
||||
): void {
|
||||
setInvisibleOverlayVisibleService({
|
||||
visible,
|
||||
setInvisibleOverlayVisibleState: deps.setInvisibleOverlayVisibleState,
|
||||
updateInvisibleOverlayVisibility: deps.updateInvisibleOverlayVisibility,
|
||||
syncInvisibleOverlayMousePassthrough: deps.syncInvisibleOverlayMousePassthrough,
|
||||
});
|
||||
}
|
||||
|
||||
export function toggleVisibleOverlayRuntimeFacadeService(
|
||||
deps: OverlayVisibilityFacadeDeps,
|
||||
): void {
|
||||
setVisibleOverlayVisibleRuntimeFacadeService(
|
||||
!deps.getVisibleOverlayVisible(),
|
||||
deps,
|
||||
);
|
||||
}
|
||||
|
||||
export function toggleInvisibleOverlayRuntimeFacadeService(
|
||||
deps: OverlayVisibilityFacadeDeps,
|
||||
): void {
|
||||
setInvisibleOverlayVisibleRuntimeFacadeService(
|
||||
!deps.getInvisibleOverlayVisible(),
|
||||
deps,
|
||||
);
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { createRuntimeOptionsIpcDepsRuntimeService } from "./runtime-options-ipc-deps-runtime-service";
|
||||
|
||||
test("createRuntimeOptionsIpcDepsRuntimeService delegates set/cycle with osd", () => {
|
||||
const osd: string[] = [];
|
||||
const deps = createRuntimeOptionsIpcDepsRuntimeService({
|
||||
getRuntimeOptionsManager: () => ({
|
||||
setOptionValue: () => ({ ok: true, osdMessage: "set ok" }),
|
||||
cycleOption: () => ({ ok: true, osdMessage: "cycle ok" }),
|
||||
}),
|
||||
showMpvOsd: (text) => {
|
||||
osd.push(text);
|
||||
},
|
||||
});
|
||||
|
||||
const setResult = deps.setRuntimeOption("subtitles.secondaryMode", "hidden") as {
|
||||
ok: boolean;
|
||||
};
|
||||
const cycleResult = deps.cycleRuntimeOption("subtitles.secondaryMode", 1) as {
|
||||
ok: boolean;
|
||||
};
|
||||
|
||||
assert.equal(setResult.ok, true);
|
||||
assert.equal(cycleResult.ok, true);
|
||||
assert.ok(osd.includes("set ok"));
|
||||
assert.ok(osd.includes("cycle ok"));
|
||||
});
|
||||
@@ -1,38 +0,0 @@
|
||||
import {
|
||||
RuntimeOptionId,
|
||||
RuntimeOptionValue,
|
||||
} from "../../types";
|
||||
import {
|
||||
cycleRuntimeOptionFromIpcRuntimeService,
|
||||
RuntimeOptionsManagerLike,
|
||||
setRuntimeOptionFromIpcRuntimeService,
|
||||
} from "./runtime-options-runtime-service";
|
||||
|
||||
export interface RuntimeOptionsIpcDepsRuntimeOptions {
|
||||
getRuntimeOptionsManager: () => RuntimeOptionsManagerLike | null;
|
||||
showMpvOsd: (text: string) => void;
|
||||
}
|
||||
|
||||
export function createRuntimeOptionsIpcDepsRuntimeService(
|
||||
options: RuntimeOptionsIpcDepsRuntimeOptions,
|
||||
): {
|
||||
setRuntimeOption: (id: string, value: unknown) => unknown;
|
||||
cycleRuntimeOption: (id: string, direction: 1 | -1) => unknown;
|
||||
} {
|
||||
return {
|
||||
setRuntimeOption: (id, value) =>
|
||||
setRuntimeOptionFromIpcRuntimeService(
|
||||
options.getRuntimeOptionsManager(),
|
||||
id as RuntimeOptionId,
|
||||
value as RuntimeOptionValue,
|
||||
options.showMpvOsd,
|
||||
),
|
||||
cycleRuntimeOption: (id, direction) =>
|
||||
cycleRuntimeOptionFromIpcRuntimeService(
|
||||
options.getRuntimeOptionsManager(),
|
||||
id as RuntimeOptionId,
|
||||
direction,
|
||||
options.showMpvOsd,
|
||||
),
|
||||
};
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { createStartupLifecycleHooksRuntimeService } from "./startup-lifecycle-hooks-runtime-service";
|
||||
|
||||
test("createStartupLifecycleHooksRuntimeService wires app-ready and app-shutdown handlers", async () => {
|
||||
const calls: string[] = [];
|
||||
const hooks = createStartupLifecycleHooksRuntimeService({
|
||||
appReadyDeps: {
|
||||
loadSubtitlePosition: () => calls.push("loadSubtitlePosition"),
|
||||
resolveKeybindings: () => calls.push("resolveKeybindings"),
|
||||
createMpvClient: () => calls.push("createMpvClient"),
|
||||
reloadConfig: () => calls.push("reloadConfig"),
|
||||
getResolvedConfig: () => ({
|
||||
secondarySub: { defaultMode: "hover" },
|
||||
websocket: { enabled: "auto", port: 1234 },
|
||||
}),
|
||||
getConfigWarnings: () => [],
|
||||
logConfigWarning: () => calls.push("logConfigWarning"),
|
||||
initRuntimeOptionsManager: () => calls.push("initRuntimeOptionsManager"),
|
||||
setSecondarySubMode: () => calls.push("setSecondarySubMode"),
|
||||
defaultSecondarySubMode: "hover",
|
||||
defaultWebsocketPort: 8765,
|
||||
hasMpvWebsocketPlugin: () => true,
|
||||
startSubtitleWebsocket: () => calls.push("startSubtitleWebsocket"),
|
||||
log: () => calls.push("log"),
|
||||
createMecabTokenizerAndCheck: async () => {
|
||||
calls.push("createMecabTokenizerAndCheck");
|
||||
},
|
||||
createSubtitleTimingTracker: () => calls.push("createSubtitleTimingTracker"),
|
||||
loadYomitanExtension: async () => {
|
||||
calls.push("loadYomitanExtension");
|
||||
},
|
||||
texthookerOnlyMode: false,
|
||||
shouldAutoInitializeOverlayRuntimeFromConfig: () => false,
|
||||
initializeOverlayRuntime: () => calls.push("initializeOverlayRuntime"),
|
||||
handleInitialArgs: () => calls.push("handleInitialArgs"),
|
||||
},
|
||||
appShutdownDeps: {
|
||||
unregisterAllGlobalShortcuts: () => calls.push("unregisterAllGlobalShortcuts"),
|
||||
stopSubtitleWebsocket: () => calls.push("stopSubtitleWebsocket"),
|
||||
stopTexthookerService: () => calls.push("stopTexthookerService"),
|
||||
destroyYomitanParserWindow: () => calls.push("destroyYomitanParserWindow"),
|
||||
clearYomitanParserPromises: () => calls.push("clearYomitanParserPromises"),
|
||||
stopWindowTracker: () => calls.push("stopWindowTracker"),
|
||||
destroyMpvSocket: () => calls.push("destroyMpvSocket"),
|
||||
clearReconnectTimer: () => calls.push("clearReconnectTimer"),
|
||||
destroySubtitleTimingTracker: () => calls.push("destroySubtitleTimingTracker"),
|
||||
destroyAnkiIntegration: () => calls.push("destroyAnkiIntegration"),
|
||||
},
|
||||
shouldRestoreWindowsOnActivate: () => true,
|
||||
restoreWindowsOnActivate: () => calls.push("restoreWindowsOnActivate"),
|
||||
});
|
||||
|
||||
await hooks.onReady();
|
||||
hooks.onWillQuitCleanup();
|
||||
assert.equal(hooks.shouldRestoreWindowsOnActivate(), true);
|
||||
hooks.restoreWindowsOnActivate();
|
||||
|
||||
assert.ok(calls.includes("loadSubtitlePosition"));
|
||||
assert.ok(calls.includes("handleInitialArgs"));
|
||||
assert.ok(calls.includes("destroyAnkiIntegration"));
|
||||
assert.ok(calls.includes("restoreWindowsOnActivate"));
|
||||
});
|
||||
@@ -1,36 +0,0 @@
|
||||
import { AppLifecycleDepsRuntimeOptions } from "./app-lifecycle-deps-runtime-service";
|
||||
import {
|
||||
AppReadyRuntimeDeps,
|
||||
runAppReadyRuntimeService,
|
||||
} from "./app-ready-runtime-service";
|
||||
import {
|
||||
AppShutdownRuntimeDeps,
|
||||
runAppShutdownRuntimeService,
|
||||
} from "./app-shutdown-runtime-service";
|
||||
|
||||
type StartupLifecycleHookDeps = Pick<
|
||||
AppLifecycleDepsRuntimeOptions,
|
||||
"onReady" | "onWillQuitCleanup" | "shouldRestoreWindowsOnActivate" | "restoreWindowsOnActivate"
|
||||
>;
|
||||
|
||||
export interface StartupLifecycleHooksRuntimeOptions {
|
||||
appReadyDeps: AppReadyRuntimeDeps;
|
||||
appShutdownDeps: AppShutdownRuntimeDeps;
|
||||
shouldRestoreWindowsOnActivate: () => boolean;
|
||||
restoreWindowsOnActivate: () => void;
|
||||
}
|
||||
|
||||
export function createStartupLifecycleHooksRuntimeService(
|
||||
options: StartupLifecycleHooksRuntimeOptions,
|
||||
): StartupLifecycleHookDeps {
|
||||
return {
|
||||
onReady: async () => {
|
||||
await runAppReadyRuntimeService(options.appReadyDeps);
|
||||
},
|
||||
onWillQuitCleanup: () => {
|
||||
runAppShutdownRuntimeService(options.appShutdownDeps);
|
||||
},
|
||||
shouldRestoreWindowsOnActivate: options.shouldRestoreWindowsOnActivate,
|
||||
restoreWindowsOnActivate: options.restoreWindowsOnActivate,
|
||||
};
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
import test from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { createSubsyncRuntimeDepsService } from "./subsync-deps-runtime-service";
|
||||
|
||||
test("createSubsyncRuntimeDepsService opens manual picker via visible overlay", () => {
|
||||
let inProgress = false;
|
||||
const calls: Array<{ channel: string; payload?: unknown; restore?: string }> = [];
|
||||
|
||||
const deps = createSubsyncRuntimeDepsService({
|
||||
getMpvClient: () => null,
|
||||
getResolvedSubsyncConfig: () => ({
|
||||
defaultMode: "auto",
|
||||
ffsubsyncPath: "/usr/bin/ffsubsync",
|
||||
alassPath: "/usr/bin/alass",
|
||||
ffmpegPath: "/usr/bin/ffmpeg",
|
||||
}),
|
||||
isSubsyncInProgress: () => inProgress,
|
||||
setSubsyncInProgress: (next) => {
|
||||
inProgress = next;
|
||||
},
|
||||
showMpvOsd: () => {},
|
||||
sendToVisibleOverlay: (channel, payload, options) => {
|
||||
calls.push({ channel, payload, restore: options?.restoreOnModalClose });
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
deps.setSubsyncInProgress(true);
|
||||
deps.openManualPicker({
|
||||
sourceTracks: [{ id: 1, label: "Japanese Track" }],
|
||||
});
|
||||
|
||||
assert.equal(deps.isSubsyncInProgress(), true);
|
||||
assert.equal(calls.length, 1);
|
||||
assert.equal(calls[0]?.channel, "subsync:open-manual");
|
||||
assert.equal(calls[0]?.restore, "subsync");
|
||||
});
|
||||
@@ -1,44 +0,0 @@
|
||||
import {
|
||||
SubsyncManualPayload,
|
||||
} from "../../types";
|
||||
import {
|
||||
SubsyncRuntimeDeps,
|
||||
} from "./subsync-runtime-service";
|
||||
import { SubsyncResolvedConfig } from "../../subsync/utils";
|
||||
|
||||
interface MpvClientLike {
|
||||
connected: boolean;
|
||||
currentAudioStreamIndex: number | null;
|
||||
send: (payload: { command: (string | number)[] }) => void;
|
||||
requestProperty: (name: string) => Promise<unknown>;
|
||||
}
|
||||
|
||||
export interface SubsyncDepsRuntimeOptions {
|
||||
getMpvClient: () => MpvClientLike | null;
|
||||
getResolvedSubsyncConfig: () => SubsyncResolvedConfig;
|
||||
isSubsyncInProgress: () => boolean;
|
||||
setSubsyncInProgress: (inProgress: boolean) => void;
|
||||
showMpvOsd: (text: string) => void;
|
||||
sendToVisibleOverlay: (
|
||||
channel: string,
|
||||
payload?: unknown,
|
||||
options?: { restoreOnModalClose?: "runtime-options" | "subsync" },
|
||||
) => boolean;
|
||||
}
|
||||
|
||||
export function createSubsyncRuntimeDepsService(
|
||||
options: SubsyncDepsRuntimeOptions,
|
||||
): SubsyncRuntimeDeps {
|
||||
return {
|
||||
getMpvClient: options.getMpvClient,
|
||||
getResolvedSubsyncConfig: options.getResolvedSubsyncConfig,
|
||||
isSubsyncInProgress: options.isSubsyncInProgress,
|
||||
setSubsyncInProgress: options.setSubsyncInProgress,
|
||||
showMpvOsd: options.showMpvOsd,
|
||||
openManualPicker: (payload: SubsyncManualPayload) => {
|
||||
options.sendToVisibleOverlay("subsync:open-manual", payload, {
|
||||
restoreOnModalClose: "subsync",
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user