mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-27 18:22:41 -08:00
refactor: extract ipc runtime handler wiring
This commit is contained in:
39
src/main.ts
39
src/main.ts
@@ -380,14 +380,7 @@ import {
|
||||
createBuildSendToActiveOverlayWindowMainDepsHandler,
|
||||
createBuildSetOverlayDebugVisualizationEnabledMainDepsHandler,
|
||||
} from './main/runtime/overlay-runtime-main-actions-main-deps';
|
||||
import {
|
||||
createHandleMpvCommandFromIpcHandler,
|
||||
createRunSubsyncManualFromIpcHandler,
|
||||
} from './main/runtime/ipc-bridge-actions';
|
||||
import {
|
||||
createBuildHandleMpvCommandFromIpcMainDepsHandler,
|
||||
createBuildRunSubsyncManualFromIpcMainDepsHandler,
|
||||
} from './main/runtime/ipc-bridge-actions-main-deps';
|
||||
import { createIpcRuntimeHandlers } from './main/runtime/ipc-runtime-handlers';
|
||||
import { createBuildMpvCommandFromIpcRuntimeMainDepsHandler } from './main/runtime/ipc-mpv-command-main-deps';
|
||||
import {
|
||||
createCreateInvisibleWindowHandler,
|
||||
@@ -2957,27 +2950,17 @@ const buildMpvCommandFromIpcRuntimeMainDepsHandler =
|
||||
hasRuntimeOptionsManager: () => appState.runtimeOptionsManager !== null,
|
||||
});
|
||||
|
||||
const buildHandleMpvCommandFromIpcMainDepsHandler =
|
||||
createBuildHandleMpvCommandFromIpcMainDepsHandler({
|
||||
handleMpvCommandFromIpcRuntime,
|
||||
buildMpvCommandDeps: () => mpvCommandFromIpcRuntimeMainDeps,
|
||||
});
|
||||
const mpvCommandFromIpcRuntimeMainDeps = buildMpvCommandFromIpcRuntimeMainDepsHandler();
|
||||
const handleMpvCommandFromIpcMainDeps =
|
||||
buildHandleMpvCommandFromIpcMainDepsHandler();
|
||||
const handleMpvCommandFromIpcHandler = createHandleMpvCommandFromIpcHandler(
|
||||
handleMpvCommandFromIpcMainDeps,
|
||||
);
|
||||
|
||||
const buildRunSubsyncManualFromIpcMainDepsHandler =
|
||||
createBuildRunSubsyncManualFromIpcMainDepsHandler({
|
||||
runManualFromIpc: (request: SubsyncManualRunRequest) => subsyncRuntime.runManualFromIpc(request),
|
||||
});
|
||||
const runSubsyncManualFromIpcMainDeps =
|
||||
buildRunSubsyncManualFromIpcMainDepsHandler();
|
||||
const runSubsyncManualFromIpcHandler = createRunSubsyncManualFromIpcHandler(
|
||||
runSubsyncManualFromIpcMainDeps,
|
||||
);
|
||||
const { handleMpvCommandFromIpc: handleMpvCommandFromIpcHandler, runSubsyncManualFromIpc: runSubsyncManualFromIpcHandler } =
|
||||
createIpcRuntimeHandlers<SubsyncManualRunRequest, Awaited<ReturnType<typeof subsyncRuntime.runManualFromIpc>>>({
|
||||
handleMpvCommandFromIpcDeps: {
|
||||
handleMpvCommandFromIpcRuntime,
|
||||
buildMpvCommandDeps: () => mpvCommandFromIpcRuntimeMainDeps,
|
||||
},
|
||||
runSubsyncManualFromIpcDeps: {
|
||||
runManualFromIpc: (request) => subsyncRuntime.runManualFromIpc(request),
|
||||
},
|
||||
});
|
||||
const buildCliCommandContextMainDepsHandler = createBuildCliCommandContextMainDepsHandler({
|
||||
appState,
|
||||
texthookerService,
|
||||
|
||||
38
src/main/runtime/ipc-runtime-handlers.test.ts
Normal file
38
src/main/runtime/ipc-runtime-handlers.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createIpcRuntimeHandlers } from './ipc-runtime-handlers';
|
||||
|
||||
test('ipc runtime handlers wire command and subsync handlers through built deps', async () => {
|
||||
let receivedCommand: (string | number)[] | null = null;
|
||||
let receivedCommandDeps: { tag: string } | null = null;
|
||||
let buildMpvCommandDepsCalls = 0;
|
||||
let receivedSubsyncRequest: { id: string } | null = null;
|
||||
|
||||
const runtime = createIpcRuntimeHandlers({
|
||||
handleMpvCommandFromIpcDeps: {
|
||||
handleMpvCommandFromIpcRuntime: (command, deps) => {
|
||||
receivedCommand = command;
|
||||
receivedCommandDeps = deps as unknown as { tag: string };
|
||||
},
|
||||
buildMpvCommandDeps: () => {
|
||||
buildMpvCommandDepsCalls += 1;
|
||||
return { tag: 'mpv-deps' } as never;
|
||||
},
|
||||
},
|
||||
runSubsyncManualFromIpcDeps: {
|
||||
runManualFromIpc: async (request: { id: string }) => {
|
||||
receivedSubsyncRequest = request;
|
||||
return { ok: true, id: request.id };
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
runtime.handleMpvCommandFromIpc(['set_property', 'pause', 'yes']);
|
||||
assert.deepEqual(receivedCommand, ['set_property', 'pause', 'yes']);
|
||||
assert.deepEqual(receivedCommandDeps, { tag: 'mpv-deps' });
|
||||
assert.equal(buildMpvCommandDepsCalls, 1);
|
||||
|
||||
const response = await runtime.runSubsyncManualFromIpc({ id: 'abc' });
|
||||
assert.deepEqual(receivedSubsyncRequest, { id: 'abc' });
|
||||
assert.deepEqual(response, { ok: true, id: 'abc' });
|
||||
});
|
||||
37
src/main/runtime/ipc-runtime-handlers.ts
Normal file
37
src/main/runtime/ipc-runtime-handlers.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { createHandleMpvCommandFromIpcHandler, createRunSubsyncManualFromIpcHandler } from './ipc-bridge-actions';
|
||||
import {
|
||||
createBuildHandleMpvCommandFromIpcMainDepsHandler,
|
||||
createBuildRunSubsyncManualFromIpcMainDepsHandler,
|
||||
} from './ipc-bridge-actions-main-deps';
|
||||
|
||||
type HandleMpvCommandFromIpcMainDeps = Parameters<
|
||||
typeof createBuildHandleMpvCommandFromIpcMainDepsHandler
|
||||
>[0];
|
||||
type RunSubsyncManualFromIpcMainDeps<TRequest, TResult> = Parameters<
|
||||
typeof createBuildRunSubsyncManualFromIpcMainDepsHandler<TRequest, TResult>
|
||||
>[0];
|
||||
|
||||
export function createIpcRuntimeHandlers<TRequest, TResult>(deps: {
|
||||
handleMpvCommandFromIpcDeps: HandleMpvCommandFromIpcMainDeps;
|
||||
runSubsyncManualFromIpcDeps: RunSubsyncManualFromIpcMainDeps<TRequest, TResult>;
|
||||
}) {
|
||||
const handleMpvCommandFromIpcMainDeps = createBuildHandleMpvCommandFromIpcMainDepsHandler(
|
||||
deps.handleMpvCommandFromIpcDeps,
|
||||
)();
|
||||
const handleMpvCommandFromIpc = createHandleMpvCommandFromIpcHandler(
|
||||
handleMpvCommandFromIpcMainDeps,
|
||||
);
|
||||
|
||||
const runSubsyncManualFromIpcMainDeps =
|
||||
createBuildRunSubsyncManualFromIpcMainDepsHandler<TRequest, TResult>(
|
||||
deps.runSubsyncManualFromIpcDeps,
|
||||
)();
|
||||
const runSubsyncManualFromIpc = createRunSubsyncManualFromIpcHandler<TRequest, TResult>(
|
||||
runSubsyncManualFromIpcMainDeps,
|
||||
);
|
||||
|
||||
return {
|
||||
handleMpvCommandFromIpc,
|
||||
runSubsyncManualFromIpc,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user