Handle all download events in completed block.

'update-downloaded' and 'update-not-available' events are now called
in the completed block.
This commit is contained in:
probablycorey 2014-01-31 16:13:01 -08:00
parent 6949af5427
commit a59756485e

View file

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