mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
refactor(main): extract IPC registration wiring into main/ipc-runtime module
This commit is contained in:
157
src/main.ts
157
src/main.ts
@@ -97,7 +97,6 @@ import {
|
|||||||
createCliCommandDepsRuntimeService,
|
createCliCommandDepsRuntimeService,
|
||||||
createOverlayManagerService,
|
createOverlayManagerService,
|
||||||
createFieldGroupingOverlayRuntimeService,
|
createFieldGroupingOverlayRuntimeService,
|
||||||
createIpcDepsRuntimeService,
|
|
||||||
createNumericShortcutRuntimeService,
|
createNumericShortcutRuntimeService,
|
||||||
createOverlayContentMeasurementStoreService,
|
createOverlayContentMeasurementStoreService,
|
||||||
createOverlayShortcutRuntimeHandlers,
|
createOverlayShortcutRuntimeHandlers,
|
||||||
@@ -124,9 +123,7 @@ import {
|
|||||||
openYomitanSettingsWindow,
|
openYomitanSettingsWindow,
|
||||||
playNextSubtitleRuntimeService,
|
playNextSubtitleRuntimeService,
|
||||||
refreshOverlayShortcutsRuntimeService,
|
refreshOverlayShortcutsRuntimeService,
|
||||||
registerAnkiJimakuIpcRuntimeService,
|
|
||||||
registerGlobalShortcutsService,
|
registerGlobalShortcutsService,
|
||||||
registerIpcHandlersService,
|
|
||||||
registerOverlayShortcutsService,
|
registerOverlayShortcutsService,
|
||||||
replayCurrentSubtitleRuntimeService,
|
replayCurrentSubtitleRuntimeService,
|
||||||
resolveJimakuApiKeyService,
|
resolveJimakuApiKeyService,
|
||||||
@@ -163,9 +160,7 @@ import type { SubsyncRuntimeDeps } from "./core/services/subsync-runner-service"
|
|||||||
import { applyRuntimeOptionResultRuntimeService } from "./core/services/runtime-options-ipc-service";
|
import { applyRuntimeOptionResultRuntimeService } from "./core/services/runtime-options-ipc-service";
|
||||||
import {
|
import {
|
||||||
createRuntimeOptionsIpcDeps,
|
createRuntimeOptionsIpcDeps,
|
||||||
createAnkiJimakuIpcRuntimeServiceDeps,
|
|
||||||
createCliCommandRuntimeServiceDeps,
|
createCliCommandRuntimeServiceDeps,
|
||||||
createMainIpcRuntimeServiceDeps,
|
|
||||||
createSubsyncRuntimeDeps,
|
createSubsyncRuntimeDeps,
|
||||||
} from "./main/dependencies";
|
} from "./main/dependencies";
|
||||||
import {
|
import {
|
||||||
@@ -173,6 +168,10 @@ import {
|
|||||||
createAppReadyRuntimeDeps as createAppReadyRuntimeDepsBuilder,
|
createAppReadyRuntimeDeps as createAppReadyRuntimeDepsBuilder,
|
||||||
} from "./main/app-lifecycle";
|
} from "./main/app-lifecycle";
|
||||||
import { handleMpvCommandFromIpcRuntime } from "./main/ipc-mpv-command";
|
import { handleMpvCommandFromIpcRuntime } from "./main/ipc-mpv-command";
|
||||||
|
import {
|
||||||
|
registerAnkiJimakuIpcRuntimeServices,
|
||||||
|
registerMainIpcRuntimeServices,
|
||||||
|
} from "./main/ipc-runtime";
|
||||||
import { createStartupBootstrapRuntimeDeps } from "./main/startup";
|
import { createStartupBootstrapRuntimeDeps } from "./main/startup";
|
||||||
import {
|
import {
|
||||||
ConfigService,
|
ConfigService,
|
||||||
@@ -1532,81 +1531,75 @@ const runtimeOptionsIpcDeps = createRuntimeOptionsIpcDeps({
|
|||||||
showMpvOsd,
|
showMpvOsd,
|
||||||
});
|
});
|
||||||
|
|
||||||
registerIpcHandlersService(
|
registerMainIpcRuntimeServices({
|
||||||
createIpcDepsRuntimeService(
|
getInvisibleWindow: () => overlayManager.getInvisibleWindow(),
|
||||||
createMainIpcRuntimeServiceDeps({
|
getMainWindow: () => overlayManager.getMainWindow(),
|
||||||
getInvisibleWindow: () => overlayManager.getInvisibleWindow(),
|
getVisibleOverlayVisibility: () => overlayManager.getVisibleOverlayVisible(),
|
||||||
getMainWindow: () => overlayManager.getMainWindow(),
|
getInvisibleOverlayVisibility: () => overlayManager.getInvisibleOverlayVisible(),
|
||||||
getVisibleOverlayVisibility: () => overlayManager.getVisibleOverlayVisible(),
|
onOverlayModalClosed: (modal) => {
|
||||||
getInvisibleOverlayVisibility: () => overlayManager.getInvisibleOverlayVisible(),
|
handleOverlayModalClosed(modal as OverlayHostedModal);
|
||||||
onOverlayModalClosed: (modal) => {
|
},
|
||||||
handleOverlayModalClosed(modal as OverlayHostedModal);
|
openYomitanSettings: () => openYomitanSettings(),
|
||||||
},
|
quitApp: () => app.quit(),
|
||||||
openYomitanSettings: () => openYomitanSettings(),
|
toggleVisibleOverlay: () => toggleVisibleOverlay(),
|
||||||
quitApp: () => app.quit(),
|
tokenizeCurrentSubtitle: () => tokenizeSubtitle(appState.currentSubText),
|
||||||
toggleVisibleOverlay: () => toggleVisibleOverlay(),
|
getCurrentSubtitleAss: () => appState.currentSubAssText,
|
||||||
tokenizeCurrentSubtitle: () => tokenizeSubtitle(appState.currentSubText),
|
getMpvSubtitleRenderMetrics: () => appState.mpvSubtitleRenderMetrics,
|
||||||
getCurrentSubtitleAss: () => appState.currentSubAssText,
|
getSubtitlePosition: () => loadSubtitlePosition(),
|
||||||
getMpvSubtitleRenderMetrics: () => appState.mpvSubtitleRenderMetrics,
|
getSubtitleStyle: () => getResolvedConfig().subtitleStyle ?? null,
|
||||||
getSubtitlePosition: () => loadSubtitlePosition(),
|
saveSubtitlePosition: (position: unknown) =>
|
||||||
getSubtitleStyle: () => getResolvedConfig().subtitleStyle ?? null,
|
saveSubtitlePosition(position as SubtitlePosition),
|
||||||
saveSubtitlePosition: (position: unknown) =>
|
getMecabTokenizer: () => appState.mecabTokenizer,
|
||||||
saveSubtitlePosition(position as SubtitlePosition),
|
handleMpvCommand: (command: (string | number)[]) =>
|
||||||
getMecabTokenizer: () => appState.mecabTokenizer,
|
handleMpvCommandFromIpc(command),
|
||||||
handleMpvCommand: (command: (string | number)[]) =>
|
getKeybindings: () => appState.keybindings,
|
||||||
handleMpvCommandFromIpc(command),
|
getSecondarySubMode: () => appState.secondarySubMode,
|
||||||
getKeybindings: () => appState.keybindings,
|
getMpvClient: () => appState.mpvClient,
|
||||||
getSecondarySubMode: () => appState.secondarySubMode,
|
runSubsyncManual: (request: unknown) =>
|
||||||
getMpvClient: () => appState.mpvClient,
|
runSubsyncManualFromIpc(request as SubsyncManualRunRequest),
|
||||||
runSubsyncManual: (request: unknown) =>
|
getAnkiConnectStatus: () => appState.ankiIntegration !== null,
|
||||||
runSubsyncManualFromIpc(request as SubsyncManualRunRequest),
|
getRuntimeOptions: () => getRuntimeOptionsState(),
|
||||||
getAnkiConnectStatus: () => appState.ankiIntegration !== null,
|
setRuntimeOption: runtimeOptionsIpcDeps.setRuntimeOption,
|
||||||
getRuntimeOptions: () => getRuntimeOptionsState(),
|
cycleRuntimeOption: runtimeOptionsIpcDeps.cycleRuntimeOption,
|
||||||
setRuntimeOption: runtimeOptionsIpcDeps.setRuntimeOption,
|
reportOverlayContentBounds: (payload: unknown) => {
|
||||||
cycleRuntimeOption: runtimeOptionsIpcDeps.cycleRuntimeOption,
|
overlayContentMeasurementStore.report(payload);
|
||||||
reportOverlayContentBounds: (payload: unknown) => {
|
},
|
||||||
overlayContentMeasurementStore.report(payload);
|
});
|
||||||
},
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
registerAnkiJimakuIpcRuntimeService(
|
registerAnkiJimakuIpcRuntimeServices({
|
||||||
createAnkiJimakuIpcRuntimeServiceDeps({
|
patchAnkiConnectEnabled: (enabled: boolean) => {
|
||||||
patchAnkiConnectEnabled: (enabled: boolean) => {
|
configService.patchRawConfig({ ankiConnect: { enabled } });
|
||||||
configService.patchRawConfig({ ankiConnect: { enabled } });
|
},
|
||||||
},
|
getResolvedConfig: () => getResolvedConfig(),
|
||||||
getResolvedConfig: () => getResolvedConfig(),
|
getRuntimeOptionsManager: () => appState.runtimeOptionsManager,
|
||||||
getRuntimeOptionsManager: () => appState.runtimeOptionsManager,
|
getSubtitleTimingTracker: () => appState.subtitleTimingTracker,
|
||||||
getSubtitleTimingTracker: () => appState.subtitleTimingTracker,
|
getMpvClient: () => appState.mpvClient,
|
||||||
getMpvClient: () => appState.mpvClient,
|
getAnkiIntegration: () => appState.ankiIntegration,
|
||||||
getAnkiIntegration: () => appState.ankiIntegration,
|
setAnkiIntegration: (integration: AnkiIntegration | null) => {
|
||||||
setAnkiIntegration: (integration: AnkiIntegration | null) => {
|
appState.ankiIntegration = integration;
|
||||||
appState.ankiIntegration = integration;
|
},
|
||||||
},
|
showDesktopNotification,
|
||||||
showDesktopNotification,
|
createFieldGroupingCallback: () => createFieldGroupingCallback(),
|
||||||
createFieldGroupingCallback: () => createFieldGroupingCallback(),
|
broadcastRuntimeOptionsChanged: () => broadcastRuntimeOptionsChanged(),
|
||||||
broadcastRuntimeOptionsChanged: () => broadcastRuntimeOptionsChanged(),
|
getFieldGroupingResolver: () => getFieldGroupingResolver(),
|
||||||
getFieldGroupingResolver: () => getFieldGroupingResolver(),
|
setFieldGroupingResolver: (
|
||||||
setFieldGroupingResolver: (
|
resolver: ((choice: KikuFieldGroupingChoice) => void) | null,
|
||||||
resolver: ((choice: KikuFieldGroupingChoice) => void) | null,
|
) => setFieldGroupingResolver(resolver),
|
||||||
) => setFieldGroupingResolver(resolver),
|
parseMediaInfo: (mediaPath: string | null) =>
|
||||||
parseMediaInfo: (mediaPath: string | null) =>
|
parseMediaInfo(resolveMediaPathForJimaku(mediaPath)),
|
||||||
parseMediaInfo(resolveMediaPathForJimaku(mediaPath)),
|
getCurrentMediaPath: () => appState.currentMediaPath,
|
||||||
getCurrentMediaPath: () => appState.currentMediaPath,
|
jimakuFetchJson: <T>(
|
||||||
jimakuFetchJson: <T>(
|
endpoint: string,
|
||||||
endpoint: string,
|
query?: Record<string, string | number | boolean | null | undefined>,
|
||||||
query?: Record<string, string | number | boolean | null | undefined>,
|
): Promise<JimakuApiResponse<T>> =>
|
||||||
): Promise<JimakuApiResponse<T>> =>
|
jimakuFetchJson<T>(endpoint, query),
|
||||||
jimakuFetchJson<T>(endpoint, query),
|
getJimakuMaxEntryResults: () => getJimakuMaxEntryResults(),
|
||||||
getJimakuMaxEntryResults: () => getJimakuMaxEntryResults(),
|
getJimakuLanguagePreference: () => getJimakuLanguagePreference(),
|
||||||
getJimakuLanguagePreference: () => getJimakuLanguagePreference(),
|
resolveJimakuApiKey: () => resolveJimakuApiKey(),
|
||||||
resolveJimakuApiKey: () => resolveJimakuApiKey(),
|
isRemoteMediaPath: (mediaPath: string) => isRemoteMediaPath(mediaPath),
|
||||||
isRemoteMediaPath: (mediaPath: string) => isRemoteMediaPath(mediaPath),
|
downloadToFile: (
|
||||||
downloadToFile: (
|
url: string,
|
||||||
url: string,
|
destPath: string,
|
||||||
destPath: string,
|
headers: Record<string, string>,
|
||||||
headers: Record<string, string>,
|
) => downloadToFile(url, destPath, headers),
|
||||||
) => downloadToFile(url, destPath, headers),
|
});
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|||||||
28
src/main/ipc-runtime.ts
Normal file
28
src/main/ipc-runtime.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import {
|
||||||
|
createIpcDepsRuntimeService,
|
||||||
|
registerAnkiJimakuIpcRuntimeService,
|
||||||
|
registerIpcHandlersService,
|
||||||
|
} from "../core/services";
|
||||||
|
import {
|
||||||
|
createAnkiJimakuIpcRuntimeServiceDeps,
|
||||||
|
AnkiJimakuIpcRuntimeServiceDepsParams,
|
||||||
|
createMainIpcRuntimeServiceDeps,
|
||||||
|
MainIpcRuntimeServiceDepsParams,
|
||||||
|
} from "./dependencies";
|
||||||
|
|
||||||
|
export function registerMainIpcRuntimeServices(
|
||||||
|
params: MainIpcRuntimeServiceDepsParams,
|
||||||
|
): void {
|
||||||
|
registerIpcHandlersService(
|
||||||
|
createIpcDepsRuntimeService(createMainIpcRuntimeServiceDeps(params)),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function registerAnkiJimakuIpcRuntimeServices(
|
||||||
|
params: AnkiJimakuIpcRuntimeServiceDepsParams,
|
||||||
|
): void {
|
||||||
|
registerAnkiJimakuIpcRuntimeService(
|
||||||
|
createAnkiJimakuIpcRuntimeServiceDeps(params),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user