From 05f582e00de74b6572c320b89705aca9d931faf1 Mon Sep 17 00:00:00 2001 From: sudacode Date: Sat, 14 Feb 2026 01:16:32 -0800 Subject: [PATCH] refactor(main): extract mpv IPC command deps into factory --- src/main.ts | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/src/main.ts b/src/main.ts index 14bbd92..dbe7939 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1473,30 +1473,31 @@ function handleOverlayModalClosed(modal: OverlayHostedModal): void { } function handleMpvCommandFromIpc(command: (string | number)[]): void { - handleMpvCommandFromIpcService( - command, - { - specialCommands: SPECIAL_COMMANDS, - triggerSubsyncFromConfig: () => triggerSubsyncFromConfig(), - openRuntimeOptionsPalette: () => openRuntimeOptionsPalette(), - runtimeOptionsCycle: (id, direction) => { - if (!appState.runtimeOptionsManager) { - return { ok: false, error: "Runtime options manager unavailable" }; - } - return applyRuntimeOptionResultRuntimeService( - appState.runtimeOptionsManager.cycleOption(id, direction), - (text) => showMpvOsd(text), - ); - }, - showMpvOsd: (text) => showMpvOsd(text), - mpvReplaySubtitle: () => replayCurrentSubtitleRuntimeService(appState.mpvClient), - mpvPlayNextSubtitle: () => playNextSubtitleRuntimeService(appState.mpvClient), - mpvSendCommand: (rawCommand) => - sendMpvCommandRuntimeService(appState.mpvClient, rawCommand), - isMpvConnected: () => Boolean(appState.mpvClient && appState.mpvClient.connected), - hasRuntimeOptionsManager: () => appState.runtimeOptionsManager !== null, + handleMpvCommandFromIpcService(command, createMpvCommandRuntimeServiceDeps()); +} + +function createMpvCommandRuntimeServiceDeps() { + return { + specialCommands: SPECIAL_COMMANDS, + triggerSubsyncFromConfig: () => triggerSubsyncFromConfig(), + openRuntimeOptionsPalette: () => openRuntimeOptionsPalette(), + runtimeOptionsCycle: (id, direction) => { + if (!appState.runtimeOptionsManager) { + return { ok: false, error: "Runtime options manager unavailable" }; + } + return applyRuntimeOptionResultRuntimeService( + appState.runtimeOptionsManager.cycleOption(id, direction), + (text) => showMpvOsd(text), + ); }, - ); + showMpvOsd: (text) => showMpvOsd(text), + mpvReplaySubtitle: () => replayCurrentSubtitleRuntimeService(appState.mpvClient), + mpvPlayNextSubtitle: () => playNextSubtitleRuntimeService(appState.mpvClient), + mpvSendCommand: (rawCommand) => + sendMpvCommandRuntimeService(appState.mpvClient, rawCommand), + isMpvConnected: () => Boolean(appState.mpvClient && appState.mpvClient.connected), + hasRuntimeOptionsManager: () => appState.runtimeOptionsManager !== null, + }; } async function runSubsyncManualFromIpc(