(targetPath: string)
| 14 | } |
| 15 | |
| 16 | export async function openPathWithSystem(targetPath: string) { |
| 17 | const { command, args } = getOpenCommand() |
| 18 | |
| 19 | return new Promise<boolean>((resolve) => { |
| 20 | let settled = false |
| 21 | const child = spawn(command, [...args, targetPath], { |
| 22 | stdio: 'ignore', |
| 23 | windowsHide: true, |
| 24 | }) |
| 25 | |
| 26 | const finish = (ok: boolean) => { |
| 27 | if (settled) { |
| 28 | return |
| 29 | } |
| 30 | |
| 31 | settled = true |
| 32 | resolve(ok) |
| 33 | } |
| 34 | |
| 35 | child.once('error', () => { |
| 36 | finish(false) |
| 37 | }) |
| 38 | child.once('exit', (code) => { |
| 39 | finish(code === 0) |
| 40 | }) |
| 41 | |
| 42 | setTimeout(() => { |
| 43 | child.kill() |
| 44 | finish(false) |
| 45 | }, 10_000).unref() |
| 46 | }) |
| 47 | } |
no test coverage detected