"use strict"; import defaultOptions from "./options/defaultOptions"; import messageRouter from "./messageRouter"; import getBridgeInfo from "./lib/getBridgeInfo"; import semver from "semver"; const _ = browser.i18n.getMessage; browser.runtime.onInstalled.addListener(async details => { switch (details.reason) { // Set default options case "install": { await browser.storage.sync.set({ options: defaultOptions }); break; }; // Set newly added options case "update": { const { options: existingOptions } = await browser.storage.sync.get("options"); const newOptions = {}; // Find options not already in storage for (const [ key, val ] of Object.entries(defaultOptions)) { if (!existingOptions.hasOwnProperty(key)) { newOptions[key] = val; } } // Update storage with default values of new options await browser.storage.sync.set({ options: { ...existingOptions , ...newOptions } }); break; }; } // Call after default options have been set createMenus(); }); // Menu IDs let mirrorCastMenuId; let mediaCastMenuId; const mediaCastTargetUrlPatterns = new Set([ "http://*/*" , "https://*/*" ]); const LOCAL_MEDIA_URL_PATTERN = "file://*/*"; async function createMenus () { const { options } = await browser.storage.sync.get("options"); /** * If options aren't set or menus have already been * created, return. */ if (!options || mirrorCastMenuId || mediaCastMenuId) return; if (options.localMediaEnabled) { mediaCastTargetUrlPatterns.add(LOCAL_MEDIA_URL_PATTERN); } //