mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 18:19:58 +00:00
Improve handling of bridge errors
This commit is contained in:
@@ -5,7 +5,7 @@ import loadSender from "../lib/loadSender";
|
|||||||
import logger from "../lib/logger";
|
import logger from "../lib/logger";
|
||||||
import messaging from "../messaging";
|
import messaging from "../messaging";
|
||||||
import options from "../lib/options";
|
import options from "../lib/options";
|
||||||
import bridge from "../lib/bridge";
|
import bridge, { BridgeInfo } from "../lib/bridge";
|
||||||
|
|
||||||
import { getChromeUserAgent } from "../lib/userAgents";
|
import { getChromeUserAgent } from "../lib/userAgents";
|
||||||
import { getMediaTypesForPageUrl, stringify } from "../lib/utils";
|
import { getMediaTypesForPageUrl, stringify } from "../lib/utils";
|
||||||
@@ -656,7 +656,13 @@ async function initMediaOverlay () {
|
|||||||
async function checkBridgeCompat () {
|
async function checkBridgeCompat () {
|
||||||
logger.info("checking for bridge...");
|
logger.info("checking for bridge...");
|
||||||
|
|
||||||
const info = await bridge.getInfo();
|
let info: BridgeInfo;
|
||||||
|
try {
|
||||||
|
info = await bridge.getInfo();
|
||||||
|
} catch (err) {
|
||||||
|
logger.info("... bridge issue!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (info.isVersionCompatible) {
|
if (info.isVersionCompatible) {
|
||||||
logger.info("... bridge compatible!");
|
logger.info("... bridge compatible!");
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ const BridgeStats = (props: BridgeStatsProps) => (
|
|||||||
interface BridgeProps {
|
interface BridgeProps {
|
||||||
info?: BridgeInfo;
|
info?: BridgeInfo;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
|
loadingTimedOut: boolean;
|
||||||
options?: Options;
|
options?: Options;
|
||||||
onChange: (ev: React.ChangeEvent<HTMLInputElement>) => void;
|
onChange: (ev: React.ChangeEvent<HTMLInputElement>) => void;
|
||||||
}
|
}
|
||||||
@@ -177,15 +178,20 @@ export default class Bridge extends Component<BridgeProps, BridgeState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private renderStatus () {
|
private renderStatus () {
|
||||||
const infoClasses = `bridge__info ${this.props.info
|
const infoClasses = `bridge__info ${!this.props.info
|
||||||
? "bridge__info--found"
|
? this.props.loadingTimedOut
|
||||||
: "bridge__info--not-found"}`;
|
? "bridge__info--timed-out"
|
||||||
|
: "bridge__info--not-found"
|
||||||
|
: "bridge__info--found"}`;
|
||||||
|
|
||||||
let statusIcon: string;
|
let statusIcon: string;
|
||||||
let statusTitle: string;
|
let statusTitle: string;
|
||||||
let statusText: (string | null);
|
let statusText: (string | null) = null;
|
||||||
|
|
||||||
if (!this.props.info) {
|
if (this.props.loadingTimedOut) {
|
||||||
|
statusIcon = "assets/icons8-warn-120.png";
|
||||||
|
statusTitle = _("optionsBridgeIssueStatusTitle");
|
||||||
|
} else if (!this.props.info) {
|
||||||
statusIcon = "assets/icons8-cancel-120.png";
|
statusIcon = "assets/icons8-cancel-120.png";
|
||||||
statusTitle = _("optionsBridgeNotFoundStatusTitle");
|
statusTitle = _("optionsBridgeNotFoundStatusTitle");
|
||||||
statusText = _("optionsBridgeNotFoundStatusText");
|
statusText = _("optionsBridgeNotFoundStatusText");
|
||||||
@@ -197,8 +203,6 @@ export default class Bridge extends Component<BridgeProps, BridgeState> {
|
|||||||
statusIcon = "assets/icons8-warn-120.png";
|
statusIcon = "assets/icons8-warn-120.png";
|
||||||
statusTitle = _("optionsBridgeIssueStatusTitle");
|
statusTitle = _("optionsBridgeIssueStatusTitle");
|
||||||
}
|
}
|
||||||
|
|
||||||
statusText = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -106,6 +106,7 @@ function getInputValue (input: HTMLInputElement) {
|
|||||||
interface OptionsAppState {
|
interface OptionsAppState {
|
||||||
hasLoaded: boolean;
|
hasLoaded: boolean;
|
||||||
bridgeLoading: boolean;
|
bridgeLoading: boolean;
|
||||||
|
bridgeLoadingTimedOut: boolean;
|
||||||
isFormValid: boolean;
|
isFormValid: boolean;
|
||||||
hasSaved: boolean;
|
hasSaved: boolean;
|
||||||
|
|
||||||
@@ -123,6 +124,7 @@ class OptionsApp extends Component<{}, OptionsAppState> {
|
|||||||
this.state = {
|
this.state = {
|
||||||
hasLoaded: false
|
hasLoaded: false
|
||||||
, bridgeLoading: true
|
, bridgeLoading: true
|
||||||
|
, bridgeLoadingTimedOut: false
|
||||||
, isFormValid: true
|
, isFormValid: true
|
||||||
, hasSaved: false
|
, hasSaved: false
|
||||||
};
|
};
|
||||||
@@ -147,6 +149,13 @@ class OptionsApp extends Component<{}, OptionsAppState> {
|
|||||||
, platform: (await browser.runtime.getPlatformInfo()).os
|
, platform: (await browser.runtime.getPlatformInfo()).os
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const bridgeTimeoutId = setTimeout(() => {
|
||||||
|
this.setState({
|
||||||
|
bridgeLoading: false
|
||||||
|
, bridgeLoadingTimedOut: true
|
||||||
|
});
|
||||||
|
}, 500);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const bridgeInfo = await bridge.getInfo();
|
const bridgeInfo = await bridge.getInfo();
|
||||||
|
|
||||||
@@ -161,6 +170,8 @@ class OptionsApp extends Component<{}, OptionsAppState> {
|
|||||||
bridgeLoading: false
|
bridgeLoading: false
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearTimeout(bridgeTimeoutId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public render () {
|
public render () {
|
||||||
@@ -176,6 +187,7 @@ class OptionsApp extends Component<{}, OptionsAppState> {
|
|||||||
|
|
||||||
<Bridge info={ this.state.bridgeInfo }
|
<Bridge info={ this.state.bridgeInfo }
|
||||||
loading={ this.state.bridgeLoading }
|
loading={ this.state.bridgeLoading }
|
||||||
|
loadingTimedOut={ this.state.bridgeLoadingTimedOut }
|
||||||
options={ this.state.options }
|
options={ this.state.options }
|
||||||
onChange={ this.handleInputChange } />
|
onChange={ this.handleInputChange } />
|
||||||
|
|
||||||
|
|||||||
@@ -130,6 +130,12 @@ button.ghost:not(:hover) {
|
|||||||
padding-inline-end: 25px;
|
padding-inline-end: 25px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bridge__info--timed-out .bridge__status {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
gap: 20px;
|
||||||
|
}
|
||||||
|
|
||||||
.bridge__status-title {
|
.bridge__status-title {
|
||||||
margin: initial;
|
margin: initial;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
@@ -141,7 +147,6 @@ button.ghost:not(:hover) {
|
|||||||
margin: initial;
|
margin: initial;
|
||||||
margin-top: 5px;
|
margin-top: 5px;
|
||||||
font-size: 1.15em;
|
font-size: 1.15em;
|
||||||
font-weight: 300;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +167,6 @@ button.ghost:not(:hover) {
|
|||||||
}
|
}
|
||||||
.bridge__info--not-found .bridge__status-title {
|
.bridge__info--not-found .bridge__status-title {
|
||||||
grid-area: status-title;
|
grid-area: status-title;
|
||||||
font-weight: normal;
|
|
||||||
white-space: normal;
|
white-space: normal;
|
||||||
}
|
}
|
||||||
.bridge__info--not-found .bridge__status-text {
|
.bridge__info--not-found .bridge__status-text {
|
||||||
|
|||||||
Reference in New Issue
Block a user