mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
refactor: extract runtime option ipc helpers
This commit is contained in:
46
src/main.ts
46
src/main.ts
@@ -65,7 +65,6 @@ import {
|
||||
KikuFieldGroupingChoice,
|
||||
KikuMergePreviewRequest,
|
||||
KikuMergePreviewResponse,
|
||||
RuntimeOptionApplyResult,
|
||||
RuntimeOptionId,
|
||||
RuntimeOptionState,
|
||||
RuntimeOptionValue,
|
||||
@@ -139,6 +138,11 @@ import {
|
||||
setMpvSubVisibilityRuntimeService,
|
||||
showMpvOsdRuntimeService,
|
||||
} from "./core/services/mpv-runtime-service";
|
||||
import {
|
||||
applyRuntimeOptionResultRuntimeService,
|
||||
cycleRuntimeOptionFromIpcRuntimeService,
|
||||
setRuntimeOptionFromIpcRuntimeService,
|
||||
} from "./core/services/runtime-options-runtime-service";
|
||||
import { showDesktopNotification } from "./core/utils/notification";
|
||||
import { openYomitanSettingsWindow } from "./core/services/yomitan-settings-service";
|
||||
import { tokenizeSubtitleService } from "./core/services/tokenizer-service";
|
||||
@@ -306,15 +310,6 @@ function broadcastRuntimeOptionsChanged(): void { broadcastToOverlayWindows("run
|
||||
|
||||
function setOverlayDebugVisualizationEnabled(enabled: boolean): void { if (overlayDebugVisualizationEnabled === enabled) return; overlayDebugVisualizationEnabled = enabled; broadcastToOverlayWindows("overlay-debug-visualization:set", overlayDebugVisualizationEnabled); }
|
||||
|
||||
function applyRuntimeOptionResult(
|
||||
result: RuntimeOptionApplyResult,
|
||||
): RuntimeOptionApplyResult {
|
||||
if (result.ok && result.osdMessage) {
|
||||
showMpvOsd(result.osdMessage);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
function openRuntimeOptionsPalette(): void { sendToVisibleOverlay("runtime-options:open", undefined, { restoreOnModalClose: "runtime-options" }); }
|
||||
|
||||
function getResolvedConfig() { return configService.getConfig(); }
|
||||
@@ -1134,8 +1129,9 @@ function handleMpvCommandFromIpc(command: (string | number)[]): void {
|
||||
if (!runtimeOptionsManager) {
|
||||
return { ok: false, error: "Runtime options manager unavailable" };
|
||||
}
|
||||
return applyRuntimeOptionResult(
|
||||
return applyRuntimeOptionResultRuntimeService(
|
||||
runtimeOptionsManager.cycleOption(id, direction),
|
||||
(text) => showMpvOsd(text),
|
||||
);
|
||||
},
|
||||
showMpvOsd: (text) => showMpvOsd(text),
|
||||
@@ -1195,28 +1191,20 @@ registerIpcHandlersService({
|
||||
getAnkiConnectStatus: () => ankiIntegration !== null,
|
||||
getRuntimeOptions: () => getRuntimeOptionsState(),
|
||||
setRuntimeOption: (id, value) => {
|
||||
if (!runtimeOptionsManager) {
|
||||
return { ok: false, error: "Runtime options manager unavailable" };
|
||||
}
|
||||
const result = applyRuntimeOptionResult(
|
||||
runtimeOptionsManager.setOptionValue(id as RuntimeOptionId, value as RuntimeOptionValue),
|
||||
return setRuntimeOptionFromIpcRuntimeService(
|
||||
runtimeOptionsManager,
|
||||
id as RuntimeOptionId,
|
||||
value as RuntimeOptionValue,
|
||||
(text) => showMpvOsd(text),
|
||||
);
|
||||
if (!result.ok && result.error) {
|
||||
showMpvOsd(result.error);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
cycleRuntimeOption: (id, direction) => {
|
||||
if (!runtimeOptionsManager) {
|
||||
return { ok: false, error: "Runtime options manager unavailable" };
|
||||
}
|
||||
const result = applyRuntimeOptionResult(
|
||||
runtimeOptionsManager.cycleOption(id as RuntimeOptionId, direction),
|
||||
return cycleRuntimeOptionFromIpcRuntimeService(
|
||||
runtimeOptionsManager,
|
||||
id as RuntimeOptionId,
|
||||
direction,
|
||||
(text) => showMpvOsd(text),
|
||||
);
|
||||
if (!result.ok && result.error) {
|
||||
showMpvOsd(result.error);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user