mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-04-26 16:19:26 -07:00
* chore(backlog): add mining workflow milestone and tasks
* refactor: split character dictionary runtime modules
* refactor: split shared type entrypoints
* refactor: use bun serve for stats server
* feat: add repo-local subminer workflow plugin
* fix: add stats server node fallback
* refactor: split immersion tracker query modules
* chore: update backlog task records
* refactor: migrate shared type imports
* refactor: compose startup and setup window wiring
* Add backlog tasks and launcher time helper tests
- Track follow-up cleanup work in Backlog.md
- Replace Date.now usage with shared nowMs helper
- Add launcher args/parser and core regression tests
* test: increase launcher test timeout for CI stability
* fix: address CodeRabbit review feedback
* refactor(main): extract remaining inline runtime logic from main
* chore(backlog): update task notes and changelog fragment
* refactor: split main boot phases
* test: stabilize bun coverage reporting
* Switch plausible endpoint and harden coverage lane parsing
- update docs-site tracking to use the Plausible capture endpoint
- tighten coverage lane argument and LCOV parsing checks
- make script entrypoint use CommonJS main guard
* Restrict docs analytics and build coverage input
- limit Plausible init to docs.subminer.moe
- build Yomitan before src coverage lane
* fix(ci): normalize Windows shortcut paths for cross-platform tests
* Fix verification and immersion-tracker grouping
- isolate verifier artifacts and lease handling
- switch weekly/monthly tracker cutoffs to calendar boundaries
- tighten boot lifecycle and zip writer tests
* fix: resolve CI type failures in boot and immersion query tests
* fix: remove strict spread usage in Date mocks
* fix: use explicit super args for MockDate constructors
* Factor out mock date helper in tracker tests
- reuse a shared `withMockDate` helper for date-sensitive query tests
- make monthly rollup assertions key off `videoId` instead of row order
* fix: use variadic array type for MockDate constructor args
TS2367: fixed-length tuple made args.length === 0 unreachable.
* refactor: remove unused createMainBootRuntimes/Handlers aggregate functions
These functions were never called by production code — main.ts imports
the individual composeBoot* re-exports directly.
* refactor: remove boot re-export alias layer
main.ts now imports directly from the runtime/composers and runtime/domains
modules, eliminating the intermediate boot/ indirection.
* refactor: consolidate 3 near-identical setup window factories
Extract shared createSetupWindowHandler with a config parameter.
Public API unchanged.
* refactor: parameterize duplicated getAffected*Ids query helpers
Four structurally identical functions collapsed into two parameterized
helpers while preserving the existing public API.
* refactor: inline identity composers (stats-startup, overlay-window)
composeStatsStartupRuntime was a no-op that returned its input.
composeOverlayWindowHandlers was a 1-line delegation.
Both removed in favor of direct usage.
* chore: remove unused token/queue file path constants from main.ts
* fix: replace any types in boot services with proper signatures
* refactor: deduplicate ensureDir into shared/fs-utils
5 copies of mkdir-p-if-not-exists consolidated into one shared module
with ensureDir (directory path) and ensureDirForFile (file path) variants.
* fix: tighten type safety in boot services
- Add AppLifecycleShape and OverlayModalInputStateShape constraints
so TAppLifecycleApp and TOverlayModalInputState generics are bounded
- Remove unsafe `as { handleModalInputStateChange? }` cast — now
directly callable via the constraint
- Use `satisfies AppLifecycleShape` for structural validation on the
appLifecycleApp object literal
- Document Electron App.on incompatibility with simple signatures
* refactor: inline subtitle-prefetch-runtime-composer
The composer was a pure pass-through that destructured an object and
reassembled it with the same fields. Inlined at the call site.
* chore: consolidate duplicate import paths in main.ts
* test: extract mpv composer test fixture factory to reduce duplication
* test: add behavioral assertions to composer tests
Upgrade 8 composer test files from shape-only typeof checks to behavioral
assertions that invoke returned handlers and verify injected dependencies are
actually called, following the mpv-runtime-composer pattern.
* refactor: normalize import extensions in query modules
* refactor: consolidate toDbMs into query-shared.ts
* refactor: remove Node.js fallback from stats-server, use Bun only
* Fix monthly rollup test expectations
- Preserve multi-arg Date construction in mock helper
- Align rollup assertions with the correct videoId
* fix: address PR 36 CodeRabbit follow-ups
* fix: harden coverage lane cleanup
* fix(stats): fallback to node server when Bun.serve unavailable
* fix(ci): restore coverage lane compatibility
* chore(backlog): close TASK-242
* fix: address latest CodeRabbit review round
* fix: guard disabled immersion retention windows
* fix: migrate discord rpc wrapper
* fix(ci): add changelog fragment for PR 36
* fix: stabilize macOS visible overlay toggle
* fix: pin installed mpv plugin to current binary
* fix: strip inline subtitle markup from sidebar cues
* fix(renderer): restore subtitle sidebar mpv passthrough
* feat(discord): add configurable presence style presets
Replace the hardcoded "Mining and crafting (Anki cards)" meme message
with a preset system. New `discordPresence.presenceStyle` option
supports four presets: "default" (clean bilingual), "meme" (the OG
Minecraft joke), "japanese" (fully JP), and "minimal". The default
preset shows "Sentence Mining" with 日本語学習中 as the small image
tooltip. Existing users can set presenceStyle to "meme" to keep the
old behavior.
* fix: finalize v0.10.0 release prep
* docs: add subtitle sidebar guide and release note
* chore(backlog): mark docs task done
* fix: lazily resolve youtube playback socket path
* chore(release): build v0.10.0 changelog
* Revert "chore(release): build v0.10.0 changelog"
This reverts commit 9741c0f020.
586 lines
18 KiB
TypeScript
586 lines
18 KiB
TypeScript
import type {
|
|
ControllerAxisBinding,
|
|
ControllerAxisBindingConfig,
|
|
ControllerAxisDirection,
|
|
ControllerButtonBinding,
|
|
ControllerButtonIndicesConfig,
|
|
ControllerDpadFallback,
|
|
ControllerDiscreteBindingConfig,
|
|
ResolvedControllerAxisBinding,
|
|
ResolvedControllerDiscreteBinding,
|
|
} from '../../types/runtime';
|
|
import { ResolveContext } from './context';
|
|
import { asBoolean, asNumber, asString, isObject } from './shared';
|
|
|
|
const CONTROLLER_BUTTON_BINDINGS = [
|
|
'none',
|
|
'select',
|
|
'buttonSouth',
|
|
'buttonEast',
|
|
'buttonNorth',
|
|
'buttonWest',
|
|
'leftShoulder',
|
|
'rightShoulder',
|
|
'leftStickPress',
|
|
'rightStickPress',
|
|
'leftTrigger',
|
|
'rightTrigger',
|
|
] as const;
|
|
|
|
const CONTROLLER_AXIS_BINDINGS = [
|
|
'leftStickX',
|
|
'leftStickY',
|
|
'rightStickX',
|
|
'rightStickY',
|
|
] as const;
|
|
|
|
const CONTROLLER_AXIS_INDEX_BY_BINDING: Record<ControllerAxisBinding, number> = {
|
|
leftStickX: 0,
|
|
leftStickY: 1,
|
|
rightStickX: 3,
|
|
rightStickY: 4,
|
|
};
|
|
|
|
const CONTROLLER_BUTTON_INDEX_KEY_BY_BINDING: Record<
|
|
Exclude<ControllerButtonBinding, 'none'>,
|
|
keyof Required<ControllerButtonIndicesConfig>
|
|
> = {
|
|
select: 'select',
|
|
buttonSouth: 'buttonSouth',
|
|
buttonEast: 'buttonEast',
|
|
buttonNorth: 'buttonNorth',
|
|
buttonWest: 'buttonWest',
|
|
leftShoulder: 'leftShoulder',
|
|
rightShoulder: 'rightShoulder',
|
|
leftStickPress: 'leftStickPress',
|
|
rightStickPress: 'rightStickPress',
|
|
leftTrigger: 'leftTrigger',
|
|
rightTrigger: 'rightTrigger',
|
|
};
|
|
|
|
const CONTROLLER_AXIS_FALLBACK_BY_SLOT = {
|
|
leftStickHorizontal: 'horizontal',
|
|
leftStickVertical: 'vertical',
|
|
rightStickHorizontal: 'none',
|
|
rightStickVertical: 'none',
|
|
} as const satisfies Record<string, ControllerDpadFallback>;
|
|
|
|
function isControllerAxisDirection(value: unknown): value is ControllerAxisDirection {
|
|
return value === 'negative' || value === 'positive';
|
|
}
|
|
|
|
function isControllerDpadFallback(value: unknown): value is ControllerDpadFallback {
|
|
return value === 'none' || value === 'horizontal' || value === 'vertical';
|
|
}
|
|
|
|
function resolveLegacyDiscreteBinding(
|
|
value: ControllerButtonBinding,
|
|
buttonIndices: Required<ControllerButtonIndicesConfig>,
|
|
): ResolvedControllerDiscreteBinding {
|
|
if (value === 'none') {
|
|
return { kind: 'none' };
|
|
}
|
|
return {
|
|
kind: 'button',
|
|
buttonIndex: buttonIndices[CONTROLLER_BUTTON_INDEX_KEY_BY_BINDING[value]],
|
|
};
|
|
}
|
|
|
|
function resolveLegacyAxisBinding(
|
|
value: ControllerAxisBinding,
|
|
slot: keyof typeof CONTROLLER_AXIS_FALLBACK_BY_SLOT,
|
|
): ResolvedControllerAxisBinding {
|
|
return {
|
|
kind: 'axis',
|
|
axisIndex: CONTROLLER_AXIS_INDEX_BY_BINDING[value],
|
|
dpadFallback: CONTROLLER_AXIS_FALLBACK_BY_SLOT[slot],
|
|
};
|
|
}
|
|
|
|
function parseDiscreteBindingObject(value: unknown): ResolvedControllerDiscreteBinding | null {
|
|
if (!isObject(value) || typeof value.kind !== 'string') return null;
|
|
if (value.kind === 'none') {
|
|
return { kind: 'none' };
|
|
}
|
|
if (value.kind === 'button') {
|
|
return typeof value.buttonIndex === 'number' &&
|
|
Number.isInteger(value.buttonIndex) &&
|
|
value.buttonIndex >= 0
|
|
? { kind: 'button', buttonIndex: value.buttonIndex }
|
|
: null;
|
|
}
|
|
if (value.kind === 'axis') {
|
|
return typeof value.axisIndex === 'number' &&
|
|
Number.isInteger(value.axisIndex) &&
|
|
value.axisIndex >= 0 &&
|
|
isControllerAxisDirection(value.direction)
|
|
? { kind: 'axis', axisIndex: value.axisIndex, direction: value.direction }
|
|
: null;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function parseAxisBindingObject(
|
|
value: unknown,
|
|
slot: keyof typeof CONTROLLER_AXIS_FALLBACK_BY_SLOT,
|
|
): ResolvedControllerAxisBinding | null {
|
|
if (isObject(value) && value.kind === 'none') {
|
|
return { kind: 'none' };
|
|
}
|
|
if (!isObject(value) || value.kind !== 'axis') return null;
|
|
if (
|
|
typeof value.axisIndex !== 'number' ||
|
|
!Number.isInteger(value.axisIndex) ||
|
|
value.axisIndex < 0
|
|
) {
|
|
return null;
|
|
}
|
|
if (value.dpadFallback !== undefined && !isControllerDpadFallback(value.dpadFallback)) {
|
|
return null;
|
|
}
|
|
return {
|
|
kind: 'axis',
|
|
axisIndex: value.axisIndex,
|
|
dpadFallback: value.dpadFallback ?? CONTROLLER_AXIS_FALLBACK_BY_SLOT[slot],
|
|
};
|
|
}
|
|
|
|
export function applyCoreDomainConfig(context: ResolveContext): void {
|
|
const { src, resolved, warn } = context;
|
|
|
|
if (isObject(src.texthooker)) {
|
|
const launchAtStartup = asBoolean(src.texthooker.launchAtStartup);
|
|
if (launchAtStartup !== undefined) {
|
|
resolved.texthooker.launchAtStartup = launchAtStartup;
|
|
} else if (src.texthooker.launchAtStartup !== undefined) {
|
|
warn(
|
|
'texthooker.launchAtStartup',
|
|
src.texthooker.launchAtStartup,
|
|
resolved.texthooker.launchAtStartup,
|
|
'Expected boolean.',
|
|
);
|
|
}
|
|
|
|
const openBrowser = asBoolean(src.texthooker.openBrowser);
|
|
if (openBrowser !== undefined) {
|
|
resolved.texthooker.openBrowser = openBrowser;
|
|
} else if (src.texthooker.openBrowser !== undefined) {
|
|
warn(
|
|
'texthooker.openBrowser',
|
|
src.texthooker.openBrowser,
|
|
resolved.texthooker.openBrowser,
|
|
'Expected boolean.',
|
|
);
|
|
}
|
|
}
|
|
|
|
if (isObject(src.websocket)) {
|
|
const enabled = src.websocket.enabled;
|
|
if (enabled === 'auto' || enabled === true || enabled === false) {
|
|
resolved.websocket.enabled = enabled;
|
|
} else if (enabled !== undefined) {
|
|
warn(
|
|
'websocket.enabled',
|
|
enabled,
|
|
resolved.websocket.enabled,
|
|
"Expected true, false, or 'auto'.",
|
|
);
|
|
}
|
|
|
|
const port = asNumber(src.websocket.port);
|
|
if (port !== undefined && port > 0 && port <= 65535) {
|
|
resolved.websocket.port = Math.floor(port);
|
|
} else if (src.websocket.port !== undefined) {
|
|
warn(
|
|
'websocket.port',
|
|
src.websocket.port,
|
|
resolved.websocket.port,
|
|
'Expected integer between 1 and 65535.',
|
|
);
|
|
}
|
|
}
|
|
|
|
if (isObject(src.annotationWebsocket)) {
|
|
const enabled = asBoolean(src.annotationWebsocket.enabled);
|
|
if (enabled !== undefined) {
|
|
resolved.annotationWebsocket.enabled = enabled;
|
|
} else if (src.annotationWebsocket.enabled !== undefined) {
|
|
warn(
|
|
'annotationWebsocket.enabled',
|
|
src.annotationWebsocket.enabled,
|
|
resolved.annotationWebsocket.enabled,
|
|
'Expected boolean.',
|
|
);
|
|
}
|
|
|
|
const port = asNumber(src.annotationWebsocket.port);
|
|
if (port !== undefined && port > 0 && port <= 65535) {
|
|
resolved.annotationWebsocket.port = Math.floor(port);
|
|
} else if (src.annotationWebsocket.port !== undefined) {
|
|
warn(
|
|
'annotationWebsocket.port',
|
|
src.annotationWebsocket.port,
|
|
resolved.annotationWebsocket.port,
|
|
'Expected integer between 1 and 65535.',
|
|
);
|
|
}
|
|
}
|
|
|
|
if (isObject(src.logging)) {
|
|
const logLevel = asString(src.logging.level);
|
|
if (
|
|
logLevel === 'debug' ||
|
|
logLevel === 'info' ||
|
|
logLevel === 'warn' ||
|
|
logLevel === 'error'
|
|
) {
|
|
resolved.logging.level = logLevel;
|
|
} else if (src.logging.level !== undefined) {
|
|
warn(
|
|
'logging.level',
|
|
src.logging.level,
|
|
resolved.logging.level,
|
|
'Expected debug, info, warn, or error.',
|
|
);
|
|
}
|
|
}
|
|
|
|
if (isObject(src.controller)) {
|
|
const enabled = asBoolean(src.controller.enabled);
|
|
if (enabled !== undefined) {
|
|
resolved.controller.enabled = enabled;
|
|
} else if (src.controller.enabled !== undefined) {
|
|
warn(
|
|
'controller.enabled',
|
|
src.controller.enabled,
|
|
resolved.controller.enabled,
|
|
'Expected boolean.',
|
|
);
|
|
}
|
|
|
|
const preferredGamepadId = asString(src.controller.preferredGamepadId);
|
|
if (preferredGamepadId !== undefined) {
|
|
resolved.controller.preferredGamepadId = preferredGamepadId;
|
|
}
|
|
|
|
const preferredGamepadLabel = asString(src.controller.preferredGamepadLabel);
|
|
if (preferredGamepadLabel !== undefined) {
|
|
resolved.controller.preferredGamepadLabel = preferredGamepadLabel;
|
|
}
|
|
|
|
const smoothScroll = asBoolean(src.controller.smoothScroll);
|
|
if (smoothScroll !== undefined) {
|
|
resolved.controller.smoothScroll = smoothScroll;
|
|
} else if (src.controller.smoothScroll !== undefined) {
|
|
warn(
|
|
'controller.smoothScroll',
|
|
src.controller.smoothScroll,
|
|
resolved.controller.smoothScroll,
|
|
'Expected boolean.',
|
|
);
|
|
}
|
|
|
|
const triggerInputMode = asString(src.controller.triggerInputMode);
|
|
if (
|
|
triggerInputMode === 'auto' ||
|
|
triggerInputMode === 'digital' ||
|
|
triggerInputMode === 'analog'
|
|
) {
|
|
resolved.controller.triggerInputMode = triggerInputMode;
|
|
} else if (src.controller.triggerInputMode !== undefined) {
|
|
warn(
|
|
'controller.triggerInputMode',
|
|
src.controller.triggerInputMode,
|
|
resolved.controller.triggerInputMode,
|
|
"Expected 'auto', 'digital', or 'analog'.",
|
|
);
|
|
}
|
|
|
|
const boundedNumberKeys = [
|
|
'scrollPixelsPerSecond',
|
|
'horizontalJumpPixels',
|
|
'repeatDelayMs',
|
|
'repeatIntervalMs',
|
|
] as const;
|
|
for (const key of boundedNumberKeys) {
|
|
const value = asNumber(src.controller[key]);
|
|
if (value !== undefined && Math.floor(value) > 0) {
|
|
resolved.controller[key] = Math.floor(value) as (typeof resolved.controller)[typeof key];
|
|
} else if (src.controller[key] !== undefined) {
|
|
warn(
|
|
`controller.${key}`,
|
|
src.controller[key],
|
|
resolved.controller[key],
|
|
'Expected positive number.',
|
|
);
|
|
}
|
|
}
|
|
|
|
const deadzoneKeys = ['stickDeadzone', 'triggerDeadzone'] as const;
|
|
for (const key of deadzoneKeys) {
|
|
const value = asNumber(src.controller[key]);
|
|
if (value !== undefined && value >= 0 && value <= 1) {
|
|
resolved.controller[key] = value as (typeof resolved.controller)[typeof key];
|
|
} else if (src.controller[key] !== undefined) {
|
|
warn(
|
|
`controller.${key}`,
|
|
src.controller[key],
|
|
resolved.controller[key],
|
|
'Expected number between 0 and 1.',
|
|
);
|
|
}
|
|
}
|
|
|
|
if (isObject(src.controller.buttonIndices)) {
|
|
const buttonIndexKeys = [
|
|
'select',
|
|
'buttonSouth',
|
|
'buttonEast',
|
|
'buttonNorth',
|
|
'buttonWest',
|
|
'leftShoulder',
|
|
'rightShoulder',
|
|
'leftStickPress',
|
|
'rightStickPress',
|
|
'leftTrigger',
|
|
'rightTrigger',
|
|
] as const;
|
|
|
|
for (const key of buttonIndexKeys) {
|
|
const value = asNumber(src.controller.buttonIndices[key]);
|
|
if (value !== undefined && value >= 0 && Number.isInteger(value)) {
|
|
resolved.controller.buttonIndices[key] = value;
|
|
} else if (src.controller.buttonIndices[key] !== undefined) {
|
|
warn(
|
|
`controller.buttonIndices.${key}`,
|
|
src.controller.buttonIndices[key],
|
|
resolved.controller.buttonIndices[key],
|
|
'Expected non-negative integer.',
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (isObject(src.controller.bindings)) {
|
|
const buttonBindingKeys = [
|
|
'toggleLookup',
|
|
'closeLookup',
|
|
'toggleKeyboardOnlyMode',
|
|
'mineCard',
|
|
'quitMpv',
|
|
'previousAudio',
|
|
'nextAudio',
|
|
'playCurrentAudio',
|
|
'toggleMpvPause',
|
|
] as const;
|
|
|
|
for (const key of buttonBindingKeys) {
|
|
const bindingValue = src.controller.bindings[key];
|
|
const legacyValue = asString(bindingValue);
|
|
if (
|
|
legacyValue !== undefined &&
|
|
CONTROLLER_BUTTON_BINDINGS.includes(
|
|
legacyValue as (typeof CONTROLLER_BUTTON_BINDINGS)[number],
|
|
)
|
|
) {
|
|
resolved.controller.bindings[key] = resolveLegacyDiscreteBinding(
|
|
legacyValue as ControllerButtonBinding,
|
|
resolved.controller.buttonIndices,
|
|
);
|
|
continue;
|
|
}
|
|
const parsedObject = parseDiscreteBindingObject(bindingValue);
|
|
if (parsedObject) {
|
|
resolved.controller.bindings[key] = parsedObject;
|
|
} else if (bindingValue !== undefined) {
|
|
warn(
|
|
`controller.bindings.${key}`,
|
|
bindingValue,
|
|
resolved.controller.bindings[key],
|
|
"Expected legacy controller button name or binding object with kind 'none', 'button', or 'axis'.",
|
|
);
|
|
}
|
|
}
|
|
|
|
const axisBindingKeys = [
|
|
'leftStickHorizontal',
|
|
'leftStickVertical',
|
|
'rightStickHorizontal',
|
|
'rightStickVertical',
|
|
] as const;
|
|
|
|
for (const key of axisBindingKeys) {
|
|
const bindingValue = src.controller.bindings[key];
|
|
const legacyValue = asString(bindingValue);
|
|
if (
|
|
legacyValue !== undefined &&
|
|
CONTROLLER_AXIS_BINDINGS.includes(
|
|
legacyValue as (typeof CONTROLLER_AXIS_BINDINGS)[number],
|
|
)
|
|
) {
|
|
resolved.controller.bindings[key] = resolveLegacyAxisBinding(
|
|
legacyValue as ControllerAxisBinding,
|
|
key,
|
|
);
|
|
continue;
|
|
}
|
|
if (legacyValue === 'none') {
|
|
resolved.controller.bindings[key] = { kind: 'none' };
|
|
continue;
|
|
}
|
|
const parsedObject = parseAxisBindingObject(bindingValue, key);
|
|
if (parsedObject) {
|
|
resolved.controller.bindings[key] = parsedObject;
|
|
} else if (bindingValue !== undefined) {
|
|
warn(
|
|
`controller.bindings.${key}`,
|
|
bindingValue,
|
|
resolved.controller.bindings[key],
|
|
"Expected legacy controller axis name ('none' allowed) or binding object with kind 'axis'.",
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (Array.isArray(src.keybindings)) {
|
|
resolved.keybindings = src.keybindings.filter(
|
|
(entry): entry is { key: string; command: (string | number)[] | null } => {
|
|
if (!isObject(entry)) return false;
|
|
if (typeof entry.key !== 'string') return false;
|
|
if (entry.command === null) return true;
|
|
return Array.isArray(entry.command);
|
|
},
|
|
);
|
|
}
|
|
|
|
if (isObject(src.startupWarmups)) {
|
|
const startupWarmupBooleanKeys = [
|
|
'lowPowerMode',
|
|
'mecab',
|
|
'yomitanExtension',
|
|
'subtitleDictionaries',
|
|
'jellyfinRemoteSession',
|
|
] as const;
|
|
|
|
for (const key of startupWarmupBooleanKeys) {
|
|
const value = asBoolean(src.startupWarmups[key]);
|
|
if (value !== undefined) {
|
|
resolved.startupWarmups[key] = value as (typeof resolved.startupWarmups)[typeof key];
|
|
} else if (src.startupWarmups[key] !== undefined) {
|
|
warn(
|
|
`startupWarmups.${key}`,
|
|
src.startupWarmups[key],
|
|
resolved.startupWarmups[key],
|
|
'Expected boolean.',
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (isObject(src.shortcuts)) {
|
|
const shortcutKeys = [
|
|
'toggleVisibleOverlayGlobal',
|
|
'copySubtitle',
|
|
'copySubtitleMultiple',
|
|
'updateLastCardFromClipboard',
|
|
'triggerFieldGrouping',
|
|
'triggerSubsync',
|
|
'mineSentence',
|
|
'mineSentenceMultiple',
|
|
'toggleSecondarySub',
|
|
'markAudioCard',
|
|
'openRuntimeOptions',
|
|
'openJimaku',
|
|
] as const;
|
|
|
|
for (const key of shortcutKeys) {
|
|
const value = src.shortcuts[key];
|
|
if (typeof value === 'string' || value === null) {
|
|
resolved.shortcuts[key] = value as (typeof resolved.shortcuts)[typeof key];
|
|
} else if (value !== undefined) {
|
|
warn(`shortcuts.${key}`, value, resolved.shortcuts[key], 'Expected string or null.');
|
|
}
|
|
}
|
|
|
|
const timeout = asNumber(src.shortcuts.multiCopyTimeoutMs);
|
|
if (timeout !== undefined && timeout > 0) {
|
|
resolved.shortcuts.multiCopyTimeoutMs = Math.floor(timeout);
|
|
} else if (src.shortcuts.multiCopyTimeoutMs !== undefined) {
|
|
warn(
|
|
'shortcuts.multiCopyTimeoutMs',
|
|
src.shortcuts.multiCopyTimeoutMs,
|
|
resolved.shortcuts.multiCopyTimeoutMs,
|
|
'Expected positive number.',
|
|
);
|
|
}
|
|
}
|
|
|
|
if (isObject(src.secondarySub)) {
|
|
if (Array.isArray(src.secondarySub.secondarySubLanguages)) {
|
|
resolved.secondarySub.secondarySubLanguages = src.secondarySub.secondarySubLanguages.filter(
|
|
(item): item is string => typeof item === 'string',
|
|
);
|
|
}
|
|
const autoLoad = asBoolean(src.secondarySub.autoLoadSecondarySub);
|
|
if (autoLoad !== undefined) {
|
|
resolved.secondarySub.autoLoadSecondarySub = autoLoad;
|
|
}
|
|
const defaultMode = src.secondarySub.defaultMode;
|
|
if (defaultMode === 'hidden' || defaultMode === 'visible' || defaultMode === 'hover') {
|
|
resolved.secondarySub.defaultMode = defaultMode;
|
|
} else if (defaultMode !== undefined) {
|
|
warn(
|
|
'secondarySub.defaultMode',
|
|
defaultMode,
|
|
resolved.secondarySub.defaultMode,
|
|
'Expected hidden, visible, or hover.',
|
|
);
|
|
}
|
|
}
|
|
|
|
if (isObject(src.youtube)) {
|
|
if (Array.isArray(src.youtube.primarySubLanguages)) {
|
|
resolved.youtube.primarySubLanguages = src.youtube.primarySubLanguages.filter(
|
|
(item): item is string => typeof item === 'string',
|
|
);
|
|
} else if (src.youtube.primarySubLanguages !== undefined) {
|
|
warn(
|
|
'youtube.primarySubLanguages',
|
|
src.youtube.primarySubLanguages,
|
|
resolved.youtube.primarySubLanguages,
|
|
'Expected string array.',
|
|
);
|
|
}
|
|
}
|
|
|
|
if (isObject(src.subsync)) {
|
|
const mode = src.subsync.defaultMode;
|
|
if (mode === 'auto' || mode === 'manual') {
|
|
resolved.subsync.defaultMode = mode;
|
|
} else if (mode !== undefined) {
|
|
warn('subsync.defaultMode', mode, resolved.subsync.defaultMode, 'Expected auto or manual.');
|
|
}
|
|
|
|
const alass = asString(src.subsync.alass_path);
|
|
if (alass !== undefined) resolved.subsync.alass_path = alass;
|
|
const ffsubsync = asString(src.subsync.ffsubsync_path);
|
|
if (ffsubsync !== undefined) resolved.subsync.ffsubsync_path = ffsubsync;
|
|
const ffmpeg = asString(src.subsync.ffmpeg_path);
|
|
if (ffmpeg !== undefined) resolved.subsync.ffmpeg_path = ffmpeg;
|
|
const replace = asBoolean(src.subsync.replace);
|
|
if (replace !== undefined) {
|
|
resolved.subsync.replace = replace;
|
|
} else if (src.subsync.replace !== undefined) {
|
|
warn('subsync.replace', src.subsync.replace, resolved.subsync.replace, 'Expected boolean.');
|
|
}
|
|
}
|
|
|
|
if (isObject(src.subtitlePosition)) {
|
|
const y = asNumber(src.subtitlePosition.yPercent);
|
|
if (y !== undefined) {
|
|
resolved.subtitlePosition.yPercent = y;
|
|
}
|
|
}
|
|
}
|