diff --git a/ext/src/_locales/en/messages.json b/ext/src/_locales/en/messages.json index 85c24b7..806925b 100755 --- a/ext/src/_locales/en/messages.json +++ b/ext/src/_locales/en/messages.json @@ -201,6 +201,15 @@ , "description": "Update now button title. Ellipsis indicates additional information as it triggers an update window popup." } + , "optionsBridgeBackupEnabled": { + "message": "Enable backup daemon connection" + , "description": "Backup daemon checkbox label." + } + , "optionsBridgeBackupEnabledDescription": { + "message": "If the regular bridge connection fails, attempt to connect to a bridge running in daemon mode." + , "description": "Backup daemon checkbox description." + } + , "optionsMediaCategoryName": { "message": "Media casting" , "description": "Options page media casting category title." diff --git a/ext/src/defaultOptions.ts b/ext/src/defaultOptions.ts index 0763e8a..3ccdcce 100644 --- a/ext/src/defaultOptions.ts +++ b/ext/src/defaultOptions.ts @@ -6,6 +6,7 @@ import { Options } from "./lib/options"; export default { bridgeApplicationName: APPLICATION_NAME + , bridgeBackupEnabled: false , mediaEnabled: true , mediaOverlayEnabled: false , mediaSyncElement: false diff --git a/ext/src/lib/nativeMessaging.ts b/ext/src/lib/nativeMessaging.ts index ff26521..79e0118 100644 --- a/ext/src/lib/nativeMessaging.ts +++ b/ext/src/lib/nativeMessaging.ts @@ -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); diff --git a/ext/src/lib/options.ts b/ext/src/lib/options.ts index 899c5cf..7e3d7a2 100644 --- a/ext/src/lib/options.ts +++ b/ext/src/lib/options.ts @@ -15,6 +15,7 @@ const storageArea = new TypedStorageArea<{ export interface Options { bridgeApplicationName: string; + bridgeBackupEnabled: boolean; mediaEnabled: boolean; mediaOverlayEnabled: boolean; mediaSyncElement: boolean; diff --git a/ext/src/ui/options/Bridge.tsx b/ext/src/ui/options/Bridge.tsx index 8151063..70ab8f5 100644 --- a/ext/src/ui/options/Bridge.tsx +++ b/ext/src/ui/options/Bridge.tsx @@ -4,6 +4,8 @@ import React, { Component } from "react"; import semver from "semver"; +import options from "../../lib/options"; + import { BridgeInfo } from "../../lib/bridge"; import { getNextEllipsis } from "../../lib/utils"; @@ -67,6 +69,7 @@ interface BridgeState { isUpdateAvailable: boolean; wasErrorCheckingUpdates: boolean; checkUpdatesEllipsis: string; + bridgeBackupEnabled?: boolean; updateStatus?: string; } @@ -84,6 +87,11 @@ export default class Bridge extends Component { , checkUpdatesEllipsis: "..." }; + options.get("bridgeBackupEnabled") + .then(bridgeBackupEnabled => { + this.setState({ bridgeBackupEnabled }); + }); + this.onCheckUpdates = this.onCheckUpdates.bind(this); this.onCheckUpdatesResponse = this.onCheckUpdatesResponse.bind(this); this.onCheckUpdatesError = this.onCheckUpdatesError.bind(this); @@ -100,6 +108,27 @@ export default class Bridge extends Component { ) : this.renderStatus() } + { !this.props.loading && this.state.bridgeBackupEnabled !== undefined && +
+ +
} + { !this.props.loading &&
{ this.state.isUpdateAvailable diff --git a/ext/src/ui/options/styles/index.css b/ext/src/ui/options/styles/index.css index 62be244..1e9af72 100644 --- a/ext/src/ui/options/styles/index.css +++ b/ext/src/ui/options/styles/index.css @@ -129,10 +129,14 @@ white-space: nowrap; } +.bridge__options { + margin-top: 30px; +} + .bridge__update-info { align-items: center; display: flex; - margin-top: 30px; + margin-top: 10px; } .bridge__update-label {