mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-03-01 06:22:44 -08:00
refactor: split main runtime wrappers into focused modules
This commit is contained in:
42
src/main/runtime/mpv-osd-log.ts
Normal file
42
src/main/runtime/mpv-osd-log.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type { MpvRuntimeClientLike } from '../../core/services/mpv';
|
||||
|
||||
export function createAppendToMpvLogHandler(deps: {
|
||||
logPath: string;
|
||||
dirname: (targetPath: string) => string;
|
||||
mkdirSync: (targetPath: string, options: { recursive: boolean }) => void;
|
||||
appendFileSync: (
|
||||
targetPath: string,
|
||||
data: string,
|
||||
options: { encoding: 'utf8' },
|
||||
) => void;
|
||||
now: () => Date;
|
||||
}) {
|
||||
return (message: string): void => {
|
||||
try {
|
||||
deps.mkdirSync(deps.dirname(deps.logPath), { recursive: true });
|
||||
deps.appendFileSync(deps.logPath, `[${deps.now().toISOString()}] ${message}\n`, {
|
||||
encoding: 'utf8',
|
||||
});
|
||||
} catch {
|
||||
// best-effort logging
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function createShowMpvOsdHandler(deps: {
|
||||
appendToMpvLog: (message: string) => void;
|
||||
showMpvOsdRuntime: (
|
||||
mpvClient: MpvRuntimeClientLike | null,
|
||||
text: string,
|
||||
fallbackLog: (line: string) => void,
|
||||
) => void;
|
||||
getMpvClient: () => MpvRuntimeClientLike | null;
|
||||
logInfo: (line: string) => void;
|
||||
}) {
|
||||
return (text: string): void => {
|
||||
deps.appendToMpvLog(`[OSD] ${text}`);
|
||||
deps.showMpvOsdRuntime(deps.getMpvClient(), text, (line) => {
|
||||
deps.logInfo(line);
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user