]> khamidou — GitHub mirrors - electron.git/commitdiff
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 a18fdebce9d06658f72145cdfe8e259d48b11f8a..69ed10089128d85d0dd6aa4bd458e9040417cb3c 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 2bb830c2767997b6750bf8462a31232cf48d6a4d..0207cbe6a99f919b7ed4cae40bc50053b1a8c2df 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 063cc79d5e7f54096914cd38e797fa8e9b48b503..280d3ed0f97af7136b226d10c1375860435f9462 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 94c4bda279fcc34ebddac44129fb0c0fff328c1e..f2c55616a00ece573915dee1460ff5ccc4c68480 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();
+        }
     }];
   }
 }