From 222665dd9d4e0aec3b94fa831b0bbc597571d117 Mon Sep 17 00:00:00 2001 From: Hinton Date: Wed, 21 Oct 2020 19:23:27 +0200 Subject: [PATCH] Fix error in firefox --- src/background/nativeMessaging.background.ts | 12 +++++++++--- src/browser/browserApi.ts | 8 -------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/background/nativeMessaging.background.ts b/src/background/nativeMessaging.background.ts index a03554da27..562fd21b31 100644 --- a/src/background/nativeMessaging.background.ts +++ b/src/background/nativeMessaging.background.ts @@ -67,9 +67,15 @@ export class NativeMessagingBackground { } }); - this.port.onDisconnect.addListener(() => { - const error = BrowserApi.runtimeLastError().message; - if (error === 'Specified native messaging host not found.' || error === 'Access to the specified native messaging host is forbidden.') { + this.port.onDisconnect.addListener((p: any) => { + let error; + if (BrowserApi.isWebExtensionsApi) { + error = p.error.message; + } else { + error = chrome.runtime.lastError.message; + } + + if (error === 'Specified native messaging host not found.' || error === 'Access to the specified native messaging host is forbidden.' || error === 'An unexpected error occurred') { this.messagingService.send('showDialog', { text: this.i18nService.t('desktopIntegrationDisabledDesc'), title: this.i18nService.t('desktopIntegrationDisabledTitle'), diff --git a/src/browser/browserApi.ts b/src/browser/browserApi.ts index 660defcca3..1ee54a45b1 100644 --- a/src/browser/browserApi.ts +++ b/src/browser/browserApi.ts @@ -229,12 +229,4 @@ export class BrowserApi { return chrome.runtime.connectNative(application); } } - - static runtimeLastError(): browser.runtime._LastError | chrome.runtime.LastError { - if (BrowserApi.isWebExtensionsApi) { - return browser.runtime.lastError; - } else if (BrowserApi.isChromeApi) { - return chrome.runtime.lastError; - } - } }