openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
3 lines • 1.82 kB
JavaScript
import{a as getWindowsSystem32ExePath}from"./windows-install-roots-6Br0c6Nq.mjs";import{n as runCommandWithTimeout}from"./exec-runner-BiCq-T1F.mjs";import"./exec-c5tqm8tb.mjs";import{t as isWSL}from"./wsl-_7IqvQi4.mjs";import{t as detectBinary}from"./detect-binary-CIeTTVvG.mjs";import{pathToFileURL}from"node:url";import path from"node:path";
//!src/infra/browser-open.ts
async function resolveBrowserOpenCommand(){const e=process.platform;const t=process.env;const n=Boolean(t.DISPLAY||t.WAYLAND_DISPLAY);if((Boolean(t.SSH_CLIENT)||Boolean(t.SSH_TTY)||Boolean(t.SSH_CONNECTION))&&!n&&e!==`win32`&&e!==`darwin`)return null;if(e===`win32`)return[getWindowsSystem32ExePath(`rundll32.exe`),`url.dll,FileProtocolHandler`];if(e!==`darwin`&&e!==`linux`)return null;if(e===`linux`){const e=await isWSL();if(!n&&!e)return null;if(e){if(await detectBinary(`wslview`))return[`wslview`];if(!n)return null}}const r=e===`darwin`?`open`:`xdg-open`;return await detectBinary(r)?[r]:null}async function detectBrowserOpenSupport(){return{ok:Boolean(await resolveBrowserOpenCommand())}}async function openUrl(e){if(process.env.VITEST||false)return false;const t=URL.parse(e);if(t?.protocol!==`http:`&&t?.protocol!==`https:`)return false;return await openBrowserPath(t.toString())}async function openLocalFile(e){if(process.env.VITEST||false)return false;const t=process.platform===`win32`;const n=t?path.win32:path.posix;if(!n.isAbsolute(e))return false;return await openBrowserPath(pathToFileURL(n.resolve(e),{windows:t}).toString())}async function openBrowserPath(e){const t=await resolveBrowserOpenCommand();if(!t)return false;const n=[...t,e];try{const e=await runCommandWithTimeout(n,{timeoutMs:5e3});return e.code===0&&e.termination===`exit`}catch{return false}}export{openLocalFile as n,openUrl as r,detectBrowserOpenSupport as t};