diff --git a/resources/entitlements.mas.plist b/resources/entitlements.mas.plist index b237c81fe3..179caab09c 100644 --- a/resources/entitlements.mas.plist +++ b/resources/entitlements.mas.plist @@ -13,6 +13,7 @@ /Library/Application Support/Mozilla/NativeMessagingHosts/ /Library/Application Support/Google/Chrome/NativeMessagingHosts/ /Library/Application Support/Microsoft Edge/NativeMessagingHosts/ + /Library/Application Support/Vivaldi/NativeMessagingHosts/ diff --git a/src/main/nativeMessaging.main.ts b/src/main/nativeMessaging.main.ts index ff1c1032b7..19ef5c6e6e 100644 --- a/src/main/nativeMessaging.main.ts +++ b/src/main/nativeMessaging.main.ts @@ -87,22 +87,18 @@ export class NativeMessagingMain { this.createWindowsRegistry('HKCU\\SOFTWARE\\Google\\Chrome', 'HKCU\\SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.8bit.bitwarden', path.join(destination, 'chrome.json')); break; case 'darwin': - if (existsSync(`${this.homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/`)) { - this.writeManifest(`${this.homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json`, firefoxJson); - } else { - this.logService.warning(`Firefox not found skipping.`); - } - - if (existsSync(`${this.homedir()}/Library/Application\ Support/Google/Chrome/NativeMessagingHosts`)) { - this.writeManifest(`${this.homedir()}/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.8bit.bitwarden.json`, chromeJson); - } else { - this.logService.warning(`Chrome not found skipping.`); - } - - if (existsSync(`${this.homedir()}/Library/Application\ Support/Microsoft\ Edge/NativeMessagingHosts`)) { - this.writeManifest(`${this.homedir()}/Library/Application\ Support/Microsoft\ Edge/NativeMessagingHosts/com.8bit.bitwarden.json`, chromeJson); - } else { - this.logService.warning(`Microsoft Edge not found skipping.`); + const nmhs = this.getDarwinNMHS(); + for (const [key, value] of Object.entries(nmhs)) { + if (existsSync(value)) { + const p = path.join(value, 'com.8bit.bitwarden.json'); + if (key === 'Firefox') { + this.writeManifest(p, firefoxJson); + } else { + this.writeManifest(p, chromeJson); + } + } else { + this.logService.warning(`${key} not found skipping.`); + } } break; case 'linux': @@ -132,16 +128,12 @@ export class NativeMessagingMain { this.deleteWindowsRegistry('HKCU\\SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.8bit.bitwarden'); break; case 'darwin': - if (existsSync(`${this.homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json`)) { - fs.unlink(`${this.homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json`); - } - - if (existsSync(`${this.homedir()}/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.8bit.bitwarden.json`)) { - fs.unlink(`${this.homedir()}/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.8bit.bitwarden.json`); - } - - if (existsSync(`${this.homedir()}/Library/Application\ Support/Microsoft\ Edge/NativeMessagingHosts/com.8bit.bitwarden.json`)) { - fs.unlink(`${this.homedir()}/Library/Application\ Support/Microsoft\ Edge/NativeMessagingHosts/com.8bit.bitwarden.json`); + const nmhs = this.getDarwinNMHS(); + for (const [_, value] of Object.entries(nmhs)) { + const p = path.join(value, 'com.8bit.bitwarden.json'); + if (existsSync(p)) { + fs.unlink(p); + } } break; case 'linux': @@ -162,6 +154,15 @@ export class NativeMessagingMain { } } + private getDarwinNMHS() { + return { + 'Firefox': `${this.homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/`, + 'Chrome': `${this.homedir()}/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/`, + 'Microsoft Edge': `${this.homedir()}/Library/Application\ Support/Microsoft\ Edge/NativeMessagingHosts/`, + 'Vivaldi': `${this.homedir()}/Library/Application\ Support/Vivaldi/NativeMessagingHosts/`, + }; + } + private writeManifest(destination: string, manifest: object) { fs.mkdir(path.dirname(destination)); fs.writeFile(destination, JSON.stringify(manifest, null, 2)).catch(this.logService.error);