default-browser-id
Advanced tools
Comparing version 4.0.0 to 5.0.0
37
index.js
@@ -0,9 +1,6 @@ | ||
import {promisify} from 'node:util'; | ||
import process from 'node:process'; | ||
import os from 'node:os'; | ||
import fs from 'node:fs/promises'; | ||
import bplist from 'bplist-parser'; | ||
import untildify from 'untildify'; | ||
import {execFile} from 'node:child_process'; | ||
const macOsVersion = Number(os.release().split('.')[0]); | ||
const filePath = untildify(macOsVersion >= 14 ? '~/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist' : '~/Library/Preferences/com.apple.LaunchServices.plist'); | ||
const execFileAsync = promisify(execFile); | ||
@@ -15,28 +12,8 @@ export default async function defaultBrowserId() { | ||
const defaultBundleId = 'com.apple.Safari'; | ||
const {stdout} = await execFileAsync('defaults', ['read', 'com.apple.LaunchServices/com.apple.launchservices.secure', 'LSHandlers']); | ||
let buffer; | ||
try { | ||
buffer = await fs.readFile(filePath); | ||
} catch (error) { | ||
if (error.code === 'ENOENT') { | ||
return defaultBundleId; | ||
} | ||
// `(?!-)` is to prevent matching `LSHandlerRoleAll = "-";`. | ||
const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout); | ||
throw error; | ||
} | ||
const handlers = bplist.parseBuffer(buffer)?.[0]?.LSHandlers; | ||
if (!handlers || handlers.length === 0) { | ||
return defaultBundleId; | ||
} | ||
for (const handler of handlers) { | ||
if (handler.LSHandlerURLScheme === 'http' && handler.LSHandlerRoleAll) { | ||
return handler.LSHandlerRoleAll; | ||
} | ||
} | ||
return defaultBundleId; | ||
return match?.groups.id ?? 'com.apple.Safari'; | ||
} |
{ | ||
"name": "default-browser-id", | ||
"version": "4.0.0", | ||
"version": "5.0.0", | ||
"description": "Get the bundle identifier of the default browser (macOS). Example: com.apple.Safari", | ||
@@ -15,2 +15,3 @@ "license": "MIT", | ||
"exports": "./index.js", | ||
"sideEffects": false, | ||
"engines": { | ||
@@ -37,10 +38,6 @@ "node": ">=18" | ||
], | ||
"dependencies": { | ||
"bplist-parser": "^0.3.2", | ||
"untildify": "^5.0.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "^5.3.1", | ||
"ava": "^6.0.1", | ||
"xo": "^0.56.0" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
0
3016
13
- Removedbplist-parser@^0.3.2
- Removeduntildify@^5.0.0
- Removedbig-integer@1.6.52(transitive)
- Removedbplist-parser@0.3.2(transitive)
- Removeduntildify@5.0.0(transitive)