mirror of
https://github.com/electron/electron.git
synced 2026-02-11 23:54:57 -05:00
Still subscribe to "updates" for update notifications.
It seems that we should subscribeError to checkForUpdatesCommand to catch all errors, and the "updates" would only work when there is no error happened.
This commit is contained in:
@@ -37,6 +37,31 @@ void AutoUpdater::SetFeedURL(const std::string& feed) {
|
||||
NSURL* url = [NSURL URLWithString:base::SysUTF8ToNSString(feed)];
|
||||
NSURLRequest* urlRequest = [NSURLRequest requestWithURL:url];
|
||||
g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest];
|
||||
|
||||
AutoUpdaterDelegate* delegate = GetDelegate();
|
||||
if (!delegate)
|
||||
return;
|
||||
|
||||
// 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(
|
||||
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)
|
||||
delegate->OnUpdateNotAvailable();
|
||||
has_update = false;
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,28 +73,9 @@ void AutoUpdater::CheckForUpdates() {
|
||||
if (!delegate)
|
||||
return;
|
||||
|
||||
// Subscribe to events.
|
||||
__block bool has_update = false;
|
||||
[signal subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) {
|
||||
has_update = true;
|
||||
|
||||
// There is a new update that has been downloaded.
|
||||
SQRLUpdate* update = downloadedUpdate.update;
|
||||
delegate->OnUpdateDownloaded(
|
||||
base::SysNSStringToUTF8(update.releaseNotes),
|
||||
base::SysNSStringToUTF8(update.releaseName),
|
||||
base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970),
|
||||
base::SysNSStringToUTF8(update.updateURL.absoluteString),
|
||||
base::Bind(RelaunchToInstallUpdate));
|
||||
} error:^(NSError* error) {
|
||||
[signal subscribeError:^(NSError* error) {
|
||||
// Something wrong happened.
|
||||
delegate->OnError(base::SysNSStringToUTF8(error.localizedDescription));
|
||||
} completed:^() {
|
||||
// When the completed event is sent with no update, then we know there
|
||||
// is no update available.
|
||||
if (!has_update)
|
||||
delegate->OnUpdateNotAvailable();
|
||||
has_update = false;
|
||||
}];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user