mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -08:00
refactor: extract protocol url handler dependency builders
This commit is contained in:
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