| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
 
 | /* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// This file is loaded into the browser window scope.
/* eslint-env mozilla/browser-window */
XPCOMUtils.defineLazyServiceGetter(
  this,
  "ProfileService",
  "@mozilla.org/toolkit/profile-service;1",
  "nsIToolkitProfileService"
);
var gProfiles = {
  init() {
    XPCOMUtils.defineLazyPreferenceGetter(
      this,
      "PROFILES_ENABLED",
      "browser.profiles.enabled",
      false,
      this.toggleProfileButtonsVisibility.bind(this)
    );
    if (!this.PROFILES_ENABLED) {
      return;
    }
    this.toggleProfileButtonsVisibility();
  },
  toggleProfileButtonsVisibility() {
    let profilesButton = PanelMultiView.getViewNode(
      document,
      "appMenu-profiles-button"
    );
    profilesButton.hidden = !this.PROFILES_ENABLED;
    if (this.PROFILES_ENABLED) {
      document.l10n.setArgs(profilesButton, {
        profilename: ProfileService.currentProfile?.name ?? "",
      });
    }
  },
  updateView(panel) {
    this.populateSubView();
    PanelUI.showSubView("PanelUI-profiles", panel);
  },
  async populateSubView() {
    let closeProfileButton = PanelMultiView.getViewNode(
      document,
      "profiles-close-profile-button"
    );
    document.l10n.setArgs(closeProfileButton, {
      profilename: ProfileService.currentProfile?.name ?? "",
    });
    let profileIconEl = PanelMultiView.getViewNode(
      document,
      "profile-icon-image"
    );
    profileIconEl.style.listStyleImage = `url(${
      ProfileService.currentProfile?.iconURL ??
      "chrome://branding/content/icon64.png"
    })`;
    let profileNameEl = PanelMultiView.getViewNode(document, "profile-name");
    profileNameEl.textContent = ProfileService.currentProfile?.name ?? "";
    let profilesList = PanelMultiView.getViewNode(
      document,
      "PanelUI-profiles"
    ).querySelector("#profiles-list");
    while (profilesList.lastElementChild) {
      profilesList.lastElementChild.remove();
    }
    for (let profile of ProfileService.profiles) {
      if (profile === ProfileService.currentProfile) {
        continue;
      }
      let button = document.createXULElement("toolbarbutton");
      button.setAttribute("label", profile.name);
      button.className = "subviewbutton subviewbutton-iconic";
      button.style.listStyleImage = `url(${
        profile.iconURL ?? "chrome://branding/content/icon16.png"
      })`;
      button.onclick = () => {
        Services.startup.createInstanceWithProfile(profile);
      };
      profilesList.appendChild(button);
    }
  },
};
 |