mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
refactor: extract protocol url handler dependency builders
This commit is contained in:
@@ -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: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: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.
|
||||
|
||||
15
src/main.ts
15
src/main.ts
@@ -195,6 +195,7 @@ import {
|
||||
createBuildSaveSubtitlePositionMainDepsHandler,
|
||||
} from './main/runtime/subtitle-position-main-deps';
|
||||
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 { createRunJellyfinCommandHandler } from './main/runtime/jellyfin-command-dispatch';
|
||||
import { createBuildRunJellyfinCommandMainDepsHandler } from './main/runtime/jellyfin-command-dispatch-main-deps';
|
||||
@@ -1892,7 +1893,8 @@ const saveSubtitlePosition = createSaveSubtitlePositionHandler(
|
||||
|
||||
registerSubminerProtocolClient();
|
||||
|
||||
registerProtocolUrlHandlers({
|
||||
const buildRegisterProtocolUrlHandlersMainDepsHandler =
|
||||
createBuildRegisterProtocolUrlHandlersMainDepsHandler({
|
||||
registerOpenUrl: (listener) => {
|
||||
app.on('open-url', listener);
|
||||
},
|
||||
@@ -1908,6 +1910,7 @@ registerProtocolUrlHandlers({
|
||||
logger.warn('Unhandled second-instance protocol URL', { rawUrl });
|
||||
},
|
||||
});
|
||||
registerProtocolUrlHandlers(buildRegisterProtocolUrlHandlersMainDepsHandler());
|
||||
|
||||
const buildOnWillQuitCleanupDepsHandler = createBuildOnWillQuitCleanupDepsHandler({
|
||||
destroyTray: () => destroyTray(),
|
||||
@@ -2511,9 +2514,8 @@ function getConfiguredShortcuts() {
|
||||
return getConfiguredShortcutsHandler();
|
||||
}
|
||||
|
||||
function cycleSecondarySubMode(): void {
|
||||
cycleSecondarySubModeCore(
|
||||
createBuildCycleSecondarySubModeMainDepsHandler({
|
||||
const buildCycleSecondarySubModeMainDepsHandler = createBuildCycleSecondarySubModeMainDepsHandler(
|
||||
{
|
||||
getSecondarySubMode: () => appState.secondarySubMode,
|
||||
setSecondarySubMode: (mode: SecondarySubMode) => {
|
||||
appState.secondarySubMode = mode;
|
||||
@@ -2526,8 +2528,11 @@ function cycleSecondarySubMode(): void {
|
||||
broadcastToOverlayWindows(channel, mode);
|
||||
},
|
||||
showMpvOsd: (text: string) => showMpvOsd(text),
|
||||
})(),
|
||||
},
|
||||
);
|
||||
|
||||
function cycleSecondarySubMode(): void {
|
||||
cycleSecondarySubModeCore(buildCycleSecondarySubModeMainDepsHandler());
|
||||
}
|
||||
|
||||
const buildAppendToMpvLogMainDepsHandler = createBuildAppendToMpvLogMainDepsHandler({
|
||||
|
||||
29
src/main/runtime/protocol-url-handlers-main-deps.test.ts
Normal file
29
src/main/runtime/protocol-url-handlers-main-deps.test.ts
Normal 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',
|
||||
]);
|
||||
});
|
||||
16
src/main/runtime/protocol-url-handlers-main-deps.ts
Normal file
16
src/main/runtime/protocol-url-handlers-main-deps.ts
Normal 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),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user