mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
refactor(main): extract runtime options and subsync ipc deps
This commit is contained in:
29
src/main.ts
29
src/main.ts
@@ -57,9 +57,7 @@ import type {
|
||||
KikuFieldGroupingChoice,
|
||||
KikuMergePreviewRequest,
|
||||
KikuMergePreviewResponse,
|
||||
RuntimeOptionId,
|
||||
RuntimeOptionState,
|
||||
RuntimeOptionValue,
|
||||
MpvSubtitleRenderMetrics,
|
||||
} from "./types";
|
||||
import { SubtitleTimingTracker } from "./subtitle-timing-tracker";
|
||||
@@ -162,9 +160,8 @@ import type { AppReadyRuntimeDeps } from "./core/services/startup-service";
|
||||
import type { SubsyncRuntimeDeps } from "./core/services/subsync-runner-service";
|
||||
import {
|
||||
applyRuntimeOptionResultRuntimeService,
|
||||
cycleRuntimeOptionFromIpcRuntimeService,
|
||||
setRuntimeOptionFromIpcRuntimeService,
|
||||
} from "./core/services/runtime-options-ipc-service";
|
||||
import { createRuntimeOptionsIpcDeps, createSubsyncRuntimeDeps } from "./main/dependencies";
|
||||
import {
|
||||
ConfigService,
|
||||
DEFAULT_CONFIG,
|
||||
@@ -1219,7 +1216,7 @@ const multiCopySession = numericShortcutRuntime.createSession();
|
||||
const mineSentenceSession = numericShortcutRuntime.createSession();
|
||||
|
||||
function getSubsyncRuntimeDeps(): SubsyncRuntimeDeps {
|
||||
return {
|
||||
return createSubsyncRuntimeDeps({
|
||||
getMpvClient: () => appState.mpvClient,
|
||||
getResolvedSubsyncConfig: () => getSubsyncConfig(getResolvedConfig().subsync),
|
||||
isSubsyncInProgress: () => appState.subsyncInProgress,
|
||||
@@ -1232,7 +1229,7 @@ function getSubsyncRuntimeDeps(): SubsyncRuntimeDeps {
|
||||
restoreOnModalClose: "subsync",
|
||||
});
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async function triggerSubsyncFromConfig(): Promise<void> {
|
||||
@@ -1531,22 +1528,10 @@ async function runSubsyncManualFromIpc(
|
||||
return runSubsyncManualFromIpcRuntimeService(request, getSubsyncRuntimeDeps());
|
||||
}
|
||||
|
||||
const runtimeOptionsIpcDeps = {
|
||||
setRuntimeOption: (id: string, value: unknown) =>
|
||||
setRuntimeOptionFromIpcRuntimeService(
|
||||
appState.runtimeOptionsManager,
|
||||
id as RuntimeOptionId,
|
||||
value as RuntimeOptionValue,
|
||||
(text) => showMpvOsd(text),
|
||||
),
|
||||
cycleRuntimeOption: (id: string, direction: 1 | -1) =>
|
||||
cycleRuntimeOptionFromIpcRuntimeService(
|
||||
appState.runtimeOptionsManager,
|
||||
id as RuntimeOptionId,
|
||||
direction,
|
||||
(text) => showMpvOsd(text),
|
||||
),
|
||||
};
|
||||
const runtimeOptionsIpcDeps = createRuntimeOptionsIpcDeps({
|
||||
getRuntimeOptionsManager: () => appState.runtimeOptionsManager,
|
||||
showMpvOsd,
|
||||
});
|
||||
|
||||
registerIpcHandlersService(
|
||||
createIpcDepsRuntimeService(createMainIpcRuntimeServiceDeps()),
|
||||
|
||||
59
src/main/dependencies.ts
Normal file
59
src/main/dependencies.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import {
|
||||
RuntimeOptionId,
|
||||
RuntimeOptionValue,
|
||||
SubsyncManualPayload,
|
||||
} from "../types";
|
||||
import { SubsyncResolvedConfig } from "../subsync/utils";
|
||||
import type { SubsyncRuntimeDeps } from "../core/services/subsync-runner-service";
|
||||
import {
|
||||
cycleRuntimeOptionFromIpcRuntimeService,
|
||||
setRuntimeOptionFromIpcRuntimeService,
|
||||
} from "../core/services/runtime-options-ipc-service";
|
||||
import { RuntimeOptionsManager } from "../runtime-options";
|
||||
|
||||
export interface RuntimeOptionsIpcDepsParams {
|
||||
getRuntimeOptionsManager: () => RuntimeOptionsManager | null;
|
||||
showMpvOsd: (text: string) => void;
|
||||
}
|
||||
|
||||
export interface SubsyncRuntimeDepsParams {
|
||||
getMpvClient: () => ReturnType<SubsyncRuntimeDeps["getMpvClient"]>;
|
||||
getResolvedSubsyncConfig: () => SubsyncResolvedConfig;
|
||||
isSubsyncInProgress: () => boolean;
|
||||
setSubsyncInProgress: (inProgress: boolean) => void;
|
||||
showMpvOsd: (text: string) => void;
|
||||
openManualPicker: (payload: SubsyncManualPayload) => void;
|
||||
}
|
||||
|
||||
export function createRuntimeOptionsIpcDeps(params: RuntimeOptionsIpcDepsParams): {
|
||||
setRuntimeOption: (id: string, value: unknown) => unknown;
|
||||
cycleRuntimeOption: (id: string, direction: 1 | -1) => unknown;
|
||||
} {
|
||||
return {
|
||||
setRuntimeOption: (id, value) =>
|
||||
setRuntimeOptionFromIpcRuntimeService(
|
||||
params.getRuntimeOptionsManager(),
|
||||
id as RuntimeOptionId,
|
||||
value as RuntimeOptionValue,
|
||||
(text) => params.showMpvOsd(text),
|
||||
),
|
||||
cycleRuntimeOption: (id, direction) =>
|
||||
cycleRuntimeOptionFromIpcRuntimeService(
|
||||
params.getRuntimeOptionsManager(),
|
||||
id as RuntimeOptionId,
|
||||
direction,
|
||||
(text) => params.showMpvOsd(text),
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
export function createSubsyncRuntimeDeps(params: SubsyncRuntimeDepsParams): SubsyncRuntimeDeps {
|
||||
return {
|
||||
getMpvClient: params.getMpvClient,
|
||||
getResolvedSubsyncConfig: params.getResolvedSubsyncConfig,
|
||||
isSubsyncInProgress: params.isSubsyncInProgress,
|
||||
setSubsyncInProgress: params.setSubsyncInProgress,
|
||||
showMpvOsd: params.showMpvOsd,
|
||||
openManualPicker: params.openManualPicker,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user