refactor: extract protocol url handler dependency builders

This commit is contained in:
2026-02-20 01:35:24 -08:00
parent 98902b6b0e
commit 86e0527630
4 changed files with 70 additions and 17 deletions

View File

@@ -411,3 +411,6 @@
- [2026-02-20T09:32:11Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + targeted suites pass: `cli-command-context-main-deps`, `mpv-main-event-main-deps`, `mpv-main-event-bindings`, `mpv-client-runtime-service-main-deps`, `subtitle-tokenization-main-deps`. - [2026-02-20T09:32:11Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + targeted suites pass: `cli-command-context-main-deps`, `mpv-main-event-main-deps`, `mpv-main-event-bindings`, `mpv-client-runtime-service-main-deps`, `subtitle-tokenization-main-deps`.
- [2026-02-20T09:33:19Z] progress: completed another 5-block safe normalization in `main.ts` for lifecycle/startup wiring: prebuilt deps handlers for `onWillQuitCleanup`, `shouldRestoreWindowsOnActivate`, `restoreWindowsOnActivate`, `reloadConfig`, and `criticalConfigError`. - [2026-02-20T09:33:19Z] progress: completed another 5-block safe normalization in `main.ts` for lifecycle/startup wiring: prebuilt deps handlers for `onWillQuitCleanup`, `shouldRestoreWindowsOnActivate`, `restoreWindowsOnActivate`, `reloadConfig`, and `criticalConfigError`.
- [2026-02-20T09:33:19Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + targeted suites pass for `app-lifecycle-main-cleanup`, `app-lifecycle-main-activate`, `startup-config-main-deps`, and `startup-config`. - [2026-02-20T09:33:19Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + targeted suites pass for `app-lifecycle-main-cleanup`, `app-lifecycle-main-activate`, `startup-config-main-deps`, and `startup-config`.
- [2026-02-20T09:35:02Z] progress: extracted protocol URL registration dependency assembly to `protocol-url-handlers-main-deps.ts` and rewired main protocol registration call through builder.
- [2026-02-20T09:35:02Z] progress: normalized `cycleSecondarySubMode` to use prebuilt deps builder constant (avoids per-call rebuild).
- [2026-02-20T09:35:02Z] test: `bun run build` pass (expected macOS helper Swift cache fallback) + `protocol-url-handlers*` and `secondary-sub-mode-main-deps` tests pass.

View File

@@ -195,6 +195,7 @@ import {
createBuildSaveSubtitlePositionMainDepsHandler, createBuildSaveSubtitlePositionMainDepsHandler,
} from './main/runtime/subtitle-position-main-deps'; } from './main/runtime/subtitle-position-main-deps';
import { registerProtocolUrlHandlers } from './main/runtime/protocol-url-handlers'; import { registerProtocolUrlHandlers } from './main/runtime/protocol-url-handlers';
import { createBuildRegisterProtocolUrlHandlersMainDepsHandler } from './main/runtime/protocol-url-handlers-main-deps';
import { createHandleJellyfinAuthCommands } from './main/runtime/jellyfin-cli-auth'; import { createHandleJellyfinAuthCommands } from './main/runtime/jellyfin-cli-auth';
import { createRunJellyfinCommandHandler } from './main/runtime/jellyfin-command-dispatch'; import { createRunJellyfinCommandHandler } from './main/runtime/jellyfin-command-dispatch';
import { createBuildRunJellyfinCommandMainDepsHandler } from './main/runtime/jellyfin-command-dispatch-main-deps'; import { createBuildRunJellyfinCommandMainDepsHandler } from './main/runtime/jellyfin-command-dispatch-main-deps';
@@ -1892,7 +1893,8 @@ const saveSubtitlePosition = createSaveSubtitlePositionHandler(
registerSubminerProtocolClient(); registerSubminerProtocolClient();
registerProtocolUrlHandlers({ const buildRegisterProtocolUrlHandlersMainDepsHandler =
createBuildRegisterProtocolUrlHandlersMainDepsHandler({
registerOpenUrl: (listener) => { registerOpenUrl: (listener) => {
app.on('open-url', listener); app.on('open-url', listener);
}, },
@@ -1908,6 +1910,7 @@ registerProtocolUrlHandlers({
logger.warn('Unhandled second-instance protocol URL', { rawUrl }); logger.warn('Unhandled second-instance protocol URL', { rawUrl });
}, },
}); });
registerProtocolUrlHandlers(buildRegisterProtocolUrlHandlersMainDepsHandler());
const buildOnWillQuitCleanupDepsHandler = createBuildOnWillQuitCleanupDepsHandler({ const buildOnWillQuitCleanupDepsHandler = createBuildOnWillQuitCleanupDepsHandler({
destroyTray: () => destroyTray(), destroyTray: () => destroyTray(),
@@ -2511,9 +2514,8 @@ function getConfiguredShortcuts() {
return getConfiguredShortcutsHandler(); return getConfiguredShortcutsHandler();
} }
function cycleSecondarySubMode(): void { const buildCycleSecondarySubModeMainDepsHandler = createBuildCycleSecondarySubModeMainDepsHandler(
cycleSecondarySubModeCore( {
createBuildCycleSecondarySubModeMainDepsHandler({
getSecondarySubMode: () => appState.secondarySubMode, getSecondarySubMode: () => appState.secondarySubMode,
setSecondarySubMode: (mode: SecondarySubMode) => { setSecondarySubMode: (mode: SecondarySubMode) => {
appState.secondarySubMode = mode; appState.secondarySubMode = mode;
@@ -2526,8 +2528,11 @@ function cycleSecondarySubMode(): void {
broadcastToOverlayWindows(channel, mode); broadcastToOverlayWindows(channel, mode);
}, },
showMpvOsd: (text: string) => showMpvOsd(text), showMpvOsd: (text: string) => showMpvOsd(text),
})(), },
); );
function cycleSecondarySubMode(): void {
cycleSecondarySubModeCore(buildCycleSecondarySubModeMainDepsHandler());
} }
const buildAppendToMpvLogMainDepsHandler = createBuildAppendToMpvLogMainDepsHandler({ const buildAppendToMpvLogMainDepsHandler = createBuildAppendToMpvLogMainDepsHandler({

View File

@@ -0,0 +1,29 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { createBuildRegisterProtocolUrlHandlersMainDepsHandler } from './protocol-url-handlers-main-deps';
test('protocol url handlers main deps builder maps callbacks', () => {
const calls: string[] = [];
const deps = createBuildRegisterProtocolUrlHandlersMainDepsHandler({
registerOpenUrl: () => calls.push('open-register'),
registerSecondInstance: () => calls.push('second-register'),
handleAnilistSetupProtocolUrl: () => true,
findAnilistSetupDeepLinkArgvUrl: () => 'subminer://anilist-setup',
logUnhandledOpenUrl: (rawUrl) => calls.push(`open:${rawUrl}`),
logUnhandledSecondInstanceUrl: (rawUrl) => calls.push(`second:${rawUrl}`),
})();
deps.registerOpenUrl(() => {});
deps.registerSecondInstance(() => {});
assert.equal(deps.handleAnilistSetupProtocolUrl('subminer://anilist-setup'), true);
assert.equal(deps.findAnilistSetupDeepLinkArgvUrl(['x']), 'subminer://anilist-setup');
deps.logUnhandledOpenUrl('subminer://noop');
deps.logUnhandledSecondInstanceUrl('subminer://noop');
assert.deepEqual(calls, [
'open-register',
'second-register',
'open:subminer://noop',
'second:subminer://noop',
]);
});

View File

@@ -0,0 +1,16 @@
import type { registerProtocolUrlHandlers } from './protocol-url-handlers';
type RegisterProtocolUrlHandlersMainDeps = Parameters<typeof registerProtocolUrlHandlers>[0];
export function createBuildRegisterProtocolUrlHandlersMainDepsHandler(
deps: RegisterProtocolUrlHandlersMainDeps,
) {
return (): RegisterProtocolUrlHandlersMainDeps => ({
registerOpenUrl: (listener) => deps.registerOpenUrl(listener),
registerSecondInstance: (listener) => deps.registerSecondInstance(listener),
handleAnilistSetupProtocolUrl: (rawUrl: string) => deps.handleAnilistSetupProtocolUrl(rawUrl),
findAnilistSetupDeepLinkArgvUrl: (argv: string[]) => deps.findAnilistSetupDeepLinkArgvUrl(argv),
logUnhandledOpenUrl: (rawUrl: string) => deps.logUnhandledOpenUrl(rawUrl),
logUnhandledSecondInstanceUrl: (rawUrl: string) => deps.logUnhandledSecondInstanceUrl(rawUrl),
});
}