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

@@ -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."

View File

@@ -6,6 +6,7 @@ import { Options } from "./lib/options";
export default {
bridgeApplicationName: APPLICATION_NAME
, bridgeBackupEnabled: false
, mediaEnabled: true
, mediaOverlayEnabled: false
, mediaSyncElement: false

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);

View File

@@ -15,6 +15,7 @@ const storageArea = new TypedStorageArea<{
export interface Options {
bridgeApplicationName: string;
bridgeBackupEnabled: boolean;
mediaEnabled: boolean;
mediaOverlayEnabled: boolean;
mediaSyncElement: boolean;

View File

@@ -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<BridgeProps, BridgeState> {
, 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<BridgeProps, BridgeState> {
</div> )
: this.renderStatus() }
{ !this.props.loading && this.state.bridgeBackupEnabled !== undefined &&
<div className="bridge__options">
<label className="option option--inline">
<div className="option__control">
<input name="bridgeBackupEnabled"
type="checkbox"
checked={ this.state.bridgeBackupEnabled }
onChange={ ev => {
options.set("bridgeBackupEnabled"
, ev.target.checked);
}} />
</div>
<div className="option__label">
{ _("optionsBridgeBackupEnabled") }
</div>
<div className="option__description">
{ _("optionsBridgeBackupEnabledDescription") }
</div>
</label>
</div> }
{ !this.props.loading &&
<div className="bridge__update-info">
{ this.state.isUpdateAvailable

View File

@@ -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 {