Emit 'update-available' and 'checking-for-update' events.
authorprobablycorey <cj@github.com>
Sat, 1 Feb 2014 00:11:11 +0000 (16:11 -0800)
committerprobablycorey <cj@github.com>
Sat, 1 Feb 2014 00:11:11 +0000 (16:11 -0800)
browser/api/atom_api_auto_updater.cc
browser/api/atom_api_auto_updater.h
browser/auto_updater_delegate.h
browser/auto_updater_mac.mm

index a18fdeb..69ed100 100644 (file)
@@ -30,6 +30,14 @@ void AutoUpdater::OnError(const std::string& error) {
   Emit("error", &args);
 }
 
+void AutoUpdater::OnCheckingForUpdate() {
+  Emit("checking-for-update");
+}
+
+void AutoUpdater::OnUpdateAvailable() {
+  Emit("update-available");
+}
+
 void AutoUpdater::OnUpdateNotAvailable() {
   Emit("update-not-available");
 }
index 2bb830c..0207cbe 100644 (file)
@@ -26,6 +26,8 @@ class AutoUpdater : public EventEmitter,
 
   // AutoUpdaterDelegate implementations.
   virtual void OnError(const std::string& error) OVERRIDE;
+  virtual void OnCheckingForUpdate() OVERRIDE;
+  virtual void OnUpdateAvailable() OVERRIDE;
   virtual void OnUpdateNotAvailable() OVERRIDE;
   virtual void OnUpdateDownloaded(
       const std::string& release_notes,
index 063cc79..280d3ed 100644 (file)
@@ -20,6 +20,12 @@ class AutoUpdaterDelegate {
   // An error happened.
   virtual void OnError(const std::string& error) {}
 
+  // Checking to see if there is an update
+  virtual void OnCheckingForUpdate() {}
+
+  // There is an update available and it is being downloaded
+  virtual void OnUpdateAvailable() {}
+
   // There is no available update.
   virtual void OnUpdateNotAvailable() {}
 
index 94c4bda..f2c5561 100644 (file)
@@ -6,6 +6,7 @@
 
 #import <ReactiveCocoa/RACCommand.h>
 #import <ReactiveCocoa/RACSignal.h>
+#import <ReactiveCocoa/NSObject+RACPropertySubscribing.h>
 #import <Squirrel/Squirrel.h>
 
 #include "base/bind.h"
@@ -63,6 +64,15 @@ void AutoUpdater::SetFeedURL(const std::string& feed) {
       if (!has_update)
         delegate->OnUpdateNotAvailable();
       has_update = false;
+    [[g_updater rac_valuesForKeyPath:@"state" observer:g_updater]
+      subscribeNext:^(NSNumber *stateNumber) {
+        int state = [stateNumber integerValue];
+        if (state == SQRLUpdaterStateCheckingForUpdate) {
+          delegate->OnCheckingForUpdate();
+        }
+        else if (state == SQRLUpdaterStateDownloadingUpdate) {
+          delegate->OnUpdateAvailable();
+        }
     }];
   }
 }