From: probablycorey Date: Sat, 1 Feb 2014 00:13:01 +0000 (-0800) Subject: Handle all download events in completed block. X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=a59756485eda7d5b92585008bf1a742ca3297638;p=electron.git Handle all download events in completed block. 'update-downloaded' and 'update-not-available' events are now called in the completed block. --- diff --git a/browser/auto_updater_mac.mm b/browser/auto_updater_mac.mm index f2c55616..66a532b2 100644 --- a/browser/auto_updater_mac.mm +++ b/browser/auto_updater_mac.mm @@ -45,25 +45,29 @@ void AutoUpdater::SetFeedURL(const std::string& feed) { if (!delegate) return; + __block SQRLUpdate* update = nil; // Subscribe to events. - __block bool has_update = false; [g_updater.updates subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) { - has_update = true; - - // There is a new update that has been downloaded. - SQRLUpdate* update = downloadedUpdate.update; - delegate->OnUpdateDownloaded( + update = downloadedUpdate.update; + } completed:^() { + if (update) { + // There is a new update that has been downloaded. + delegate->OnUpdateDownloaded( base::SysNSStringToUTF8(update.releaseNotes), base::SysNSStringToUTF8(update.releaseName), base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970), base::SysNSStringToUTF8(update.updateURL.absoluteString), base::Bind(RelaunchToInstallUpdate)); - } completed:^() { - // When the completed event is sent with no update, then we know there - // is no update available. - if (!has_update) + } + else { + // When the completed event is sent with no update, then we know there + // is no update available. delegate->OnUpdateNotAvailable(); - has_update = false; + } + + update = nil; + }]; + [[g_updater rac_valuesForKeyPath:@"state" observer:g_updater] subscribeNext:^(NSNumber *stateNumber) { int state = [stateNumber integerValue]; @@ -90,5 +94,4 @@ void AutoUpdater::CheckForUpdates() { delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription)); }]; } - } // namespace auto_updater