1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 08:43:33 +00:00

Initial PoC for browser <-> desktop communication

This commit is contained in:
Hinton
2020-10-05 15:11:37 +02:00
parent 38ecc3b74b
commit f09a788103
13 changed files with 960 additions and 4 deletions

4
src/global.d.ts vendored
View File

@@ -1,2 +1,6 @@
declare function escape(s: string): string;
declare function unescape(s: string): string;
declare module 'node-ipc' {
const x: any;
export = x;
}

View File

@@ -18,6 +18,7 @@ import { ElectronStorageService } from 'jslib/electron/services/electronStorage.
import { TrayMain } from 'jslib/electron/tray.main';
import { UpdaterMain } from 'jslib/electron/updater.main';
import { WindowMain } from 'jslib/electron/window.main';
import { NativeMessagingService } from './services/nativeMessaging.service';
export class Main {
logService: ElectronLogService;
@@ -33,6 +34,7 @@ export class Main {
powerMonitorMain: PowerMonitorMain;
trayMain: TrayMain;
biometricMain: BiometricMain;
nativeMessagingService: NativeMessagingService;
constructor() {
// Set paths for portable builds
@@ -116,6 +118,8 @@ export class Main {
const BiometricDarwinMain = require('jslib/electron/biometric.darwin.main').default;
this.biometricMain = new BiometricDarwinMain(this.storageService, this.i18nService);
}
this.nativeMessagingService = new NativeMessagingService();
}
bootstrap() {
@@ -153,6 +157,7 @@ export class Main {
// tslint:disable-next-line
console.error(e);
});
this.nativeMessagingService.listen();
}
private processDeepLink(argv: string[]): void {

View File

@@ -19,6 +19,7 @@
"electron-store": "1.3.0",
"electron-updater": "4.3.5",
"keytar": "4.13.0",
"node-ipc": "^9.1.1",
"zxcvbn": "4.4.2"
}
}

View File

@@ -0,0 +1,33 @@
import * as ipc from 'node-ipc';
export class NativeMessagingService {
private connected = false;
listen() {
ipc.config.id = 'bitwarden';
ipc.config.retry = 1500;
ipc.serve(() => {
ipc.server.on('message', (data: any, socket: any) => {
ipc.log('got a message : ', data);
ipc.server.emit(socket, 'message', data + ' world!');
});
ipc.server.on('connect', () => {
this.connected = true;
})
ipc.server.on(
'socket.disconnected',
(socket: any, destroyedSocketID: any) => {
this.connected = false;
ipc.log(
'client ' + destroyedSocketID + ' has disconnected!'
);
}
);
});
ipc.server.start();
}
}