mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-10 01:29:58 +00:00
Disable browser action unless there are available receivers
This commit is contained in:
@@ -21,6 +21,7 @@ import ReceiverSelectorManager
|
||||
|
||||
import createMenus from "./background/createMenus";
|
||||
import ShimManager from "./background/ShimManager";
|
||||
import StatusManager from "./background/StatusManager";
|
||||
|
||||
|
||||
const _ = browser.i18n.getMessage;
|
||||
@@ -48,6 +49,39 @@ browser.runtime.onInstalled.addListener(async details => {
|
||||
|
||||
|
||||
|
||||
function initBrowserAction () {
|
||||
browser.browserAction.disable();
|
||||
|
||||
function onServiceChange () {
|
||||
if (StatusManager.getReceivers().length) {
|
||||
browser.browserAction.enable();
|
||||
} else {
|
||||
browser.browserAction.disable();
|
||||
}
|
||||
}
|
||||
|
||||
StatusManager.addEventListener("serviceUp", onServiceChange);
|
||||
StatusManager.addEventListener("serviceDown", onServiceChange);
|
||||
|
||||
|
||||
/**
|
||||
* When the browser action is clicked, open a receiver
|
||||
* selector and load a sender for the response. The
|
||||
* mirroring sender is loaded into the current tab at the
|
||||
* top-level frame.
|
||||
*/
|
||||
browser.browserAction.onClicked.addListener(async tab => {
|
||||
const selection = await ReceiverSelectorManager.getSelection();
|
||||
|
||||
loadSender({
|
||||
tabId: tab.id
|
||||
, frameId: 0
|
||||
, selection
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
async function initMenus () {
|
||||
console.info("fx_cast (Debug): init (menus)");
|
||||
|
||||
@@ -265,9 +299,13 @@ async function init () {
|
||||
await initRequestListener();
|
||||
await initWhitelist();
|
||||
|
||||
await StatusManager.init();
|
||||
await ShimManager.init();
|
||||
|
||||
|
||||
await initBrowserAction();
|
||||
|
||||
|
||||
/**
|
||||
* When a message port connection with the name "shim" is
|
||||
* established, pass it to createShim to handle the setup
|
||||
@@ -278,22 +316,6 @@ async function init () {
|
||||
ShimManager.createShim(port);
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* When the browser action is clicked, open a receiver
|
||||
* selector and load a sender for the response. The
|
||||
* mirroring sender is loaded into the current tab at the
|
||||
* top-level frame.
|
||||
*/
|
||||
browser.browserAction.onClicked.addListener(async tab => {
|
||||
const selection = await ReceiverSelectorManager.getSelection();
|
||||
|
||||
loadSender({
|
||||
tabId: tab.id
|
||||
, frameId: 0
|
||||
, selection
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
Reference in New Issue
Block a user