mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-10 01:29:58 +00:00
Fix unused locals and better receiver selector available media checking
This commit is contained in:
@@ -4,9 +4,9 @@ import bridge from "../lib/bridge";
|
||||
import loadSender from "../lib/loadSender";
|
||||
import options from "../lib/options";
|
||||
|
||||
import { TypedEventTarget } from "../lib/typedEvents";
|
||||
import { Message } from "../types";
|
||||
|
||||
import { getMediaTypesForPageUrl } from "../lib/utils";
|
||||
import { ReceiverSelectorMediaType } from "./receiverSelector";
|
||||
|
||||
import ReceiverSelectorManager
|
||||
@@ -140,17 +140,15 @@ export default new class ShimManager {
|
||||
}
|
||||
|
||||
case "main:/selectReceiverBegin": {
|
||||
const allMediaTypes =
|
||||
ReceiverSelectorMediaType.App
|
||||
| ReceiverSelectorMediaType.Tab
|
||||
| ReceiverSelectorMediaType.Screen
|
||||
| ReceiverSelectorMediaType.File;
|
||||
const contentTab = await browser.tabs.get(shim.contentTabId);
|
||||
const availableMediaTypes = getMediaTypesForPageUrl(
|
||||
contentTab.url);
|
||||
|
||||
try {
|
||||
const selection = await ReceiverSelectorManager
|
||||
.getSelection(
|
||||
ReceiverSelectorMediaType.App
|
||||
, allMediaTypes);
|
||||
, availableMediaTypes);
|
||||
|
||||
// Handle cancellation
|
||||
if (!selection) {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
import bridge from "../lib/bridge";
|
||||
import options from "../lib/options";
|
||||
|
||||
import { TypedEventTarget } from "../lib/typedEvents";
|
||||
import { Message, Receiver, ReceiverStatus } from "../types";
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
|
||||
import defaultOptions from "../defaultOptions";
|
||||
import loadSender from "../lib/loadSender";
|
||||
import options, { Options } from "../lib/options";
|
||||
import options from "../lib/options";
|
||||
|
||||
import { getChromeUserAgent } from "../lib/userAgents";
|
||||
import { stringify } from "../lib/utils";
|
||||
|
||||
import { Message } from "../types";
|
||||
import { getMediaTypesForPageUrl, stringify } from "../lib/utils";
|
||||
|
||||
import { CAST_FRAMEWORK_LOADER_SCRIPT_URL
|
||||
, CAST_LOADER_SCRIPT_URL } from "../lib/endpoints";
|
||||
@@ -45,7 +43,6 @@ browser.runtime.onInstalled.addListener(async details => {
|
||||
});
|
||||
|
||||
|
||||
|
||||
function initBrowserAction () {
|
||||
browser.browserAction.disable();
|
||||
|
||||
@@ -68,7 +65,10 @@ function initBrowserAction () {
|
||||
* top-level frame.
|
||||
*/
|
||||
browser.browserAction.onClicked.addListener(async tab => {
|
||||
const selection = await ReceiverSelectorManager.getSelection();
|
||||
const selection = await ReceiverSelectorManager.getSelection(
|
||||
ReceiverSelectorMediaType.Tab
|
||||
, getMediaTypesForPageUrl(tab.url)
|
||||
& ~ReceiverSelectorMediaType.App);
|
||||
|
||||
if (selection) {
|
||||
loadSender({
|
||||
@@ -154,17 +154,14 @@ async function initMenus () {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
const availableMediaTypes = getMediaTypesForPageUrl(info.pageUrl);
|
||||
|
||||
switch (info.menuItemId) {
|
||||
case menuIdMediaCast: {
|
||||
const allMediaTypes =
|
||||
ReceiverSelectorMediaType.App
|
||||
| ReceiverSelectorMediaType.Tab
|
||||
| ReceiverSelectorMediaType.Screen
|
||||
| ReceiverSelectorMediaType.File;
|
||||
|
||||
const selection = await ReceiverSelectorManager.getSelection(
|
||||
ReceiverSelectorMediaType.App
|
||||
, allMediaTypes);
|
||||
, availableMediaTypes);
|
||||
|
||||
// Selection cancelled
|
||||
if (!selection) {
|
||||
@@ -203,7 +200,9 @@ async function initMenus () {
|
||||
}
|
||||
|
||||
case menuIdMirroringCast: {
|
||||
const selection = await ReceiverSelectorManager.getSelection();
|
||||
const selection = await ReceiverSelectorManager.getSelection(
|
||||
ReceiverSelectorMediaType.Tab
|
||||
, availableMediaTypes & ~ReceiverSelectorMediaType.App);
|
||||
|
||||
loadSender({
|
||||
tabId: tab.id
|
||||
@@ -319,11 +318,9 @@ async function initMenus () {
|
||||
.reverse();
|
||||
|
||||
if (pathSegments.length) {
|
||||
let index = 0;
|
||||
|
||||
for (const pathSegment of pathSegments) {
|
||||
for (let i = 0; i < pathSegments.length; i++) {
|
||||
const partialPath = pathSegments
|
||||
.slice(index)
|
||||
.slice(i)
|
||||
.reverse()
|
||||
.join("/");
|
||||
|
||||
@@ -336,8 +333,6 @@ async function initMenus () {
|
||||
|
||||
whitelistChildMenuPatterns.set(
|
||||
partialPathMenuId, pattern);
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ export default class PopupReceiverSelector
|
||||
implements ReceiverSelector {
|
||||
|
||||
private windowId: number;
|
||||
private openerWindowId: number;
|
||||
|
||||
private messagePort: browser.runtime.Port;
|
||||
private messagePortDisconnected: boolean;
|
||||
@@ -102,7 +101,6 @@ export default class PopupReceiverSelector
|
||||
this._isOpen = true;
|
||||
|
||||
this.windowId = popup.id;
|
||||
this.openerWindowId = openerWindow.id;
|
||||
|
||||
// Size/position not set correctly on creation (bug?)
|
||||
await browser.windows.update(this.windowId, {
|
||||
@@ -168,7 +166,6 @@ export default class PopupReceiverSelector
|
||||
|
||||
// Cleanup
|
||||
this.windowId = null;
|
||||
this.openerWindowId = null;
|
||||
this.messagePort = null;
|
||||
this.receivers = null;
|
||||
this.defaultMediaType = null;
|
||||
|
||||
@@ -83,6 +83,29 @@ 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;
|
||||
}
|
||||
|
||||
if (!availableMediaTypes || availableMediaTypes
|
||||
=== ReceiverSelectorMediaType.File) {
|
||||
console.error("fx_cast (Debug): No available media types");
|
||||
resolve(null);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// Ensure status manager is initialized
|
||||
await StatusManager.init();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user