Add acknowledgement handlers to no update found / errors

This way, if the errors are not presented modally, they won't be dismissed
until we tell the updater we are finished acknowledging them
This commit is contained in:
Zorg committed 2016-03-05 14:42:17 -05:00
1 parent 337f39e8b9
commit 96f016a790
6 files changed
+66 -15

No files matched your search

+10 -2
View File
@@ -244,25 +244,33 @@
#pragma mark Update Errors
- (void)showUpdaterError:(NSError *)error
- (void)showUpdaterError:(NSError *)error acknowledgement:(void (^)(void))acknowledgement
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreComponent registerAcknowledgement:acknowledgement];
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = SULocalizedString(@"Update Error!", nil);
alert.informativeText = [NSString stringWithFormat:@"%@", [error localizedDescription]];
[alert addButtonWithTitle:SULocalizedString(@"Cancel Update", nil)];
[self showAlert:alert];
[self.coreComponent acceptAcknowledgement];
});
}
- (void)showUpdateNotFound
- (void)showUpdateNotFoundWithAcknowledgement:(void (^)(void))acknowledgement
{
dispatch_async(dispatch_get_main_queue(), ^{
[self.coreComponent registerAcknowledgement:acknowledgement];
NSAlert *alert = [[NSAlert alloc] init];
alert.messageText = SULocalizedString(@"You're up-to-date!", "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates.");
alert.informativeText = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [self.host name], [self.host displayVersion]];
[alert addButtonWithTitle:SULocalizedString(@"OK", nil)];
[self showAlert:alert];
[self.coreComponent acceptAcknowledgement];
});
}
+10 -6
View File
@@ -54,10 +54,12 @@
if (!self.automaticallyInstallUpdates) {
[self showNotice:^{
[self.updater.userDriver showUpdateNotFound];
[self.updater.userDriver showUpdateNotFoundWithAcknowledgement:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self abortUpdate];
});
}];
}];
[self abortUpdate];
}
}
@@ -166,10 +168,12 @@
- (void)abortUpdateWithError:(NSError *)error
{
[self showNotice:^{
[self.updater.userDriver showUpdaterError:error];
[self.updater.userDriver showUpdaterError:error acknowledgement:^{
dispatch_async(dispatch_get_main_queue(), ^{
[super abortUpdateWithError:error];
});
}];
}];
[super abortUpdateWithError:error];
}
// Calling deprecated modal alert methods just to preserve backwards compatibility
+6 -2
View File
@@ -150,9 +150,11 @@ NS_ASSUME_NONNULL_BEGIN
*
* Let the user know a new update was not found after they tried initiating an update check.
*
* @param acknowledgement Acknowledge to the updater that no update found was shown.
*
* This can be called from any thread
*/
- (void)showUpdateNotFound;
- (void)showUpdateNotFoundWithAcknowledgement:(void (^)(void))acknowledgement;
/*!
* Show the user an update error occurred
@@ -160,9 +162,11 @@ NS_ASSUME_NONNULL_BEGIN
* Let the user know that the updater failed with an error. This will not be invoked without the user having been
* aware that an update was in progress.
*
* @param acknowledgement Acknowledge to the updater that the error was shown.
*
* This can be called from any thread
*/
- (void)showUpdaterError:(NSError *)error;
- (void)showUpdaterError:(NSError *)error acknowledgement:(void (^)(void))acknowledgement;
/*!
* Show the user that downloading the new update initiated
+3
View File
@@ -42,6 +42,9 @@
- (void)cancelDownloadStatus;
- (void)completeDownloadStatus;
- (void)registerAcknowledgement:(void (^)(void))acknowledgement;
- (void)acceptAcknowledgement;
- (void)dismissUpdateInstallation;
- (void)invalidate;
+19
View File
@@ -28,6 +28,7 @@
@property (nonatomic, copy) void (^installUpdateHandler)(SUInstallUpdateStatus);
@property (nonatomic, copy) void (^updateCheckStatusCompletion)(SUUserInitiatedCheckStatus);
@property (nonatomic, copy) void (^downloadStatusCompletion)(SUDownloadUpdateStatus);
@property (nonatomic, copy) void (^acknowledgement)(void);
@end
@@ -42,6 +43,7 @@
@synthesize installUpdateHandler = _installUpdateHandler;
@synthesize updateCheckStatusCompletion = _updateCheckStatusCompletion;
@synthesize downloadStatusCompletion = _downloadStatusCompletion;
@synthesize acknowledgement = _acknowledgement;
#pragma mark Birth
@@ -194,6 +196,21 @@
}
}
#pragma mark Simple Acknoledgments
- (void)registerAcknowledgement:(void (^)(void))acknowledgement
{
self.acknowledgement = acknowledgement;
}
- (void)acceptAcknowledgement
{
if (self.acknowledgement != nil) {
self.acknowledgement();
self.acknowledgement = nil;
}
}
#pragma mark Aborting Everything
- (void)dismissUpdateInstallation
@@ -202,6 +219,7 @@
self.updateInProgress = NO;
[self acceptAcknowledgement];
[self cancelUpdateCheckStatus];
[self cancelDownloadStatus];
[self cancelInstallAndRestart];
@@ -211,6 +229,7 @@
- (void)invalidate
{
// Make sure any remote handlers will not be invoked
self.acknowledgement = nil;
self.checkForUpdatesReply = nil;
self.downloadStatusCompletion = nil;
self.installUpdateHandler = nil;
+18 -5
View File
@@ -233,19 +233,32 @@
#pragma mark Update Errors
- (void)showUpdaterError:(NSError *)error
- (void)showUpdaterError:(NSError *)error acknowledgement:(void (^)(void))acknowledgement
{
dispatch_async(dispatch_get_main_queue(), ^{
// Too lazy to show an alert; the update installation will be dismissed shortly
[self.coreComponent registerAcknowledgement:acknowledgement];
NSLog(@"Error: %@", error);
[self addUpdateButtonWithTitle:@"Update Errored!" action:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// Installation will be dismissed shortly after this
[self.coreComponent acceptAcknowledgement];
});
});
}
- (void)showUpdateNotFound
- (void)showUpdateNotFoundWithAcknowledgement:(void (^)(void))acknowledgement
{
dispatch_async(dispatch_get_main_queue(), ^{
// Too lazy to show an alert; the update installation will be dismissed shortly
NSLog(@"No Update Found");
[self.coreComponent registerAcknowledgement:acknowledgement];
[self addUpdateButtonWithTitle:@"No Update Available" action:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// Installation will be dismissed shortly after this
[self.coreComponent acceptAcknowledgement];
});
});
}