Add error and update-not-available events for auto updater.
This commit is contained in:
parent
df399f7c8c
commit
d4e362ec89
4 changed files with 43 additions and 12 deletions
|
@ -24,6 +24,16 @@ AutoUpdater::~AutoUpdater() {
|
||||||
auto_updater::AutoUpdater::SetDelegate(NULL);
|
auto_updater::AutoUpdater::SetDelegate(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AutoUpdater::OnError(const std::string& error) {
|
||||||
|
base::ListValue args;
|
||||||
|
args.AppendString(error);
|
||||||
|
Emit("error", &args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AutoUpdater::OnUpdateNotAvailable() {
|
||||||
|
Emit("update-not-available");
|
||||||
|
}
|
||||||
|
|
||||||
void AutoUpdater::OnUpdateDownloaded(const std::string& release_notes,
|
void AutoUpdater::OnUpdateDownloaded(const std::string& release_notes,
|
||||||
const std::string& release_name,
|
const std::string& release_name,
|
||||||
const base::Time& release_date,
|
const base::Time& release_date,
|
||||||
|
|
|
@ -25,6 +25,8 @@ class AutoUpdater : public EventEmitter,
|
||||||
explicit AutoUpdater(v8::Handle<v8::Object> wrapper);
|
explicit AutoUpdater(v8::Handle<v8::Object> wrapper);
|
||||||
|
|
||||||
// AutoUpdaterDelegate implementations.
|
// AutoUpdaterDelegate implementations.
|
||||||
|
virtual void OnError(const std::string& error) OVERRIDE;
|
||||||
|
virtual void OnUpdateNotAvailable() OVERRIDE;
|
||||||
virtual void OnUpdateDownloaded(
|
virtual void OnUpdateDownloaded(
|
||||||
const std::string& release_notes,
|
const std::string& release_notes,
|
||||||
const std::string& release_name,
|
const std::string& release_name,
|
||||||
|
|
|
@ -17,6 +17,12 @@ namespace auto_updater {
|
||||||
|
|
||||||
class AutoUpdaterDelegate {
|
class AutoUpdaterDelegate {
|
||||||
public:
|
public:
|
||||||
|
// An error happened.
|
||||||
|
virtual void OnError(const std::string& error) {}
|
||||||
|
|
||||||
|
// There is no available update.
|
||||||
|
virtual void OnUpdateNotAvailable() {}
|
||||||
|
|
||||||
// There is a new update which has been downloaded.
|
// There is a new update which has been downloaded.
|
||||||
virtual void OnUpdateDownloaded(const std::string& release_notes,
|
virtual void OnUpdateDownloaded(const std::string& release_notes,
|
||||||
const std::string& release_name,
|
const std::string& release_name,
|
||||||
|
|
|
@ -35,19 +35,32 @@ void AutoUpdater::SetFeedURL(const std::string& feed) {
|
||||||
NSURLRequest* urlRequest = [NSURLRequest requestWithURL:url];
|
NSURLRequest* urlRequest = [NSURLRequest requestWithURL:url];
|
||||||
g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest];
|
g_updater = [[SQRLUpdater alloc] initWithUpdateRequest:urlRequest];
|
||||||
|
|
||||||
// Subscribe to events.
|
AutoUpdaterDelegate* delegate = GetDelegate();
|
||||||
[g_updater.updates subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) {
|
if (!delegate)
|
||||||
AutoUpdaterDelegate* delegate = GetDelegate();
|
return;
|
||||||
if (!delegate)
|
|
||||||
return;
|
|
||||||
|
|
||||||
SQRLUpdate* update = downloadedUpdate.update;
|
// Subscribe to events.
|
||||||
delegate->OnUpdateDownloaded(
|
__block bool has_update = false;
|
||||||
base::SysNSStringToUTF8(update.releaseNotes),
|
[g_updater.updates subscribeNext:^(SQRLDownloadedUpdate* downloadedUpdate) {
|
||||||
base::SysNSStringToUTF8(update.releaseName),
|
has_update = true;
|
||||||
base::Time::FromDoubleT(update.releaseDate.timeIntervalSince1970),
|
|
||||||
base::SysNSStringToUTF8(update.updateURL.absoluteString),
|
// There is a new update that has been downloaded.
|
||||||
base::Bind(RelaunchToInstallUpdate));
|
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) {
|
||||||
|
// 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;
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue