mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-10 01:29:58 +00:00
Show app name in receiver selector if known based on app ID
This commit is contained in:
@@ -22,6 +22,7 @@ export interface Shim {
|
||||
contentPort: Port;
|
||||
contentTabId?: number;
|
||||
contentFrameId?: number;
|
||||
requestedAppId?: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +34,18 @@ export default new class ShimManager {
|
||||
await this.initStatusListeners();
|
||||
}
|
||||
|
||||
public getShim (tabId: number, frameId?: number) {
|
||||
for (const activeShim of this.activeShims) {
|
||||
if (activeShim.contentTabId === tabId) {
|
||||
if (frameId && activeShim.contentFrameId !== frameId) {
|
||||
continue;
|
||||
}
|
||||
|
||||
return activeShim;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async createShim (port: Port) {
|
||||
const shim = await (port instanceof MessagePort
|
||||
? this.createShimFromBackground(port)
|
||||
@@ -129,6 +142,8 @@ export default new class ShimManager {
|
||||
|
||||
switch (message.subject) {
|
||||
case "main:/shimInitialized": {
|
||||
shim.requestedAppId = message.data.appId;
|
||||
|
||||
for (const receiver of StatusManager.getReceivers()) {
|
||||
shim.contentPort.postMessage({
|
||||
subject: "shim:/serviceUp"
|
||||
@@ -148,7 +163,8 @@ export default new class ShimManager {
|
||||
const selection = await ReceiverSelectorManager
|
||||
.getSelection(
|
||||
ReceiverSelectorMediaType.App
|
||||
, availableMediaTypes);
|
||||
, availableMediaTypes
|
||||
, shim.requestedAppId);
|
||||
|
||||
// Handle cancellation
|
||||
if (!selection) {
|
||||
|
||||
@@ -65,10 +65,12 @@ function initBrowserAction () {
|
||||
* top-level frame.
|
||||
*/
|
||||
browser.browserAction.onClicked.addListener(async tab => {
|
||||
const currentShim = ShimManager.getShim(tab.id);
|
||||
const selection = await ReceiverSelectorManager.getSelection(
|
||||
ReceiverSelectorMediaType.Tab
|
||||
, getMediaTypesForPageUrl(tab.url)
|
||||
& ~ReceiverSelectorMediaType.App);
|
||||
& ~ReceiverSelectorMediaType.App
|
||||
, currentShim.requestedAppId);
|
||||
|
||||
if (selection) {
|
||||
loadSender({
|
||||
@@ -159,9 +161,11 @@ async function initMenus () {
|
||||
|
||||
switch (info.menuItemId) {
|
||||
case menuIdMediaCast: {
|
||||
const currentShim = ShimManager.getShim(tab.id, info.frameId);
|
||||
const selection = await ReceiverSelectorManager.getSelection(
|
||||
ReceiverSelectorMediaType.App
|
||||
, availableMediaTypes);
|
||||
, availableMediaTypes
|
||||
, currentShim.requestedAppId);
|
||||
|
||||
// Selection cancelled
|
||||
if (!selection) {
|
||||
@@ -200,9 +204,11 @@ async function initMenus () {
|
||||
}
|
||||
|
||||
case menuIdMirroringCast: {
|
||||
const currentShim = ShimManager.getShim(tab.id, info.frameId);
|
||||
const selection = await ReceiverSelectorManager.getSelection(
|
||||
ReceiverSelectorMediaType.Tab
|
||||
, availableMediaTypes & ~ReceiverSelectorMediaType.App);
|
||||
, availableMediaTypes & ~ReceiverSelectorMediaType.App
|
||||
, currentShim.requestedAppId);
|
||||
|
||||
loadSender({
|
||||
tabId: tab.id
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
import bridge from "../../lib/bridge";
|
||||
import knownApps from "../../lib/knownApps";
|
||||
import options from "../../lib/options";
|
||||
|
||||
import { TypedEventTarget } from "../../lib/typedEvents";
|
||||
@@ -43,7 +44,8 @@ export default class NativeReceiverSelector
|
||||
public async open (
|
||||
receivers: Receiver[]
|
||||
, defaultMediaType: ReceiverSelectorMediaType
|
||||
, availableMediaTypes: ReceiverSelectorMediaType): Promise<void> {
|
||||
, availableMediaTypes: ReceiverSelectorMediaType
|
||||
, requestedAppId: string): Promise<void> {
|
||||
|
||||
this.bridgePort = await bridge.connect();
|
||||
|
||||
@@ -94,7 +96,8 @@ export default class NativeReceiverSelector
|
||||
|
||||
, i18n_extensionName: _("extensionName")
|
||||
, i18n_castButtonTitle: _("popupCastButtonTitle")
|
||||
, i18n_mediaTypeApp: _("popupMediaTypeApp")
|
||||
, i18n_mediaTypeApp:
|
||||
knownApps[requestedAppId] ?? _("popupMediaTypeApp")
|
||||
, i18n_mediaTypeTab: _("popupMediaTypeTab")
|
||||
, i18n_mediaTypeScreen: _("popupMediaTypeScreen")
|
||||
, i18n_mediaTypeFile: _("popupMediaTypeFile")
|
||||
|
||||
@@ -27,6 +27,7 @@ export default class PopupReceiverSelector
|
||||
private wasReceiverSelected: boolean = false;
|
||||
|
||||
private _isOpen: boolean = false;
|
||||
private requestedAppId: string;
|
||||
|
||||
|
||||
constructor () {
|
||||
@@ -59,6 +60,11 @@ export default class PopupReceiverSelector
|
||||
this.messagePortDisconnected = true;
|
||||
});
|
||||
|
||||
this.messagePort.postMessage({
|
||||
subject: "popup:/sendRequestedAppId"
|
||||
, data: { requestedAppId: this.requestedAppId }
|
||||
});
|
||||
|
||||
this.messagePort.postMessage({
|
||||
subject: "popup:/populateReceiverList"
|
||||
, data: {
|
||||
@@ -77,7 +83,10 @@ export default class PopupReceiverSelector
|
||||
public async open (
|
||||
receivers: Receiver[]
|
||||
, defaultMediaType: ReceiverSelectorMediaType
|
||||
, availableMediaTypes: ReceiverSelectorMediaType): Promise<void> {
|
||||
, availableMediaTypes: ReceiverSelectorMediaType
|
||||
, requestedAppId: string): Promise<void> {
|
||||
|
||||
this.requestedAppId = requestedAppId;
|
||||
|
||||
// If popup already exists, close it
|
||||
if (this.windowId) {
|
||||
@@ -124,6 +133,7 @@ export default class PopupReceiverSelector
|
||||
}
|
||||
|
||||
this._isOpen = false;
|
||||
this.requestedAppId = null;
|
||||
|
||||
if (this.messagePort && !this.messagePortDisconnected) {
|
||||
this.messagePort.disconnect();
|
||||
|
||||
@@ -31,7 +31,8 @@ export default interface ReceiverSelector
|
||||
|
||||
open (receivers: Receiver[]
|
||||
, defaultMediaType: ReceiverSelectorMediaType
|
||||
, availableMediaTypes: ReceiverSelectorMediaType): void;
|
||||
, availableMediaTypes: ReceiverSelectorMediaType
|
||||
, requestedAppId: string): void;
|
||||
|
||||
close (): void;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,8 @@ async function getSelection (
|
||||
, availableMediaTypes =
|
||||
ReceiverSelectorMediaType.Tab
|
||||
| ReceiverSelectorMediaType.Screen
|
||||
| ReceiverSelectorMediaType.File)
|
||||
| ReceiverSelectorMediaType.File
|
||||
, requestedAppId: string)
|
||||
: Promise<ReceiverSelection> {
|
||||
|
||||
return new Promise(async (resolve, reject) => {
|
||||
@@ -104,7 +105,8 @@ async function getSelection (
|
||||
sharedSelector.open(
|
||||
Array.from(StatusManager.getReceivers())
|
||||
, defaultMediaType
|
||||
, availableMediaTypes);
|
||||
, availableMediaTypes
|
||||
, requestedAppId);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user