mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
refactor(main): move IPC runtime deps build to shared dependency mapper
This commit is contained in:
150
src/main.ts
150
src/main.ts
@@ -149,6 +149,9 @@ import { handleMpvCommandFromIpcRuntime } from "./main/ipc-mpv-command";
|
|||||||
import {
|
import {
|
||||||
registerIpcRuntimeServices,
|
registerIpcRuntimeServices,
|
||||||
} from "./main/ipc-runtime";
|
} from "./main/ipc-runtime";
|
||||||
|
import {
|
||||||
|
createAnkiJimakuIpcRuntimeServiceDeps,
|
||||||
|
} from "./main/dependencies";
|
||||||
import {
|
import {
|
||||||
handleCliCommandRuntimeServiceWithContext,
|
handleCliCommandRuntimeServiceWithContext,
|
||||||
} from "./main/cli-runtime";
|
} from "./main/cli-runtime";
|
||||||
@@ -1317,82 +1320,77 @@ async function runSubsyncManualFromIpc(
|
|||||||
return runSubsyncManualFromIpcRuntime(request, getSubsyncRuntimeServiceParams());
|
return runSubsyncManualFromIpcRuntime(request, getSubsyncRuntimeServiceParams());
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildIpcRuntimeServicesParams() {
|
registerIpcRuntimeServices({
|
||||||
return {
|
runtimeOptions: {
|
||||||
runtimeOptions: {
|
getRuntimeOptionsManager: () => appState.runtimeOptionsManager,
|
||||||
getRuntimeOptionsManager: () => appState.runtimeOptionsManager,
|
showMpvOsd: (text: string) => showMpvOsd(text),
|
||||||
showMpvOsd: (text: string) => showMpvOsd(text),
|
},
|
||||||
|
mainDeps: {
|
||||||
|
getInvisibleWindow: () => overlayManager.getInvisibleWindow(),
|
||||||
|
getMainWindow: () => overlayManager.getMainWindow(),
|
||||||
|
getVisibleOverlayVisibility: () => overlayManager.getVisibleOverlayVisible(),
|
||||||
|
getInvisibleOverlayVisibility: () => overlayManager.getInvisibleOverlayVisible(),
|
||||||
|
onOverlayModalClosed: (modal: string) => {
|
||||||
|
handleOverlayModalClosed(modal as OverlayHostedModal);
|
||||||
},
|
},
|
||||||
mainDeps: {
|
openYomitanSettings: () => openYomitanSettings(),
|
||||||
getInvisibleWindow: () => overlayManager.getInvisibleWindow(),
|
quitApp: () => app.quit(),
|
||||||
getMainWindow: () => overlayManager.getMainWindow(),
|
toggleVisibleOverlay: () => toggleVisibleOverlay(),
|
||||||
getVisibleOverlayVisibility: () => overlayManager.getVisibleOverlayVisible(),
|
tokenizeCurrentSubtitle: () => tokenizeCurrentSubtitle(appState.currentSubText),
|
||||||
getInvisibleOverlayVisibility: () => overlayManager.getInvisibleOverlayVisible(),
|
getCurrentSubtitleAss: () => appState.currentSubAssText,
|
||||||
onOverlayModalClosed: (modal: string) => {
|
getMpvSubtitleRenderMetrics: () => appState.mpvSubtitleRenderMetrics,
|
||||||
handleOverlayModalClosed(modal as OverlayHostedModal);
|
getSubtitlePosition: () => loadSubtitlePosition(),
|
||||||
},
|
getSubtitleStyle: () => getResolvedConfig().subtitleStyle ?? null,
|
||||||
openYomitanSettings: () => openYomitanSettings(),
|
saveSubtitlePosition: (position: unknown) =>
|
||||||
quitApp: () => app.quit(),
|
saveSubtitlePosition(position as SubtitlePosition),
|
||||||
toggleVisibleOverlay: () => toggleVisibleOverlay(),
|
getMecabTokenizer: () => appState.mecabTokenizer,
|
||||||
tokenizeCurrentSubtitle: () => tokenizeSubtitle(appState.currentSubText),
|
handleMpvCommand: (command: (string | number)[]) =>
|
||||||
getCurrentSubtitleAss: () => appState.currentSubAssText,
|
handleMpvCommandFromIpc(command),
|
||||||
getMpvSubtitleRenderMetrics: () => appState.mpvSubtitleRenderMetrics,
|
getKeybindings: () => appState.keybindings,
|
||||||
getSubtitlePosition: () => loadSubtitlePosition(),
|
getSecondarySubMode: () => appState.secondarySubMode,
|
||||||
getSubtitleStyle: () => getResolvedConfig().subtitleStyle ?? null,
|
getMpvClient: () => appState.mpvClient,
|
||||||
saveSubtitlePosition: (position: unknown) =>
|
runSubsyncManual: (request: unknown) =>
|
||||||
saveSubtitlePosition(position as SubtitlePosition),
|
runSubsyncManualFromIpc(request as SubsyncManualRunRequest),
|
||||||
getMecabTokenizer: () => appState.mecabTokenizer,
|
getAnkiConnectStatus: () => appState.ankiIntegration !== null,
|
||||||
handleMpvCommand: (command: (string | number)[]) =>
|
getRuntimeOptions: () => getRuntimeOptionsState(),
|
||||||
handleMpvCommandFromIpc(command),
|
reportOverlayContentBounds: (payload: unknown) => {
|
||||||
getKeybindings: () => appState.keybindings,
|
overlayContentMeasurementStore.report(payload);
|
||||||
getSecondarySubMode: () => appState.secondarySubMode,
|
|
||||||
getMpvClient: () => appState.mpvClient,
|
|
||||||
runSubsyncManual: (request: unknown) =>
|
|
||||||
runSubsyncManualFromIpc(request as SubsyncManualRunRequest),
|
|
||||||
getAnkiConnectStatus: () => appState.ankiIntegration !== null,
|
|
||||||
getRuntimeOptions: () => getRuntimeOptionsState(),
|
|
||||||
reportOverlayContentBounds: (payload: unknown) => {
|
|
||||||
overlayContentMeasurementStore.report(payload);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
ankiJimakuDeps: {
|
},
|
||||||
patchAnkiConnectEnabled: (enabled: boolean) => {
|
ankiJimakuDeps: createAnkiJimakuIpcRuntimeServiceDeps({
|
||||||
configService.patchRawConfig({ ankiConnect: { enabled } });
|
patchAnkiConnectEnabled: (enabled: boolean) => {
|
||||||
},
|
configService.patchRawConfig({ ankiConnect: { enabled } });
|
||||||
getResolvedConfig: () => getResolvedConfig(),
|
|
||||||
getRuntimeOptionsManager: () => appState.runtimeOptionsManager,
|
|
||||||
getSubtitleTimingTracker: () => appState.subtitleTimingTracker,
|
|
||||||
getMpvClient: () => appState.mpvClient,
|
|
||||||
getAnkiIntegration: () => appState.ankiIntegration,
|
|
||||||
setAnkiIntegration: (integration: AnkiIntegration | null) => {
|
|
||||||
appState.ankiIntegration = integration;
|
|
||||||
},
|
|
||||||
showDesktopNotification,
|
|
||||||
createFieldGroupingCallback: () => createFieldGroupingCallback(),
|
|
||||||
broadcastRuntimeOptionsChanged: () => broadcastRuntimeOptionsChanged(),
|
|
||||||
getFieldGroupingResolver: () => getFieldGroupingResolver(),
|
|
||||||
setFieldGroupingResolver: (
|
|
||||||
resolver: ((choice: KikuFieldGroupingChoice) => void) | null,
|
|
||||||
) => setFieldGroupingResolver(resolver),
|
|
||||||
parseMediaInfo: (mediaPath: string | null) =>
|
|
||||||
parseMediaInfo(resolveMediaPathForJimaku(mediaPath)),
|
|
||||||
getCurrentMediaPath: () => appState.currentMediaPath,
|
|
||||||
jimakuFetchJson: <T>(
|
|
||||||
endpoint: string,
|
|
||||||
query?: Record<string, string | number | boolean | null | undefined>,
|
|
||||||
): Promise<JimakuApiResponse<T>> =>
|
|
||||||
jimakuFetchJson<T>(endpoint, query),
|
|
||||||
getJimakuMaxEntryResults: () => getJimakuMaxEntryResults(),
|
|
||||||
getJimakuLanguagePreference: () => getJimakuLanguagePreference(),
|
|
||||||
resolveJimakuApiKey: () => resolveJimakuApiKey(),
|
|
||||||
isRemoteMediaPath: (mediaPath: string) => isRemoteMediaPath(mediaPath),
|
|
||||||
downloadToFile: (
|
|
||||||
url: string,
|
|
||||||
destPath: string,
|
|
||||||
headers: Record<string, string>,
|
|
||||||
) => downloadToFile(url, destPath, headers),
|
|
||||||
},
|
},
|
||||||
};
|
getResolvedConfig: () => getResolvedConfig(),
|
||||||
}
|
getRuntimeOptionsManager: () => appState.runtimeOptionsManager,
|
||||||
|
getSubtitleTimingTracker: () => appState.subtitleTimingTracker,
|
||||||
registerIpcRuntimeServices(buildIpcRuntimeServicesParams());
|
getMpvClient: () => appState.mpvClient,
|
||||||
|
getAnkiIntegration: () => appState.ankiIntegration,
|
||||||
|
setAnkiIntegration: (integration: AnkiIntegration | null) => {
|
||||||
|
appState.ankiIntegration = integration;
|
||||||
|
},
|
||||||
|
showDesktopNotification,
|
||||||
|
createFieldGroupingCallback: () => createFieldGroupingCallback(),
|
||||||
|
broadcastRuntimeOptionsChanged: () => broadcastRuntimeOptionsChanged(),
|
||||||
|
getFieldGroupingResolver: () => getFieldGroupingResolver(),
|
||||||
|
setFieldGroupingResolver: (
|
||||||
|
resolver: ((choice: KikuFieldGroupingChoice) => void) | null,
|
||||||
|
) => setFieldGroupingResolver(resolver),
|
||||||
|
parseMediaInfo: (mediaPath: string | null) =>
|
||||||
|
parseMediaInfo(resolveMediaPathForJimaku(mediaPath)),
|
||||||
|
getCurrentMediaPath: () => appState.currentMediaPath,
|
||||||
|
jimakuFetchJson: <T>(
|
||||||
|
endpoint: string,
|
||||||
|
query?: Record<string, string | number | boolean | null | undefined>,
|
||||||
|
): Promise<JimakuApiResponse<T>> => jimakuFetchJson<T>(endpoint, query),
|
||||||
|
getJimakuMaxEntryResults: () => getJimakuMaxEntryResults(),
|
||||||
|
getJimakuLanguagePreference: () => getJimakuLanguagePreference(),
|
||||||
|
resolveJimakuApiKey: () => resolveJimakuApiKey(),
|
||||||
|
isRemoteMediaPath: (mediaPath: string) => isRemoteMediaPath(mediaPath),
|
||||||
|
downloadToFile: (
|
||||||
|
url: string,
|
||||||
|
destPath: string,
|
||||||
|
headers: Record<string, string>,
|
||||||
|
) => downloadToFile(url, destPath, headers),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user