refactor: extract subsync deps runtime service

This commit is contained in:
2026-02-10 01:12:28 -08:00
parent 119f0da7a6
commit 073f84b03e
4 changed files with 87 additions and 9 deletions

View 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");
});

View 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",
});
},
};
}