diff --git a/src/core/services/cli-command.test.ts b/src/core/services/cli-command.test.ts index 76563a5..3935d24 100644 --- a/src/core/services/cli-command.test.ts +++ b/src/core/services/cli-command.test.ts @@ -220,6 +220,18 @@ test('handleCliCommand processes --start for second-instance when overlay runtim ); }); +test('handleCliCommand applies cli log level for second-instance commands', () => { + const { deps, calls } = createDeps({ + setLogLevel: (level) => { + calls.push(`setLogLevel:${level}`); + }, + }); + + handleCliCommand(makeArgs({ start: true, logLevel: 'debug' }), 'second-instance', deps); + + assert.ok(calls.includes('setLogLevel:debug')); +}); + test('handleCliCommand runs texthooker flow with browser open', () => { const { deps, calls } = createDeps(); const args = makeArgs({ texthooker: true }); diff --git a/src/core/services/cli-command.ts b/src/core/services/cli-command.ts index ff22bfd..0d2ec35 100644 --- a/src/core/services/cli-command.ts +++ b/src/core/services/cli-command.ts @@ -1,6 +1,7 @@ import { CliArgs, CliCommandSource, commandNeedsOverlayRuntime } from '../../cli/args'; export interface CliCommandServiceDeps { + setLogLevel?: (level: NonNullable) => void; getMpvSocketPath: () => string; setMpvSocketPath: (socketPath: string) => void; setMpvClientSocketPath: (socketPath: string) => void; @@ -127,6 +128,7 @@ interface AppCliRuntime { } export interface CliCommandDepsRuntimeOptions { + setLogLevel?: (level: NonNullable) => void; mpv: MpvCliRuntime; texthooker: TexthookerCliRuntime; overlay: OverlayCliRuntime; @@ -149,6 +151,7 @@ export function createCliCommandDepsRuntime( options: CliCommandDepsRuntimeOptions, ): CliCommandServiceDeps { return { + setLogLevel: options.setLogLevel, getMpvSocketPath: options.mpv.getSocketPath, setMpvSocketPath: options.mpv.setSocketPath, setMpvClientSocketPath: (socketPath) => { @@ -232,6 +235,10 @@ export function handleCliCommand( source: CliCommandSource = 'initial', deps: CliCommandServiceDeps, ): void { + if (args.logLevel) { + deps.setLogLevel?.(args.logLevel); + } + const hasNonStartAction = args.stop || args.toggle || diff --git a/src/main.ts b/src/main.ts index 88419c0..4ed428e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1255,6 +1255,17 @@ function getResolvedConfig() { return configService.getConfig(); } +function getRuntimeBooleanOption( + id: + | 'subtitle.annotation.nPlusOne' + | 'subtitle.annotation.jlpt' + | 'subtitle.annotation.frequency', + fallback: boolean, +): boolean { + const value = appState.runtimeOptionsManager?.getOptionValue(id); + return typeof value === 'boolean' ? value : fallback; +} + const { getResolvedJellyfinConfig, getJellyfinClientInfo, @@ -2025,7 +2036,9 @@ const { reloadConfig: reloadConfigHandler, appReadyRuntimeRunner } = composeAppR appState.ankiIntegration.applyRuntimeConfigPatch(patch); } }, + getSubtitleStyleConfig: () => configService.getConfig().subtitleStyle, onOptionsChanged: () => { + subtitleProcessingController.invalidateTokenizationCache(); broadcastRuntimeOptionsChanged(); refreshOverlayShortcuts(); }, @@ -2296,13 +2309,21 @@ const { getKnownWordMatchMode: () => appState.ankiIntegration?.getKnownWordMatchMode() ?? getResolvedConfig().ankiConnect.nPlusOne.matchMode, - getNPlusOneEnabled: () => getResolvedConfig().ankiConnect.nPlusOne.highlightEnabled, + getNPlusOneEnabled: () => + getRuntimeBooleanOption( + 'subtitle.annotation.nPlusOne', + getResolvedConfig().ankiConnect.nPlusOne.highlightEnabled, + ), getMinSentenceWordsForNPlusOne: () => getResolvedConfig().ankiConnect.nPlusOne.minSentenceWords, getJlptLevel: (text) => appState.jlptLevelLookup(text), - getJlptEnabled: () => getResolvedConfig().subtitleStyle.enableJlpt, + getJlptEnabled: () => + getRuntimeBooleanOption('subtitle.annotation.jlpt', getResolvedConfig().subtitleStyle.enableJlpt), getFrequencyDictionaryEnabled: () => - getResolvedConfig().subtitleStyle.frequencyDictionary.enabled, + getRuntimeBooleanOption( + 'subtitle.annotation.frequency', + getResolvedConfig().subtitleStyle.frequencyDictionary.enabled, + ), getFrequencyDictionaryMatchMode: () => getResolvedConfig().subtitleStyle.frequencyDictionary.matchMode, getFrequencyRank: (text) => appState.frequencyRankLookup(text), @@ -2920,6 +2941,7 @@ const { }); const createCliCommandContextHandler = createCliCommandContextFactory({ appState, + setLogLevel: (level) => setLogLevel(level, 'cli'), texthookerService, getResolvedConfig: () => getResolvedConfig(), openExternal: (url: string) => shell.openExternal(url), diff --git a/src/main/cli-runtime.ts b/src/main/cli-runtime.ts index 21c2d17..5bf34d8 100644 --- a/src/main/cli-runtime.ts +++ b/src/main/cli-runtime.ts @@ -6,6 +6,7 @@ import { } from './dependencies'; export interface CliCommandRuntimeServiceContext { + setLogLevel?: (level: NonNullable) => void; getSocketPath: () => string; setSocketPath: (socketPath: string) => void; getClient: CliCommandRuntimeServiceDepsParams['mpv']['getClient']; @@ -55,6 +56,7 @@ function createCliCommandDepsFromContext( context: CliCommandRuntimeServiceContext & CliCommandRuntimeServiceContextHandlers, ): CliCommandRuntimeServiceDepsParams { return { + setLogLevel: context.setLogLevel, mpv: { getSocketPath: context.getSocketPath, setSocketPath: context.setSocketPath, diff --git a/src/main/dependencies.ts b/src/main/dependencies.ts index 829fb2c..7260dbf 100644 --- a/src/main/dependencies.ts +++ b/src/main/dependencies.ts @@ -112,6 +112,7 @@ export interface AnkiJimakuIpcRuntimeServiceDepsParams { } export interface CliCommandRuntimeServiceDepsParams { + setLogLevel?: CliCommandDepsRuntimeOptions['setLogLevel']; mpv: { getSocketPath: CliCommandDepsRuntimeOptions['mpv']['getSocketPath']; setSocketPath: CliCommandDepsRuntimeOptions['mpv']['setSocketPath']; @@ -254,6 +255,7 @@ export function createCliCommandRuntimeServiceDeps( params: CliCommandRuntimeServiceDepsParams, ): CliCommandDepsRuntimeOptions { return { + setLogLevel: params.setLogLevel, mpv: { getSocketPath: params.mpv.getSocketPath, setSocketPath: params.mpv.setSocketPath, diff --git a/src/main/runtime/cli-command-context-deps.ts b/src/main/runtime/cli-command-context-deps.ts index ebd31f4..5496d8c 100644 --- a/src/main/runtime/cli-command-context-deps.ts +++ b/src/main/runtime/cli-command-context-deps.ts @@ -2,6 +2,7 @@ import type { CliArgs } from '../../cli/args'; import type { CliCommandContextFactoryDeps } from './cli-command-context'; export function createBuildCliCommandContextDepsHandler(deps: { + setLogLevel?: (level: NonNullable) => void; getSocketPath: () => string; setSocketPath: (socketPath: string) => void; getMpvClient: CliCommandContextFactoryDeps['getMpvClient']; @@ -45,6 +46,7 @@ export function createBuildCliCommandContextDepsHandler(deps: { logError: (message: string, err: unknown) => void; }) { return (): CliCommandContextFactoryDeps => ({ + setLogLevel: deps.setLogLevel, getSocketPath: deps.getSocketPath, setSocketPath: deps.setSocketPath, getMpvClient: deps.getMpvClient, diff --git a/src/main/runtime/cli-command-context-main-deps.ts b/src/main/runtime/cli-command-context-main-deps.ts index 831c89d..de46fa4 100644 --- a/src/main/runtime/cli-command-context-main-deps.ts +++ b/src/main/runtime/cli-command-context-main-deps.ts @@ -10,6 +10,7 @@ type CliCommandContextMainState = { export function createBuildCliCommandContextMainDepsHandler(deps: { appState: CliCommandContextMainState; + setLogLevel?: (level: NonNullable) => void; texthookerService: CliCommandContextFactoryDeps['texthookerService']; getResolvedConfig: () => { texthooker?: { openBrowser?: boolean } }; openExternal: (url: string) => Promise; @@ -51,6 +52,7 @@ export function createBuildCliCommandContextMainDepsHandler(deps: { logError: (message: string, err: unknown) => void; }) { return (): CliCommandContextFactoryDeps => ({ + setLogLevel: deps.setLogLevel, getSocketPath: () => deps.appState.mpvSocketPath, setSocketPath: (socketPath: string) => { deps.appState.mpvSocketPath = socketPath; diff --git a/src/main/runtime/cli-command-context.ts b/src/main/runtime/cli-command-context.ts index d2aa185..5bba428 100644 --- a/src/main/runtime/cli-command-context.ts +++ b/src/main/runtime/cli-command-context.ts @@ -7,6 +7,7 @@ import type { type MpvClientLike = CliCommandRuntimeServiceContext['getClient'] extends () => infer T ? T : never; export type CliCommandContextFactoryDeps = { + setLogLevel?: (level: NonNullable) => void; getSocketPath: () => string; setSocketPath: (socketPath: string) => void; getMpvClient: () => MpvClientLike; @@ -54,6 +55,7 @@ export function createCliCommandContext( deps: CliCommandContextFactoryDeps, ): CliCommandRuntimeServiceContext & CliCommandRuntimeServiceContextHandlers { return { + setLogLevel: deps.setLogLevel, getSocketPath: deps.getSocketPath, setSocketPath: deps.setSocketPath, getClient: deps.getMpvClient,