refactor: split main.ts into domain runtimes

This commit is contained in:
2026-03-31 23:48:14 -07:00
parent 3502cdc607
commit 983f3b38ee
84 changed files with 15591 additions and 4251 deletions

View File

@@ -0,0 +1,95 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import type { JellyfinRuntimeInput } from './jellyfin-runtime';
import { createJellyfinRuntime } from './jellyfin-runtime';
test('jellyfin runtime reuses existing setup window', () => {
const calls: string[] = [];
let windowCount = 0;
const runtime = createJellyfinRuntime({
getResolvedConfig: () =>
({
jellyfin: {
enabled: true,
serverUrl: 'https://media.example',
username: 'demo',
},
}) as ReturnType<JellyfinRuntimeInput['getResolvedConfig']>,
getEnv: () => undefined,
patchRawConfig: () => {},
defaultJellyfinConfig: {
enabled: false,
serverUrl: '',
username: '',
} as JellyfinRuntimeInput['defaultJellyfinConfig'],
tokenStore: {
loadSession: () => null,
saveSession: () => {},
clearSession: () => {},
},
platform: 'linux',
execPath: '/usr/bin/electron',
defaultMpvLogPath: '/tmp/mpv.log',
defaultMpvArgs: ['--idle=yes'],
connectTimeoutMs: 1000,
autoLaunchTimeoutMs: 1000,
langPref: 'ja,en',
progressIntervalMs: 3000,
ticksPerSecond: 10_000_000,
getMpvSocketPath: () => '/tmp/mpv.sock',
getMpvClient: () => null,
setMpvClient: () => {},
createMpvClient: () => ({}),
sendMpvCommand: () => {},
applyJellyfinMpvDefaults: () => {},
showMpvOsd: () => {},
removeSocketPath: () => {},
spawnMpv: () => ({}),
wait: async () => {},
authenticateWithPassword: async () => {
throw new Error('not used');
},
listJellyfinLibraries: async () => [],
listJellyfinItems: async () => [],
listJellyfinSubtitleTracks: async () => [],
writeJellyfinPreviewAuth: () => {},
resolvePlaybackPlan: async () => ({}),
convertTicksToSeconds: (ticks) => ticks / 10_000_000,
createRemoteSessionService: () => ({}),
defaultDeviceId: 'device',
defaultClientName: 'SubMiner',
defaultClientVersion: '1.0.0',
createBrowserWindow: () => {
windowCount += 1;
return {
webContents: {
on: () => {},
},
loadURL: () => {
calls.push('loadURL');
},
on: () => {},
focus: () => {
calls.push('focus');
},
close: () => {},
isDestroyed: () => false,
};
},
encodeURIComponent: (value) => encodeURIComponent(value),
logInfo: () => {},
logWarn: () => {},
logDebug: () => {},
logError: () => {},
});
runtime.openJellyfinSetupWindow();
runtime.openJellyfinSetupWindow();
assert.equal(windowCount, 1);
assert.deepEqual(calls, ['loadURL', 'focus']);
assert.equal(runtime.getQuitOnDisconnectArmed(), false);
assert.ok(runtime.getSetupWindow());
});