From 96f016a790ddf87631f1035f7c61fe9ed6392103 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 5 Mar 2016 14:42:17 -0500 Subject: [PATCH] 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 --- Sparkle/SUStandardUserDriver.m | 12 +++++++++-- Sparkle/SUUIBasedUpdateDriver.m | 16 ++++++++------ Sparkle/SUUserDriver.h | 8 +++++-- Sparkle/SUUserDriverCoreComponent.h | 3 +++ Sparkle/SUUserDriverCoreComponent.m | 19 +++++++++++++++++ TestApplication/SUPopUpTitlebarUserDriver.m | 23 ++++++++++++++++----- 6 files changed, 66 insertions(+), 15 deletions(-) diff --git a/Sparkle/SUStandardUserDriver.m b/Sparkle/SUStandardUserDriver.m index 4cfcb7cb..5329648c 100644 --- a/Sparkle/SUStandardUserDriver.m +++ b/Sparkle/SUStandardUserDriver.m @@ -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]; }); } diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index 351d9c5b..f59ee5b9 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -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 diff --git a/Sparkle/SUUserDriver.h b/Sparkle/SUUserDriver.h index ba69cd4a..919429fd 100644 --- a/Sparkle/SUUserDriver.h +++ b/Sparkle/SUUserDriver.h @@ -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 diff --git a/Sparkle/SUUserDriverCoreComponent.h b/Sparkle/SUUserDriverCoreComponent.h index 2a86a831..a1e22828 100644 --- a/Sparkle/SUUserDriverCoreComponent.h +++ b/Sparkle/SUUserDriverCoreComponent.h @@ -42,6 +42,9 @@ - (void)cancelDownloadStatus; - (void)completeDownloadStatus; +- (void)registerAcknowledgement:(void (^)(void))acknowledgement; +- (void)acceptAcknowledgement; + - (void)dismissUpdateInstallation; - (void)invalidate; diff --git a/Sparkle/SUUserDriverCoreComponent.m b/Sparkle/SUUserDriverCoreComponent.m index 145e5ccd..e664b403 100644 --- a/Sparkle/SUUserDriverCoreComponent.m +++ b/Sparkle/SUUserDriverCoreComponent.m @@ -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; diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index 665ad5fd..d6c5bf9a 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -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]; + }); }); }