refactor(main): fold remaining main-deps builders into their handlers (#308)

* refactor(main): drop remaining pass-through main-deps builders

Jellyfin client-info/setup-window/remote, overlay shortcuts/visibility/
layout/window-factory, config hot-reload, and startup bootstrap factory
builders only forwarded deps. Callers now pass deps to the handlers
directly; createWatchConfigPathHandler moves into config-hot-reload-handlers.

* refactor(main): fold small-logic main-deps builders into their handlers

Tray click, mpv client factory, startup bootstrap exit callbacks, overlay
runtime options, and dictionary roots/runtime builders move their logic
into the owning handler or call site. The two duplicated dictionary-root
builders become one createBuildDictionaryRootsHandler(vendorDirName).

* refactor(main): fold cli command context builders into the factory

createCliCommandContextFactory now adapts appState and main services to
the CLI command context deps directly (socket-path change notification,
texthooker port/websocket URL, browser-open default). The pass-through
cli-command-context-main-deps and cli-command-context-deps layers are
removed; their behavioural tests now run against the factory's context.

* refactor(main): fold subtitle tokenization builder into the mpv composer

The tokenizer deps builder's logic (known-word lookup recording and the
character-dictionary gate on name matching) becomes
buildTokenizerRuntimeOptions in mpv-runtime-composer, tested through the
composer. The MeCab check and dictionary prewarm handlers move to
subtitle-tokenization-warmup.ts, and the unused BuiltMainDeps type is
removed from composer contracts.

* refactor(main): drop redundant tokenizer deps keys and cast

* refactor(main): end the main-deps builder pattern

mpv-main-event-main-deps becomes mpv-main-event-binding-deps
(createMpvMainEventBindingDeps), returning the binding deps directly
instead of a thunk; it owns the subtitle-recording state. The will-quit
cleanup adapter likewise returns its deps directly, and the pass-through
app-lifecycle activate builders are removed.

* docs: drop references to main-deps builders
This commit is contained in:
sudacode authored and GitHub committed 2026-10-31 14:07:07 -07:00
1 parent 2a0e931325
commit 90fc7cf940
63 files changed
+1282 -2480

No files matched your search

@@ -1,15 +1,14 @@
import {
createBuildHandleJellyfinRemoteGeneralCommandMainDepsHandler,
createBuildHandleJellyfinRemotePlayMainDepsHandler,
createBuildHandleJellyfinRemotePlaystateMainDepsHandler,
createBuildReportJellyfinRemoteProgressMainDepsHandler,
createBuildReportJellyfinRemoteStoppedMainDepsHandler,
createHandleJellyfinRemoteGeneralCommand,
createHandleJellyfinRemotePlay,
createHandleJellyfinRemotePlaystate,
createJellyfinRemoteReportTracker,
createReportJellyfinRemoteProgressHandler,
createReportJellyfinRemoteStoppedHandler,
type JellyfinRemoteGeneralCommandHandlerDeps,
type JellyfinRemotePlayHandlerDeps,
type JellyfinRemotePlaystateHandlerDeps,
type JellyfinRemoteProgressReporterDeps,
} from '../domains/jellyfin';
import type { ComposerInputs, ComposerOutputs } from './contracts';
@@ -18,44 +17,24 @@ type RemotePlaystatePayload = Parameters<ReturnType<typeof createHandleJellyfinR
type RemoteGeneralPayload = Parameters<
ReturnType<typeof createHandleJellyfinRemoteGeneralCommand>
>[0];
type JellyfinRemotePlayMainDeps = Parameters<
typeof createBuildHandleJellyfinRemotePlayMainDepsHandler
>[0];
type JellyfinRemotePlaystateMainDeps = Parameters<
typeof createBuildHandleJellyfinRemotePlaystateMainDepsHandler
>[0];
type JellyfinRemoteGeneralMainDeps = Parameters<
typeof createBuildHandleJellyfinRemoteGeneralCommandMainDepsHandler
>[0];
type JellyfinRemoteProgressMainDeps = Parameters<
typeof createBuildReportJellyfinRemoteProgressMainDepsHandler
>[0];
export type JellyfinRemoteComposerOptions = ComposerInputs<{
getConfiguredSession: JellyfinRemotePlayMainDeps['getConfiguredSession'];
getClientInfo: JellyfinRemotePlayMainDeps['getClientInfo'];
getJellyfinConfig: JellyfinRemotePlayMainDeps['getJellyfinConfig'];
playJellyfinItem: JellyfinRemotePlayMainDeps['playJellyfinItem'];
logWarn: JellyfinRemotePlayMainDeps['logWarn'];
getMpvClient: JellyfinRemoteProgressMainDeps['getMpvClient'];
sendMpvCommand: JellyfinRemotePlaystateMainDeps['sendMpvCommand'];
jellyfinTicksToSeconds: Parameters<
typeof createBuildHandleJellyfinRemotePlaystateMainDepsHandler
>[0]['jellyfinTicksToSeconds'];
getActivePlayback: JellyfinRemoteGeneralMainDeps['getActivePlayback'];
clearActivePlayback: JellyfinRemoteProgressMainDeps['clearActivePlayback'];
getNow: JellyfinRemoteProgressMainDeps['getNow'];
getLastProgressAtMs: Parameters<
typeof createBuildReportJellyfinRemoteProgressMainDepsHandler
>[0]['getLastProgressAtMs'];
setLastProgressAtMs: Parameters<
typeof createBuildReportJellyfinRemoteProgressMainDepsHandler
>[0]['setLastProgressAtMs'];
getConfiguredSession: JellyfinRemotePlayHandlerDeps['getConfiguredSession'];
getClientInfo: JellyfinRemotePlayHandlerDeps['getClientInfo'];
getJellyfinConfig: JellyfinRemotePlayHandlerDeps['getJellyfinConfig'];
playJellyfinItem: JellyfinRemotePlayHandlerDeps['playJellyfinItem'];
logWarn: JellyfinRemotePlayHandlerDeps['logWarn'];
getMpvClient: JellyfinRemoteProgressReporterDeps['getMpvClient'];
sendMpvCommand: JellyfinRemotePlaystateHandlerDeps['sendMpvCommand'];
jellyfinTicksToSeconds: JellyfinRemotePlaystateHandlerDeps['jellyfinTicksToSeconds'];
getActivePlayback: JellyfinRemoteGeneralCommandHandlerDeps['getActivePlayback'];
clearActivePlayback: JellyfinRemoteProgressReporterDeps['clearActivePlayback'];
getNow: JellyfinRemoteProgressReporterDeps['getNow'];
getLastProgressAtMs: JellyfinRemoteProgressReporterDeps['getLastProgressAtMs'];
setLastProgressAtMs: JellyfinRemoteProgressReporterDeps['setLastProgressAtMs'];
progressIntervalMs: number;
ticksPerSecond: number;
logDebug: Parameters<
typeof createBuildReportJellyfinRemoteProgressMainDepsHandler
>[0]['logDebug'];
logDebug: JellyfinRemoteProgressReporterDeps['logDebug'];
}>;
export type JellyfinRemoteComposerResult = ComposerOutputs<{
@@ -69,75 +48,54 @@ export type JellyfinRemoteComposerResult = ComposerOutputs<{
export function composeJellyfinRemoteHandlers(
options: JellyfinRemoteComposerOptions,
): JellyfinRemoteComposerResult {
const buildReportJellyfinRemoteProgressMainDepsHandler =
createBuildReportJellyfinRemoteProgressMainDepsHandler({
getActivePlayback: options.getActivePlayback,
clearActivePlayback: options.clearActivePlayback,
getMpvClient: options.getMpvClient,
getNow: options.getNow,
getLastProgressAtMs: options.getLastProgressAtMs,
setLastProgressAtMs: options.setLastProgressAtMs,
progressIntervalMs: options.progressIntervalMs,
ticksPerSecond: options.ticksPerSecond,
logDebug: options.logDebug,
});
const buildReportJellyfinRemoteStoppedMainDepsHandler =
createBuildReportJellyfinRemoteStoppedMainDepsHandler({
getActivePlayback: options.getActivePlayback,
clearActivePlayback: options.clearActivePlayback,
getMpvClient: options.getMpvClient,
getNow: options.getNow,
ticksPerSecond: options.ticksPerSecond,
logDebug: options.logDebug,
logWarn: options.logWarn,
});
const reportTracker = createJellyfinRemoteReportTracker();
const reportJellyfinRemoteProgress = createReportJellyfinRemoteProgressHandler({
...buildReportJellyfinRemoteProgressMainDepsHandler(),
getActivePlayback: options.getActivePlayback,
clearActivePlayback: options.clearActivePlayback,
getMpvClient: options.getMpvClient,
getNow: options.getNow,
getLastProgressAtMs: options.getLastProgressAtMs,
setLastProgressAtMs: options.setLastProgressAtMs,
progressIntervalMs: options.progressIntervalMs,
ticksPerSecond: options.ticksPerSecond,
logDebug: options.logDebug,
reportTracker,
});
const reportJellyfinRemoteStopped = createReportJellyfinRemoteStoppedHandler({
...buildReportJellyfinRemoteStoppedMainDepsHandler(),
getActivePlayback: options.getActivePlayback,
clearActivePlayback: options.clearActivePlayback,
getMpvClient: options.getMpvClient,
getNow: options.getNow,
ticksPerSecond: options.ticksPerSecond,
logDebug: options.logDebug,
logWarn: options.logWarn,
reportTracker,
});
const buildHandleJellyfinRemotePlayMainDepsHandler =
createBuildHandleJellyfinRemotePlayMainDepsHandler({
return {
reportJellyfinRemoteProgress,
reportJellyfinRemoteStopped,
handleJellyfinRemotePlay: createHandleJellyfinRemotePlay({
getConfiguredSession: options.getConfiguredSession,
getClientInfo: options.getClientInfo,
getJellyfinConfig: options.getJellyfinConfig,
getActivePlayback: options.getActivePlayback,
playJellyfinItem: options.playJellyfinItem,
logWarn: options.logWarn,
});
const buildHandleJellyfinRemotePlaystateMainDepsHandler =
createBuildHandleJellyfinRemotePlaystateMainDepsHandler({
}),
handleJellyfinRemotePlaystate: createHandleJellyfinRemotePlaystate({
getMpvClient: options.getMpvClient,
sendMpvCommand: options.sendMpvCommand,
reportJellyfinRemoteProgress: (force) => reportJellyfinRemoteProgress(force),
reportJellyfinRemoteStopped: () => reportJellyfinRemoteStopped(),
jellyfinTicksToSeconds: options.jellyfinTicksToSeconds,
});
const buildHandleJellyfinRemoteGeneralCommandMainDepsHandler =
createBuildHandleJellyfinRemoteGeneralCommandMainDepsHandler({
}),
handleJellyfinRemoteGeneralCommand: createHandleJellyfinRemoteGeneralCommand({
getMpvClient: options.getMpvClient,
sendMpvCommand: options.sendMpvCommand,
getActivePlayback: options.getActivePlayback,
reportJellyfinRemoteProgress: (force) => reportJellyfinRemoteProgress(force),
logDebug: (message) => options.logDebug(message, undefined),
});
return {
reportJellyfinRemoteProgress,
reportJellyfinRemoteStopped,
handleJellyfinRemotePlay: createHandleJellyfinRemotePlay(
buildHandleJellyfinRemotePlayMainDepsHandler(),
),
handleJellyfinRemotePlaystate: createHandleJellyfinRemotePlaystate(
buildHandleJellyfinRemotePlaystateMainDepsHandler(),
),
handleJellyfinRemoteGeneralCommand: createHandleJellyfinRemoteGeneralCommand(
buildHandleJellyfinRemoteGeneralCommandMainDepsHandler(),
),
}),
};
}