// @bun
function A(t,p,r){let u=(a)=>Object.defineProperty(t,p,{value:a,enumerable:!0,writable:!0});return Object.defineProperty(t,p,{configurable:!0,enumerable:!0,get(){let a=r();return u(a),a},set(a){u(a)}}),t}import{promisify as Q}from"util";import O from"process";import{execFile as R}from"child_process";import{promisify as C}from"util";import E from"process";import{execFile as L}from"child_process";var $=C(L);async function m(){if(E.platform!=="darwin")throw Error("macOS only");let{stdout:t}=await $("defaults",["read","com.apple.LaunchServices/com.apple.launchservices.secure","LSHandlers"]),r=/LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(t)?.groups.id??"com.apple.Safari";if(r==="com.apple.safari")return"com.apple.Safari";return r}import e from"process";import{promisify as q}from"util";import{execFile as G,execFileSync as k}from"child_process";var J=q(G);async function g(t,{humanReadableOutput:p=!0,signal:r}={}){if(e.platform!=="darwin")throw Error("macOS only");let u=p?[]:["-ss"],a={};if(r)a.signal=r;let{stdout:f}=await J("osascript",["-e",t,u],a);return f.trim()}async function l(t){return g(`tell application "Finder" to set app_path to application file id "${t}" as string
tell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`)}import{promisify as K}from"util";import{execFile as M}from"child_process";var N=K(M),n={MSEdgeHTM:{name:"Edge",id:"com.microsoft.edge"},MSEdgeBHTML:{name:"Edge Beta",id:"com.microsoft.edge.beta"},MSEdgeDHTML:{name:"Edge Dev",id:"com.microsoft.edge.dev"},AppXq0fevzme2pys62n3e0fbqa7peapykr8v:{name:"Edge",id:"com.microsoft.edge.old"},ChromeHTML:{name:"Chrome",id:"com.google.chrome"},ChromeBHTML:{name:"Chrome Beta",id:"com.google.chrome.beta"},ChromeDHTML:{name:"Chrome Dev",id:"com.google.chrome.dev"},ChromiumHTM:{name:"Chromium",id:"org.chromium.Chromium"},BraveHTML:{name:"Brave",id:"com.brave.Browser"},BraveBHTML:{name:"Brave Beta",id:"com.brave.Browser.beta"},BraveDHTML:{name:"Brave Dev",id:"com.brave.Browser.dev"},BraveSSHTM:{name:"Brave Nightly",id:"com.brave.Browser.nightly"},FirefoxURL:{name:"Firefox",id:"org.mozilla.firefox"},OperaStable:{name:"Opera",id:"com.operasoftware.Opera"},VivaldiHTM:{name:"Vivaldi",id:"com.vivaldi.Vivaldi"},"IE.HTTP":{name:"Internet Explorer",id:"com.microsoft.ie"}},b=new Map(Object.entries(n));class o extends Error{}async function S(t=N){let{stdout:p}=await t("reg",["QUERY"," HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice","/v","ProgId"]),r=/ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(p);if(!r)throw new o(`Cannot find Windows browser in stdout: ${JSON.stringify(p)}`);let{id:u}=r.groups,a=u.lastIndexOf("."),f=u.lastIndexOf("-"),c=a===-1?void 0:u.slice(0,a),v=f===-1?void 0:u.slice(0,f);return n[u]??n[c]??n[v]??{name:u,id:u}}var V=Q(R),W=(t)=>t.toLowerCase().replaceAll(/(?:^|\s|-)\S/g,(p)=>p.toUpperCase());async function X(){if(O.platform==="darwin"){let t=await m();return{name:await l(t),id:t}}if(O.platform==="linux"){let{stdout:t}=await V("xdg-mime",["query","default","x-scheme-handler/http"]),p=t.trim();return{name:W(p.replace(/.desktop$/,"").replace("-"," ")),id:p}}if(O.platform==="win32")return S();throw Error("Only macOS, Linux, and Windows are supported")}
export{A as nw,X as ow};
