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,
|
KikuFieldGroupingChoice,
|
||||||
KikuMergePreviewRequest,
|
KikuMergePreviewRequest,
|
||||||
KikuMergePreviewResponse,
|
KikuMergePreviewResponse,
|
||||||
RuntimeOptionId,
|
|
||||||
RuntimeOptionState,
|
RuntimeOptionState,
|
||||||
RuntimeOptionValue,
|
|
||||||
MpvSubtitleRenderMetrics,
|
MpvSubtitleRenderMetrics,
|
||||||
} from "./types";
|
} from "./types";
|
||||||
import { SubtitleTimingTracker } from "./subtitle-timing-tracker";
|
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 type { SubsyncRuntimeDeps } from "./core/services/subsync-runner-service";
|
||||||
import {
|
import {
|
||||||
applyRuntimeOptionResultRuntimeService,
|
applyRuntimeOptionResultRuntimeService,
|
||||||
cycleRuntimeOptionFromIpcRuntimeService,
|
|
||||||
setRuntimeOptionFromIpcRuntimeService,
|
|
||||||
} from "./core/services/runtime-options-ipc-service";
|
} from "./core/services/runtime-options-ipc-service";
|
||||||
|
import { createRuntimeOptionsIpcDeps, createSubsyncRuntimeDeps } from "./main/dependencies";
|
||||||
import {
|
import {
|
||||||
ConfigService,
|
ConfigService,
|
||||||
DEFAULT_CONFIG,
|
DEFAULT_CONFIG,
|
||||||
@@ -1219,7 +1216,7 @@ const multiCopySession = numericShortcutRuntime.createSession();
|
|||||||
const mineSentenceSession = numericShortcutRuntime.createSession();
|
const mineSentenceSession = numericShortcutRuntime.createSession();
|
||||||
|
|
||||||
function getSubsyncRuntimeDeps(): SubsyncRuntimeDeps {
|
function getSubsyncRuntimeDeps(): SubsyncRuntimeDeps {
|
||||||
return {
|
return createSubsyncRuntimeDeps({
|
||||||
getMpvClient: () => appState.mpvClient,
|
getMpvClient: () => appState.mpvClient,
|
||||||
getResolvedSubsyncConfig: () => getSubsyncConfig(getResolvedConfig().subsync),
|
getResolvedSubsyncConfig: () => getSubsyncConfig(getResolvedConfig().subsync),
|
||||||
isSubsyncInProgress: () => appState.subsyncInProgress,
|
isSubsyncInProgress: () => appState.subsyncInProgress,
|
||||||
@@ -1232,7 +1229,7 @@ function getSubsyncRuntimeDeps(): SubsyncRuntimeDeps {
|
|||||||
restoreOnModalClose: "subsync",
|
restoreOnModalClose: "subsync",
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function triggerSubsyncFromConfig(): Promise<void> {
|
async function triggerSubsyncFromConfig(): Promise<void> {
|
||||||
@@ -1531,22 +1528,10 @@ async function runSubsyncManualFromIpc(
|
|||||||
return runSubsyncManualFromIpcRuntimeService(request, getSubsyncRuntimeDeps());
|
return runSubsyncManualFromIpcRuntimeService(request, getSubsyncRuntimeDeps());
|
||||||
}
|
}
|
||||||
|
|
||||||
const runtimeOptionsIpcDeps = {
|
const runtimeOptionsIpcDeps = createRuntimeOptionsIpcDeps({
|
||||||
setRuntimeOption: (id: string, value: unknown) =>
|
getRuntimeOptionsManager: () => appState.runtimeOptionsManager,
|
||||||
setRuntimeOptionFromIpcRuntimeService(
|
showMpvOsd,
|
||||||
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),
|
|
||||||
),
|
|
||||||
};
|
|
||||||
|
|
||||||
registerIpcHandlersService(
|
registerIpcHandlersService(
|
||||||
createIpcDepsRuntimeService(createMainIpcRuntimeServiceDeps()),
|
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