Bug 1577437 - fix "Make Changes and Reset" - AddonManager.getAllAddons doesn't use a callback anymore. r=pmorris
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Mon, 01 Jun 2020 20:15:15 +0300
changeset 39309 5cefc4c791654b07bd821daf75496ca05a2ff96d
parent 39308 4f509afebd6f6b0ab9f8994773c44d7b5624691d
child 39310 206d9568b8841e6d0596b34b580926d67d1afbd8
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewerspmorris
bugs1577437
Bug 1577437 - fix "Make Changes and Reset" - AddonManager.getAllAddons doesn't use a callback anymore. r=pmorris
mail/base/content/safeMode.js
--- a/mail/base/content/safeMode.js
+++ b/mail/base/content/safeMode.js
@@ -3,79 +3,78 @@
  * 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/. */
 
 var { AddonManager } = ChromeUtils.import(
   "resource://gre/modules/AddonManager.jsm"
 );
 var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
-document.addEventListener("dialogaccept", onOK);
-document.addEventListener("dialogcancel", onCancel);
-document.addEventListener("dialogextra1", () => window.close());
-
 function restartApp() {
   Services.startup.quit(
     Services.startup.eForceQuit | Services.startup.eRestart
   );
 }
 
 function deleteLocalstore() {
   // Delete the xulstore file.
   let xulstoreFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
   xulstoreFile.append("xulstore.json");
   if (xulstoreFile.exists()) {
     xulstoreFile.remove(false);
   }
 }
 
-function disableAddons() {
-  AddonManager.getAllAddons(function(aAddons) {
-    aAddons.forEach(function(aAddon) {
-      if (aAddon.type == "theme") {
-        // Setting userDisabled to false on the default theme activates it,
-        // disables all other themes and deactivates the applied persona, if
-        // any.
-        const DEFAULT_THEME_ID = "{972ce4c6-7e08-4474-a285-3208198ce6fd}";
-        if (aAddon.id == DEFAULT_THEME_ID) {
-          aAddon.userDisabled = false;
-        }
-      } else {
-        aAddon.userDisabled = true;
+async function disableAddons() {
+  for (let addon of await AddonManager.getAllAddons()) {
+    if (addon.type == "theme") {
+      // Setting userDisabled to false on the default theme activates it,
+      // disables all other themes and deactivates the applied persona, if
+      // any.
+      const DEFAULT_THEME_ID = "{972ce4c6-7e08-4474-a285-3208198ce6fd}";
+      if (addon.id == DEFAULT_THEME_ID) {
+        addon.userDisabled = false;
       }
-    });
-
-    restartApp();
-  });
+    } else {
+      addon.userDisabled = true;
+    }
+  }
+  restartApp();
 }
 
 function onOK(event) {
   try {
     if (document.getElementById("resetToolbars").checked) {
       deleteLocalstore();
     }
     if (document.getElementById("disableAddons").checked) {
       disableAddons();
       // disableAddons will asynchronously restart the application
       event.preventDefault();
       return;
     }
-  } catch (e) {}
+  } catch (e) {
+    Cu.reportError(e);
+  }
 
   restartApp();
   event.preventDefault();
 }
 
 function onCancel() {
   Services.startup.quit(Services.startup.eForceQuit);
 }
 
 function onLoad() {
   document
     .getElementById("tasks")
     .addEventListener("CheckboxStateChange", updateOKButtonState);
+
+  document.addEventListener("dialogaccept", onOK);
+  document.addEventListener("dialogcancel", onCancel);
+  document.addEventListener("dialogextra1", () => window.close());
 }
 
 function updateOKButtonState() {
   document.querySelector("dialog").getButton("accept").disabled =
     !document.getElementById("resetToolbars").checked &&
     !document.getElementById("disableAddons").checked;
 }