From 3686340f25d1463afaecc9e0609fb6d010f304e0 Mon Sep 17 00:00:00 2001 From: hensm Date: Mon, 18 Apr 2022 04:41:29 +0100 Subject: [PATCH] Refactor menus module --- ext/src/background/background.ts | 21 +- ext/src/background/menus.ts | 220 +++++++++--------- .../receiverSelector/ReceiverSelector.ts | 6 +- .../ReceiverSelectorManager.ts | 12 +- ext/src/cast/CastManager.ts | 40 ++-- ext/src/cast/api/Session.ts | 7 +- 6 files changed, 146 insertions(+), 160 deletions(-) diff --git a/ext/src/background/background.ts b/ext/src/background/background.ts index 8bc4e52..866ac41 100755 --- a/ext/src/background/background.ts +++ b/ext/src/background/background.ts @@ -16,8 +16,8 @@ const _ = browser.i18n.getMessage; /** * On install, set the default options before initializing the - * extension. On update, handle any unset values and set to - * the new defaults. + * extension. On update, handle any unset values and set to the new + * defaults. */ browser.runtime.onInstalled.addListener(async details => { switch (details.reason) { @@ -39,9 +39,9 @@ browser.runtime.onInstalled.addListener(async details => { }); /** - * Checks whether the bridge can be reached and is compatible - * with the current version of the extension. If not, triggers - * a notification with the appropriate info. + * Checks whether the bridge can be reached and is compatible with the + * current version of the extension. If not, triggers a notification + * with the appropriate info. */ async function notifyBridgeCompat() { logger.info("checking for bridge..."); @@ -89,9 +89,8 @@ async function init() { } /** - * If options haven't been set yet, we can't properly - * initialize, so wait until init is called again in the - * onInstalled listener. + * If options haven't been set yet, we can't properly initialize, + * so wait until init is called again in the onInstalled listener. */ if (!(await options.getAll())) { return; @@ -109,9 +108,9 @@ async function init() { await initWhitelist(); /** - * 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 + * 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 => { diff --git a/ext/src/background/menus.ts b/ext/src/background/menus.ts index f11f790..960476b 100644 --- a/ext/src/background/menus.ts +++ b/ext/src/background/menus.ts @@ -6,6 +6,7 @@ import options from "../lib/options"; import { stringify } from "../lib/utils"; import { + ReceiverSelection, ReceiverSelectionActionType, ReceiverSelectorMediaType } from "./receiverSelector"; @@ -25,12 +26,14 @@ const URL_PATTERNS_ALL = [...URL_PATTERNS_REMOTE, URL_PATTERN_FILE]; type MenuId = string | number; let menuIdCast: MenuId; -let menuIdMediaCast: MenuId; +let menuIdCastMedia: MenuId; let menuIdWhitelist: MenuId; let menuIdWhitelistRecommended: MenuId; +/** Match patterns for the whitelist option menus. */ const whitelistChildMenuPatterns = new Map(); +/** Handles initial menu setup. */ export async function initMenus() { logger.info("init (menus)"); @@ -43,7 +46,7 @@ export async function initMenus() { }); //