1
0
mirror of https://github.com/bitwarden/desktop.git synced 2024-11-24 11:55:50 +01:00

Fix paths for native messaging on mac (#691)

This commit is contained in:
Oscar Hinton 2021-01-26 18:01:46 +01:00 committed by GitHub
parent 7126aeb0b2
commit d1011870f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 18 deletions

View File

@ -2,7 +2,7 @@ import { promises as fs, existsSync } from 'fs';
import * as ipc from 'node-ipc'; import * as ipc from 'node-ipc';
import * as path from 'path'; import * as path from 'path';
import * as util from 'util'; import * as util from 'util';
import { homedir } from 'os'; import { homedir, userInfo } from 'os';
import { LogService } from 'jslib/abstractions/log.service'; import { LogService } from 'jslib/abstractions/log.service';
import { ipcMain } from 'electron'; import { ipcMain } from 'electron';
@ -17,6 +17,7 @@ export class NativeMessagingMain {
listen() { listen() {
ipc.config.id = 'bitwarden'; ipc.config.id = 'bitwarden';
ipc.config.retry = 1500; ipc.config.retry = 1500;
ipc.config.socketRoot = path.join(homedir(), 'tmp');
ipc.serve(() => { ipc.serve(() => {
ipc.server.on('message', (data: any, socket: any) => { ipc.server.on('message', (data: any, socket: any) => {
@ -84,21 +85,25 @@ 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(`${homedir()}/Library/Application\ Support/Mozilla/`)) { if (existsSync(`${this.homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/`)) {
this.writeManifest(`${homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json`, firefoxJson); this.writeManifest(`${this.homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json`, firefoxJson);
} else {
this.logService.warning(`Firefox not found skipping.`);
} }
if (existsSync(`${homedir()}/Library/Application\ Support/Google/Chrome`)) { if (existsSync(`${this.homedir()}/Library/Application\ Support/Google/Chrome/NativeMessagingHosts`)) {
this.writeManifest(`${homedir()}/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.8bit.bitwarden.json`, chromeJson); this.writeManifest(`${this.homedir()}/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.8bit.bitwarden.json`, chromeJson);
} else {
this.logService.warning(`Chrome not found skipping.`);
} }
break; break;
case 'linux': case 'linux':
if (existsSync(`${homedir()}/.mozilla/`)) { if (existsSync(`${this.homedir()}/.mozilla/`)) {
this.writeManifest(`${homedir()}/.mozilla/native-messaging-hosts/com.8bit.bitwarden.json`, firefoxJson); this.writeManifest(`${this.homedir()}/.mozilla/native-messaging-hosts/com.8bit.bitwarden.json`, firefoxJson);
} }
if (existsSync(`${homedir()}/.config/google-chrome/`)) { if (existsSync(`${this.homedir()}/.config/google-chrome/`)) {
this.writeManifest(`${homedir()}/.config/google-chrome/NativeMessagingHosts/com.8bit.bitwarden.json`, chromeJson); this.writeManifest(`${this.homedir()}/.config/google-chrome/NativeMessagingHosts/com.8bit.bitwarden.json`, chromeJson);
} }
break; break;
default: default:
@ -115,21 +120,21 @@ 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(`${homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json`)) { if (existsSync(`${this.homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json`)) {
fs.unlink(`${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(`${homedir()}/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.8bit.bitwarden.json`)) { if (existsSync(`${this.homedir()}/Library/Application\ Support/Google/Chrome/NativeMessagingHosts/com.8bit.bitwarden.json`)) {
fs.unlink(`${homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json`); fs.unlink(`${this.homedir()}/Library/Application\ Support/Mozilla/NativeMessagingHosts/com.8bit.bitwarden.json`);
} }
break; break;
case 'linux': case 'linux':
if (existsSync(`${homedir()}/.mozilla/native-messaging-hosts/com.8bit.bitwarden.json`)) { if (existsSync(`${this.homedir()}/.mozilla/native-messaging-hosts/com.8bit.bitwarden.json`)) {
fs.unlink(`${homedir()}/.mozilla/native-messaging-hosts/com.8bit.bitwarden.json`); fs.unlink(`${this.homedir()}/.mozilla/native-messaging-hosts/com.8bit.bitwarden.json`);
} }
if (existsSync(`${homedir()}/.config/google-chrome/NativeMessagingHosts/com.8bit.bitwarden.json`)) { if (existsSync(`${this.homedir()}/.config/google-chrome/NativeMessagingHosts/com.8bit.bitwarden.json`)) {
fs.unlink(`${homedir()}/.config/google-chrome/NativeMessagingHosts/com.8bit.bitwarden.json`); fs.unlink(`${this.homedir()}/.config/google-chrome/NativeMessagingHosts/com.8bit.bitwarden.json`);
} }
break; break;
default: default:
@ -147,7 +152,7 @@ export class NativeMessagingMain {
if (process.platform === 'win32') { if (process.platform === 'win32') {
return path.join(dir, 'native-messaging.bat'); return path.join(dir, 'native-messaging.bat');
} else if (process.platform === 'darwin') { } else if (process.platform === 'darwin') {
return path.join(dir, '..', 'MacOS', 'Bitwarden'); return '/Applications/Bitwarden.app/Contents/MacOS/Bitwarden';
} }
return path.join(dir, '..', 'bitwarden'); return path.join(dir, '..', 'bitwarden');
@ -204,4 +209,12 @@ export class NativeMessagingMain {
// Do nothing // Do nothing
} }
} }
private homedir() {
if (process.platform === 'darwin') {
return userInfo().homedir;
} else {
return homedir();
}
}
} }

View File

@ -1,9 +1,12 @@
/* tslint:disable:no-console */ /* tslint:disable:no-console */
import * as ipc from 'node-ipc'; import * as ipc from 'node-ipc';
import { homedir } from 'os';
import * as path from 'path';
ipc.config.id = 'proxy'; ipc.config.id = 'proxy';
ipc.config.retry = 1500; ipc.config.retry = 1500;
ipc.config.logger = console.warn; // Stdout is used for native messaging ipc.config.logger = console.warn; // Stdout is used for native messaging
ipc.config.socketRoot = path.join(homedir(), 'tmp');
export default class IPC { export default class IPC {
onMessage: (message: object) => void onMessage: (message: object) => void