(file: string)
| 2 | import {platform} from 'os'; |
| 3 | |
| 4 | export function openInExplorer(file: string) { |
| 5 | let command: string | null = null; |
| 6 | let args = [file]; |
| 7 | const os = platform(); |
| 8 | |
| 9 | switch (os) { |
| 10 | case 'win32': |
| 11 | command = 'explorer'; |
| 12 | break; |
| 13 | case 'linux': |
| 14 | if (isRunningOnWSL()) { |
| 15 | command = 'bash'; |
| 16 | args = ['-c', `cd ${file} && explorer.exe .`]; |
| 17 | } else { |
| 18 | command = 'xdg-open'; |
| 19 | } |
| 20 | break; |
| 21 | case 'darwin': |
| 22 | command = 'open'; |
| 23 | break; |
| 24 | } |
| 25 | |
| 26 | if (command) { |
| 27 | spawn(command, args, {detached: true}).unref(); |
| 28 | } else { |
| 29 | console.warn(`Unsupported OS: ${os}`); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | function isRunningOnWSL(): boolean { |
| 34 | try { |
no test coverage detected