mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-01 18:22:41 -08:00
refactor: extract main runtime helper groups
- Extract remaining runtime helper clusters from main.ts into dedicated modules for readability:\n - src/main/jlpt-runtime.ts\n - src/main/media-runtime.ts\n - src/main/overlay-visibility-runtime.ts\n- Wire main.ts to use the new runtime services and remove duplicated in-file helpers.\n- Preserve existing behavior via full typecheck + test:fast verification.\n- Finalize and archive TASK-56 backlog entry; update TASK-54 with completion metadata and summary.
This commit is contained in:
70
src/main/media-runtime.ts
Normal file
70
src/main/media-runtime.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import { updateCurrentMediaPathService } from "../core/services";
|
||||
|
||||
import type { SubtitlePosition } from "../types";
|
||||
|
||||
export interface MediaRuntimeDeps {
|
||||
isRemoteMediaPath: (mediaPath: string) => boolean;
|
||||
loadSubtitlePosition: () => SubtitlePosition | null;
|
||||
getCurrentMediaPath: () => string | null;
|
||||
getPendingSubtitlePosition: () => SubtitlePosition | null;
|
||||
getSubtitlePositionsDir: () => string;
|
||||
setCurrentMediaPath: (mediaPath: string | null) => void;
|
||||
clearPendingSubtitlePosition: () => void;
|
||||
setSubtitlePosition: (position: SubtitlePosition | null) => void;
|
||||
broadcastSubtitlePosition: (position: SubtitlePosition | null) => void;
|
||||
getCurrentMediaTitle: () => string | null;
|
||||
setCurrentMediaTitle: (title: string | null) => void;
|
||||
}
|
||||
|
||||
export interface MediaRuntimeService {
|
||||
updateCurrentMediaPath: (mediaPath: unknown) => void;
|
||||
updateCurrentMediaTitle: (mediaTitle: unknown) => void;
|
||||
resolveMediaPathForJimaku: (mediaPath: string | null) => string | null;
|
||||
}
|
||||
|
||||
export function createMediaRuntimeService(
|
||||
deps: MediaRuntimeDeps,
|
||||
): MediaRuntimeService {
|
||||
return {
|
||||
updateCurrentMediaPath(mediaPath: unknown): void {
|
||||
if (typeof mediaPath !== "string" || !deps.isRemoteMediaPath(mediaPath)) {
|
||||
deps.setCurrentMediaTitle(null);
|
||||
}
|
||||
|
||||
updateCurrentMediaPathService({
|
||||
mediaPath,
|
||||
currentMediaPath: deps.getCurrentMediaPath(),
|
||||
pendingSubtitlePosition: deps.getPendingSubtitlePosition(),
|
||||
subtitlePositionsDir: deps.getSubtitlePositionsDir(),
|
||||
loadSubtitlePosition: () => deps.loadSubtitlePosition(),
|
||||
setCurrentMediaPath: (nextPath: string | null) => {
|
||||
deps.setCurrentMediaPath(nextPath);
|
||||
},
|
||||
clearPendingSubtitlePosition: () => {
|
||||
deps.clearPendingSubtitlePosition();
|
||||
},
|
||||
setSubtitlePosition: (position: SubtitlePosition | null) => {
|
||||
deps.setSubtitlePosition(position);
|
||||
},
|
||||
broadcastSubtitlePosition: (position: SubtitlePosition | null) => {
|
||||
deps.broadcastSubtitlePosition(position);
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
updateCurrentMediaTitle(mediaTitle: unknown): void {
|
||||
if (typeof mediaTitle === "string") {
|
||||
const sanitized = mediaTitle.trim();
|
||||
deps.setCurrentMediaTitle(sanitized.length > 0 ? sanitized : null);
|
||||
return;
|
||||
}
|
||||
deps.setCurrentMediaTitle(null);
|
||||
},
|
||||
|
||||
resolveMediaPathForJimaku(mediaPath: string | null): string | null {
|
||||
return mediaPath && deps.isRemoteMediaPath(mediaPath) && deps.getCurrentMediaTitle()
|
||||
? deps.getCurrentMediaTitle()
|
||||
: mediaPath;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user