async init()

in mail/components/preferences/general.js [184:493]


  async init() {
    function setEventListener(aId, aEventType, aCallback) {
      document
        .getElementById(aId)
        .addEventListener(aEventType, aCallback.bind(gGeneralPane));
    }

    Preferences.addSyncFromPrefListener(
      document.getElementById("saveWhere"),
      () => gDownloadDirSection.onReadUseDownloadDir()
    );

    this.mPane = document.getElementById("paneGeneral");
    this._prefsBundle = document.getElementById("bundlePreferences");
    this._brandShortName = document
      .getElementById("bundleBrand")
      .getString("brandShortName");
    this._handlerTbody = document.querySelector("#handlersTable > tbody");
    this._filter = document.getElementById("filter");

    this._handlerSort = { type: "type", descending: false };
    this._handlerSortHeaders = document.querySelectorAll(
      "#handlersTable > thead th[sort-type]"
    );
    for (const header of this._handlerSortHeaders) {
      const button = header.querySelector("button");
      button.addEventListener(
        "click",
        this.sort.bind(this, header.getAttribute("sort-type"))
      );
    }

    this.updateStartPage();
    this.updatePlaySound(
      !Preferences.get("mail.biff.play_sound").value,
      Preferences.get("mail.biff.play_sound.url").value,
      Preferences.get("mail.biff.play_sound.type").value
    );
    if (AppConstants.platform != "macosx") {
      this.updateShowAlert();
    }
    await this.updateWebSearch();

    // Search integration -- check whether we should hide or disable integration
    let hideSearchUI = false;
    let disableSearchUI = false;
    if (SearchIntegration) {
      disableSearchUI = SearchIntegration.osComponentsNotRunning;
    } else {
      hideSearchUI = true;
    }

    if (hideSearchUI) {
      document.getElementById("searchIntegrationContainer").hidden = true;
    } else if (disableSearchUI) {
      const searchCheckbox = document.getElementById("searchIntegration");
      searchCheckbox.checked = false;
      Preferences.get("searchintegration.enable").updateControlDisabledState(
        true
      );
    } else {
      // Mirror value to the actual search integration.
      Preferences.get("searchintegration.enable").value =
        SearchIntegration.prefEnabled;
      Preferences.get("searchintegration.enable").on("change", () => {
        SearchIntegration.prefEnabled = Preferences.get(
          "searchintegration.enable"
        ).value;
      });
    }

    // If the shell service is not working, disable the "Check now" button
    // and "perform check at startup" checkbox.
    try {
      Cc["@mozilla.org/mail/shell-service;1"].getService(Ci.nsIShellService);
      this.mShellServiceWorking = true;
    } catch (ex) {
      // The elements may not exist if HAVE_SHELL_SERVICE is off.
      if (document.getElementById("alwaysCheckDefault")) {
        document.getElementById("alwaysCheckDefault").disabled = true;
        document.getElementById("alwaysCheckDefault").checked = false;
      }
      if (document.getElementById("checkDefaultButton")) {
        document.getElementById("checkDefaultButton").disabled = true;
      }
      this.mShellServiceWorking = false;
    }
    this._rebuildFonts();

    var menulist = document.getElementById("defaultFont");
    if (menulist.selectedIndex == -1) {
      // Prepend menuitem with empty name and value.
      const item = document.createXULElement("menuitem");
      item.setAttribute("label", "");
      item.setAttribute("value", "");
      menulist.menupopup.insertBefore(
        item,
        menulist.menupopup.firstElementChild
      );
      menulist.selectedIndex = 0;
    }

    this.formatLocaleSetLabels();

    if (Services.prefs.getBoolPref("intl.multilingual.enabled")) {
      this.initPrimaryMessengerLanguageUI();
    }

    this.mTagListBox = document.getElementById("tagList");
    this.buildTagList();
    this.updateMarkAsReadOptions();

    document.getElementById("citationmenu").value = Preferences.get(
      "mail.citation_color"
    ).value;

    // By doing this in a timeout, we let the preferences dialog resize itself
    // to an appropriate size before we add a bunch of items to the list.
    // Otherwise, if there are many items, and the Applications prefpane
    // is the one that gets displayed when the user first opens the dialog,
    // the dialog might stretch too much in an attempt to fit them all in.
    // XXX Shouldn't we perhaps just set a max-height on the richlistbox?
    var _delayedPaneLoad = function (self) {
      self._loadAppHandlerData();
      self._rebuildVisibleTypes();
      self._sortVisibleTypes();
      self._rebuildView();

      // Notify observers that the UI is now ready
      Services.obs.notifyObservers(window, "app-handler-pane-loaded");
    };
    this.updateActualCacheSize();
    this.updateCompactOptions();

    // Default store type initialization.
    const storeTypeElement = document.getElementById("storeTypeMenulist");
    // set the menuitem to match the account
    const defaultStoreID = Services.prefs.getCharPref(
      "mail.serverDefaultStoreContractID"
    );
    const targetItem = storeTypeElement.getElementsByAttribute(
      "value",
      defaultStoreID
    );
    storeTypeElement.selectedItem = targetItem[0];
    setTimeout(_delayedPaneLoad, 0, this);

    if (AppConstants.MOZ_UPDATER) {
      gAppUpdater = new appUpdater(); // eslint-disable-line no-global-assign
      const updateDisabled =
        Services.policies && !Services.policies.isAllowed("appUpdate");

      if (gIsPackagedApp) {
        // When we're running inside an app package, there's no point in
        // displaying any update content here, and it would get confusing if we
        // did, because our updater is not enabled.
        // We can't rely on the hidden attribute for the toplevel elements,
        // because of the pane hiding/showing code interfering.
        document
          .getElementById("updatesCategory")
          .setAttribute("style", "display: none !important");
        document
          .getElementById("updateApp")
          .setAttribute("style", "display: none !important");
      } else if (updateDisabled || UpdateUtils.appUpdateAutoSettingIsLocked()) {
        document.getElementById("updateAllowDescription").hidden = true;
        document.getElementById("updateSettingsContainer").hidden = true;
        if (updateDisabled && AppConstants.MOZ_MAINTENANCE_SERVICE) {
          document.getElementById("useService").hidden = true;
        }
      } else {
        // Start with no option selected since we are still reading the value
        document.getElementById("autoDesktop").removeAttribute("selected");
        document.getElementById("manualDesktop").removeAttribute("selected");
        // Start reading the correct value from the disk
        this.readUpdateAutoPref();
        setEventListener("updateRadioGroup", "command", event => {
          if (event.target.id == "backgroundUpdate") {
            this.writeBackgroundUpdatePref();
          } else {
            this.writeUpdateAutoPref();
          }
        });
        if (this.isBackgroundUpdateUIAvailable()) {
          document.getElementById("backgroundUpdate").hidden = false;
          // Start reading the background update pref's value from the disk.
          this.readBackgroundUpdatePref();
        }
      }

      const defaults = Services.prefs.getDefaultBranch(null);
      const distroId = defaults.getCharPref("distribution.id", "");
      if (distroId) {
        const distroVersion = defaults.getCharPref("distribution.version", "");

        const distroIdField = document.getElementById("distributionId");
        distroIdField.value = distroId + " - " + distroVersion;
        distroIdField.style.display = "block";

        const distroAbout = defaults.getStringPref("distribution.about", "");
        if (distroAbout) {
          const distroField = document.getElementById("distribution");
          distroField.value = distroAbout;
          distroField.style.display = "block";
        }
      }

      if (AppConstants.platform == "win") {
        // On Windows, the Application Update setting is an installation-
        // specific preference, not a profile-specific one. Show a warning to
        // inform users of this.
        const updateContainer = document.getElementById(
          "updateSettingsContainer"
        );
        updateContainer.classList.add("updateSettingCrossUserWarningContainer");
        document.getElementById("updateSettingCrossUserWarning").hidden = false;
      }

      if (AppConstants.MOZ_MAINTENANCE_SERVICE) {
        // Check to see if the maintenance service is installed.
        // If it isn't installed, don't show the preference at all.
        let installed;
        try {
          const wrk = Cc["@mozilla.org/windows-registry-key;1"].createInstance(
            Ci.nsIWindowsRegKey
          );
          wrk.open(
            wrk.ROOT_KEY_LOCAL_MACHINE,
            "SOFTWARE\\Mozilla\\MaintenanceService",
            wrk.ACCESS_READ | wrk.WOW64_64
          );
          installed = wrk.readIntValue("Installed");
          wrk.close();
        } catch (e) {}
        if (installed != 1) {
          document.getElementById("useService").hidden = true;
        }
      }

      let version = AppConstants.MOZ_APP_VERSION_DISPLAY;

      // Include the build ID and display warning if this is an "a#" (nightly) build
      if (/a\d+$/.test(version)) {
        const buildID = Services.appinfo.appBuildID;
        const year = buildID.slice(0, 4);
        const month = buildID.slice(4, 6);
        const day = buildID.slice(6, 8);
        version += ` (${year}-${month}-${day})`;
      }

      // Append "(32-bit)" or "(64-bit)" build architecture to the version number:
      const bundle = Services.strings.createBundle(
        "chrome://messenger/locale/messenger.properties"
      );
      const archResource = Services.appinfo.is64Bit
        ? "aboutDialog.architecture.sixtyFourBit"
        : "aboutDialog.architecture.thirtyTwoBit";
      const arch = bundle.GetStringFromName(archResource);
      version += ` (${arch})`;

      document.l10n.setAttributes(
        document.getElementById("version"),
        "update-app-version",
        { version }
      );

      if (!AppConstants.NIGHTLY_BUILD) {
        // Show a release notes link if we have a URL.
        const relNotesLink = document.getElementById("releasenotes");
        const relNotesPrefType = Services.prefs.getPrefType(
          "app.releaseNotesURL"
        );
        if (relNotesPrefType != Services.prefs.PREF_INVALID) {
          const relNotesURL = Services.urlFormatter.formatURLPref(
            "app.releaseNotesURL"
          );
          if (relNotesURL != "about:blank") {
            relNotesLink.href = relNotesURL;
            relNotesLink.hidden = false;
          }
        }
      }
      // Initialize Application section.

      Services.obs.addObserver(this, AUTO_UPDATE_CHANGED_TOPIC);
    }
    // Listen for window unload so we can remove our preference observers.
    window.addEventListener("unload", this);
    Services.prefs.addObserver("mailnews.tags.", this);

    Preferences.addSyncFromPrefListener(
      document.getElementById("allowSmartSize"),
      () => this.readSmartSizeEnabled()
    );

    const element = document.getElementById("cacheSize");
    Preferences.addSyncFromPrefListener(element, () => this.readCacheSize());
    Preferences.addSyncToPrefListener(element, () => this.writeCacheSize());
    Preferences.addSyncFromPrefListener(menulist, () =>
      this.readFontSelection()
    );
    Preferences.addSyncFromPrefListener(
      document.getElementById("soundUrlLocation"),
      () => this.readSoundLocation()
    );

    if (!Services.policies.isAllowed("about:config")) {
      document.getElementById("configEditor").disabled = true;
    }
  },