From 64da326be359d6e4b878ad2647e2eedbbb2cf01d Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Tue, 23 Mar 2021 23:35:25 +0100 Subject: [PATCH] Attempt to create NativeMessagingHosts directory if not already exist (#808) --- src/main/nativeMessaging.main.ts | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/main/nativeMessaging.main.ts b/src/main/nativeMessaging.main.ts index 39f6cd0229b..220c48e10b7 100644 --- a/src/main/nativeMessaging.main.ts +++ b/src/main/nativeMessaging.main.ts @@ -93,12 +93,14 @@ export class NativeMessagingMain { const nmhs = this.getDarwinNMHS(); for (const [key, value] of Object.entries(nmhs)) { if (existsSync(value)) { - const p = path.join(value, 'com.8bit.bitwarden.json'); + const p = path.join(value, 'NativeMessagingHosts', 'com.8bit.bitwarden.json'); + + let manifest: any = chromeJson; if (key === 'Firefox') { - this.writeManifest(p, firefoxJson); - } else { - this.writeManifest(p, chromeJson); + manifest = firefoxJson; } + + this.writeManifest(p, manifest).catch(e => this.logService.error(`Error writing manifest for ${key}. ${e}`)); } else { this.logService.warning(`${key} not found skipping.`); } @@ -133,7 +135,7 @@ export class NativeMessagingMain { case 'darwin': const nmhs = this.getDarwinNMHS(); for (const [_, value] of Object.entries(nmhs)) { - const p = path.join(value, 'com.8bit.bitwarden.json'); + const p = path.join(value, 'NativeMessagingHosts', 'com.8bit.bitwarden.json'); if (existsSync(p)) { fs.unlink(p); } @@ -159,16 +161,16 @@ export class NativeMessagingMain { private getDarwinNMHS() { return { - 'Firefox': `${this.homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/`, - 'Chrome': `${this.homedir()}/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/`, - 'Chrome Beta': `${this.homedir()}/Library/Application\ Support/Google/Chrome\ Beta/NativeMessagingHosts/`, - 'Chrome Dev': `${this.homedir()}/Library/Application\ Support/Google/Chrome\ Dev/NativeMessagingHosts/`, - 'Chrome Canary': `${this.homedir()}/Library/Application\ Support/Google/Chrome\ Canary/NativeMessagingHosts/`, - 'Microsoft Edge': `${this.homedir()}/Library/Application\ Support/Microsoft\ Edge/NativeMessagingHosts/`, - 'Microsoft Edge Beta': `${this.homedir()}/Library/Application\ Support/Microsoft\ Edge\ Beta/NativeMessagingHosts/`, - 'Microsoft Edge Dev': `${this.homedir()}/Library/Application\ Support/Microsoft\ Edge\ Dev/NativeMessagingHosts/`, - 'Microsoft Edge Canary': `${this.homedir()}/Library/Application\ Support/Microsoft\ Edge\ Canary/NativeMessagingHosts/`, - 'Vivaldi': `${this.homedir()}/Library/Application\ Support/Vivaldi/NativeMessagingHosts/`, + 'Firefox': `${this.homedir()}/Library/Application\ Support/Mozilla/`, + 'Chrome': `${this.homedir()}/Library/Application\ Support/Google/Chrome/`, + 'Chrome Beta': `${this.homedir()}/Library/Application\ Support/Google/Chrome\ Beta/`, + 'Chrome Dev': `${this.homedir()}/Library/Application\ Support/Google/Chrome\ Dev/`, + 'Chrome Canary': `${this.homedir()}/Library/Application\ Support/Google/Chrome\ Canary/`, + 'Microsoft Edge': `${this.homedir()}/Library/Application\ Support/Microsoft\ Edge/`, + 'Microsoft Edge Beta': `${this.homedir()}/Library/Application\ Support/Microsoft\ Edge\ Beta/`, + 'Microsoft Edge Dev': `${this.homedir()}/Library/Application\ Support/Microsoft\ Edge\ Dev/`, + 'Microsoft Edge Canary': `${this.homedir()}/Library/Application\ Support/Microsoft\ Edge\ Canary/`, + 'Vivaldi': `${this.homedir()}/Library/Application\ Support/Vivaldi/`, }; }