index.js (797B)
1 import process from 'node:process'; 2 import defaultBrowserId from 'default-browser-id'; 3 import bundleName from 'bundle-name'; 4 import titleize from 'titleize'; 5 import {execa} from 'execa'; 6 import windows from './windows.js'; 7 8 export default async function defaultBrowser() { 9 if (process.platform === 'linux') { 10 const {stdout} = await execa('xdg-mime', ['query', 'default', 'x-scheme-handler/http']); 11 const name = titleize(stdout.trim().replace(/.desktop$/, '').replace('-', ' ')); 12 13 return { 14 name, 15 id: stdout, 16 }; 17 } 18 19 if (process.platform === 'darwin') { 20 const id = await defaultBrowserId(); 21 const name = await bundleName(id); 22 return {name, id}; 23 } 24 25 if (process.platform === 'win32') { 26 return windows(); 27 } 28 29 throw new Error('Only macOS, Linux, and Windows are supported'); 30 }