fix(host): drop the folder-dialog Description both picker modes render badly

.NET 10's modern FolderBrowserDialog renders Description as a bottom
strip above the folder input, and the 5.1 classic dialog as an unthemed
white box; the property is dropped entirely and a regression assertion
pins its absence.
This commit is contained in:
Huanqi Cao
2026-08-02 00:23:30 +08:00
parent 5c51589665
commit da1b1ff87d
5 changed files with 9 additions and 6 deletions

View File

@@ -68,14 +68,15 @@ export async function pickNativeDirectory(
// PowerShell 5.1's FolderBrowserDialog is hardwired to the legacy
// SHBrowseForFolder tree; prefer pwsh and fall back only when it is absent.
// Both hosts spawn DPI-unaware, so the script opts the process into system
// DPI awareness before any window is created.
// DPI awareness before any window is created. No Description is set: the
// modern dialog renders it as a bottom strip and the classic dialog as an
// unthemed box.
const script = [
"$ErrorActionPreference = 'Stop'",
"Add-Type -TypeDefinition 'using System; using System.Runtime.InteropServices; public static class DpiAware { [DllImport(\"user32.dll\")] public static extern bool SetProcessDPIAware(); }'",
'[DpiAware]::SetProcessDPIAware() | Out-Null',
'Add-Type -AssemblyName System.Windows.Forms',
'$dialog = New-Object System.Windows.Forms.FolderBrowserDialog',
"$dialog.Description = 'Select Workspace Directory'",
'$dialog.ShowNewFolderButton = $true',
'$result = $dialog.ShowDialog()',
'if ($result -eq [System.Windows.Forms.DialogResult]::OK) {',

View File

@@ -57,6 +57,8 @@ describe('native directory picker', () => {
const script = run.mock.calls[0]?.[1].at(-1)
expect(script).toContain("$ErrorActionPreference = 'Stop'")
expect(script).toContain('SetProcessDPIAware')
// Description renders as a bottom strip (modern) / unthemed box (classic); never set it.
expect(script).not.toContain('Description')
run.mockResolvedValueOnce({ stdout: '', stderr: '' })
await expect(pickNativeDirectory(signal(), { platform: 'win32', run })).resolves.toBeNull()
run.mockRejectedValueOnce(failure(1, 'Add-Type failed'))