fix(files): handle reveal launcher failures (#2490)

This commit is contained in:
Pascal André
2026-08-06 23:31:51 +03:00
committed by GitHub
parent 61083c3915
commit 27c46aa0b9
2 changed files with 123 additions and 4 deletions
+25 -4
View File
@@ -382,6 +382,7 @@ export const registerFsRoutes = (app, dependencies) => {
path,
fsPromises,
spawn,
platform = process.platform,
crypto,
normalizeDirectoryPath,
resolveProjectDirectory,
@@ -393,6 +394,27 @@ export const registerFsRoutes = (app, dependencies) => {
realpath: fsPromises.realpath.bind(fsPromises),
});
const spawnDetached = (command, args) => new Promise((resolve, reject) => {
let child;
try {
child = spawn(command, args, { windowsHide: true, stdio: 'ignore', detached: true });
} catch (error) {
reject(new Error('Failed to launch file browser', { cause: error }));
return;
}
const onError = (error) => {
child.removeListener('spawn', onSpawn);
reject(new Error('Failed to launch file browser', { cause: error }));
};
const onSpawn = () => {
child.removeListener('error', onError);
child.unref();
resolve();
};
child.once('error', onError);
child.once('spawn', onSpawn);
});
const execJobs = new Map();
const commandTimeoutMs = createCommandTimeoutMs();
const gitReadCacheTtlMs = createGitReadCacheTtlMs();
@@ -1134,13 +1156,12 @@ export const registerFsRoutes = (app, dependencies) => {
const resolved = path.resolve(targetPath.trim());
await fsPromises.access(resolved);
const platform = process.platform;
if (platform === 'darwin') {
const stat = await fsPromises.stat(resolved);
if (stat.isDirectory()) {
spawn('open', [resolved], { windowsHide: true, stdio: 'ignore', detached: true }).unref();
await spawnDetached('open', [resolved]);
} else {
spawn('open', ['-R', resolved], { windowsHide: true, stdio: 'ignore', detached: true }).unref();
await spawnDetached('open', ['-R', resolved]);
}
} else if (platform === 'win32') {
const stat = await fsPromises.stat(resolved);
@@ -1164,7 +1185,7 @@ export const registerFsRoutes = (app, dependencies) => {
} else {
const stat = await fsPromises.stat(resolved);
const dir = stat.isDirectory() ? resolved : path.dirname(resolved);
spawn('xdg-open', [dir], { windowsHide: true, stdio: 'ignore', detached: true }).unref();
await spawnDetached('xdg-open', [dir]);
}
return res.json({ success: true, path: resolved });