mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-02-28 06:22:45 -08:00
refactor: extract yomitan settings runtime wiring
This commit is contained in:
31
src/main/runtime/yomitan-settings-runtime.test.ts
Normal file
31
src/main/runtime/yomitan-settings-runtime.test.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { createYomitanSettingsRuntime } from './yomitan-settings-runtime';
|
||||
|
||||
test('yomitan settings runtime composes opener with built deps', async () => {
|
||||
let existingWindow: { id: string } | null = null;
|
||||
const calls: string[] = [];
|
||||
|
||||
const runtime = createYomitanSettingsRuntime({
|
||||
ensureYomitanExtensionLoaded: async () => ({ id: 'ext' }),
|
||||
openYomitanSettingsWindow: ({ getExistingWindow, setWindow }) => {
|
||||
calls.push('open-window');
|
||||
const current = getExistingWindow();
|
||||
if (!current) {
|
||||
setWindow({ id: 'settings' });
|
||||
}
|
||||
},
|
||||
getExistingWindow: () => existingWindow as never,
|
||||
setWindow: (window) => {
|
||||
existingWindow = window as { id: string } | null;
|
||||
},
|
||||
logWarn: (message) => calls.push(`warn:${message}`),
|
||||
logError: (message) => calls.push(`error:${message}`),
|
||||
});
|
||||
|
||||
runtime.openYomitanSettings();
|
||||
await new Promise((resolve) => setTimeout(resolve, 0));
|
||||
|
||||
assert.deepEqual(existingWindow, { id: 'settings' });
|
||||
assert.deepEqual(calls, ['open-window']);
|
||||
});
|
||||
13
src/main/runtime/yomitan-settings-runtime.ts
Normal file
13
src/main/runtime/yomitan-settings-runtime.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { createBuildOpenYomitanSettingsMainDepsHandler } from './app-runtime-main-deps';
|
||||
import { createOpenYomitanSettingsHandler } from './yomitan-settings-opener';
|
||||
|
||||
type OpenYomitanSettingsMainDeps = Parameters<typeof createBuildOpenYomitanSettingsMainDepsHandler>[0];
|
||||
|
||||
export function createYomitanSettingsRuntime(deps: OpenYomitanSettingsMainDeps) {
|
||||
const openYomitanSettingsMainDeps = createBuildOpenYomitanSettingsMainDepsHandler(deps)();
|
||||
const openYomitanSettings = createOpenYomitanSettingsHandler(openYomitanSettingsMainDeps);
|
||||
|
||||
return {
|
||||
openYomitanSettings,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user