* Read file path from clipboard when a file has been copied (Windows). * Returns the file path if found, null otherwise.
()
| 451 | * Returns the file path if found, null otherwise. |
| 452 | */ |
| 453 | function readClipboardFilePathWindows(): string | null { |
| 454 | try { |
| 455 | const script = ` |
| 456 | Add-Type -AssemblyName System.Windows.Forms |
| 457 | $files = [System.Windows.Forms.Clipboard]::GetFileDropList() |
| 458 | if ($files.Count -gt 0) { |
| 459 | Write-Output $files[0] |
| 460 | } |
| 461 | ` |
| 462 | const result = spawnSync('powershell', ['-STA', '-Command', script], { |
| 463 | encoding: 'utf-8', |
| 464 | timeout: 1000, |
| 465 | }) |
| 466 | |
| 467 | if (result.status === 0 && result.stdout) { |
| 468 | const filePath = result.stdout.trim() |
| 469 | if (filePath && existsSync(filePath)) { |
| 470 | return filePath |
| 471 | } |
| 472 | } |
| 473 | return null |
| 474 | } catch { |
| 475 | return null |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | /** |
| 480 | * Read file path from clipboard when a file has been copied (Linux). |
no outgoing calls
no test coverage detected