mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -08:00
refactor: extract subsync deps runtime service
This commit is contained in:
37
src/core/services/subsync-deps-runtime-service.test.ts
Normal file
37
src/core/services/subsync-deps-runtime-service.test.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
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");
|
||||
});
|
||||
44
src/core/services/subsync-deps-runtime-service.ts
Normal file
44
src/core/services/subsync-deps-runtime-service.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
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",
|
||||
});
|
||||
},
|
||||
};
|
||||
}
|
||||
13
src/main.ts
13
src/main.ts
@@ -59,7 +59,6 @@ import {
|
||||
Keybinding,
|
||||
WindowGeometry,
|
||||
SecondarySubMode,
|
||||
SubsyncManualPayload,
|
||||
SubsyncManualRunRequest,
|
||||
SubsyncResult,
|
||||
KikuFieldGroupingChoice,
|
||||
@@ -205,6 +204,7 @@ import { createCliCommandDepsRuntimeService } from "./core/services/cli-command-
|
||||
import { createIpcDepsRuntimeService } from "./core/services/ipc-deps-runtime-service";
|
||||
import { createAnkiJimakuIpcDepsRuntimeService } from "./core/services/anki-jimaku-ipc-deps-runtime-service";
|
||||
import { createFieldGroupingOverlayRuntimeService } from "./core/services/field-grouping-overlay-runtime-service";
|
||||
import { createSubsyncRuntimeDepsService } from "./core/services/subsync-deps-runtime-service";
|
||||
import { createRuntimeOptionsManagerRuntimeService } from "./core/services/runtime-options-manager-runtime-service";
|
||||
import { createAppLoggingRuntimeService } from "./core/services/app-logging-runtime-service";
|
||||
import {
|
||||
@@ -978,7 +978,7 @@ const mineSentenceSession = createNumericShortcutSessionService({
|
||||
});
|
||||
|
||||
function getSubsyncRuntimeDeps() {
|
||||
return {
|
||||
return createSubsyncRuntimeDepsService({
|
||||
getMpvClient: () => mpvClient,
|
||||
getResolvedSubsyncConfig: () => getSubsyncConfig(getResolvedConfig().subsync),
|
||||
isSubsyncInProgress: () => subsyncInProgress,
|
||||
@@ -986,12 +986,9 @@ function getSubsyncRuntimeDeps() {
|
||||
subsyncInProgress = inProgress;
|
||||
},
|
||||
showMpvOsd: (text: string) => showMpvOsd(text),
|
||||
openManualPicker: (payload: SubsyncManualPayload) => {
|
||||
sendToVisibleOverlay("subsync:open-manual", payload, {
|
||||
restoreOnModalClose: "subsync",
|
||||
});
|
||||
},
|
||||
};
|
||||
sendToVisibleOverlay: (channel, payload, options) =>
|
||||
sendToVisibleOverlay(channel, payload, options),
|
||||
});
|
||||
}
|
||||
|
||||
async function triggerSubsyncFromConfig(): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user