Normalize mpv args only when safe on Windows

This commit is contained in:
2026-04-03 12:54:16 -07:00
parent 0498cfa07d
commit ea22fda16b
2 changed files with 18 additions and 4 deletions

View File

@@ -705,7 +705,9 @@ export async function startMpv(
mpvArgs.push(`--input-ipc-server=${socketPath}`); mpvArgs.push(`--input-ipc-server=${socketPath}`);
mpvArgs.push(target); mpvArgs.push(target);
const mpvTarget = resolveCommandInvocation('mpv', mpvArgs); const mpvTarget = resolveCommandInvocation('mpv', mpvArgs, {
normalizeWindowsShellArgs: false,
});
state.mpvProc = spawn(mpvTarget.command, mpvTarget.args, { stdio: 'inherit' }); state.mpvProc = spawn(mpvTarget.command, mpvTarget.args, { stdio: 'inherit' });
} }
@@ -1147,7 +1149,9 @@ export function launchMpvIdleDetached(
); );
mpvArgs.push(`--log-file=${getMpvLogPath()}`); mpvArgs.push(`--log-file=${getMpvLogPath()}`);
mpvArgs.push(`--input-ipc-server=${socketPath}`); mpvArgs.push(`--input-ipc-server=${socketPath}`);
const mpvTarget = resolveCommandInvocation('mpv', mpvArgs); const mpvTarget = resolveCommandInvocation('mpv', mpvArgs, {
normalizeWindowsShellArgs: false,
});
const proc = spawn(mpvTarget.command, mpvTarget.args, { const proc = spawn(mpvTarget.command, mpvTarget.args, {
stdio: 'ignore', stdio: 'ignore',
detached: true, detached: true,

View File

@@ -244,13 +244,19 @@ export function inferWhisperLanguage(langCodes: string[], fallback: string): str
return fallback; return fallback;
} }
export interface CommandInvocationOptions {
normalizeWindowsShellArgs?: boolean;
}
export function resolveCommandInvocation( export function resolveCommandInvocation(
executable: string, executable: string,
args: string[], args: string[],
options: CommandInvocationOptions = {},
): { command: string; args: string[] } { ): { command: string; args: string[] } {
if (process.platform !== 'win32') { if (process.platform !== 'win32') {
return { command: executable, args }; return { command: executable, args };
} }
const { normalizeWindowsShellArgs = true } = options;
const resolvedExecutable = resolveExecutablePath(executable) ?? executable; const resolvedExecutable = resolveExecutablePath(executable) ?? executable;
const extension = path.extname(resolvedExecutable).toLowerCase(); const extension = path.extname(resolvedExecutable).toLowerCase();
@@ -267,7 +273,9 @@ export function resolveCommandInvocation(
command: bashTarget.command, command: bashTarget.command,
args: [ args: [
normalizeWindowsShellArg(resolvedExecutable, bashTarget.flavor), normalizeWindowsShellArg(resolvedExecutable, bashTarget.flavor),
...args.map((arg) => normalizeWindowsShellArg(arg, bashTarget.flavor)), ...args.map((arg) =>
normalizeWindowsShellArgs ? normalizeWindowsShellArg(arg, bashTarget.flavor) : arg,
),
], ],
}; };
} }
@@ -280,7 +288,9 @@ export function resolveCommandInvocation(
command: bashTarget.command, command: bashTarget.command,
args: [ args: [
normalizeWindowsShellArg(resolvedExecutable, bashTarget.flavor), normalizeWindowsShellArg(resolvedExecutable, bashTarget.flavor),
...args.map((arg) => normalizeWindowsShellArg(arg, bashTarget.flavor)), ...args.map((arg) =>
normalizeWindowsShellArgs ? normalizeWindowsShellArg(arg, bashTarget.flavor) : arg,
),
], ],
}; };
} }