1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-09-14 02:08:50 +02:00

support vivaldi for macos

This commit is contained in:
aimuz 2021-03-15 12:11:56 +08:00
parent 0e1dab40cc
commit 444a06d6f7
2 changed files with 28 additions and 26 deletions

View File

@ -13,6 +13,7 @@
<string>/Library/Application Support/Mozilla/NativeMessagingHosts/</string> <string>/Library/Application Support/Mozilla/NativeMessagingHosts/</string>
<string>/Library/Application Support/Google/Chrome/NativeMessagingHosts/</string> <string>/Library/Application Support/Google/Chrome/NativeMessagingHosts/</string>
<string>/Library/Application Support/Microsoft Edge/NativeMessagingHosts/</string> <string>/Library/Application Support/Microsoft Edge/NativeMessagingHosts/</string>
<string>/Library/Application Support/Vivaldi/NativeMessagingHosts/</string>
</array> </array>
</dict> </dict>
</plist> </plist>

View File

@ -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')); this.createWindowsRegistry('HKCU\\SOFTWARE\\Google\\Chrome', 'HKCU\\SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.8bit.bitwarden', path.join(destination, 'chrome.json'));
break; break;
case 'darwin': case 'darwin':
if (existsSync(`${this.homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/`)) { const nmhs = this.getDarwinNMHS();
this.writeManifest(`${this.homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json`, firefoxJson); for (const [key, value] of Object.entries(nmhs)) {
} else { if (existsSync(value)) {
this.logService.warning(`Firefox not found skipping.`); const p = path.join(value, 'com.8bit.bitwarden.json');
} if (key === 'Firefox') {
this.writeManifest(p, firefoxJson);
if (existsSync(`${this.homedir()}/Library/Application\ Support/Google/Chrome/NativeMessagingHosts`)) { } else {
this.writeManifest(`${this.homedir()}/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.8bit.bitwarden.json`, chromeJson); this.writeManifest(p, chromeJson);
} else { }
this.logService.warning(`Chrome not found skipping.`); } else {
} this.logService.warning(`${key} 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.`);
} }
break; break;
case 'linux': case 'linux':
@ -132,16 +128,12 @@ export class NativeMessagingMain {
this.deleteWindowsRegistry('HKCU\\SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.8bit.bitwarden'); this.deleteWindowsRegistry('HKCU\\SOFTWARE\\Google\\Chrome\\NativeMessagingHosts\\com.8bit.bitwarden');
break; break;
case 'darwin': case 'darwin':
if (existsSync(`${this.homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json`)) { const nmhs = this.getDarwinNMHS();
fs.unlink(`${this.homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json`); for (const [_, value] of Object.entries(nmhs)) {
} const p = path.join(value, 'com.8bit.bitwarden.json');
if (existsSync(p)) {
if (existsSync(`${this.homedir()}/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.8bit.bitwarden.json`)) { fs.unlink(p);
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`);
} }
break; break;
case 'linux': 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) { private writeManifest(destination: string, manifest: object) {
fs.mkdir(path.dirname(destination)); fs.mkdir(path.dirname(destination));
fs.writeFile(destination, JSON.stringify(manifest, null, 2)).catch(this.logService.error); fs.writeFile(destination, JSON.stringify(manifest, null, 2)).catch(this.logService.error);