Attempt to create NativeMessagingHosts directory if not already exist (#808)

This commit is contained in:
Oscar Hinton 2021-03-23 23:35:25 +01:00 committed by GitHub
parent 85f29e1222
commit 64da326be3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 17 additions and 15 deletions

View File

@ -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/`,
};
}