mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-11-24 04:46:07 -08:00
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:
1 parent
2a0e931325
commit
90fc7cf940
63 files changed
+1282
-2480
No files matched your search
@@ -3,11 +3,3 @@ type ComposerShape = Record<string, unknown>;
|
||||
export type ComposerInputs<T extends ComposerShape> = Readonly<Required<T>>;
|
||||
|
||||
export type ComposerOutputs<T extends ComposerShape> = Readonly<T>;
|
||||
|
||||
export type BuiltMainDeps<TFactory> = TFactory extends (
|
||||
...args: infer _TFactoryArgs
|
||||
) => infer TBuilder
|
||||
? TBuilder extends (...args: infer _TBuilderArgs) => infer TDeps
|
||||
? TDeps
|
||||
: never
|
||||
: never;
|
||||
@@ -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(),
|
||||
),
|
||||
}),
|
||||
};
|
||||
}
|
||||
@@ -1,9 +1,6 @@
|
||||
import {
|
||||
buildJellyfinSetupFormHtml,
|
||||
createEnsureMpvConnectedForJellyfinPlaybackHandler,
|
||||
createBuildGetJellyfinClientInfoMainDepsHandler,
|
||||
createBuildGetResolvedJellyfinConfigMainDepsHandler,
|
||||
createBuildOpenJellyfinSetupWindowMainDepsHandler,
|
||||
createGetJellyfinClientInfoHandler,
|
||||
createGetResolvedJellyfinConfigHandler,
|
||||
createHandleJellyfinAuthCommands,
|
||||
@@ -35,17 +32,11 @@ type HandlePlayCommandMainDeps = Parameters<typeof createHandleJellyfinPlayComma
|
||||
type HandleRemoteAnnounceMainDeps = Parameters<typeof createHandleJellyfinRemoteAnnounceCommand>[0];
|
||||
type StartRemoteSessionMainDeps = Parameters<typeof createStartJellyfinRemoteSessionHandler>[0];
|
||||
type RunJellyfinCommandMainDeps = Parameters<typeof createRunJellyfinCommandHandler>[0];
|
||||
type OpenJellyfinSetupWindowMainDeps = Parameters<
|
||||
typeof createBuildOpenJellyfinSetupWindowMainDepsHandler
|
||||
>[0];
|
||||
type OpenJellyfinSetupWindowMainDeps = Parameters<typeof createOpenJellyfinSetupWindowHandler>[0];
|
||||
|
||||
export type JellyfinRuntimeComposerOptions = ComposerInputs<{
|
||||
getResolvedJellyfinConfigMainDeps: Parameters<
|
||||
typeof createBuildGetResolvedJellyfinConfigMainDepsHandler
|
||||
>[0];
|
||||
getJellyfinClientInfoMainDeps: Parameters<
|
||||
typeof createBuildGetJellyfinClientInfoMainDepsHandler
|
||||
>[0];
|
||||
getResolvedJellyfinConfigMainDeps: Parameters<typeof createGetResolvedJellyfinConfigHandler>[0];
|
||||
getJellyfinClientInfoMainDeps: Parameters<typeof createGetJellyfinClientInfoHandler>[0];
|
||||
waitForMpvConnectedMainDeps: Parameters<typeof createWaitForMpvConnectedHandler>[0];
|
||||
launchMpvIdleForJellyfinPlaybackMainDeps: Parameters<
|
||||
typeof createLaunchMpvIdleForJellyfinPlaybackHandler
|
||||
@@ -141,12 +132,10 @@ export function composeJellyfinRuntimeHandlers(
|
||||
options: JellyfinRuntimeComposerOptions,
|
||||
): JellyfinRuntimeComposerResult {
|
||||
const getResolvedJellyfinConfig = createGetResolvedJellyfinConfigHandler(
|
||||
createBuildGetResolvedJellyfinConfigMainDepsHandler(
|
||||
options.getResolvedJellyfinConfigMainDeps,
|
||||
)(),
|
||||
options.getResolvedJellyfinConfigMainDeps,
|
||||
);
|
||||
const getJellyfinClientInfo = createGetJellyfinClientInfoHandler(
|
||||
createBuildGetJellyfinClientInfoMainDepsHandler(options.getJellyfinClientInfoMainDeps)(),
|
||||
options.getJellyfinClientInfoMainDeps,
|
||||
);
|
||||
|
||||
const waitForMpvConnected = createWaitForMpvConnectedHandler(options.waitForMpvConnectedMainDeps);
|
||||
@@ -233,16 +222,14 @@ export function composeJellyfinRuntimeHandlers(
|
||||
getCurrentSession: () => options.startJellyfinRemoteSessionMainDeps.getCurrentSession(),
|
||||
startJellyfinRemoteSession: (startOptions) => startJellyfinRemoteSession(startOptions),
|
||||
});
|
||||
const openJellyfinSetupWindow = createOpenJellyfinSetupWindowHandler(
|
||||
createBuildOpenJellyfinSetupWindowMainDepsHandler({
|
||||
...options.openJellyfinSetupWindowMainDeps,
|
||||
maybeFocusExistingSetupWindow: maybeFocusExistingJellyfinSetupWindow,
|
||||
getResolvedJellyfinConfig: () => getResolvedJellyfinConfig(),
|
||||
getJellyfinClientInfo: () => getJellyfinClientInfo(),
|
||||
restartRemoteSession: () => restartJellyfinRemoteSessionAfterSetupLogin(),
|
||||
stopRemoteSession: () => stopJellyfinRemoteSession(),
|
||||
})(),
|
||||
);
|
||||
const openJellyfinSetupWindow = createOpenJellyfinSetupWindowHandler({
|
||||
...options.openJellyfinSetupWindowMainDeps,
|
||||
maybeFocusExistingSetupWindow: maybeFocusExistingJellyfinSetupWindow,
|
||||
getResolvedJellyfinConfig: () => getResolvedJellyfinConfig(),
|
||||
getJellyfinClientInfo: () => getJellyfinClientInfo(),
|
||||
restartRemoteSession: () => restartJellyfinRemoteSessionAfterSetupLogin(),
|
||||
stopRemoteSession: () => stopJellyfinRemoteSession(),
|
||||
});
|
||||
|
||||
return {
|
||||
getResolvedJellyfinConfig,
|
||||
|
||||
@@ -423,3 +423,63 @@ test('composeMpvRuntimeHandlers reuses completed background tokenization warmups
|
||||
assert.equal(jlptWarmupCalls, 1);
|
||||
assert.equal(frequencyWarmupCalls, 1);
|
||||
});
|
||||
|
||||
type TokenizerMainDeps = Parameters<
|
||||
typeof composeMpvRuntimeHandlers
|
||||
>[0]['tokenizer']['buildTokenizerDepsMainDeps'];
|
||||
type TokenizerRuntimeOptions = Parameters<
|
||||
Parameters<typeof composeMpvRuntimeHandlers>[0]['tokenizer']['createTokenizerRuntimeDeps']
|
||||
>[0];
|
||||
|
||||
async function captureTokenizerRuntimeOptions(
|
||||
overrides: Partial<TokenizerMainDeps>,
|
||||
): Promise<TokenizerRuntimeOptions> {
|
||||
const fixture = createDefaultMpvFixture();
|
||||
let captured: TokenizerRuntimeOptions | null = null;
|
||||
const composed = composeMpvRuntimeHandlers<
|
||||
{ connect: () => void; on: () => void },
|
||||
TokenizerRuntimeOptions,
|
||||
{ text: string }
|
||||
>({
|
||||
...fixture,
|
||||
tokenizer: {
|
||||
...fixture.tokenizer,
|
||||
buildTokenizerDepsMainDeps: { ...fixture.tokenizer.buildTokenizerDepsMainDeps, ...overrides },
|
||||
createTokenizerRuntimeDeps: (deps) => {
|
||||
captured = deps;
|
||||
return deps;
|
||||
},
|
||||
tokenizeSubtitle: async (text) => ({ text }),
|
||||
},
|
||||
});
|
||||
await composed.tokenizeSubtitle('line');
|
||||
assert.ok(captured);
|
||||
return captured;
|
||||
}
|
||||
|
||||
test('composeMpvRuntimeHandlers records every known-word lookup result', async () => {
|
||||
const lookups: boolean[] = [];
|
||||
const runtimeOptions = await captureTokenizerRuntimeOptions({
|
||||
isKnownWord: (text) => text === 'known',
|
||||
recordLookup: (hit) => lookups.push(hit),
|
||||
});
|
||||
|
||||
assert.equal(runtimeOptions.isKnownWord('known'), true);
|
||||
assert.equal(runtimeOptions.isKnownWord('unknown'), false);
|
||||
assert.deepEqual(lookups, [true, false]);
|
||||
});
|
||||
|
||||
test('composeMpvRuntimeHandlers disables name matching while the character dictionary is disabled', async () => {
|
||||
let characterDictionaryEnabled = false;
|
||||
const runtimeOptions = await captureTokenizerRuntimeOptions({
|
||||
getCharacterDictionaryEnabled: () => characterDictionaryEnabled,
|
||||
getNameMatchEnabled: () => true,
|
||||
getNameMatchImagesEnabled: () => true,
|
||||
});
|
||||
|
||||
assert.equal(runtimeOptions.getNameMatchEnabled?.(), false);
|
||||
assert.equal(runtimeOptions.getNameMatchImagesEnabled?.(), false);
|
||||
characterDictionaryEnabled = true;
|
||||
assert.equal(runtimeOptions.getNameMatchEnabled?.(), true);
|
||||
assert.equal(runtimeOptions.getNameMatchImagesEnabled?.(), true);
|
||||
});
|
||||
@@ -1,47 +1,54 @@
|
||||
import { createBindMpvMainEventHandlersHandler } from '../mpv-main-event-bindings';
|
||||
import { createBuildBindMpvMainEventHandlersMainDepsHandler } from '../mpv-main-event-main-deps';
|
||||
import { createBuildMpvClientRuntimeServiceFactoryDepsHandler } from '../mpv-client-runtime-service-main-deps';
|
||||
import { createMpvMainEventBindingDeps } from '../mpv-main-event-binding-deps';
|
||||
import { createMpvClientRuntimeServiceFactory } from '../mpv-client-runtime-service';
|
||||
import type { MpvClientRuntimeServiceOptions } from '../mpv-client-runtime-service';
|
||||
import type { Config } from '../../../types';
|
||||
import { createUpdateMpvSubtitleRenderMetricsHandler } from '../mpv-subtitle-render-metrics';
|
||||
import {
|
||||
createBuildTokenizerDepsMainHandler,
|
||||
createCreateMecabTokenizerAndCheckMainHandler,
|
||||
createPrewarmSubtitleDictionariesMainHandler,
|
||||
} from '../subtitle-tokenization-main-deps';
|
||||
createMecabTokenizerAndCheckHandler,
|
||||
createPrewarmSubtitleDictionariesHandler,
|
||||
} from '../subtitle-tokenization-warmup';
|
||||
import type { TokenizerDepsRuntimeOptions } from '../../../core/services/tokenizer';
|
||||
import {
|
||||
createLaunchBackgroundWarmupTaskHandler as createLaunchBackgroundWarmupTaskFromStartup,
|
||||
createStartBackgroundWarmupsHandler as createStartBackgroundWarmupsFromStartup,
|
||||
} from '../startup-warmups';
|
||||
import type { BuiltMainDeps, ComposerInputs, ComposerOutputs } from './contracts';
|
||||
import type { ComposerInputs, ComposerOutputs } from './contracts';
|
||||
|
||||
type BindMpvMainEventHandlersMainDeps = Parameters<
|
||||
typeof createBuildBindMpvMainEventHandlersMainDepsHandler
|
||||
>[0];
|
||||
type BindMpvMainEventHandlersMainDeps = Parameters<typeof createMpvMainEventBindingDeps>[0];
|
||||
type BindMpvMainEventHandlers = ReturnType<typeof createBindMpvMainEventHandlersHandler>;
|
||||
type BoundMpvClient = Parameters<BindMpvMainEventHandlers>[0];
|
||||
type RuntimeMpvClient = BoundMpvClient & { connect: () => void };
|
||||
type MpvClientRuntimeServiceFactoryMainDeps<TMpvClient extends RuntimeMpvClient> = Omit<
|
||||
Parameters<
|
||||
typeof createBuildMpvClientRuntimeServiceFactoryDepsHandler<
|
||||
TMpvClient,
|
||||
Config,
|
||||
MpvClientRuntimeServiceOptions
|
||||
>
|
||||
>[0],
|
||||
Parameters<typeof createMpvClientRuntimeServiceFactory<TMpvClient>>[0],
|
||||
'bindEventHandlers'
|
||||
>;
|
||||
type UpdateMpvSubtitleRenderMetricsMainDeps = Parameters<
|
||||
typeof createUpdateMpvSubtitleRenderMetricsHandler
|
||||
>[0];
|
||||
type BuildTokenizerDepsMainDeps = Parameters<typeof createBuildTokenizerDepsMainHandler>[0];
|
||||
type TokenizerMainDeps = BuiltMainDeps<typeof createBuildTokenizerDepsMainHandler>;
|
||||
// Tokenizer deps as main.ts supplies them: the core runtime options plus lookup recording and
|
||||
// the character-dictionary gate applied in buildTokenizerRuntimeOptions.
|
||||
type BuildTokenizerDepsMainDeps = TokenizerDepsRuntimeOptions & {
|
||||
getJlptEnabled: NonNullable<TokenizerDepsRuntimeOptions['getJlptEnabled']>;
|
||||
getCharacterDictionaryEnabled?: () => boolean;
|
||||
getFrequencyDictionaryEnabled: NonNullable<
|
||||
TokenizerDepsRuntimeOptions['getFrequencyDictionaryEnabled']
|
||||
>;
|
||||
getFrequencyDictionaryMatchMode: NonNullable<
|
||||
TokenizerDepsRuntimeOptions['getFrequencyDictionaryMatchMode']
|
||||
>;
|
||||
getFrequencyRank: NonNullable<TokenizerDepsRuntimeOptions['getFrequencyRank']>;
|
||||
getMinSentenceWordsForNPlusOne: NonNullable<
|
||||
TokenizerDepsRuntimeOptions['getMinSentenceWordsForNPlusOne']
|
||||
>;
|
||||
getYomitanGroupDebugEnabled: NonNullable<
|
||||
TokenizerDepsRuntimeOptions['getYomitanGroupDebugEnabled']
|
||||
>;
|
||||
recordLookup: (hit: boolean) => void;
|
||||
};
|
||||
type CreateMecabTokenizerAndCheckMainDeps = Parameters<
|
||||
typeof createCreateMecabTokenizerAndCheckMainHandler
|
||||
typeof createMecabTokenizerAndCheckHandler
|
||||
>[0];
|
||||
type PrewarmSubtitleDictionariesMainDeps = Parameters<
|
||||
typeof createPrewarmSubtitleDictionariesMainHandler
|
||||
typeof createPrewarmSubtitleDictionariesHandler
|
||||
>[0];
|
||||
type LaunchBackgroundWarmupTaskMainDeps = Parameters<
|
||||
typeof createLaunchBackgroundWarmupTaskFromStartup
|
||||
@@ -61,7 +68,7 @@ export type MpvRuntimeComposerOptions<
|
||||
updateMpvSubtitleRenderMetricsMainDeps: UpdateMpvSubtitleRenderMetricsMainDeps;
|
||||
tokenizer: {
|
||||
buildTokenizerDepsMainDeps: BuildTokenizerDepsMainDeps;
|
||||
createTokenizerRuntimeDeps: (deps: TokenizerMainDeps) => TTokenizerRuntimeDeps;
|
||||
createTokenizerRuntimeDeps: (deps: TokenizerDepsRuntimeOptions) => TTokenizerRuntimeDeps;
|
||||
tokenizeSubtitle: (text: string, deps: TTokenizerRuntimeDeps) => Promise<TTokenizedSubtitle>;
|
||||
createMecabTokenizerAndCheckMainDeps: CreateMecabTokenizerAndCheckMainDeps;
|
||||
prewarmSubtitleDictionariesMainDeps: PrewarmSubtitleDictionariesMainDeps;
|
||||
@@ -88,6 +95,39 @@ export type MpvRuntimeComposerResult<
|
||||
startBackgroundWarmups: ReturnType<typeof createStartBackgroundWarmupsFromStartup>;
|
||||
}>;
|
||||
|
||||
// Adapts main's tokenizer deps to the core runtime options: every known-word lookup is
|
||||
// recorded, and name matching is off while the character dictionary is disabled. Returns a
|
||||
// fresh object, since the composer wraps onTokenizationReady on it.
|
||||
function buildTokenizerRuntimeOptions(
|
||||
deps: BuildTokenizerDepsMainDeps,
|
||||
): TokenizerDepsRuntimeOptions {
|
||||
const {
|
||||
recordLookup,
|
||||
getCharacterDictionaryEnabled,
|
||||
getNameMatchEnabled,
|
||||
getNameMatchImagesEnabled,
|
||||
...runtimeOptions
|
||||
} = deps;
|
||||
const characterDictionaryEnabled = (): boolean => getCharacterDictionaryEnabled?.() !== false;
|
||||
return {
|
||||
...runtimeOptions,
|
||||
isKnownWord: (text, reading, options) => {
|
||||
const hit = deps.isKnownWord(text, reading, options);
|
||||
recordLookup(hit);
|
||||
return hit;
|
||||
},
|
||||
...(getNameMatchEnabled
|
||||
? { getNameMatchEnabled: () => characterDictionaryEnabled() && getNameMatchEnabled() }
|
||||
: {}),
|
||||
...(getNameMatchImagesEnabled
|
||||
? {
|
||||
getNameMatchImagesEnabled: () =>
|
||||
characterDictionaryEnabled() && getNameMatchImagesEnabled(),
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
export function composeMpvRuntimeHandlers<
|
||||
TMpvClient extends RuntimeMpvClient,
|
||||
TTokenizerRuntimeDeps,
|
||||
@@ -95,36 +135,23 @@ export function composeMpvRuntimeHandlers<
|
||||
>(
|
||||
options: MpvRuntimeComposerOptions<TMpvClient, TTokenizerRuntimeDeps, TTokenizedSubtitle>,
|
||||
): MpvRuntimeComposerResult<TMpvClient, TTokenizedSubtitle> {
|
||||
const bindMpvMainEventHandlersMainDeps = createBuildBindMpvMainEventHandlersMainDepsHandler(
|
||||
options.bindMpvMainEventHandlersMainDeps,
|
||||
)();
|
||||
const bindMpvClientEventHandlers = createBindMpvMainEventHandlersHandler(
|
||||
bindMpvMainEventHandlersMainDeps,
|
||||
createMpvMainEventBindingDeps(options.bindMpvMainEventHandlersMainDeps),
|
||||
);
|
||||
|
||||
const buildMpvClientRuntimeServiceFactoryMainDepsHandler =
|
||||
createBuildMpvClientRuntimeServiceFactoryDepsHandler<
|
||||
TMpvClient,
|
||||
Config,
|
||||
MpvClientRuntimeServiceOptions
|
||||
>({
|
||||
...options.mpvClientRuntimeServiceFactoryMainDeps,
|
||||
bindEventHandlers: (client) => bindMpvClientEventHandlers(client),
|
||||
});
|
||||
const createMpvClientRuntimeService = (): TMpvClient =>
|
||||
createMpvClientRuntimeServiceFactory(buildMpvClientRuntimeServiceFactoryMainDepsHandler())();
|
||||
const createMpvClientRuntimeService = createMpvClientRuntimeServiceFactory<TMpvClient>({
|
||||
...options.mpvClientRuntimeServiceFactoryMainDeps,
|
||||
bindEventHandlers: (client) => bindMpvClientEventHandlers(client),
|
||||
});
|
||||
|
||||
const updateMpvSubtitleRenderMetrics = createUpdateMpvSubtitleRenderMetricsHandler(
|
||||
options.updateMpvSubtitleRenderMetricsMainDeps,
|
||||
);
|
||||
|
||||
const buildTokenizerDepsHandler = createBuildTokenizerDepsMainHandler(
|
||||
options.tokenizer.buildTokenizerDepsMainDeps,
|
||||
);
|
||||
const createMecabTokenizerAndCheck = createCreateMecabTokenizerAndCheckMainHandler(
|
||||
const createMecabTokenizerAndCheck = createMecabTokenizerAndCheckHandler(
|
||||
options.tokenizer.createMecabTokenizerAndCheckMainDeps,
|
||||
);
|
||||
const prewarmSubtitleDictionaries = createPrewarmSubtitleDictionariesMainHandler(
|
||||
const prewarmSubtitleDictionaries = createPrewarmSubtitleDictionariesHandler(
|
||||
options.tokenizer.prewarmSubtitleDictionariesMainDeps,
|
||||
);
|
||||
const shouldInitializeMecabForAnnotations = (): boolean => {
|
||||
@@ -227,7 +254,9 @@ export function composeMpvRuntimeHandlers<
|
||||
if (cachedTokenizerRuntimeDeps) {
|
||||
return cachedTokenizerRuntimeDeps;
|
||||
}
|
||||
const tokenizerMainDeps = buildTokenizerDepsHandler();
|
||||
const tokenizerMainDeps = buildTokenizerRuntimeOptions(
|
||||
options.tokenizer.buildTokenizerDepsMainDeps,
|
||||
);
|
||||
const baseOnTokenizationReady = tokenizerMainDeps.onTokenizationReady;
|
||||
tokenizerMainDeps.onTokenizationReady = (tokenizedText: string): void => {
|
||||
if (!shouldWarmupAnnotationDictionaries()) {
|
||||
|
||||
@@ -3,22 +3,16 @@ import {
|
||||
createRestoreWindowsOnActivateHandler,
|
||||
createShouldRestoreWindowsOnActivateHandler,
|
||||
} from '../app-lifecycle-actions';
|
||||
import { createBuildOnWillQuitCleanupDepsHandler } from '../app-lifecycle-main-cleanup';
|
||||
import {
|
||||
createBuildRestoreWindowsOnActivateMainDepsHandler,
|
||||
createBuildShouldRestoreWindowsOnActivateMainDepsHandler,
|
||||
} from '../app-lifecycle-main-activate';
|
||||
import { createOnWillQuitCleanupDeps } from '../app-lifecycle-main-cleanup';
|
||||
import { registerProtocolUrlHandlers } from '../protocol-url-handlers';
|
||||
import type { ComposerInputs, ComposerOutputs } from './contracts';
|
||||
|
||||
type RegisterProtocolUrlHandlersMainDeps = Parameters<typeof registerProtocolUrlHandlers>[0];
|
||||
type OnWillQuitCleanupDeps = Parameters<typeof createBuildOnWillQuitCleanupDepsHandler>[0];
|
||||
type OnWillQuitCleanupDeps = Parameters<typeof createOnWillQuitCleanupDeps>[0];
|
||||
type ShouldRestoreWindowsOnActivateMainDeps = Parameters<
|
||||
typeof createBuildShouldRestoreWindowsOnActivateMainDepsHandler
|
||||
>[0];
|
||||
type RestoreWindowsOnActivateMainDeps = Parameters<
|
||||
typeof createBuildRestoreWindowsOnActivateMainDepsHandler
|
||||
typeof createShouldRestoreWindowsOnActivateHandler
|
||||
>[0];
|
||||
type RestoreWindowsOnActivateMainDeps = Parameters<typeof createRestoreWindowsOnActivateHandler>[0];
|
||||
|
||||
export type StartupLifecycleComposerOptions = ComposerInputs<{
|
||||
registerProtocolUrlHandlersMainDeps: RegisterProtocolUrlHandlersMainDeps;
|
||||
@@ -38,15 +32,13 @@ export function composeStartupLifecycleHandlers(
|
||||
options: StartupLifecycleComposerOptions,
|
||||
): StartupLifecycleComposerResult {
|
||||
const onWillQuitCleanupHandler = createOnWillQuitCleanupHandler(
|
||||
createBuildOnWillQuitCleanupDepsHandler(options.onWillQuitCleanupMainDeps)(),
|
||||
createOnWillQuitCleanupDeps(options.onWillQuitCleanupMainDeps),
|
||||
);
|
||||
const shouldRestoreWindowsOnActivateHandler = createShouldRestoreWindowsOnActivateHandler(
|
||||
createBuildShouldRestoreWindowsOnActivateMainDepsHandler(
|
||||
options.shouldRestoreWindowsOnActivateMainDeps,
|
||||
)(),
|
||||
options.shouldRestoreWindowsOnActivateMainDeps,
|
||||
);
|
||||
const restoreWindowsOnActivateHandler = createRestoreWindowsOnActivateHandler(
|
||||
createBuildRestoreWindowsOnActivateMainDepsHandler(options.restoreWindowsOnActivateMainDeps)(),
|
||||
options.restoreWindowsOnActivateMainDeps,
|
||||
);
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user