refactor(main): drop pass-through main-deps builders (#306)

* refactor(main): drop mining/anki main-deps builders

* refactor(anilist): drop main-deps builders

* refactor(jellyfin): drop main-deps builders

* refactor(overlay): drop overlay and shortcut main-deps builders

* refactor(main): drop ipc, tray, and osd main-deps builders

* refactor(startup): drop startup main-deps builders

* test(scripts): ignore stray local requests in AUR download test

Also apply prettier to launcher/mpv.test.ts so format:check:src passes.

* fix(shortcuts): forward overlay numeric selection hooks through the composer

composeShortcutRuntimes only passed the digit callbacks, so the visible-overlay
selection added in #78 never ran from the multi-copy/mine-sentence shortcuts.

* fix(stats): skip mpv auto-connect when stats starts the immersion tracker

The immersion-startup main-deps builder never forwarded shouldAutoConnectMpv,
so background stats and stats CLI startup always connected to mpv. Drop the
builder and pass the deps straight to the handler.

* build(deps): bump follow-redirects override to 1.16.2

Resolves GHSA-mrwp-f3q8-3g9p (high), which fails the quality-gate
bun audit --audit-level high step.

* test(subtitles): cover the null-tokenization settle path in prefetch test

The mock ignored the value the test resolved, so the null case never ran.

* test(e2e): surface mpv crashes and install current mpv on macOS CI

The harness IPC client never handled socket close, so a crashed mpv left
commands pending until the 120s test timeout with an empty mpv.log. Reject
pending commands on close, write mpv's own log via --log-file, and refresh
Homebrew on macOS CI so the installed mpv build no longer depends on the
runner image.

* test(e2e): render mpv through cocoa-cb OpenGL on macOS

mpv 0.41.0_12 with libplacebo 7.387.0 segfaults in gpu-next's MoltenVK path
on GitHub's paravirtual macOS GPU on the first frame, so the E2E session
never started.

* test(e2e): name mpv-stdio.log in the mpv close diagnostic
This commit is contained in:
sudacode authored and GitHub committed 2026-10-31 00:50:33 -07:00
1 parent 0129e03c0f
commit 2a0e931325
84 files changed
+719 -2754

No files matched your search

@@ -1,8 +1,4 @@
import {
createBuildConsumeAnilistSetupTokenFromUrlMainDepsHandler,
createBuildHandleAnilistSetupProtocolUrlMainDepsHandler,
createBuildNotifyAnilistSetupMainDepsHandler,
createBuildRegisterSubminerProtocolClientMainDepsHandler,
createConsumeAnilistSetupTokenFromUrlHandler,
createHandleAnilistSetupProtocolUrlHandler,
createNotifyAnilistSetupHandler,
@@ -16,12 +12,10 @@ type HandleProtocolHandler = ReturnType<typeof createHandleAnilistSetupProtocolU
type RegisterClientHandler = ReturnType<typeof createRegisterSubminerProtocolClientHandler>;
export type AnilistSetupComposerOptions = ComposerInputs<{
notifyDeps: Parameters<typeof createBuildNotifyAnilistSetupMainDepsHandler>[0];
consumeTokenDeps: Parameters<typeof createBuildConsumeAnilistSetupTokenFromUrlMainDepsHandler>[0];
handleProtocolDeps: Parameters<typeof createBuildHandleAnilistSetupProtocolUrlMainDepsHandler>[0];
registerProtocolClientDeps: Parameters<
typeof createBuildRegisterSubminerProtocolClientMainDepsHandler
>[0];
notifyDeps: Parameters<typeof createNotifyAnilistSetupHandler>[0];
consumeTokenDeps: Parameters<typeof createConsumeAnilistSetupTokenFromUrlHandler>[0];
handleProtocolDeps: Parameters<typeof createHandleAnilistSetupProtocolUrlHandler>[0];
registerProtocolClientDeps: Parameters<typeof createRegisterSubminerProtocolClientHandler>[0];
}>;
export type AnilistSetupComposerResult = ComposerOutputs<{
@@ -34,17 +28,15 @@ export type AnilistSetupComposerResult = ComposerOutputs<{
export function composeAnilistSetupHandlers(
options: AnilistSetupComposerOptions,
): AnilistSetupComposerResult {
const notifyAnilistSetup = createNotifyAnilistSetupHandler(
createBuildNotifyAnilistSetupMainDepsHandler(options.notifyDeps)(),
);
const notifyAnilistSetup = createNotifyAnilistSetupHandler(options.notifyDeps);
const consumeAnilistSetupTokenFromUrl = createConsumeAnilistSetupTokenFromUrlHandler(
createBuildConsumeAnilistSetupTokenFromUrlMainDepsHandler(options.consumeTokenDeps)(),
options.consumeTokenDeps,
);
const handleAnilistSetupProtocolUrl = createHandleAnilistSetupProtocolUrlHandler(
createBuildHandleAnilistSetupProtocolUrlMainDepsHandler(options.handleProtocolDeps)(),
options.handleProtocolDeps,
);
const registerSubminerProtocolClient = createRegisterSubminerProtocolClientHandler(
createBuildRegisterSubminerProtocolClientMainDepsHandler(options.registerProtocolClientDeps)(),
options.registerProtocolClientDeps,
);
return {
@@ -1,15 +1,4 @@
import {
createBuildEnsureAnilistMediaGuessMainDepsHandler,
createBuildGetAnilistMediaGuessRuntimeStateMainDepsHandler,
createBuildGetCurrentAnilistMediaKeyMainDepsHandler,
createBuildMaybeProbeAnilistDurationMainDepsHandler,
createBuildMaybeRunAnilistPostWatchUpdateMainDepsHandler,
createBuildProcessNextAnilistRetryUpdateMainDepsHandler,
createBuildRecordAnilistMediaDurationMainDepsHandler,
createBuildRefreshAnilistClientSecretStateMainDepsHandler,
createBuildResetAnilistMediaGuessStateMainDepsHandler,
createBuildResetAnilistMediaTrackingMainDepsHandler,
createBuildSetAnilistMediaGuessRuntimeStateMainDepsHandler,
createEnsureAnilistMediaGuessHandler,
createGetAnilistMediaGuessRuntimeStateHandler,
createGetCurrentAnilistMediaKeyHandler,
@@ -25,36 +14,22 @@ import {
import type { ComposerInputs, ComposerOutputs } from './contracts';
export type AnilistTrackingComposerOptions = ComposerInputs<{
refreshClientSecretMainDeps: Parameters<
typeof createBuildRefreshAnilistClientSecretStateMainDepsHandler
>[0];
getCurrentMediaKeyMainDeps: Parameters<
typeof createBuildGetCurrentAnilistMediaKeyMainDepsHandler
>[0];
resetMediaTrackingMainDeps: Parameters<
typeof createBuildResetAnilistMediaTrackingMainDepsHandler
>[0];
refreshClientSecretMainDeps: Parameters<typeof createRefreshAnilistClientSecretStateHandler>[0];
getCurrentMediaKeyMainDeps: Parameters<typeof createGetCurrentAnilistMediaKeyHandler>[0];
resetMediaTrackingMainDeps: Parameters<typeof createResetAnilistMediaTrackingHandler>[0];
getMediaGuessRuntimeStateMainDeps: Parameters<
typeof createBuildGetAnilistMediaGuessRuntimeStateMainDepsHandler
typeof createGetAnilistMediaGuessRuntimeStateHandler
>[0];
setMediaGuessRuntimeStateMainDeps: Parameters<
typeof createBuildSetAnilistMediaGuessRuntimeStateMainDepsHandler
>[0];
recordMediaDurationMainDeps: Parameters<
typeof createBuildRecordAnilistMediaDurationMainDepsHandler
>[0];
resetMediaGuessStateMainDeps: Parameters<
typeof createBuildResetAnilistMediaGuessStateMainDepsHandler
>[0];
maybeProbeDurationMainDeps: Parameters<
typeof createBuildMaybeProbeAnilistDurationMainDepsHandler
>[0];
ensureMediaGuessMainDeps: Parameters<typeof createBuildEnsureAnilistMediaGuessMainDepsHandler>[0];
processNextRetryUpdateMainDeps: Parameters<
typeof createBuildProcessNextAnilistRetryUpdateMainDepsHandler
typeof createSetAnilistMediaGuessRuntimeStateHandler
>[0];
recordMediaDurationMainDeps: Parameters<typeof createRecordAnilistMediaDurationHandler>[0];
resetMediaGuessStateMainDeps: Parameters<typeof createResetAnilistMediaGuessStateHandler>[0];
maybeProbeDurationMainDeps: Parameters<typeof createMaybeProbeAnilistDurationHandler>[0];
ensureMediaGuessMainDeps: Parameters<typeof createEnsureAnilistMediaGuessHandler>[0];
processNextRetryUpdateMainDeps: Parameters<typeof createProcessNextAnilistRetryUpdateHandler>[0];
maybeRunPostWatchUpdateMainDeps: Parameters<
typeof createBuildMaybeRunAnilistPostWatchUpdateMainDepsHandler
typeof createMaybeRunAnilistPostWatchUpdateHandler
>[0];
}>;
@@ -80,47 +55,37 @@ export function composeAnilistTrackingHandlers(
options: AnilistTrackingComposerOptions,
): AnilistTrackingComposerResult {
const refreshAnilistClientSecretState = createRefreshAnilistClientSecretStateHandler(
createBuildRefreshAnilistClientSecretStateMainDepsHandler(
options.refreshClientSecretMainDeps,
)(),
options.refreshClientSecretMainDeps,
);
const getCurrentAnilistMediaKey = createGetCurrentAnilistMediaKeyHandler(
createBuildGetCurrentAnilistMediaKeyMainDepsHandler(options.getCurrentMediaKeyMainDeps)(),
options.getCurrentMediaKeyMainDeps,
);
const resetAnilistMediaTracking = createResetAnilistMediaTrackingHandler(
createBuildResetAnilistMediaTrackingMainDepsHandler(options.resetMediaTrackingMainDeps)(),
options.resetMediaTrackingMainDeps,
);
const getAnilistMediaGuessRuntimeState = createGetAnilistMediaGuessRuntimeStateHandler(
createBuildGetAnilistMediaGuessRuntimeStateMainDepsHandler(
options.getMediaGuessRuntimeStateMainDeps,
)(),
options.getMediaGuessRuntimeStateMainDeps,
);
const setAnilistMediaGuessRuntimeState = createSetAnilistMediaGuessRuntimeStateHandler(
createBuildSetAnilistMediaGuessRuntimeStateMainDepsHandler(
options.setMediaGuessRuntimeStateMainDeps,
)(),
options.setMediaGuessRuntimeStateMainDeps,
);
const recordAnilistMediaDuration = createRecordAnilistMediaDurationHandler(
createBuildRecordAnilistMediaDurationMainDepsHandler(options.recordMediaDurationMainDeps)(),
options.recordMediaDurationMainDeps,
);
const resetAnilistMediaGuessState = createResetAnilistMediaGuessStateHandler(
createBuildResetAnilistMediaGuessStateMainDepsHandler(options.resetMediaGuessStateMainDeps)(),
options.resetMediaGuessStateMainDeps,
);
const maybeProbeAnilistDuration = createMaybeProbeAnilistDurationHandler(
createBuildMaybeProbeAnilistDurationMainDepsHandler(options.maybeProbeDurationMainDeps)(),
options.maybeProbeDurationMainDeps,
);
const ensureAnilistMediaGuess = createEnsureAnilistMediaGuessHandler(
createBuildEnsureAnilistMediaGuessMainDepsHandler(options.ensureMediaGuessMainDeps)(),
options.ensureMediaGuessMainDeps,
);
const processNextAnilistRetryUpdate = createProcessNextAnilistRetryUpdateHandler(
createBuildProcessNextAnilistRetryUpdateMainDepsHandler(
options.processNextRetryUpdateMainDeps,
)(),
options.processNextRetryUpdateMainDeps,
);
const maybeRunAnilistPostWatchUpdate = createMaybeRunAnilistPostWatchUpdateHandler(
createBuildMaybeRunAnilistPostWatchUpdateMainDepsHandler(
options.maybeRunPostWatchUpdateMainDeps,
)(),
options.maybeRunPostWatchUpdateMainDeps,
);
return {
@@ -1,27 +1,22 @@
import { createAppReadyRuntimeRunner } from '../../app-lifecycle';
import { createBuildAppReadyRuntimeMainDepsHandler } from '../app-ready-main-deps';
import {
createBuildCriticalConfigErrorMainDepsHandler,
createBuildReloadConfigMainDepsHandler,
} from '../startup-config-main-deps';
createAppReadyRuntimeRunner,
type AppReadyRuntimeDepsFactoryInput,
} from '../../app-lifecycle';
import { createCriticalConfigErrorHandler, createReloadConfigHandler } from '../startup-config';
import { createBuildImmersionTrackerStartupMainDepsHandler } from '../immersion-startup-main-deps';
import { createImmersionTrackerStartupHandler } from '../immersion-startup';
import type { ComposerInputs, ComposerOutputs } from './contracts';
type ReloadConfigMainDeps = Parameters<typeof createBuildReloadConfigMainDepsHandler>[0];
type CriticalConfigErrorMainDeps = Parameters<
typeof createBuildCriticalConfigErrorMainDepsHandler
>[0];
type AppReadyRuntimeMainDeps = Parameters<typeof createBuildAppReadyRuntimeMainDepsHandler>[0];
type ReloadConfigMainDeps = Parameters<typeof createReloadConfigHandler>[0];
type CriticalConfigErrorMainDeps = Parameters<typeof createCriticalConfigErrorHandler>[0];
export type AppReadyComposerOptions = ComposerInputs<{
reloadConfigMainDeps: ReloadConfigMainDeps;
criticalConfigErrorMainDeps: CriticalConfigErrorMainDeps;
appReadyRuntimeMainDeps: Omit<AppReadyRuntimeMainDeps, 'reloadConfig' | 'onCriticalConfigErrors'>;
immersionTrackerStartupMainDeps: Parameters<
typeof createBuildImmersionTrackerStartupMainDepsHandler
>[0];
appReadyRuntimeMainDeps: Omit<
AppReadyRuntimeDepsFactoryInput,
'reloadConfig' | 'onCriticalConfigErrors'
>;
immersionTrackerStartupMainDeps: Parameters<typeof createImmersionTrackerStartupHandler>[0];
}>;
export type AppReadyComposerResult = ComposerOutputs<{
@@ -31,27 +26,17 @@ export type AppReadyComposerResult = ComposerOutputs<{
}>;
export function composeAppReadyRuntime(options: AppReadyComposerOptions): AppReadyComposerResult {
const reloadConfig = createReloadConfigHandler(
createBuildReloadConfigMainDepsHandler(options.reloadConfigMainDeps)(),
);
const criticalConfigError = createCriticalConfigErrorHandler(
createBuildCriticalConfigErrorMainDepsHandler(options.criticalConfigErrorMainDeps)(),
);
const reloadConfig = createReloadConfigHandler(options.reloadConfigMainDeps);
const criticalConfigError = createCriticalConfigErrorHandler(options.criticalConfigErrorMainDeps);
const appReadyRuntimeRunner = createAppReadyRuntimeRunner(
createBuildAppReadyRuntimeMainDepsHandler({
...options.appReadyRuntimeMainDeps,
reloadConfig,
createImmersionTracker:
options.appReadyRuntimeMainDeps.createImmersionTracker ??
createImmersionTrackerStartupHandler(
createBuildImmersionTrackerStartupMainDepsHandler(
options.immersionTrackerStartupMainDeps,
)(),
),
onCriticalConfigErrors: criticalConfigError,
})(),
);
const appReadyRuntimeRunner = createAppReadyRuntimeRunner({
...options.appReadyRuntimeMainDeps,
reloadConfig,
createImmersionTracker:
options.appReadyRuntimeMainDeps.createImmersionTracker ??
createImmersionTrackerStartupHandler(options.immersionTrackerStartupMainDeps),
onCriticalConfigErrors: criticalConfigError,
});
return {
reloadConfig,
@@ -1,9 +1,7 @@
import type { RegisterIpcRuntimeServicesParams } from '../../ipc-runtime';
import type { MpvCommandFromIpcRuntimeDeps } from '../../ipc-mpv-command';
import type { SubsyncManualRunRequest, SubsyncResult } from '../../../types';
import {
createBuildMpvCommandFromIpcRuntimeMainDepsHandler,
createIpcRuntimeHandlers,
} from '../domains/ipc';
import { createIpcRuntimeHandlers } from '../domains/ipc';
import type { ComposerInputs, ComposerOutputs } from './contracts';
type MpvCommand = (string | number)[];
@@ -17,7 +15,7 @@ type IpcRuntimeDeps = Parameters<
>[0];
export type IpcRuntimeComposerOptions = ComposerInputs<{
mpvCommandMainDeps: Parameters<typeof createBuildMpvCommandFromIpcRuntimeMainDepsHandler>[0];
mpvCommandMainDeps: MpvCommandFromIpcRuntimeDeps;
handleMpvCommandFromIpcRuntime: IpcRuntimeDeps['handleMpvCommandFromIpcDeps']['handleMpvCommandFromIpcRuntime'];
runSubsyncManualFromIpc: RunSubsyncManual;
registration: {
@@ -37,16 +35,13 @@ export type IpcRuntimeComposerResult = ComposerOutputs<{
export function composeIpcRuntimeHandlers(
options: IpcRuntimeComposerOptions,
): IpcRuntimeComposerResult {
const mpvCommandFromIpcRuntimeMainDeps = createBuildMpvCommandFromIpcRuntimeMainDepsHandler(
options.mpvCommandMainDeps,
)();
const { handleMpvCommandFromIpc, runSubsyncManualFromIpc } = createIpcRuntimeHandlers<
SubsyncManualRunRequest,
SubsyncResult
>({
handleMpvCommandFromIpcDeps: {
handleMpvCommandFromIpcRuntime: options.handleMpvCommandFromIpcRuntime,
buildMpvCommandDeps: () => mpvCommandFromIpcRuntimeMainDeps,
buildMpvCommandDeps: () => options.mpvCommandMainDeps,
},
runSubsyncManualFromIpcDeps: {
runManualFromIpc: (request) => options.runSubsyncManualFromIpc(request),
@@ -1,21 +1,9 @@
import {
buildJellyfinSetupFormHtml,
createEnsureMpvConnectedForJellyfinPlaybackHandler,
createBuildEnsureMpvConnectedForJellyfinPlaybackMainDepsHandler,
createBuildGetJellyfinClientInfoMainDepsHandler,
createBuildGetResolvedJellyfinConfigMainDepsHandler,
createBuildHandleJellyfinAuthCommandsMainDepsHandler,
createBuildHandleJellyfinListCommandsMainDepsHandler,
createBuildHandleJellyfinPlayCommandMainDepsHandler,
createBuildHandleJellyfinRemoteAnnounceCommandMainDepsHandler,
createBuildLaunchMpvIdleForJellyfinPlaybackMainDepsHandler,
createBuildOpenJellyfinSetupWindowMainDepsHandler,
createBuildPlayJellyfinItemInMpvMainDepsHandler,
createBuildPreloadJellyfinExternalSubtitlesMainDepsHandler,
createBuildRunJellyfinCommandMainDepsHandler,
createBuildStartJellyfinRemoteSessionMainDepsHandler,
createBuildStopJellyfinRemoteSessionMainDepsHandler,
createBuildWaitForMpvConnectedMainDepsHandler,
createGetJellyfinClientInfoHandler,
createGetResolvedJellyfinConfigHandler,
createHandleJellyfinAuthCommands,
@@ -40,23 +28,13 @@ import {
import type { ComposerInputs, ComposerOutputs } from './contracts';
type EnsureMpvConnectedMainDeps = Parameters<
typeof createBuildEnsureMpvConnectedForJellyfinPlaybackMainDepsHandler
>[0];
type PlayJellyfinItemMainDeps = Parameters<
typeof createBuildPlayJellyfinItemInMpvMainDepsHandler
>[0];
type HandlePlayCommandMainDeps = Parameters<
typeof createBuildHandleJellyfinPlayCommandMainDepsHandler
>[0];
type HandleRemoteAnnounceMainDeps = Parameters<
typeof createBuildHandleJellyfinRemoteAnnounceCommandMainDepsHandler
>[0];
type StartRemoteSessionMainDeps = Parameters<
typeof createBuildStartJellyfinRemoteSessionMainDepsHandler
>[0];
type RunJellyfinCommandMainDeps = Parameters<
typeof createBuildRunJellyfinCommandMainDepsHandler
typeof createEnsureMpvConnectedForJellyfinPlaybackHandler
>[0];
type PlayJellyfinItemMainDeps = Parameters<typeof createPlayJellyfinItemInMpvHandler>[0];
type HandlePlayCommandMainDeps = Parameters<typeof createHandleJellyfinPlayCommand>[0];
type HandleRemoteAnnounceMainDeps = Parameters<typeof createHandleJellyfinRemoteAnnounceCommand>[0];
type StartRemoteSessionMainDeps = Parameters<typeof createStartJellyfinRemoteSessionHandler>[0];
type RunJellyfinCommandMainDeps = Parameters<typeof createRunJellyfinCommandHandler>[0];
type OpenJellyfinSetupWindowMainDeps = Parameters<
typeof createBuildOpenJellyfinSetupWindowMainDepsHandler
>[0];
@@ -68,16 +46,16 @@ export type JellyfinRuntimeComposerOptions = ComposerInputs<{
getJellyfinClientInfoMainDeps: Parameters<
typeof createBuildGetJellyfinClientInfoMainDepsHandler
>[0];
waitForMpvConnectedMainDeps: Parameters<typeof createBuildWaitForMpvConnectedMainDepsHandler>[0];
waitForMpvConnectedMainDeps: Parameters<typeof createWaitForMpvConnectedHandler>[0];
launchMpvIdleForJellyfinPlaybackMainDeps: Parameters<
typeof createBuildLaunchMpvIdleForJellyfinPlaybackMainDepsHandler
typeof createLaunchMpvIdleForJellyfinPlaybackHandler
>[0];
ensureMpvConnectedForJellyfinPlaybackMainDeps: Omit<
EnsureMpvConnectedMainDeps,
'waitForMpvConnected' | 'launchMpvIdleForJellyfinPlayback'
>;
preloadJellyfinExternalSubtitlesMainDeps: Parameters<
typeof createBuildPreloadJellyfinExternalSubtitlesMainDepsHandler
typeof createPreloadJellyfinExternalSubtitlesHandler
>[0];
playJellyfinItemInMpvMainDeps: Omit<
PlayJellyfinItemMainDeps,
@@ -87,12 +65,8 @@ export type JellyfinRuntimeComposerOptions = ComposerInputs<{
JellyfinRemoteComposerOptions,
'getClientInfo' | 'getJellyfinConfig' | 'playJellyfinItem'
>;
handleJellyfinAuthCommandsMainDeps: Parameters<
typeof createBuildHandleJellyfinAuthCommandsMainDepsHandler
>[0];
handleJellyfinListCommandsMainDeps: Parameters<
typeof createBuildHandleJellyfinListCommandsMainDepsHandler
>[0];
handleJellyfinAuthCommandsMainDeps: Parameters<typeof createHandleJellyfinAuthCommands>[0];
handleJellyfinListCommandsMainDeps: Parameters<typeof createHandleJellyfinListCommands>[0];
handleJellyfinPlayCommandMainDeps: Omit<HandlePlayCommandMainDeps, 'playJellyfinItemInMpv'>;
handleJellyfinRemoteAnnounceCommandMainDeps: Omit<
HandleRemoteAnnounceMainDeps,
@@ -106,9 +80,7 @@ export type JellyfinRuntimeComposerOptions = ComposerInputs<{
| 'handlePlaystate'
| 'handleGeneralCommand'
>;
stopJellyfinRemoteSessionMainDeps: Parameters<
typeof createBuildStopJellyfinRemoteSessionMainDepsHandler
>[0];
stopJellyfinRemoteSessionMainDeps: Parameters<typeof createStopJellyfinRemoteSessionHandler>[0];
runJellyfinCommandMainDeps: Omit<
RunJellyfinCommandMainDeps,
| 'getJellyfinConfig'
@@ -177,36 +149,26 @@ export function composeJellyfinRuntimeHandlers(
createBuildGetJellyfinClientInfoMainDepsHandler(options.getJellyfinClientInfoMainDeps)(),
);
const waitForMpvConnected = createWaitForMpvConnectedHandler(
createBuildWaitForMpvConnectedMainDepsHandler(options.waitForMpvConnectedMainDeps)(),
);
const waitForMpvConnected = createWaitForMpvConnectedHandler(options.waitForMpvConnectedMainDeps);
const launchMpvIdleForJellyfinPlayback = createLaunchMpvIdleForJellyfinPlaybackHandler(
createBuildLaunchMpvIdleForJellyfinPlaybackMainDepsHandler(
options.launchMpvIdleForJellyfinPlaybackMainDeps,
)(),
);
const ensureMpvConnectedForJellyfinPlayback = createEnsureMpvConnectedForJellyfinPlaybackHandler(
createBuildEnsureMpvConnectedForJellyfinPlaybackMainDepsHandler({
...options.ensureMpvConnectedForJellyfinPlaybackMainDeps,
waitForMpvConnected: (timeoutMs) => waitForMpvConnected(timeoutMs),
launchMpvIdleForJellyfinPlayback: () => launchMpvIdleForJellyfinPlayback(),
})(),
options.launchMpvIdleForJellyfinPlaybackMainDeps,
);
const ensureMpvConnectedForJellyfinPlayback = createEnsureMpvConnectedForJellyfinPlaybackHandler({
...options.ensureMpvConnectedForJellyfinPlaybackMainDeps,
waitForMpvConnected: (timeoutMs) => waitForMpvConnected(timeoutMs),
launchMpvIdleForJellyfinPlayback: () => launchMpvIdleForJellyfinPlayback(),
});
const preloadJellyfinExternalSubtitles = createPreloadJellyfinExternalSubtitlesHandler(
createBuildPreloadJellyfinExternalSubtitlesMainDepsHandler(
options.preloadJellyfinExternalSubtitlesMainDeps,
)(),
);
const playJellyfinItemInMpv = createPlayJellyfinItemInMpvHandler(
createBuildPlayJellyfinItemInMpvMainDepsHandler({
...options.playJellyfinItemInMpvMainDeps,
ensureMpvConnectedForPlayback: () => ensureMpvConnectedForJellyfinPlayback(),
preloadExternalSubtitles: (params) => {
void preloadJellyfinExternalSubtitles(params);
},
})(),
options.preloadJellyfinExternalSubtitlesMainDeps,
);
const playJellyfinItemInMpv = createPlayJellyfinItemInMpvHandler({
...options.playJellyfinItemInMpvMainDeps,
ensureMpvConnectedForPlayback: () => ensureMpvConnectedForJellyfinPlayback(),
preloadExternalSubtitles: (params) => {
void preloadJellyfinExternalSubtitles(params);
},
});
const {
reportJellyfinRemoteProgress,
@@ -223,59 +185,45 @@ export function composeJellyfinRuntimeHandlers(
});
const handleJellyfinAuthCommands = createHandleJellyfinAuthCommands(
createBuildHandleJellyfinAuthCommandsMainDepsHandler(
options.handleJellyfinAuthCommandsMainDeps,
)(),
options.handleJellyfinAuthCommandsMainDeps,
);
const handleJellyfinListCommands = createHandleJellyfinListCommands(
createBuildHandleJellyfinListCommandsMainDepsHandler(
options.handleJellyfinListCommandsMainDeps,
)(),
);
const handleJellyfinPlayCommand = createHandleJellyfinPlayCommand(
createBuildHandleJellyfinPlayCommandMainDepsHandler({
...options.handleJellyfinPlayCommandMainDeps,
playJellyfinItemInMpv: (params) =>
playJellyfinItemInMpv(params as Parameters<typeof playJellyfinItemInMpv>[0]),
})(),
options.handleJellyfinListCommandsMainDeps,
);
const handleJellyfinPlayCommand = createHandleJellyfinPlayCommand({
...options.handleJellyfinPlayCommandMainDeps,
playJellyfinItemInMpv: (params) =>
playJellyfinItemInMpv(params as Parameters<typeof playJellyfinItemInMpv>[0]),
});
let startJellyfinRemoteSession!: ReturnType<typeof createStartJellyfinRemoteSessionHandler>;
const handleJellyfinRemoteAnnounceCommand = createHandleJellyfinRemoteAnnounceCommand(
createBuildHandleJellyfinRemoteAnnounceCommandMainDepsHandler({
...options.handleJellyfinRemoteAnnounceCommandMainDeps,
startJellyfinRemoteSession: (startOptions) => startJellyfinRemoteSession(startOptions),
})(),
);
const handleJellyfinRemoteAnnounceCommand = createHandleJellyfinRemoteAnnounceCommand({
...options.handleJellyfinRemoteAnnounceCommandMainDeps,
startJellyfinRemoteSession: (startOptions) => startJellyfinRemoteSession(startOptions),
});
startJellyfinRemoteSession = createStartJellyfinRemoteSessionHandler(
createBuildStartJellyfinRemoteSessionMainDepsHandler({
...options.startJellyfinRemoteSessionMainDeps,
getJellyfinConfig: () => getResolvedJellyfinConfig(),
getClientInfo: () => getJellyfinClientInfo(),
handlePlay: (payload) => handleJellyfinRemotePlay(payload),
handlePlaystate: (payload) => handleJellyfinRemotePlaystate(payload),
handleGeneralCommand: (payload) => handleJellyfinRemoteGeneralCommand(payload),
})(),
);
startJellyfinRemoteSession = createStartJellyfinRemoteSessionHandler({
...options.startJellyfinRemoteSessionMainDeps,
getJellyfinConfig: () => getResolvedJellyfinConfig(),
getClientInfo: () => getJellyfinClientInfo(),
handlePlay: (payload) => handleJellyfinRemotePlay(payload),
handlePlaystate: (payload) => handleJellyfinRemotePlaystate(payload),
handleGeneralCommand: (payload) => handleJellyfinRemoteGeneralCommand(payload),
});
const stopJellyfinRemoteSession = createStopJellyfinRemoteSessionHandler(
createBuildStopJellyfinRemoteSessionMainDepsHandler(
options.stopJellyfinRemoteSessionMainDeps,
)(),
options.stopJellyfinRemoteSessionMainDeps,
);
const runJellyfinCommand = createRunJellyfinCommandHandler(
createBuildRunJellyfinCommandMainDepsHandler({
...options.runJellyfinCommandMainDeps,
getJellyfinConfig: () => getResolvedJellyfinConfig(),
getJellyfinClientInfo: (jellyfinConfig) => getJellyfinClientInfo(jellyfinConfig),
handleAuthCommands: (params) => handleJellyfinAuthCommands(params),
handleRemoteAnnounceCommand: (args) => handleJellyfinRemoteAnnounceCommand(args),
handleListCommands: (params) => handleJellyfinListCommands(params),
handlePlayCommand: (params) => handleJellyfinPlayCommand(params),
})(),
);
const runJellyfinCommand = createRunJellyfinCommandHandler({
...options.runJellyfinCommandMainDeps,
getJellyfinConfig: () => getResolvedJellyfinConfig(),
getJellyfinClientInfo: (jellyfinConfig) => getJellyfinClientInfo(jellyfinConfig),
handleAuthCommands: (params) => handleJellyfinAuthCommands(params),
handleRemoteAnnounceCommand: (args) => handleJellyfinRemoteAnnounceCommand(args),
handleListCommands: (params) => handleJellyfinListCommands(params),
handlePlayCommand: (params) => handleJellyfinPlayCommand(params),
});
const maybeFocusExistingJellyfinSetupWindow = createMaybeFocusExistingJellyfinSetupWindowHandler(
options.maybeFocusExistingJellyfinSetupWindowMainDeps,
@@ -4,17 +4,12 @@ import { createBuildMpvClientRuntimeServiceFactoryDepsHandler } from '../mpv-cli
import { createMpvClientRuntimeServiceFactory } from '../mpv-client-runtime-service';
import type { MpvClientRuntimeServiceOptions } from '../mpv-client-runtime-service';
import type { Config } from '../../../types';
import { createBuildUpdateMpvSubtitleRenderMetricsMainDepsHandler } from '../mpv-subtitle-render-metrics-main-deps';
import { createUpdateMpvSubtitleRenderMetricsHandler } from '../mpv-subtitle-render-metrics';
import {
createBuildTokenizerDepsMainHandler,
createCreateMecabTokenizerAndCheckMainHandler,
createPrewarmSubtitleDictionariesMainHandler,
} from '../subtitle-tokenization-main-deps';
import {
createBuildLaunchBackgroundWarmupTaskMainDepsHandler,
createBuildStartBackgroundWarmupsMainDepsHandler,
} from '../startup-warmups-main-deps';
import {
createLaunchBackgroundWarmupTaskHandler as createLaunchBackgroundWarmupTaskFromStartup,
createStartBackgroundWarmupsHandler as createStartBackgroundWarmupsFromStartup,
@@ -38,7 +33,7 @@ type MpvClientRuntimeServiceFactoryMainDeps<TMpvClient extends RuntimeMpvClient>
'bindEventHandlers'
>;
type UpdateMpvSubtitleRenderMetricsMainDeps = Parameters<
typeof createBuildUpdateMpvSubtitleRenderMetricsMainDepsHandler
typeof createUpdateMpvSubtitleRenderMetricsHandler
>[0];
type BuildTokenizerDepsMainDeps = Parameters<typeof createBuildTokenizerDepsMainHandler>[0];
type TokenizerMainDeps = BuiltMainDeps<typeof createBuildTokenizerDepsMainHandler>;
@@ -49,10 +44,10 @@ type PrewarmSubtitleDictionariesMainDeps = Parameters<
typeof createPrewarmSubtitleDictionariesMainHandler
>[0];
type LaunchBackgroundWarmupTaskMainDeps = Parameters<
typeof createBuildLaunchBackgroundWarmupTaskMainDepsHandler
typeof createLaunchBackgroundWarmupTaskFromStartup
>[0];
type StartBackgroundWarmupsMainDeps = Omit<
Parameters<typeof createBuildStartBackgroundWarmupsMainDepsHandler>[0],
Parameters<typeof createStartBackgroundWarmupsFromStartup>[0],
'launchTask' | 'createMecabTokenizerAndCheck' | 'prewarmSubtitleDictionaries'
>;
@@ -120,9 +115,7 @@ export function composeMpvRuntimeHandlers<
createMpvClientRuntimeServiceFactory(buildMpvClientRuntimeServiceFactoryMainDepsHandler())();
const updateMpvSubtitleRenderMetrics = createUpdateMpvSubtitleRenderMetricsHandler(
createBuildUpdateMpvSubtitleRenderMetricsMainDepsHandler(
options.updateMpvSubtitleRenderMetricsMainDeps,
)(),
options.updateMpvSubtitleRenderMetricsMainDeps,
);
const buildTokenizerDepsHandler = createBuildTokenizerDepsMainHandler(
@@ -257,48 +250,44 @@ export function composeMpvRuntimeHandlers<
};
const launchBackgroundWarmupTask = createLaunchBackgroundWarmupTaskFromStartup(
createBuildLaunchBackgroundWarmupTaskMainDepsHandler(
options.warmups.launchBackgroundWarmupTaskMainDeps,
)(),
);
const startBackgroundWarmups = createStartBackgroundWarmupsFromStartup(
createBuildStartBackgroundWarmupsMainDepsHandler({
...options.warmups.startBackgroundWarmupsMainDeps,
launchTask: (label, task) => launchBackgroundWarmupTask(label, task),
createMecabTokenizerAndCheck: () => createMecabTokenizerAndCheck(),
prewarmSubtitleDictionaries: () => prewarmSubtitleDictionaries(),
onYomitanExtensionWarmupScheduled: (promise) => {
if (tokenizationPrerequisiteWarmupCompleted) {
return;
}
const finalizedPromise = promise
.then(() => {
markTokenizationPrerequisiteWarmupCompleted();
})
.finally(() => {
if (tokenizationPrerequisiteWarmupInFlight === finalizedPromise) {
tokenizationPrerequisiteWarmupInFlight = null;
}
});
tokenizationPrerequisiteWarmupInFlight = finalizedPromise;
},
onTokenizationWarmupScheduled: (promise) => {
if (tokenizationWarmupCompleted || !backgroundWarmupCoversOnDemandTokenization()) {
return;
}
const finalizedPromise = promise
.then(() => {
markTokenizationWarmupCompleted();
})
.finally(() => {
if (tokenizationWarmupInFlight === finalizedPromise) {
tokenizationWarmupInFlight = null;
}
});
tokenizationWarmupInFlight = finalizedPromise;
},
})(),
options.warmups.launchBackgroundWarmupTaskMainDeps,
);
const startBackgroundWarmups = createStartBackgroundWarmupsFromStartup({
...options.warmups.startBackgroundWarmupsMainDeps,
launchTask: (label, task) => launchBackgroundWarmupTask(label, task),
createMecabTokenizerAndCheck: () => createMecabTokenizerAndCheck(),
prewarmSubtitleDictionaries: () => prewarmSubtitleDictionaries(),
onYomitanExtensionWarmupScheduled: (promise) => {
if (tokenizationPrerequisiteWarmupCompleted) {
return;
}
const finalizedPromise = promise
.then(() => {
markTokenizationPrerequisiteWarmupCompleted();
})
.finally(() => {
if (tokenizationPrerequisiteWarmupInFlight === finalizedPromise) {
tokenizationPrerequisiteWarmupInFlight = null;
}
});
tokenizationPrerequisiteWarmupInFlight = finalizedPromise;
},
onTokenizationWarmupScheduled: (promise) => {
if (tokenizationWarmupCompleted || !backgroundWarmupCoversOnDemandTokenization()) {
return;
}
const finalizedPromise = promise
.then(() => {
markTokenizationWarmupCompleted();
})
.finally(() => {
if (tokenizationWarmupInFlight === finalizedPromise) {
tokenizationWarmupInFlight = null;
}
});
tokenizationWarmupInFlight = finalizedPromise;
},
});
return {
bindMpvClientEventHandlers: (client) => bindMpvClientEventHandlers(client),
@@ -5,29 +5,22 @@ import {
createSendToActiveOverlayWindowHandler,
createSetOverlayDebugVisualizationEnabledHandler,
} from '../overlay-runtime-main-actions';
import {
createBuildBroadcastRuntimeOptionsChangedMainDepsHandler,
createBuildOpenRuntimeOptionsPaletteMainDepsHandler,
createBuildRestorePreviousSecondarySubVisibilityMainDepsHandler,
createBuildSendToActiveOverlayWindowMainDepsHandler,
createBuildSetOverlayDebugVisualizationEnabledMainDepsHandler,
} from '../overlay-runtime-main-actions-main-deps';
import type { ComposerInputs, ComposerOutputs } from './contracts';
type RestorePreviousSecondarySubVisibilityMainDeps = Parameters<
typeof createBuildRestorePreviousSecondarySubVisibilityMainDepsHandler
typeof createRestorePreviousSecondarySubVisibilityHandler
>[0];
type BroadcastRuntimeOptionsChangedMainDeps = Parameters<
typeof createBuildBroadcastRuntimeOptionsChangedMainDepsHandler
typeof createBroadcastRuntimeOptionsChangedHandler
>[0];
type SendToActiveOverlayWindowMainDeps = Parameters<
typeof createBuildSendToActiveOverlayWindowMainDepsHandler
typeof createSendToActiveOverlayWindowHandler
>[0];
type SetOverlayDebugVisualizationEnabledMainDeps = Parameters<
typeof createBuildSetOverlayDebugVisualizationEnabledMainDepsHandler
typeof createSetOverlayDebugVisualizationEnabledHandler
>[0];
type OpenRuntimeOptionsPaletteMainDeps = Parameters<
typeof createBuildOpenRuntimeOptionsPaletteMainDepsHandler
typeof createOpenRuntimeOptionsPaletteHandler
>[0];
export type OverlayVisibilityRuntimeComposerOptions = ComposerInputs<{
@@ -61,29 +54,19 @@ export function composeOverlayVisibilityRuntime(
updateVisibleOverlayVisibility: () =>
options.overlayVisibilityRuntime.updateVisibleOverlayVisibility(),
restorePreviousSecondarySubVisibility: createRestorePreviousSecondarySubVisibilityHandler(
createBuildRestorePreviousSecondarySubVisibilityMainDepsHandler(
options.restorePreviousSecondarySubVisibilityMainDeps,
)(),
options.restorePreviousSecondarySubVisibilityMainDeps,
),
broadcastRuntimeOptionsChanged: createBroadcastRuntimeOptionsChangedHandler(
createBuildBroadcastRuntimeOptionsChangedMainDepsHandler(
options.broadcastRuntimeOptionsChangedMainDeps,
)(),
options.broadcastRuntimeOptionsChangedMainDeps,
),
sendToActiveOverlayWindow: createSendToActiveOverlayWindowHandler(
createBuildSendToActiveOverlayWindowMainDepsHandler(
options.sendToActiveOverlayWindowMainDeps,
)(),
options.sendToActiveOverlayWindowMainDeps,
),
setOverlayDebugVisualizationEnabled: createSetOverlayDebugVisualizationEnabledHandler(
createBuildSetOverlayDebugVisualizationEnabledMainDepsHandler(
options.setOverlayDebugVisualizationEnabledMainDeps,
)(),
options.setOverlayDebugVisualizationEnabledMainDeps,
),
openRuntimeOptionsPalette: createOpenRuntimeOptionsPaletteHandler(
createBuildOpenRuntimeOptionsPaletteMainDepsHandler(
options.openRuntimeOptionsPaletteMainDeps,
)(),
options.openRuntimeOptionsPaletteMainDeps,
),
};
}
@@ -0,0 +1,69 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import {
composeShortcutRuntimes,
type ShortcutsRuntimeComposerOptions,
} from './shortcuts-runtime-composer';
type GlobalShortcutsOptions = ShortcutsRuntimeComposerOptions['globalShortcuts'];
function createComposerOptions(tryBeginOverlaySelection: (timeoutMs: number) => boolean) {
const registeredAccelerators: string[] = [];
const options: ShortcutsRuntimeComposerOptions = {
// Global and overlay shortcut handlers are only constructed here, never invoked.
globalShortcuts: {
getConfiguredShortcutsMainDeps:
{} as GlobalShortcutsOptions['getConfiguredShortcutsMainDeps'],
buildRegisterGlobalShortcutsMainDeps: () =>
({}) as ReturnType<GlobalShortcutsOptions['buildRegisterGlobalShortcutsMainDeps']>,
buildRefreshGlobalAndOverlayShortcutsMainDeps: () =>
({}) as ReturnType<GlobalShortcutsOptions['buildRefreshGlobalAndOverlayShortcutsMainDeps']>,
},
overlayShortcutsRuntimeMainDeps:
{} as ShortcutsRuntimeComposerOptions['overlayShortcutsRuntimeMainDeps'],
numericShortcutRuntimeMainDeps: {
globalShortcut: {
register: (accelerator) => {
registeredAccelerators.push(accelerator);
return true;
},
unregister: () => {},
},
showMpvOsd: () => {},
setTimer: () => setTimeout(() => {}, 0),
clearTimer: (timer) => clearTimeout(timer),
},
numericSessions: {
onMultiCopyDigit: () => {},
onMineSentenceDigit: () => {},
tryBeginMultiCopyOverlaySelection: tryBeginOverlaySelection,
tryBeginMineSentenceOverlaySelection: tryBeginOverlaySelection,
},
};
return { options, registeredAccelerators };
}
test('numeric sessions delegate to the visible overlay when it accepts the selection', () => {
const timeouts: number[] = [];
const { options, registeredAccelerators } = createComposerOptions((timeoutMs) => {
timeouts.push(timeoutMs);
return true;
});
const runtimes = composeShortcutRuntimes(options);
runtimes.startPendingMultiCopy(3000);
runtimes.startPendingMineSentenceMultiple(4000);
assert.deepEqual(timeouts, [3000, 4000]);
assert.deepEqual(registeredAccelerators, []);
});
test('numeric sessions fall back to global digit shortcuts when the overlay declines', () => {
const { options, registeredAccelerators } = createComposerOptions(() => false);
const runtimes = composeShortcutRuntimes(options);
runtimes.startPendingMultiCopy(3000);
assert.ok(registeredAccelerators.length > 0);
runtimes.cancelPendingMultiCopy();
});
@@ -1,6 +1,5 @@
import { createNumericShortcutRuntime } from '../../../core/services/numeric-shortcut';
import {
createBuildNumericShortcutRuntimeMainDepsHandler,
createGlobalShortcutsRuntimeHandlers,
createNumericShortcutSessionRuntimeHandlers,
createOverlayShortcutsRuntimeHandlers,
@@ -8,9 +7,7 @@ import {
import type { ComposerInputs, ComposerOutputs } from './contracts';
type GlobalShortcutsOptions = Parameters<typeof createGlobalShortcutsRuntimeHandlers>[0];
type NumericShortcutRuntimeMainDeps = Parameters<
typeof createBuildNumericShortcutRuntimeMainDepsHandler
>[0];
type NumericShortcutRuntimeMainDeps = Parameters<typeof createNumericShortcutRuntime>[0];
type NumericSessionOptions = Omit<
Parameters<typeof createNumericShortcutSessionRuntimeHandlers>[0],
'multiCopySession' | 'mineSentenceSession'
@@ -37,15 +34,13 @@ export function composeShortcutRuntimes(
): ShortcutsRuntimeComposerResult {
const globalShortcuts = createGlobalShortcutsRuntimeHandlers(options.globalShortcuts);
const numericShortcutRuntimeMainDeps = createBuildNumericShortcutRuntimeMainDepsHandler(
const numericShortcutRuntime = createNumericShortcutRuntime(
options.numericShortcutRuntimeMainDeps,
)();
const numericShortcutRuntime = createNumericShortcutRuntime(numericShortcutRuntimeMainDeps);
);
const numericSessions = createNumericShortcutSessionRuntimeHandlers({
...options.numericSessions,
multiCopySession: numericShortcutRuntime.createSession(),
mineSentenceSession: numericShortcutRuntime.createSession(),
onMultiCopyDigit: options.numericSessions.onMultiCopyDigit,
onMineSentenceDigit: options.numericSessions.onMineSentenceDigit,
});
const overlayShortcuts = createOverlayShortcutsRuntimeHandlers({