Bug 1554511 - Port bug 336267: When disabling automatic updating and there is an update in progress, ask the user if they want to cancel the update. r=jorgk DONTBUILD
authorRichard Marti <richard.marti@gmail.com>
Fri, 31 May 2019 08:55:56 +0200
changeset 35729 0cc63242c9a4f3441112010907fb65c4a49d4f24
parent 35728 9c160ed8bd8db02495a86609d6cd4b5f75310123
child 35730 538ca411c73d9cbcb93216d3e6f90925217e3428
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersjorgk
bugs1554511, 336267
Bug 1554511 - Port bug 336267: When disabling automatic updating and there is an update in progress, ask the user if they want to cancel the update. r=jorgk DONTBUILD
mail/components/preferences/advanced.js
mail/locales/en-US/messenger/preferences/preferences.ftl
--- a/mail/components/preferences/advanced.js
+++ b/mail/components/preferences/advanced.js
@@ -389,16 +389,23 @@ var gAdvancedPane = {
       radiogroup.disabled = true;
       try {
         await UpdateUtils.setAppUpdateAutoEnabled(updateAutoValue);
         radiogroup.disabled = false;
       } catch (error) {
         Cu.reportError(error);
         await this.updateReadPrefs();
         await this.reportUpdatePrefWriteError(error);
+        return;
+      }
+
+      // If the value was changed to false the user should be given the option
+      // to discard an update if there is one.
+      if (!updateAutoValue) {
+        await this.checkUpdateInProgress();
       }
     }
   },
 
   async reportUpdatePrefWriteError(error) {
     let [title, message] = await document.l10n.formatValues([
       {id: "update-pref-write-failure-title"},
       {id: "update-pref-write-failure-message", args: {path: error.path}},
@@ -406,16 +413,50 @@ var gAdvancedPane = {
 
     // Set up the Ok Button
     let buttonFlags = (Services.prompt.BUTTON_POS_0 *
                        Services.prompt.BUTTON_TITLE_OK);
     Services.prompt.confirmEx(window, title, message, buttonFlags,
                               null, null, null, null, {});
   },
 
+  async checkUpdateInProgress() {
+    let um = Cc["@mozilla.org/updates/update-manager;1"].
+             getService(Ci.nsIUpdateManager);
+    if (!um.activeUpdate) {
+      return;
+    }
+
+    let [
+      title, message, okButton, cancelButton,
+    ] = await document.l10n.formatValues([
+      {id: "update-in-progress-title"},
+      {id: "update-in-progress-message"},
+      {id: "update-in-progress-ok-button"},
+      {id: "update-in-progress-cancel-button"},
+    ]);
+
+    // Continue is the cancel button which is BUTTON_POS_1 and is set as the
+    // default so pressing escape or using a platform standard method of closing
+    // the UI will not discard the update.
+    let buttonFlags =
+      (Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_0) +
+      (Ci.nsIPrompt.BUTTON_TITLE_IS_STRING * Ci.nsIPrompt.BUTTON_POS_1) +
+      Ci.nsIPrompt.BUTTON_POS_1_DEFAULT;
+
+    let rv = Services.prompt.confirmEx(window, title, message, buttonFlags,
+      okButton, cancelButton, null, null, {});
+    if (rv != 1) {
+      let aus = Cc["@mozilla.org/updates/update-service;1"].
+                getService(Ci.nsIApplicationUpdateService);
+      aus.stopDownload();
+      um.cleanupActiveUpdate();
+    }
+  },
+
   showUpdates() {
     gSubDialog.open("chrome://mozapps/content/update/history.xul");
   },
 
   updateCompactOptions() {
     document.getElementById("offlineCompactFolderMin").disabled =
       !Preferences.get("mail.prompt_purge_threshhold").value ||
       Preferences.get("mail.purge_threshhold_mb").locked;
--- a/mail/locales/en-US/messenger/preferences/preferences.ftl
+++ b/mail/locales/en-US/messenger/preferences/preferences.ftl
@@ -9,8 +9,17 @@ manage-messenger-languages-button =
 confirm-messenger-language-change-description = Restart { -brand-short-name } to apply these changes
 confirm-messenger-language-change-button = Apply and Restart
 
 update-pref-write-failure-title = Write Failure
 
 # Variables:
 #   $path (String) - Path to the configuration file
 update-pref-write-failure-message = Unable to save preference. Could not write to file: { $path }
+
+update-in-progress-title = Update In Progress
+
+update-in-progress-message = Do you want { -brand-short-name } to continue with this update?
+
+update-in-progress-ok-button = &Discard
+# Continue is the cancel button so pressing escape or using a platform standard
+# method of closing the UI will not discard the update.
+update-in-progress-cancel-button = &Continue