]> khamidou — GitHub mirrors - electron.git/commitdiff
Handle all download events in completed block.
authorprobablycorey <cj@github.com>
Sat, 1 Feb 2014 00:13:01 +0000 (16:13 -0800)
committerprobablycorey <cj@github.com>
Sat, 1 Feb 2014 00:13:01 +0000 (16:13 -0800)
'update-downloaded' and 'update-not-available' events are now called
in the completed block.

browser/auto_updater_mac.mm

index f2c55616a00ece573915dee1460ff5ccc4c68480..66a532b2c98d0ef6950703d2bb343f33a0b951ac 100644 (file)
@@ -45,25 +45,29 @@ void AutoUpdater::SetFeedURL(const std::string& feed) {
     if (!delegate)
       return;
 
+    __block SQRLUpdate* update = nil;
     // Subscribe to events.
-    __block bool has_update = false;
     [g_updater.updates subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) {
-      has_update = true;
-
-      // There is a new update that has been downloaded.
-      SQRLUpdate* update = downloadedUpdate.update;
-      delegate->OnUpdateDownloaded(
+      update = downloadedUpdate.update;
+    } completed:^() {
+      if (update) {
+        // There is a new update that has been downloaded.
+        delegate->OnUpdateDownloaded(
           base::SysNSStringToUTF8(update.releaseNotes),
           base::SysNSStringToUTF8(update.releaseName),
           base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970),
           base::SysNSStringToUTF8(update.updateURL.absoluteString),
           base::Bind(RelaunchToInstallUpdate));
-    } completed:^() {
-      // When the completed event is sent with no update, then we know there
-      // is no update available.
-      if (!has_update)
+      }
+      else {
+        // When the completed event is sent with no update, then we know there
+        // is no update available.
         delegate->OnUpdateNotAvailable();
-      has_update = false;
+      }
+
+      update = nil;
+    }];
+
     [[g_updater rac_valuesForKeyPath:@"state" observer:g_updater]
       subscribeNext:^(NSNumber *stateNumber) {
         int state = [stateNumber integerValue];
@@ -90,5 +94,4 @@ void AutoUpdater::CheckForUpdates() {
     delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription));
   }];
 }
-
 }  // namespace auto_updater