mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
refactor(main): move mpv IPC command composition into helper module
This commit is contained in:
25
src/main.ts
25
src/main.ts
@@ -46,7 +46,6 @@ import { BaseWindowTracker } from "./window-trackers";
|
|||||||
import type {
|
import type {
|
||||||
JimakuApiResponse,
|
JimakuApiResponse,
|
||||||
JimakuLanguagePreference,
|
JimakuLanguagePreference,
|
||||||
RuntimeOptionId,
|
|
||||||
SubtitleData,
|
SubtitleData,
|
||||||
SubtitlePosition,
|
SubtitlePosition,
|
||||||
Keybinding,
|
Keybinding,
|
||||||
@@ -112,7 +111,6 @@ import {
|
|||||||
getJimakuMaxEntryResultsService,
|
getJimakuMaxEntryResultsService,
|
||||||
handleCliCommandService,
|
handleCliCommandService,
|
||||||
handleMineSentenceDigitService,
|
handleMineSentenceDigitService,
|
||||||
handleMpvCommandFromIpcService,
|
|
||||||
handleMultiCopyDigitService,
|
handleMultiCopyDigitService,
|
||||||
hasMpvWebsocketPlugin,
|
hasMpvWebsocketPlugin,
|
||||||
initializeOverlayRuntimeService,
|
initializeOverlayRuntimeService,
|
||||||
@@ -162,28 +160,25 @@ import {
|
|||||||
} from "./core/services/startup-service";
|
} from "./core/services/startup-service";
|
||||||
import type { AppReadyRuntimeDeps } from "./core/services/startup-service";
|
import type { AppReadyRuntimeDeps } from "./core/services/startup-service";
|
||||||
import type { SubsyncRuntimeDeps } from "./core/services/subsync-runner-service";
|
import type { SubsyncRuntimeDeps } from "./core/services/subsync-runner-service";
|
||||||
import {
|
import { applyRuntimeOptionResultRuntimeService } from "./core/services/runtime-options-ipc-service";
|
||||||
applyRuntimeOptionResultRuntimeService,
|
|
||||||
} from "./core/services/runtime-options-ipc-service";
|
|
||||||
import {
|
import {
|
||||||
createRuntimeOptionsIpcDeps,
|
createRuntimeOptionsIpcDeps,
|
||||||
createAnkiJimakuIpcRuntimeServiceDeps,
|
createAnkiJimakuIpcRuntimeServiceDeps,
|
||||||
createCliCommandRuntimeServiceDeps,
|
createCliCommandRuntimeServiceDeps,
|
||||||
createMainIpcRuntimeServiceDeps,
|
createMainIpcRuntimeServiceDeps,
|
||||||
createMpvCommandRuntimeServiceDeps,
|
|
||||||
createSubsyncRuntimeDeps,
|
createSubsyncRuntimeDeps,
|
||||||
} from "./main/dependencies";
|
} from "./main/dependencies";
|
||||||
import {
|
import {
|
||||||
createAppLifecycleRuntimeDeps as createAppLifecycleRuntimeDepsBuilder,
|
createAppLifecycleRuntimeDeps as createAppLifecycleRuntimeDepsBuilder,
|
||||||
createAppReadyRuntimeDeps as createAppReadyRuntimeDepsBuilder,
|
createAppReadyRuntimeDeps as createAppReadyRuntimeDepsBuilder,
|
||||||
} from "./main/app-lifecycle";
|
} from "./main/app-lifecycle";
|
||||||
|
import { handleMpvCommandFromIpcRuntime } from "./main/ipc-mpv-command";
|
||||||
import { createStartupBootstrapRuntimeDeps } from "./main/startup";
|
import { createStartupBootstrapRuntimeDeps } from "./main/startup";
|
||||||
import {
|
import {
|
||||||
ConfigService,
|
ConfigService,
|
||||||
DEFAULT_CONFIG,
|
DEFAULT_CONFIG,
|
||||||
DEFAULT_KEYBINDINGS,
|
DEFAULT_KEYBINDINGS,
|
||||||
generateConfigTemplate,
|
generateConfigTemplate,
|
||||||
SPECIAL_COMMANDS,
|
|
||||||
} from "./config";
|
} from "./config";
|
||||||
import type {
|
import type {
|
||||||
AppLifecycleDepsRuntimeOptions,
|
AppLifecycleDepsRuntimeOptions,
|
||||||
@@ -1504,13 +1499,10 @@ function handleOverlayModalClosed(modal: OverlayHostedModal): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleMpvCommandFromIpc(command: (string | number)[]): void {
|
function handleMpvCommandFromIpc(command: (string | number)[]): void {
|
||||||
handleMpvCommandFromIpcService(
|
handleMpvCommandFromIpcRuntime(command, {
|
||||||
command,
|
|
||||||
createMpvCommandRuntimeServiceDeps({
|
|
||||||
specialCommands: SPECIAL_COMMANDS,
|
|
||||||
triggerSubsyncFromConfig: () => triggerSubsyncFromConfig(),
|
triggerSubsyncFromConfig: () => triggerSubsyncFromConfig(),
|
||||||
openRuntimeOptionsPalette: () => openRuntimeOptionsPalette(),
|
openRuntimeOptionsPalette: () => openRuntimeOptionsPalette(),
|
||||||
runtimeOptionsCycle: (id: RuntimeOptionId, direction: 1 | -1) => {
|
cycleRuntimeOption: (id, direction) => {
|
||||||
if (!appState.runtimeOptionsManager) {
|
if (!appState.runtimeOptionsManager) {
|
||||||
return { ok: false, error: "Runtime options manager unavailable" };
|
return { ok: false, error: "Runtime options manager unavailable" };
|
||||||
}
|
}
|
||||||
@@ -1520,14 +1512,13 @@ function handleMpvCommandFromIpc(command: (string | number)[]): void {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
showMpvOsd: (text: string) => showMpvOsd(text),
|
showMpvOsd: (text: string) => showMpvOsd(text),
|
||||||
mpvReplaySubtitle: () => replayCurrentSubtitleRuntimeService(appState.mpvClient),
|
replayCurrentSubtitle: () => replayCurrentSubtitleRuntimeService(appState.mpvClient),
|
||||||
mpvPlayNextSubtitle: () => playNextSubtitleRuntimeService(appState.mpvClient),
|
playNextSubtitle: () => playNextSubtitleRuntimeService(appState.mpvClient),
|
||||||
mpvSendCommand: (rawCommand: (string | number)[]) =>
|
sendMpvCommand: (rawCommand: (string | number)[]) =>
|
||||||
sendMpvCommandRuntimeService(appState.mpvClient, rawCommand),
|
sendMpvCommandRuntimeService(appState.mpvClient, rawCommand),
|
||||||
isMpvConnected: () => Boolean(appState.mpvClient && appState.mpvClient.connected),
|
isMpvConnected: () => Boolean(appState.mpvClient && appState.mpvClient.connected),
|
||||||
hasRuntimeOptionsManager: () => appState.runtimeOptionsManager !== null,
|
hasRuntimeOptionsManager: () => appState.runtimeOptionsManager !== null,
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runSubsyncManualFromIpc(
|
async function runSubsyncManualFromIpc(
|
||||||
|
|||||||
40
src/main/ipc-mpv-command.ts
Normal file
40
src/main/ipc-mpv-command.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import type { RuntimeOptionApplyResult, RuntimeOptionId } from "../types";
|
||||||
|
import { handleMpvCommandFromIpcService } from "../core/services";
|
||||||
|
import { createMpvCommandRuntimeServiceDeps } from "./dependencies";
|
||||||
|
import { SPECIAL_COMMANDS } from "../config";
|
||||||
|
|
||||||
|
export interface MpvCommandFromIpcRuntimeDeps {
|
||||||
|
triggerSubsyncFromConfig: () => void;
|
||||||
|
openRuntimeOptionsPalette: () => void;
|
||||||
|
cycleRuntimeOption: (
|
||||||
|
id: RuntimeOptionId,
|
||||||
|
direction: 1 | -1,
|
||||||
|
) => RuntimeOptionApplyResult;
|
||||||
|
showMpvOsd: (text: string) => void;
|
||||||
|
replayCurrentSubtitle: () => void;
|
||||||
|
playNextSubtitle: () => void;
|
||||||
|
sendMpvCommand: (command: (string | number)[]) => void;
|
||||||
|
isMpvConnected: () => boolean;
|
||||||
|
hasRuntimeOptionsManager: () => boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function handleMpvCommandFromIpcRuntime(
|
||||||
|
command: (string | number)[],
|
||||||
|
deps: MpvCommandFromIpcRuntimeDeps,
|
||||||
|
): void {
|
||||||
|
handleMpvCommandFromIpcService(
|
||||||
|
command,
|
||||||
|
createMpvCommandRuntimeServiceDeps({
|
||||||
|
specialCommands: SPECIAL_COMMANDS,
|
||||||
|
triggerSubsyncFromConfig: deps.triggerSubsyncFromConfig,
|
||||||
|
openRuntimeOptionsPalette: deps.openRuntimeOptionsPalette,
|
||||||
|
runtimeOptionsCycle: deps.cycleRuntimeOption,
|
||||||
|
showMpvOsd: deps.showMpvOsd,
|
||||||
|
mpvReplaySubtitle: deps.replayCurrentSubtitle,
|
||||||
|
mpvPlayNextSubtitle: deps.playNextSubtitle,
|
||||||
|
mpvSendCommand: deps.sendMpvCommand,
|
||||||
|
isMpvConnected: deps.isMpvConnected,
|
||||||
|
hasRuntimeOptionsManager: deps.hasRuntimeOptionsManager,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user