mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-05 09:10:53 +01:00
Merge pull request #1522 from Hinton/hotfix/native-messaging-silent-disconnect
Resolve native messaging silently disconnecting
This commit is contained in:
commit
76a31d089a
@ -143,7 +143,7 @@ export class NativeMessagingBackground {
|
|||||||
message.timestamp = Date.now();
|
message.timestamp = Date.now();
|
||||||
|
|
||||||
const encrypted = await this.cryptoService.encrypt(JSON.stringify(message), this.sharedSecret);
|
const encrypted = await this.cryptoService.encrypt(JSON.stringify(message), this.sharedSecret);
|
||||||
this.port.postMessage({appId: this.appId, message: encrypted});
|
this.postMessage({appId: this.appId, message: encrypted});
|
||||||
}
|
}
|
||||||
|
|
||||||
getResponse(): Promise<any> {
|
getResponse(): Promise<any> {
|
||||||
@ -152,6 +152,27 @@ export class NativeMessagingBackground {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private postMessage(message: any) {
|
||||||
|
// Wrap in try-catch to when the port disconnected without triggering `onDisconnect`.
|
||||||
|
try {
|
||||||
|
this.port.postMessage(message);
|
||||||
|
} catch (e) {
|
||||||
|
// tslint:disable-next-line
|
||||||
|
console.error("NativeMessaging port disconnected, disconnecting.");
|
||||||
|
|
||||||
|
this.sharedSecret = null;
|
||||||
|
this.privateKey = null;
|
||||||
|
this.connected = false;
|
||||||
|
|
||||||
|
this.messagingService.send('showDialog', {
|
||||||
|
text: this.i18nService.t('nativeMessagingInvalidEncryptionDesc'),
|
||||||
|
title: this.i18nService.t('nativeMessagingInvalidEncryptionTitle'),
|
||||||
|
confirmText: this.i18nService.t('ok'),
|
||||||
|
type: 'error',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private async onMessage(rawMessage: any) {
|
private async onMessage(rawMessage: any) {
|
||||||
const message = JSON.parse(await this.cryptoService.decryptToUtf8(rawMessage, this.sharedSecret));
|
const message = JSON.parse(await this.cryptoService.decryptToUtf8(rawMessage, this.sharedSecret));
|
||||||
|
|
||||||
@ -229,7 +250,7 @@ export class NativeMessagingBackground {
|
|||||||
|
|
||||||
message.timestamp = Date.now();
|
message.timestamp = Date.now();
|
||||||
|
|
||||||
this.port.postMessage({appId: this.appId, message: message});
|
this.postMessage({appId: this.appId, message: message});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async showFingerprintDialog() {
|
private async showFingerprintDialog() {
|
||||||
|
Loading…
Reference in New Issue
Block a user