diff --git a/internal/ui/sysproc_default.go b/internal/ui/sysproc_default.go new file mode 100644 index 0000000..ddc9b49 --- /dev/null +++ b/internal/ui/sysproc_default.go @@ -0,0 +1,10 @@ +//go:build !windows +// +build !windows + +package ui + +import "syscall" + +func getSysProcAttr() *syscall.SysProcAttr { + return &syscall.SysProcAttr{} +} \ No newline at end of file diff --git a/internal/ui/sysproc_windows.go b/internal/ui/sysproc_windows.go new file mode 100644 index 0000000..2633af0 --- /dev/null +++ b/internal/ui/sysproc_windows.go @@ -0,0 +1,10 @@ +//go:build windows +// +build windows + +package ui + +import "syscall" + +func getSysProcAttr() *syscall.SysProcAttr { + return &syscall.SysProcAttr{HideWindow: true} +} \ No newline at end of file diff --git a/internal/ui/windows.go b/internal/ui/windows.go index 89b0cb4..3fd2ff6 100644 --- a/internal/ui/windows.go +++ b/internal/ui/windows.go @@ -49,11 +49,10 @@ func tryLinuxNativeFolderDialog() string { // tryNativeFolderDialog attempts to open a native OS folder selection dialog. // If successful, it returns the selected path. If not available or fails, it returns an empty string. -// On Windows, use an OpenFileDialog trick to simulate a normal file browser dialog rather than the older folder dialog. +// On Windows, use an OpenFileDialog trick to simulate a folder selection with no visible cmd window. func tryNativeFolderDialog() string { switch runtime.GOOS { case "windows": - // Use PowerShell to prompt with an OpenFileDialog that can simulate folder selection cmd := exec.Command("powershell", "-NoProfile", "-NonInteractive", "-Command", "[System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms') | Out-Null; "+ "$ofd = New-Object System.Windows.Forms.OpenFileDialog; "+ @@ -61,6 +60,11 @@ func tryNativeFolderDialog() string { "$ofd.ValidateNames = $true; $ofd.CheckFileExists = $false; $ofd.CheckPathExists = $true; "+ "$ofd.FileName = 'Folder Selection.'; "+ "if ($ofd.ShowDialog() -eq 'OK') { Split-Path $ofd.FileName }") + + if runtime.GOOS == "windows" { + cmd.SysProcAttr = getSysProcAttr() + } + out, err := cmd.Output() if err == nil { folderPath := strings.TrimSpace(string(out))