mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-08 08:39:59 +00:00
Move menu IDs to reduce bundle size + misc config fixes
This commit is contained in:
@@ -2,6 +2,5 @@
|
|||||||
"arrowParens": "avoid",
|
"arrowParens": "avoid",
|
||||||
"tabWidth": 4,
|
"tabWidth": 4,
|
||||||
"trailingComma": "none",
|
"trailingComma": "none",
|
||||||
"quoteProps": "consistent",
|
"quoteProps": "consistent"
|
||||||
"plugins": ["prettier-plugin-svelte"]
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,23 +5,15 @@ import messaging, { Port, Message } from "../messaging";
|
|||||||
import options from "../lib/options";
|
import options from "../lib/options";
|
||||||
|
|
||||||
import { TypedEventTarget } from "../lib/TypedEventTarget";
|
import { TypedEventTarget } from "../lib/TypedEventTarget";
|
||||||
import { SessionRequest } from "../cast/sdk/classes";
|
|
||||||
import {
|
import {
|
||||||
ReceiverDevice,
|
ReceiverDevice,
|
||||||
ReceiverSelectionActionType,
|
ReceiverSelectionActionType,
|
||||||
ReceiverSelectorMediaType
|
ReceiverSelectorMediaType,
|
||||||
|
ReceiverSelectorPageInfo
|
||||||
} from "../types";
|
} from "../types";
|
||||||
|
|
||||||
const POPUP_URL = browser.runtime.getURL("ui/popup/index.html");
|
const POPUP_URL = browser.runtime.getURL("ui/popup/index.html");
|
||||||
|
|
||||||
/** Info about sender page context. */
|
|
||||||
export interface ReceiverSelectorPageInfo {
|
|
||||||
url: string;
|
|
||||||
tabId: number;
|
|
||||||
frameId: number;
|
|
||||||
sessionRequest?: SessionRequest;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ReceiverSelectionCast {
|
export interface ReceiverSelectionCast {
|
||||||
actionType: ReceiverSelectionActionType.Cast;
|
actionType: ReceiverSelectionActionType.Cast;
|
||||||
receiverDevice: ReceiverDevice;
|
receiverDevice: ReceiverDevice;
|
||||||
|
|||||||
@@ -30,9 +30,6 @@ let menuIdCastMedia: MenuId;
|
|||||||
let menuIdWhitelist: MenuId;
|
let menuIdWhitelist: MenuId;
|
||||||
let menuIdWhitelistRecommended: MenuId;
|
let menuIdWhitelistRecommended: MenuId;
|
||||||
|
|
||||||
export const menuIdPopupCast = "popup_cast";
|
|
||||||
export const menuIdPopupStop = "popup_stop";
|
|
||||||
|
|
||||||
/** Match patterns for the whitelist option menus. */
|
/** Match patterns for the whitelist option menus. */
|
||||||
const whitelistChildMenuPatterns = new Map<MenuId, string>();
|
const whitelistChildMenuPatterns = new Map<MenuId, string>();
|
||||||
|
|
||||||
@@ -79,12 +76,12 @@ export async function initMenus() {
|
|||||||
// Popup context menus
|
// Popup context menus
|
||||||
const popupUrlPattern = `${browser.runtime.getURL("ui/popup")}/*`;
|
const popupUrlPattern = `${browser.runtime.getURL("ui/popup")}/*`;
|
||||||
browser.menus.create({
|
browser.menus.create({
|
||||||
id: menuIdPopupCast,
|
id: "popup_cast",
|
||||||
title: _("popupCastButtonTitle"),
|
title: _("popupCastButtonTitle"),
|
||||||
documentUrlPatterns: [popupUrlPattern]
|
documentUrlPatterns: [popupUrlPattern]
|
||||||
});
|
});
|
||||||
browser.menus.create({
|
browser.menus.create({
|
||||||
id: menuIdPopupStop,
|
id: "popup_stop",
|
||||||
title: _("popupStopButtonTitle"),
|
title: _("popupStopButtonTitle"),
|
||||||
documentUrlPatterns: [popupUrlPattern]
|
documentUrlPatterns: [popupUrlPattern]
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
import { SessionRequest } from "./cast/sdk/classes";
|
||||||
import { ReceiverStatus } from "./cast/sdk/types";
|
import { ReceiverStatus } from "./cast/sdk/types";
|
||||||
|
|
||||||
export enum ReceiverDeviceCapabilities {
|
export enum ReceiverDeviceCapabilities {
|
||||||
@@ -32,3 +33,11 @@ export enum ReceiverSelectionActionType {
|
|||||||
Cast = 1,
|
Cast = 1,
|
||||||
Stop = 2
|
Stop = 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Info about sender page context. */
|
||||||
|
export interface ReceiverSelectorPageInfo {
|
||||||
|
url: string;
|
||||||
|
tabId: number;
|
||||||
|
frameId: number;
|
||||||
|
sessionRequest?: SessionRequest;
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,9 +3,6 @@
|
|||||||
|
|
||||||
import LoadingIndicator from "../LoadingIndicator.svelte";
|
import LoadingIndicator from "../LoadingIndicator.svelte";
|
||||||
|
|
||||||
import { ReceiverSelectorPageInfo } from "../../background/ReceiverSelector";
|
|
||||||
import { menuIdPopupCast, menuIdPopupStop } from "../../background/menus";
|
|
||||||
|
|
||||||
import messaging, { Message, Port } from "../../messaging";
|
import messaging, { Message, Port } from "../../messaging";
|
||||||
import options, { Options } from "../../lib/options";
|
import options, { Options } from "../../lib/options";
|
||||||
import { RemoteMatchPattern } from "../../lib/matchPattern";
|
import { RemoteMatchPattern } from "../../lib/matchPattern";
|
||||||
@@ -13,7 +10,8 @@
|
|||||||
import {
|
import {
|
||||||
ReceiverDevice,
|
ReceiverDevice,
|
||||||
ReceiverSelectionActionType,
|
ReceiverSelectionActionType,
|
||||||
ReceiverSelectorMediaType
|
ReceiverSelectorMediaType,
|
||||||
|
ReceiverSelectorPageInfo
|
||||||
} from "../../types";
|
} from "../../types";
|
||||||
|
|
||||||
import knownApps, { KnownApp } from "../../cast/knownApps";
|
import knownApps, { KnownApp } from "../../cast/knownApps";
|
||||||
@@ -272,13 +270,13 @@
|
|||||||
|
|
||||||
const device = getDeviceFromElement(target);
|
const device = getDeviceFromElement(target);
|
||||||
if (!device) {
|
if (!device) {
|
||||||
browser.menus.update(menuIdPopupCast, { visible: false });
|
browser.menus.update("popup_cast", { visible: false });
|
||||||
browser.menus.update(menuIdPopupStop, { visible: false });
|
browser.menus.update("popup_stop", { visible: false });
|
||||||
} else {
|
} else {
|
||||||
const app = device.status?.applications?.[0];
|
const app = device.status?.applications?.[0];
|
||||||
const isAppRunning = !!(app && !app.isIdleScreen);
|
const isAppRunning = !!(app && !app.isIdleScreen);
|
||||||
|
|
||||||
browser.menus.update(menuIdPopupCast, {
|
browser.menus.update("popup_cast", {
|
||||||
visible: true,
|
visible: true,
|
||||||
title: _("popupCastMenuTitle", device.friendlyName),
|
title: _("popupCastMenuTitle", device.friendlyName),
|
||||||
enabled:
|
enabled:
|
||||||
@@ -288,7 +286,7 @@
|
|||||||
isMediaTypeAvailable
|
isMediaTypeAvailable
|
||||||
});
|
});
|
||||||
|
|
||||||
browser.menus.update(menuIdPopupStop, {
|
browser.menus.update("popup_stop", {
|
||||||
visible: isAppRunning,
|
visible: isAppRunning,
|
||||||
title: isAppRunning
|
title: isAppRunning
|
||||||
? _("popupStopMenuTitle", [
|
? _("popupStopMenuTitle", [
|
||||||
@@ -305,8 +303,8 @@
|
|||||||
/** Handle click events for receiver context menus. */
|
/** Handle click events for receiver context menus. */
|
||||||
function onMenuClicked(info: browser.menus.OnClickData) {
|
function onMenuClicked(info: browser.menus.OnClickData) {
|
||||||
if (
|
if (
|
||||||
info.menuItemId !== menuIdPopupCast &&
|
info.menuItemId !== "popup_cast" &&
|
||||||
info.menuItemId !== menuIdPopupStop
|
info.menuItemId !== "popup_stop"
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -319,10 +317,10 @@
|
|||||||
if (!device) return;
|
if (!device) return;
|
||||||
|
|
||||||
switch (info.menuItemId) {
|
switch (info.menuItemId) {
|
||||||
case menuIdPopupCast:
|
case "popup_cast":
|
||||||
onReceiverCast(device);
|
onReceiverCast(device);
|
||||||
break;
|
break;
|
||||||
case menuIdPopupStop:
|
case "popup_stop":
|
||||||
onReceiverStop(device);
|
onReceiverStop(device);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,5 +9,5 @@
|
|||||||
"target": "es6",
|
"target": "es6",
|
||||||
"strict": true
|
"strict": true
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules/**/*", "dist/**/*"]
|
"exclude": ["node_modules/**/*", "**/node_modules/**/*", "dist/**/*"]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user