mirror of
https://github.com/bitwarden/browser.git
synced 2024-08-20 22:14:08 +02:00
Disconnect active connections when closing native messaging. Fix exe path on windows (#865)
This commit is contained in:
parent
163fa2aa41
commit
20b8a83dd8
9
package-lock.json
generated
9
package-lock.json
generated
|
@ -1139,6 +1139,15 @@
|
||||||
"@types/node": "*"
|
"@types/node": "*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@types/node-ipc": {
|
||||||
|
"version": "9.1.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/node-ipc/-/node-ipc-9.1.3.tgz",
|
||||||
|
"integrity": "sha512-ka7CPX9Dk2lwe4PxoZMLOwcQrtdcYe/7OKmH75fQbmt0jdKltWVkdGA81D5l55d0wNhkweHa3XmzFbt5C0ieOQ==",
|
||||||
|
"dev": true,
|
||||||
|
"requires": {
|
||||||
|
"@types/node": "*"
|
||||||
|
}
|
||||||
|
},
|
||||||
"@types/normalize-package-data": {
|
"@types/normalize-package-data": {
|
||||||
"version": "2.4.0",
|
"version": "2.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/@types/normalize-package-data/-/normalize-package-data-2.4.0.tgz",
|
||||||
|
|
|
@ -251,6 +251,7 @@
|
||||||
"@types/lunr": "^2.3.3",
|
"@types/lunr": "^2.3.3",
|
||||||
"@types/node": "^10.17.58",
|
"@types/node": "^10.17.58",
|
||||||
"@types/node-forge": "^0.9.7",
|
"@types/node-forge": "^0.9.7",
|
||||||
|
"@types/node-ipc": "^9.1.3",
|
||||||
"@types/papaparse": "^5.2.0",
|
"@types/papaparse": "^5.2.0",
|
||||||
"@types/webcrypto": "^0.0.28",
|
"@types/webcrypto": "^0.0.28",
|
||||||
"@types/webpack": "^4.4.27",
|
"@types/webpack": "^4.4.27",
|
||||||
|
|
4
src/global.d.ts
vendored
4
src/global.d.ts
vendored
|
@ -1,6 +1,2 @@
|
||||||
declare function escape(s: string): string;
|
declare function escape(s: string): string;
|
||||||
declare function unescape(s: string): string;
|
declare function unescape(s: string): string;
|
||||||
declare module 'node-ipc' {
|
|
||||||
const x: any;
|
|
||||||
export = x;
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { existsSync, promises as fs } from 'fs';
|
import { existsSync, promises as fs } from 'fs';
|
||||||
|
import { Socket } from 'net';
|
||||||
import * as ipc from 'node-ipc';
|
import * as ipc from 'node-ipc';
|
||||||
import { homedir, userInfo } from 'os';
|
import { homedir, userInfo } from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
@ -9,7 +10,7 @@ import { LogService } from 'jslib/abstractions/log.service';
|
||||||
import { WindowMain } from 'jslib/electron/window.main';
|
import { WindowMain } from 'jslib/electron/window.main';
|
||||||
|
|
||||||
export class NativeMessagingMain {
|
export class NativeMessagingMain {
|
||||||
private connected = false;
|
private connected: Socket[] = [];
|
||||||
private socket: any;
|
private socket: any;
|
||||||
|
|
||||||
constructor(private logService: LogService, private windowMain: WindowMain, private userPath: string, private exePath: string) {}
|
constructor(private logService: LogService, private windowMain: WindowMain, private userPath: string, private exePath: string) {}
|
||||||
|
@ -36,14 +37,18 @@ export class NativeMessagingMain {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ipc.server.on('connect', () => {
|
ipc.server.on('connect', (socket: Socket) => {
|
||||||
this.connected = true;
|
this.connected.push(socket);
|
||||||
});
|
});
|
||||||
|
|
||||||
ipc.server.on(
|
ipc.server.on(
|
||||||
'socket.disconnected',
|
'socket.disconnected',
|
||||||
(socket: any, destroyedSocketID: any) => {
|
(socket, destroyedSocketID) => {
|
||||||
this.connected = false;
|
const index = this.connected.indexOf(socket);
|
||||||
|
if (index > -1) {
|
||||||
|
this.connected.splice(index, 1);
|
||||||
|
}
|
||||||
|
|
||||||
this.socket = null;
|
this.socket = null;
|
||||||
ipc.log(
|
ipc.log(
|
||||||
'client ' + destroyedSocketID + ' has disconnected!'
|
'client ' + destroyedSocketID + ' has disconnected!'
|
||||||
|
@ -57,6 +62,12 @@ export class NativeMessagingMain {
|
||||||
|
|
||||||
stop() {
|
stop() {
|
||||||
ipc.server.stop();
|
ipc.server.stop();
|
||||||
|
// Kill all existing connections
|
||||||
|
this.connected.forEach(socket => {
|
||||||
|
if (!socket.destroyed) {
|
||||||
|
socket.destroy();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
send(message: object, socket: any) {
|
send(message: object, socket: any) {
|
||||||
|
@ -184,7 +195,7 @@ export class NativeMessagingMain {
|
||||||
|
|
||||||
private binaryPath() {
|
private binaryPath() {
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
return path.join(path.basename(this.exePath), 'resources', 'native-messaging.bat');
|
return path.join(path.dirname(this.exePath), 'resources', 'native-messaging.bat');
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.exePath;
|
return this.exePath;
|
||||||
|
|
|
@ -18,10 +18,7 @@ export default class IPC {
|
||||||
ipc.connectTo('bitwarden', () => {
|
ipc.connectTo('bitwarden', () => {
|
||||||
ipc.of.bitwarden.on('connect', () => {
|
ipc.of.bitwarden.on('connect', () => {
|
||||||
this.connected = true;
|
this.connected = true;
|
||||||
console.error(
|
console.error('## connected to bitwarden desktop ##');
|
||||||
'## connected to bitwarden desktop ##',
|
|
||||||
ipc.config.delay
|
|
||||||
);
|
|
||||||
|
|
||||||
// Notify browser extension, connection is established to desktop application.
|
// Notify browser extension, connection is established to desktop application.
|
||||||
this.onMessage({command: 'connected'});
|
this.onMessage({command: 'connected'});
|
||||||
|
|
Loading…
Reference in New Issue
Block a user