Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions apps/server/src/process/externalLauncher.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,12 @@ it.effect("reveals a file in File Explorer through PowerShell on Windows", () =>
]);
const encodedCommand = spawned.args[spawned.args.length - 1] ?? "";
const decodedCommand = Buffer.from(encodedCommand, "base64").toString("utf16le");
// explorer.exe expects `/select,"<path>"` with only the path quoted;
// PowerShell 5.1's Start-Process passes the argument string verbatim.
// A replacement default file manager gets the containing folder through
// the shell. Otherwise explorer.exe expects `/select,"<path>"` with only
// the path quoted; PowerShell 5.1's Start-Process passes it verbatim.
assert.equal(
decodedCommand,
"$ProgressPreference = 'SilentlyContinue'; Start-Process 'explorer.exe' -ArgumentList ('/select,\"' + 'C:\\workspace with spaces\\media\\author''s clip.mp4' + '\"')",
"$ProgressPreference = 'SilentlyContinue'; $folderVerb = (Get-ItemProperty -LiteralPath 'Registry::HKEY_CLASSES_ROOT\\Directory\\shell' -ErrorAction SilentlyContinue).'(default)'; if ($folderVerb -and $folderVerb -ne 'none') { Invoke-Item -LiteralPath ([IO.Path]::GetDirectoryName('C:\\workspace with spaces\\media\\author''s clip.mp4')) } else { $ProgressPreference = 'SilentlyContinue'; Start-Process 'explorer.exe' -ArgumentList ('/select,\"' + 'C:\\workspace with spaces\\media\\author''s clip.mp4' + '\"') }",
);
assert.equal(spawned.options.shell, false);
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
Expand Down Expand Up @@ -492,7 +493,7 @@ it.effect.skipIf(windowsHost)(
const decodedCommand = Buffer.from(encodedCommand, "base64").toString("utf16le");
assert.equal(
decodedCommand,
"$ProgressPreference = 'SilentlyContinue'; Start-Process 'explorer.exe' -ArgumentList ('/select,\"' + '\\\\wsl.localhost\\Ubuntu-24.04\\home\\t3\\workspace\\media\\clip.mp4' + '\"')",
"$ProgressPreference = 'SilentlyContinue'; $folderVerb = (Get-ItemProperty -LiteralPath 'Registry::HKEY_CLASSES_ROOT\\Directory\\shell' -ErrorAction SilentlyContinue).'(default)'; if ($folderVerb -and $folderVerb -ne 'none') { Invoke-Item -LiteralPath ([IO.Path]::GetDirectoryName('\\\\wsl.localhost\\Ubuntu-24.04\\home\\t3\\workspace\\media\\clip.mp4')) } else { $ProgressPreference = 'SilentlyContinue'; Start-Process 'explorer.exe' -ArgumentList ('/select,\"' + '\\\\wsl.localhost\\Ubuntu-24.04\\home\\t3\\workspace\\media\\clip.mp4' + '\"') }",
);
}).pipe(Effect.scoped, Effect.provide(NodeServices.layer)),
);
Expand Down
14 changes: 13 additions & 1 deletion apps/server/src/process/externalLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,18 @@ export function buildFileExplorerRevealPowerShellSource(
return `$ProgressPreference = 'SilentlyContinue'; Start-Process ${escapePowerShellStringLiteral(explorerCommand)} -ArgumentList ('/select,"' + ${escapePowerShellStringLiteral(target)} + '"')`;
}

/**
* Keeps reveals in a replacement file manager (File Pilot, Directory Opus,
* XYplorer) set as the Windows default. Those register a default verb on
* `Directory\shell`, which stock Windows leaves as `none`, and launching
* Explorer directly bypasses it. Opening the containing folder through the
* shell runs that verb; only Explorer has a selection switch, so the file
* itself is not selected there.
*/
function buildDefaultFileManagerRevealPowerShellSource(target: string): string {
return `$ProgressPreference = 'SilentlyContinue'; $folderVerb = (Get-ItemProperty -LiteralPath 'Registry::HKEY_CLASSES_ROOT\\Directory\\shell' -ErrorAction SilentlyContinue).'(default)'; if ($folderVerb -and $folderVerb -ne 'none') { Invoke-Item -LiteralPath ([IO.Path]::GetDirectoryName(${escapePowerShellStringLiteral(target)})) } else { ${buildFileExplorerRevealPowerShellSource("explorer.exe", target)} }`;
}

function fileExplorerRevealLaunch(
target: string,
explorerTarget: string,
Expand All @@ -610,7 +622,7 @@ function fileExplorerRevealLaunch(
command: powershellCommand,
args: [
...POWERSHELL_ARGUMENTS_PREFIX,
encodeUtf16LeBase64(buildFileExplorerRevealPowerShellSource("explorer.exe", explorerTarget)),
encodeUtf16LeBase64(buildDefaultFileManagerRevealPowerShellSource(explorerTarget)),
],
};
}
Expand Down
Loading