(
url: string,
opts: { env?: NodeJS.ProcessEnv; platform?: string } = {},
)
| 43 | * to spawn. Detached + unref'd so it never keeps the QodeX process alive. |
| 44 | */ |
| 45 | export async function openUrl( |
| 46 | url: string, |
| 47 | opts: { env?: NodeJS.ProcessEnv; platform?: string } = {}, |
| 48 | ): Promise<boolean> { |
| 49 | const env = opts.env ?? process.env; |
| 50 | const platform = opts.platform ?? process.platform; |
| 51 | if (!canOpenBrowser(env, platform)) return false; |
| 52 | const { cmd, args } = openerFor(url, platform); |
| 53 | try { |
| 54 | const child = spawn(cmd, args, { stdio: 'ignore', detached: true }); |
| 55 | let ok = true; |
| 56 | child.on('error', () => { ok = false; }); // ENOENT (opener missing) etc. — swallow |
| 57 | child.unref(); |
| 58 | // Give a spawn error a tick to surface before we report success. |
| 59 | await new Promise(r => setTimeout(r, 0)); |
| 60 | return ok; |
| 61 | } catch { |
| 62 | return false; |
| 63 | } |
| 64 | } |
no test coverage detected