mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-10 01:29:58 +00:00
Refresh device manager with options bridge status and propagate to popup
This commit is contained in:
@@ -149,11 +149,15 @@ export default class ReceiverSelector extends TypedEventTarget<ReceiverSelectorE
|
||||
}
|
||||
|
||||
/** Updates receiver devices displayed in the receiver selector. */
|
||||
public update(devices: ReceiverDevice[], connectedSessionIds: string[]) {
|
||||
public update(
|
||||
devices: ReceiverDevice[],
|
||||
isBridgeCompatible: boolean,
|
||||
connectedSessionIds: string[]
|
||||
) {
|
||||
this.devices = devices;
|
||||
this.messagePort?.postMessage({
|
||||
subject: "popup:update",
|
||||
data: { devices, connectedSessionIds }
|
||||
data: { devices, isBridgeCompatible, connectedSessionIds }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -205,8 +209,7 @@ export default class ReceiverSelector extends TypedEventTarget<ReceiverSelectorE
|
||||
subject: "popup:init",
|
||||
data: {
|
||||
appInfo: this.appInfo,
|
||||
pageInfo: this.pageInfo,
|
||||
isBridgeCompatible: this.isBridgeCompatible
|
||||
pageInfo: this.pageInfo
|
||||
}
|
||||
});
|
||||
|
||||
@@ -214,6 +217,7 @@ export default class ReceiverSelector extends TypedEventTarget<ReceiverSelectorE
|
||||
subject: "popup:update",
|
||||
data: {
|
||||
devices: this.devices,
|
||||
isBridgeCompatible: this.isBridgeCompatible,
|
||||
defaultMediaType: this.defaultMediaType,
|
||||
availableMediaTypes: this.availableMediaTypes
|
||||
}
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
import defaultOptions from "../defaultOptions";
|
||||
import logger from "../lib/logger";
|
||||
import options from "../lib/options";
|
||||
import bridge, { BridgeInfo } from "../lib/bridge";
|
||||
import { baseConfigStorage, fetchBaseConfig } from "../lib/chromecastConfigApi";
|
||||
|
||||
import defaultOptions from "../defaultOptions";
|
||||
import messaging from "../messaging";
|
||||
|
||||
import castManager from "./castManager";
|
||||
import deviceManager from "./deviceManager";
|
||||
|
||||
import { initMenus } from "./menus";
|
||||
import { initWhitelist } from "./whitelist";
|
||||
import { baseConfigStorage, fetchBaseConfig } from "../lib/chromecastConfigApi";
|
||||
|
||||
const _ = browser.i18n.getMessage;
|
||||
|
||||
@@ -130,6 +132,14 @@ async function init() {
|
||||
await initMenus();
|
||||
await initWhitelist();
|
||||
|
||||
messaging.onMessage.addListener(message => {
|
||||
switch (message.subject) {
|
||||
case "main:refreshDeviceManager":
|
||||
deviceManager.refresh();
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
browser.browserAction.onClicked.addListener(async tab => {
|
||||
if (tab.id === undefined) {
|
||||
logger.error("Tab ID not found in browser action handler.");
|
||||
|
||||
@@ -761,7 +761,11 @@ function createSelector() {
|
||||
}
|
||||
}
|
||||
|
||||
selector.update(deviceManager.getDevices(), connectedSessionIds);
|
||||
selector.update(
|
||||
deviceManager.getDevices(),
|
||||
deviceManager.getBridgeInfo()?.isVersionCompatible ?? false,
|
||||
connectedSessionIds
|
||||
);
|
||||
};
|
||||
|
||||
deviceManager.addEventListener("deviceUp", onDeviceChange);
|
||||
|
||||
@@ -47,7 +47,6 @@ export default new (class extends TypedEventTarget<EventMap> {
|
||||
*/
|
||||
async refresh() {
|
||||
this.bridgePort?.disconnect();
|
||||
this.receiverDevices.clear();
|
||||
|
||||
try {
|
||||
this.bridgeInfo = await bridge.getInfo();
|
||||
@@ -218,20 +217,28 @@ export default new (class extends TypedEventTarget<EventMap> {
|
||||
};
|
||||
|
||||
private onBridgeDisconnect = () => {
|
||||
const deviceIds = [...this.receiverDevices.keys()];
|
||||
|
||||
delete this.bridgeInfo;
|
||||
this.receiverDevices.clear();
|
||||
|
||||
// Notify listeners of device availablility
|
||||
for (const [, receiverDevice] of this.receiverDevices) {
|
||||
for (const deviceId of deviceIds) {
|
||||
const event = new CustomEvent("deviceDown", {
|
||||
detail: { deviceId: receiverDevice.id }
|
||||
detail: { deviceId }
|
||||
});
|
||||
|
||||
this.dispatchEvent(event);
|
||||
}
|
||||
|
||||
this.receiverDevices.clear();
|
||||
|
||||
// Re-initialize after 10 seconds
|
||||
/**
|
||||
* Reconnect 10 seconds after disconnect if not already
|
||||
* reconnected (like immediately after a refresh).
|
||||
*/
|
||||
window.setTimeout(() => {
|
||||
this.refresh();
|
||||
if (!this.bridgeInfo) {
|
||||
this.refresh();
|
||||
}
|
||||
}, 10000);
|
||||
};
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user