Add option to enable/disable the backup bridge daemon connection

This commit is contained in:
hensm
2020-01-23 16:46:45 +00:00
parent 13dfb26dd4
commit f2bb46d7c4
6 changed files with 65 additions and 3 deletions

View File

@@ -1,6 +1,8 @@
"use strict";
import logger from "./logger";
import options from "./options";
const WEBSOCKET_DAEMON_URL = "ws://localhost:9556";
@@ -96,7 +98,19 @@ function connectNative (application: string) {
};
port.onDisconnect.addListener(() => {
port.onDisconnect.addListener(async () => {
if (!(await options.get("bridgeBackupEnabled"))) {
portObject.error = {
message: ""
};
for (const listener of onDisconnectListeners) {
listener(portObject);
}
throw logger.error("Bridge connection failed and backup not enabled.");
}
if (port.error && !isNativeHostStatusKnown) {
isNativeHostStatusKnown = true;
@@ -152,7 +166,11 @@ async function sendNativeMessage (
try {
return await browser.runtime.sendNativeMessage(application, message);
} catch (err) {
} catch {
if (!(await options.get("bridgeBackupEnabled"))) {
throw logger.error("Bridge connection failed and backup not enabled.");
}
return await new Promise((resolve, reject) => {
const ws = new WebSocket(WEBSOCKET_DAEMON_URL);