mirror of
https://github.com/ksyasuda/SubMiner.git
synced 2026-07-07 13:08:54 -07:00
Fix Windows mpv logging and add log export (#88)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import type { MpvRuntimeClientLike } from '../../core/services/mpv';
|
||||
|
||||
export function createAppendToMpvLogHandler(deps: {
|
||||
logPath: string;
|
||||
getLogPath: () => string;
|
||||
dirname: (targetPath: string) => string;
|
||||
mkdir: (targetPath: string, options: { recursive: boolean }) => Promise<void>;
|
||||
appendFile: (targetPath: string, data: string, options: { encoding: 'utf8' }) => Promise<void>;
|
||||
@@ -13,9 +13,13 @@ export function createAppendToMpvLogHandler(deps: {
|
||||
const drainPendingLines = async (): Promise<void> => {
|
||||
while (pendingLines.length > 0) {
|
||||
const chunk = pendingLines.splice(0, pendingLines.length).join('');
|
||||
const logPath = deps.getLogPath();
|
||||
if (!logPath.trim()) {
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
await deps.mkdir(deps.dirname(deps.logPath), { recursive: true });
|
||||
await deps.appendFile(deps.logPath, chunk, { encoding: 'utf8' });
|
||||
await deps.mkdir(deps.dirname(logPath), { recursive: true });
|
||||
await deps.appendFile(logPath, chunk, { encoding: 'utf8' });
|
||||
} catch {
|
||||
// best-effort logging
|
||||
}
|
||||
@@ -35,6 +39,9 @@ export function createAppendToMpvLogHandler(deps: {
|
||||
};
|
||||
|
||||
const appendToMpvLog = (message: string): void => {
|
||||
if (!deps.getLogPath().trim()) {
|
||||
return;
|
||||
}
|
||||
pendingLines.push(`[${deps.now().toISOString()}] ${message}\n`);
|
||||
void scheduleDrain();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user