mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 18:19:58 +00:00
Add option to enable/disable the backup bridge daemon connection
This commit is contained in:
@@ -201,6 +201,15 @@
|
|||||||
, "description": "Update now button title. Ellipsis indicates additional information as it triggers an update window popup."
|
, "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": {
|
, "optionsMediaCategoryName": {
|
||||||
"message": "Media casting"
|
"message": "Media casting"
|
||||||
, "description": "Options page media casting category title."
|
, "description": "Options page media casting category title."
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { Options } from "./lib/options";
|
|||||||
|
|
||||||
export default {
|
export default {
|
||||||
bridgeApplicationName: APPLICATION_NAME
|
bridgeApplicationName: APPLICATION_NAME
|
||||||
|
, bridgeBackupEnabled: false
|
||||||
, mediaEnabled: true
|
, mediaEnabled: true
|
||||||
, mediaOverlayEnabled: false
|
, mediaOverlayEnabled: false
|
||||||
, mediaSyncElement: false
|
, mediaSyncElement: false
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
import logger from "./logger";
|
import logger from "./logger";
|
||||||
|
import options from "./options";
|
||||||
|
|
||||||
|
|
||||||
const WEBSOCKET_DAEMON_URL = "ws://localhost:9556";
|
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) {
|
if (port.error && !isNativeHostStatusKnown) {
|
||||||
isNativeHostStatusKnown = true;
|
isNativeHostStatusKnown = true;
|
||||||
|
|
||||||
@@ -152,7 +166,11 @@ async function sendNativeMessage (
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return await browser.runtime.sendNativeMessage(application, message);
|
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) => {
|
return await new Promise((resolve, reject) => {
|
||||||
const ws = new WebSocket(WEBSOCKET_DAEMON_URL);
|
const ws = new WebSocket(WEBSOCKET_DAEMON_URL);
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ const storageArea = new TypedStorageArea<{
|
|||||||
|
|
||||||
export interface Options {
|
export interface Options {
|
||||||
bridgeApplicationName: string;
|
bridgeApplicationName: string;
|
||||||
|
bridgeBackupEnabled: boolean;
|
||||||
mediaEnabled: boolean;
|
mediaEnabled: boolean;
|
||||||
mediaOverlayEnabled: boolean;
|
mediaOverlayEnabled: boolean;
|
||||||
mediaSyncElement: boolean;
|
mediaSyncElement: boolean;
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import semver from "semver";
|
import semver from "semver";
|
||||||
|
|
||||||
|
import options from "../../lib/options";
|
||||||
|
|
||||||
import { BridgeInfo } from "../../lib/bridge";
|
import { BridgeInfo } from "../../lib/bridge";
|
||||||
import { getNextEllipsis } from "../../lib/utils";
|
import { getNextEllipsis } from "../../lib/utils";
|
||||||
|
|
||||||
@@ -67,6 +69,7 @@ interface BridgeState {
|
|||||||
isUpdateAvailable: boolean;
|
isUpdateAvailable: boolean;
|
||||||
wasErrorCheckingUpdates: boolean;
|
wasErrorCheckingUpdates: boolean;
|
||||||
checkUpdatesEllipsis: string;
|
checkUpdatesEllipsis: string;
|
||||||
|
bridgeBackupEnabled?: boolean;
|
||||||
updateStatus?: string;
|
updateStatus?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +87,11 @@ export default class Bridge extends Component<BridgeProps, BridgeState> {
|
|||||||
, checkUpdatesEllipsis: "..."
|
, checkUpdatesEllipsis: "..."
|
||||||
};
|
};
|
||||||
|
|
||||||
|
options.get("bridgeBackupEnabled")
|
||||||
|
.then(bridgeBackupEnabled => {
|
||||||
|
this.setState({ bridgeBackupEnabled });
|
||||||
|
});
|
||||||
|
|
||||||
this.onCheckUpdates = this.onCheckUpdates.bind(this);
|
this.onCheckUpdates = this.onCheckUpdates.bind(this);
|
||||||
this.onCheckUpdatesResponse = this.onCheckUpdatesResponse.bind(this);
|
this.onCheckUpdatesResponse = this.onCheckUpdatesResponse.bind(this);
|
||||||
this.onCheckUpdatesError = this.onCheckUpdatesError.bind(this);
|
this.onCheckUpdatesError = this.onCheckUpdatesError.bind(this);
|
||||||
@@ -100,6 +108,27 @@ export default class Bridge extends Component<BridgeProps, BridgeState> {
|
|||||||
</div> )
|
</div> )
|
||||||
: this.renderStatus() }
|
: 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 &&
|
{ !this.props.loading &&
|
||||||
<div className="bridge__update-info">
|
<div className="bridge__update-info">
|
||||||
{ this.state.isUpdateAvailable
|
{ this.state.isUpdateAvailable
|
||||||
|
|||||||
@@ -129,10 +129,14 @@
|
|||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bridge__options {
|
||||||
|
margin-top: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
.bridge__update-info {
|
.bridge__update-info {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
display: flex;
|
display: flex;
|
||||||
margin-top: 30px;
|
margin-top: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bridge__update-label {
|
.bridge__update-label {
|
||||||
|
|||||||
Reference in New Issue
Block a user