Add popup warning banner when the bridge has a problem

This commit is contained in:
hensm
2022-09-03 19:08:37 +01:00
parent 89acad2f9e
commit 25bd72f0fe
10 changed files with 120 additions and 34 deletions

View File

@@ -1,4 +1,4 @@
import bridge from "../lib/bridge";
import bridge, { BridgeInfo } from "../lib/bridge";
import logger from "../lib/logger";
import { TypedEventTarget } from "../lib/TypedEventTarget";
@@ -34,6 +34,7 @@ export default new (class extends TypedEventTarget<EventMap> {
private receiverDevices = new Map<string, ReceiverDevice>();
private bridgePort?: Port;
private bridgeInfo?: BridgeInfo;
async init() {
if (!this.bridgePort) {
await this.refresh();
@@ -48,17 +49,28 @@ export default new (class extends TypedEventTarget<EventMap> {
this.bridgePort?.disconnect();
this.receiverDevices.clear();
this.bridgePort = await bridge.connect();
this.bridgePort.onMessage.addListener(this.onBridgeMessage);
this.bridgePort.onDisconnect.addListener(this.onBridgeDisconnect);
try {
this.bridgeInfo = await bridge.getInfo();
// eslint-disable-next-line no-empty
} catch {}
this.bridgePort.postMessage({
subject: "bridge:startDiscovery",
data: {
// Also send back status messages
shouldWatchStatus: true
}
});
if (this.bridgeInfo?.isVersionCompatible) {
this.bridgePort = await bridge.connect();
this.bridgePort.onMessage.addListener(this.onBridgeMessage);
this.bridgePort.onDisconnect.addListener(this.onBridgeDisconnect);
this.bridgePort.postMessage({
subject: "bridge:startDiscovery",
data: {
// Also send back status messages
shouldWatchStatus: true
}
});
}
}
getBridgeInfo() {
return this.bridgeInfo;
}
/** Gets a list of receiver devices. */