init: async()

in src/js/popup/popup.js [323:419]


        init: async () => {
          
          const generateRandomMask = document.querySelector(".js-generate-random-mask");
          const { premium } = await browser.storage.local.get("premium");
          const { dataCollection } = await browser.storage.local.get(
            "dataCollection"
          );
          const maskPanel = document.getElementById("masks-panel");
          let getMasksOptions = { fetchCustomMasks: false };

          // logic to show survey is found in shouldShowSurvey function
          const shouldShowCSAT = await popup.panel.survey.utils.shouldShowSurvey();
          const csatSurveyFlag = await checkWaffleFlag('csat_survey');
          
          if (shouldShowCSAT && csatSurveyFlag && dataCollection === "data-enabled") {
            const survey = popup.panel.survey;

            survey.utils.showSurveyLink();

            // Show the survey panel when the link is clicked
            survey.select
              .surveyLink()
              .addEventListener("click", async () =>
                popup.panel.update("survey")
              );

            survey.select
              .viewSurveyLinkButton()
              .addEventListener("click", async () => {
                popup.panel.update("survey")
            });

            // Dismiss the survey panel when the user clicks on Dismiss - intentional dismissal
            survey.select
              .surveyDismiss()
              .addEventListener("click", async () => {
                const { profileID } = await browser.storage.local.get("profileID"); 
                const reasonToShow = await popup.panel.survey.utils.getReasonToShowSurvey();

                await popup.utilities.dismissByReason(reasonToShow, profileID);

                sendRelayEvent("CSAT Survey", "click", "dismissed-CSAT");
                window.close();
              });
          }

          if (!premium) {
            await popup.panel.masks.utilities.setRemainingMaskCount();
            maskPanel.setAttribute("data-account-level", "free");
          } else {            
            maskPanel.setAttribute("data-account-level", "premium");

            // Update language of Generate Random Mask to "Generate random mask"
            generateRandomMask.textContent = browser.i18n.getMessage("pageInputIconGenerateRandomMask");

            // Prompt user to register subdomain
            const { premiumSubdomainSet } = await browser.storage.local.get("premiumSubdomainSet");
            const isPremiumSubdomainSet = (premiumSubdomainSet !== "None");  
            
            // Store this query locally for this session
            sessionState.premiumSubdomainSet = isPremiumSubdomainSet;

            // Make sure to query both custom and random masks
            getMasksOptions.fetchCustomMasks = isPremiumSubdomainSet;
          
            // premiumSubdomain is not set : display CTA to prompt user to register subdomain
            if (!sessionState.premiumSubdomainSet) {
              const registerSubdomainButton = document.querySelector(".fx-relay-regsiter-subdomain-button");
              registerSubdomainButton.classList.remove("is-hidden");
            } else {

              sessionState.premiumSubdomain = premiumSubdomainSet;
              const generateCustomMask = document.querySelector(".js-generate-custom-mask");
              
              // Show "Generate custom mask" button
              generateCustomMask.classList.remove("is-hidden");

              generateCustomMask.addEventListener("click", (e) => {
                e.preventDefault();
                popup.panel.update("custom");
              }, false);
              
              // Restyle Random Mask button to secondary
              generateRandomMask.classList.remove("t-primary");
              generateRandomMask.classList.add("t-secondary");
            }
          }
          
          generateRandomMask.addEventListener("click", (e) => {
              popup.events.generateMask(e, "random");
            }, false);
          
          // Build initial list
          // Note: If premium, buildMasksList runs `popup.panel.masks.search.init()` after completing
          // If no masks are created, this will show onboarding prompt
          popup.panel.masks.utilities.buildMasksList();
        },