From: probablycorey Date: Sat, 1 Feb 2014 00:11:11 +0000 (-0800) Subject: Emit 'update-available' and 'checking-for-update' events. X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=6949af542750742292b123e1cc93ca42696c28ee;p=electron.git Emit 'update-available' and 'checking-for-update' events. --- diff --git a/browser/api/atom_api_auto_updater.cc b/browser/api/atom_api_auto_updater.cc index a18fdebc..69ed1008 100644 --- a/browser/api/atom_api_auto_updater.cc +++ b/browser/api/atom_api_auto_updater.cc @@ -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"); } diff --git a/browser/api/atom_api_auto_updater.h b/browser/api/atom_api_auto_updater.h index 2bb830c2..0207cbe6 100644 --- a/browser/api/atom_api_auto_updater.h +++ b/browser/api/atom_api_auto_updater.h @@ -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, diff --git a/browser/auto_updater_delegate.h b/browser/auto_updater_delegate.h index 063cc79d..280d3ed0 100644 --- a/browser/auto_updater_delegate.h +++ b/browser/auto_updater_delegate.h @@ -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() {} diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index 94c4bda2..f2c55616 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -6,6 +6,7 @@ #import #import +#import #import #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(); + } }]; } }