refactor: extract yomitan settings runtime wiring

This commit is contained in:
2026-02-20 02:17:53 -08:00
parent 9db54f8037
commit 9b3cb4a42c
5 changed files with 66 additions and 21 deletions

View 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']);
});

View 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,
};
}