Emit 'update-available' and 'checking-for-update' events.

This commit is contained in:
probablycorey 2014-01-31 16:11:11 -08:00
parent da602a7c01
commit 6949af5427
4 changed files with 26 additions and 0 deletions

View 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");
}

View 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,

View 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() {}

View 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();
}
}];
}
}