mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-12 02:29:59 +00:00
Unify receiver selector launching and allow switching to app media type
This commit is contained in:
@@ -156,15 +156,11 @@ export default new class ShimManager {
|
|||||||
|
|
||||||
case "main:/selectReceiverBegin": {
|
case "main:/selectReceiverBegin": {
|
||||||
const contentTab = await browser.tabs.get(shim.contentTabId);
|
const contentTab = await browser.tabs.get(shim.contentTabId);
|
||||||
const availableMediaTypes = getMediaTypesForPageUrl(
|
|
||||||
contentTab.url);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const selection = await ReceiverSelectorManager
|
const selection =
|
||||||
.getSelection(
|
await ReceiverSelectorManager.getSelection(
|
||||||
ReceiverSelectorMediaType.App
|
shim.contentTabId, shim.contentFrameId);
|
||||||
, availableMediaTypes
|
|
||||||
, shim.requestedAppId);
|
|
||||||
|
|
||||||
// Handle cancellation
|
// Handle cancellation
|
||||||
if (!selection) {
|
if (!selection) {
|
||||||
|
|||||||
@@ -65,12 +65,7 @@ function initBrowserAction () {
|
|||||||
* top-level frame.
|
* top-level frame.
|
||||||
*/
|
*/
|
||||||
browser.browserAction.onClicked.addListener(async tab => {
|
browser.browserAction.onClicked.addListener(async tab => {
|
||||||
const currentShim = ShimManager.getShim(tab.id);
|
const selection = await ReceiverSelectorManager.getSelection(tab.id);
|
||||||
const selection = await ReceiverSelectorManager.getSelection(
|
|
||||||
ReceiverSelectorMediaType.Tab
|
|
||||||
, getMediaTypesForPageUrl(tab.url)
|
|
||||||
& ~ReceiverSelectorMediaType.App
|
|
||||||
, currentShim.requestedAppId);
|
|
||||||
|
|
||||||
if (selection) {
|
if (selection) {
|
||||||
loadSender({
|
loadSender({
|
||||||
@@ -161,11 +156,8 @@ async function initMenus () {
|
|||||||
|
|
||||||
switch (info.menuItemId) {
|
switch (info.menuItemId) {
|
||||||
case menuIdMediaCast: {
|
case menuIdMediaCast: {
|
||||||
const currentShim = ShimManager.getShim(tab.id, info.frameId);
|
|
||||||
const selection = await ReceiverSelectorManager.getSelection(
|
const selection = await ReceiverSelectorManager.getSelection(
|
||||||
ReceiverSelectorMediaType.App
|
tab.id, info.frameId);
|
||||||
, availableMediaTypes
|
|
||||||
, currentShim.requestedAppId);
|
|
||||||
|
|
||||||
// Selection cancelled
|
// Selection cancelled
|
||||||
if (!selection) {
|
if (!selection) {
|
||||||
@@ -204,11 +196,8 @@ async function initMenus () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
case menuIdMirroringCast: {
|
case menuIdMirroringCast: {
|
||||||
const currentShim = ShimManager.getShim(tab.id, info.frameId);
|
|
||||||
const selection = await ReceiverSelectorManager.getSelection(
|
const selection = await ReceiverSelectorManager.getSelection(
|
||||||
ReceiverSelectorMediaType.Tab
|
tab.id, info.frameId);
|
||||||
, availableMediaTypes & ~ReceiverSelectorMediaType.App
|
|
||||||
, currentShim.requestedAppId);
|
|
||||||
|
|
||||||
loadSender({
|
loadSender({
|
||||||
tabId: tab.id
|
tabId: tab.id
|
||||||
|
|||||||
@@ -2,8 +2,11 @@
|
|||||||
|
|
||||||
import options from "../../lib/options";
|
import options from "../../lib/options";
|
||||||
|
|
||||||
|
import ShimManager from "../ShimManager";
|
||||||
import StatusManager from "../StatusManager";
|
import StatusManager from "../StatusManager";
|
||||||
|
|
||||||
|
import { getMediaTypesForPageUrl } from "../../lib/utils";
|
||||||
|
|
||||||
import { ReceiverSelector
|
import { ReceiverSelector
|
||||||
, ReceiverSelectorType } from "./";
|
, ReceiverSelectorType } from "./";
|
||||||
import { ReceiverSelection
|
import { ReceiverSelection
|
||||||
@@ -49,16 +52,50 @@ async function getSelector () {
|
|||||||
* - Rejects if the selection fails.
|
* - Rejects if the selection fails.
|
||||||
*/
|
*/
|
||||||
async function getSelection (
|
async function getSelection (
|
||||||
defaultMediaType =
|
contextTabId: number
|
||||||
ReceiverSelectorMediaType.Tab
|
, contextFrameId = 0)
|
||||||
, availableMediaTypes =
|
|
||||||
ReceiverSelectorMediaType.Tab
|
|
||||||
| ReceiverSelectorMediaType.Screen
|
|
||||||
| ReceiverSelectorMediaType.File
|
|
||||||
, requestedAppId: string)
|
|
||||||
: Promise<ReceiverSelection> {
|
: Promise<ReceiverSelection> {
|
||||||
|
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
|
const currentShim = ShimManager.getShim(
|
||||||
|
contextTabId, contextFrameId);
|
||||||
|
|
||||||
|
let defaultMediaType = ReceiverSelectorMediaType.Tab;
|
||||||
|
let availableMediaTypes;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { url } = await browser.webNavigation.getFrame({
|
||||||
|
tabId: contextTabId
|
||||||
|
, frameId: contextFrameId
|
||||||
|
});
|
||||||
|
|
||||||
|
availableMediaTypes = getMediaTypesForPageUrl(url);
|
||||||
|
} catch (err) {
|
||||||
|
console.error("fx_cast (Debug): Failed to locate frame");
|
||||||
|
reject();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Enable app media type if initialized sender app is found
|
||||||
|
if (currentShim) {
|
||||||
|
defaultMediaType = ReceiverSelectorMediaType.App;
|
||||||
|
availableMediaTypes |= ReceiverSelectorMediaType.App;
|
||||||
|
}
|
||||||
|
|
||||||
|
const opts = await options.getAll();
|
||||||
|
|
||||||
|
// Remove mirroring media types if mirroring is not enabled
|
||||||
|
if (!opts.mirroringEnabled) {
|
||||||
|
availableMediaTypes &= ~(
|
||||||
|
ReceiverSelectorMediaType.Tab
|
||||||
|
| ReceiverSelectorMediaType.Screen);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove file media type if local media is not enabled
|
||||||
|
if (!opts.mediaEnabled || !opts.localMediaEnabled) {
|
||||||
|
availableMediaTypes &= ~ReceiverSelectorMediaType.File;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Close an existing open selector
|
// Close an existing open selector
|
||||||
if (sharedSelector && sharedSelector.isOpen) {
|
if (sharedSelector && sharedSelector.isOpen) {
|
||||||
@@ -84,21 +121,6 @@ async function getSelection (
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const opts = await options.getAll();
|
|
||||||
|
|
||||||
// Remove mirroring media types if mirroring is not enabled.
|
|
||||||
if (!opts.mirroringEnabled) {
|
|
||||||
availableMediaTypes &= ~(
|
|
||||||
ReceiverSelectorMediaType.Tab
|
|
||||||
| ReceiverSelectorMediaType.Screen);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove file media type if local media is not enabled
|
|
||||||
if (!opts.mediaEnabled || !opts.localMediaEnabled) {
|
|
||||||
availableMediaTypes &= ~ReceiverSelectorMediaType.File;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Ensure status manager is initialized
|
// Ensure status manager is initialized
|
||||||
await StatusManager.init();
|
await StatusManager.init();
|
||||||
|
|
||||||
@@ -106,7 +128,7 @@ async function getSelection (
|
|||||||
Array.from(StatusManager.getReceivers())
|
Array.from(StatusManager.getReceivers())
|
||||||
, defaultMediaType
|
, defaultMediaType
|
||||||
, availableMediaTypes
|
, availableMediaTypes
|
||||||
, requestedAppId);
|
, currentShim?.requestedAppId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,9 +63,7 @@ export function getMediaTypesForPageUrl (
|
|||||||
|
|
||||||
// Only meant to run on normal web pages
|
// Only meant to run on normal web pages
|
||||||
if (url.protocol === "http:" || url.protocol === "https:") {
|
if (url.protocol === "http:" || url.protocol === "https:") {
|
||||||
availableMediaTypes |= (
|
availableMediaTypes |= ReceiverSelectorMediaType.Tab;
|
||||||
ReceiverSelectorMediaType.App
|
|
||||||
| ReceiverSelectorMediaType.Tab);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user