Bug 758326 - Port bug 481815 - Provide a Windows service to update applications without asking Administrator password; Enable staging of background updates. r+ui-review=bwinton for port to beta. Original patches r=sid0. a=Standard8 SEAMONKEY_2_13b1_BUILD1 SEAMONKEY_2_13b1_RELEASE
authorMark Banner <bugzilla@standard8.plus.com>
Tue, 28 Aug 2012 16:55:28 +0100
changeset 12976 06268baf043ee2eddc384e2b2bf75626c2135496
parent 12975 0d44eadd4af1e578de6bd4c4bd6763580d8122f7
child 12977 d05551c89adc7521882caf5e92d93f2dd14d720e
child 12979 e69ab974bb7a46efa0798f0a28259a7fda71fbd5
child 12981 ee519271a134b7567eceaeb212145dd7b05dd540
push idunknown
push userunknown
push dateunknown
reviewerssid0, Standard8
bugs758326, 481815
Bug 758326 - Port bug 481815 - Provide a Windows service to update applications without asking Administrator password; Enable staging of background updates. r+ui-review=bwinton for port to beta. Original patches r=sid0. a=Standard8
mail/base/content/aboutDialog.js
--- a/mail/base/content/aboutDialog.js
+++ b/mail/base/content/aboutDialog.js
@@ -149,16 +149,22 @@ function appUpdater()
   }
 
   if (this.isPending) {
     this.setupUpdateButton("update.restart." +
                            (this.isMajor ? "upgradeButton" : "updateButton"));
     return;
   }
 
+  if (this.isApplied) {
+    this.setupUpdateButton("update.restart." +
+                           (this.isMajor ? "upgradeButton" : "updateButton"));
+    return;
+  }
+
   if (this.isDownloading) {
     this.startDownload();
     return;
   }
 
   if (this.updateEnabled && this.updateAuto) {
     this.selectPanel("checkingForUpdates");
     this.isChecking = true;
@@ -178,16 +184,26 @@ appUpdater.prototype =
       return this.update.state == "pending" || 
              this.update.state == "pending-service";
     }
     return this.um.activeUpdate &&
            (this.um.activeUpdate.state == "pending" ||
             this.um.activeUpdate.state == "pending-service");
   },
 
+  get isApplied() {
+    if (this.update) {
+      return this.update.state == "applied" || 
+             this.update.state == "applied-service";
+    }
+    return this.um.activeUpdate &&
+           (this.um.activeUpdate.state == "applied" ||
+            this.um.activeUpdate.state == "applied-service");
+  },
+
   // true when there is an update download in progress.
   get isDownloading() {
     if (this.update)
       return this.update.state == "downloading";
     return this.um.activeUpdate &&
            this.um.activeUpdate.state == "downloading";
   },
 
@@ -208,16 +224,22 @@ appUpdater.prototype =
   get updateEnabled() {
     try {
       return Services.prefs.getBoolPref("app.update.enabled");
     }
     catch (e) { }
     return true; // Thunderbird default is true
   },
 
+  // true when updating in background is enabled.
+  get backgroundUpdateEnabled() {
+    return this.updateEnabled &&
+           Services.prefs.getBoolPref("app.update.stage.enabled");
+  },
+
   // true when updating is automatic.
   get updateAuto() {
     try {
       return Services.prefs.getBoolPref("app.update.auto");
     }
     catch (e) { }
     return true; // Thunderbird default is true
   },
@@ -247,17 +269,17 @@ appUpdater.prototype =
         document.commandDispatcher.focusedElement == this.updateBtn)
       this.updateBtn.focus();
   },
 
   /**
    * Handles oncommand for the update button.
    */
   buttonOnCommand: function() {
-    if (this.isPending) {
+    if (this.isPending || this.isApplied) {
       // Notify all windows that an application quit has been requested.
       let cancelQuit = Components.classes["@mozilla.org/supports-PRBool;1"].
                        createInstance(Components.interfaces.nsISupportsPRBool);
       Services.obs.notifyObservers(cancelQuit, "quit-application-requested", "restart");
 
       // Something aborted the quit process.
       if (cancelQuit.data)
         return;
@@ -525,19 +547,45 @@ appUpdater.prototype =
       // Verification failed for a partial patch, complete patch is now
       // downloading so return early and do NOT remove the download listener!
       break;
     case Components.results.NS_BINDING_ABORTED:
       // Do not remove UI listener since the user may resume downloading again.
       break;
     case Components.results.NS_OK:
       this.removeDownloadListener();
-      this.selectPanel("updateButtonBox");
-      this.setupUpdateButton("update.restart." +
-                             (this.isMajor ? "upgradeButton" : "updateButton"));
+      if (this.backgroundUpdateEnabled) {
+        // For TB 16, just keep displaying the downloading box until we've applied the
+        // update.
+        //this.selectPanel("applying");
+        let update = this.um.activeUpdate;
+        let self = this;
+        Services.obs.addObserver(function (aSubject, aTopic, aData) {
+          // Update the UI when the background updater is finished
+          let status = update.state;
+          if (status == "applied" || status == "applied-service" ||
+              status == "pending" || status == "pending-service") {
+            // If the update is successfully applied, or if the updater has
+            // fallen back to non-staged updates, show the Restart to Update
+            // button.
+            self.selectPanel("updateButtonBox");
+            self.setupUpdateButton("update.restart." +
+                                   (self.isMajor ? "upgradeButton" : "updateButton"));
+          } else if (status == "failed") {
+            // Background update has failed, let's show the UI responsible for
+            // prompting the user to update manually.
+            self.selectPanel("downloadFailed");
+          }
+          Services.obs.removeObserver(arguments.callee, "update-staged");
+        }, "update-staged", false);
+      } else {
+        this.selectPanel("updateButtonBox");
+        this.setupUpdateButton("update.restart." +
+                               (this.isMajor ? "upgradeButton" : "updateButton"));
+      }
       break;
     default:
       this.removeDownloadListener();
       this.selectPanel("downloadFailed");
       break;
     }
 
   },