From dca21149340528585e6a926839c6e1a184b7d5c0 Mon Sep 17 00:00:00 2001 From: Zorg Date: Mon, 2 Jan 2017 18:00:17 -0500 Subject: [PATCH] Add user driver method to show informational only updates This will increase the chance of a user driver implementing being able to show informational only updates. Also it's better to use a new method rather than re-use another existing one inappropriately. --- Sparkle/SPUStandardUserDriver.m | 10 +++++++++ Sparkle/SPUStatusCompletionResults.h | 5 +++++ Sparkle/SPUUIBasedUpdateDriver.m | 24 +++++++++++++++------ Sparkle/SPUUserDriver.h | 24 +++++++++++++++++++-- Sparkle/SUUpdateAlert.h | 2 ++ Sparkle/SUUpdateAlert.m | 23 ++++++++++++++++++++ TestApplication/SUPopUpTitlebarUserDriver.m | 10 +++++++++ sparkle-cli/SPUCommandLineUserDriver.m | 9 ++++++++ 8 files changed, 99 insertions(+), 8 deletions(-) diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index e8a7203b..9668cc12 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -157,6 +157,16 @@ }]; } +- (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply +{ + [self showUpdateFoundWithAlertHandler:^SUUpdateAlert *(SPUStandardUserDriver *weakSelf, SUHost *host, id versionDisplayer) { + return [[SUUpdateAlert alloc] initWithAppcastItem:appcastItem host:host versionDisplayer:versionDisplayer informationalCompletionBlock:^(SPUInformationalUpdateAlertChoice choice) { + reply(choice); + weakSelf.activeUpdateAlert = nil; + }]; + }]; +} + - (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData { dispatch_async(dispatch_get_main_queue(), ^{ diff --git a/Sparkle/SPUStatusCompletionResults.h b/Sparkle/SPUStatusCompletionResults.h index 929dbb38..f16a1a2a 100644 --- a/Sparkle/SPUStatusCompletionResults.h +++ b/Sparkle/SPUStatusCompletionResults.h @@ -37,4 +37,9 @@ typedef NS_ENUM(NSInteger, SPUUpdateAlertChoice) { SPUSkipThisVersionChoice }; +typedef NS_ENUM(NSInteger, SPUInformationalUpdateAlertChoice) { + SPUDismissInformationalNoticeChoice, + SPUSkipThisInformationalVersionChoice +}; + #endif /* SPUStatusCompletionResults_h */ diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index 13e4a804..36923e8b 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -107,7 +107,23 @@ - (void)basicDriverDidFindUpdateWithAppcastItem:(SUAppcastItem *)updateItem { - if (self.resumingDownloadedUpdate) { + if (updateItem.isInformationOnlyUpdate) { + assert(!self.resumingDownloadedUpdate); + assert(!self.resumingInstallingUpdate); + + [self.userDriver showInformationalUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUInformationalUpdateAlertChoice choice) { + dispatch_async(dispatch_get_main_queue(), ^{ + switch (choice) { + case SPUSkipThisInformationalVersionChoice: + [self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; + // Fall through + case SPUDismissInformationalNoticeChoice: + [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; + break; + } + }); + }]; + } else if (self.resumingDownloadedUpdate) { [self.userDriver showDownloadedUpdateFoundWithAppcastItem:updateItem userInitiated:self.userInitiated reply:^(SPUUpdateAlertChoice choice) { dispatch_async(dispatch_get_main_queue(), ^{ [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; @@ -131,11 +147,7 @@ [self.host setObject:nil forUserDefaultsKey:SUSkippedVersionKey]; switch (choice) { case SPUInstallUpdateChoice: - if (!updateItem.isInformationOnlyUpdate) { - [self.coreDriver downloadUpdateFromAppcastItem:updateItem]; - } else { - [self.delegate uiDriverIsRequestingAbortUpdateWithError:nil]; - } + [self.coreDriver downloadUpdateFromAppcastItem:updateItem]; break; case SPUSkipThisVersionChoice: [self.host setObject:[updateItem versionString] forUserDefaultsKey:SUSkippedVersionKey]; diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index 9bf6ed9b..6851b110 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -84,7 +84,7 @@ SU_EXPORT @protocol SPUUserDriver - (void)dismissUserInitiatedUpdateCheck; /*! - * Show the user a new update is found + * Show the user a new update is found and can be downloaded and installed * * Let the user know a new update is found and ask them what they want to do. * @@ -94,7 +94,6 @@ SU_EXPORT @protocol SPUUserDriver * * @param reply * A reply of SPUInstallUpdateChoice begins downloading and installing the new update. - * Note if the update is only informational (appcastItem.isInformationOnlyUpdate), this response shouldn't be made. * * A reply of SPUInstallLaterChoice reminds the user later of the update, which can act as a "do nothing" option. * @@ -133,6 +132,27 @@ SU_EXPORT @protocol SPUUserDriver */ - (void)showResumableUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUInstallUpdateStatus))reply; +/*! + * Show the user a new informational only update has been found + * + * Let the user know a new informational update is found and ask them what they want to do. + * + * @param appcastItem The Appcast Item containing information that reflects the new update. + * The infoURL property for the appcastItem may be of interest. + * + * @param userInitiated A flag indicating whether or not a user initiated this update check + * + * @param reply + * A reply of SPUDismissInformationalNoticeChoice dismisses this notice. + * An implementor may decide to invoke another action before dismissing the notice. + * + * A reply of SPUSkipThisInformationalVersionChoice skips this particular version and won't bother the user again, + * unless they initiate an update check themselves. + * + * This can be called from any thread + */ +- (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply; + /*! * Show the user the release notes for the new update * diff --git a/Sparkle/SUUpdateAlert.h b/Sparkle/SUUpdateAlert.h index f2d131b0..cc7152b8 100644 --- a/Sparkle/SUUpdateAlert.h +++ b/Sparkle/SUUpdateAlert.h @@ -24,6 +24,8 @@ - (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer resumableCompletionBlock:(void (^)(SPUInstallUpdateStatus))block; +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer informationalCompletionBlock:(void (^)(SPUInformationalUpdateAlertChoice))block; + - (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData; - (void)showReleaseNotesFailedToDownload; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index edb92ec2..628d7fc1 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -40,6 +40,7 @@ @property (nonatomic) BOOL allowsAutomaticUpdates; @property (nonatomic, copy, nullable) void(^completionBlock)(SPUUpdateAlertChoice); @property (nonatomic, copy, nullable) void(^resumableCompletionBlock)(SPUInstallUpdateStatus); +@property (nonatomic, copy, nullable) void(^informationalCompletionBlock)(SPUInformationalUpdateAlertChoice); @property (strong) NSProgressIndicator *releaseNotesSpinner; @property (assign) BOOL webViewFinishedLoading; @@ -59,6 +60,7 @@ @synthesize completionBlock = _completionBlock; @synthesize alreadyDownloaded = _alreadyDownloaded; @synthesize resumableCompletionBlock = _resumableCompletionBlock; +@synthesize informationalCompletionBlock = _informationalCompletionBlock; @synthesize versionDisplayer; @synthesize updateItem; @@ -118,6 +120,16 @@ return self; } +- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost versionDisplayer:(id )aVersionDisplayer informationalCompletionBlock:(void (^)(SPUInformationalUpdateAlertChoice))block +{ + self = [self initWithAppcastItem:item host:aHost versionDisplayer:aVersionDisplayer]; + if (self != nil) + { + _informationalCompletionBlock = [block copy]; + } + return self; +} + - (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], [self.host bundlePath]]; } @@ -144,6 +156,17 @@ abort(); } self.resumableCompletionBlock = nil; + } else if (self.informationalCompletionBlock != nil) { + switch (choice) { + case SPUInstallLaterChoice: + self.informationalCompletionBlock(SPUDismissInformationalNoticeChoice); + break; + case SPUSkipThisVersionChoice: + self.informationalCompletionBlock(SPUSkipThisInformationalVersionChoice); + break; + case SPUInstallUpdateChoice: + abort(); + } } } diff --git a/TestApplication/SUPopUpTitlebarUserDriver.m b/TestApplication/SUPopUpTitlebarUserDriver.m index b6cb9d8c..adcd48b8 100644 --- a/TestApplication/SUPopUpTitlebarUserDriver.m +++ b/TestApplication/SUPopUpTitlebarUserDriver.m @@ -184,6 +184,16 @@ }); } +- (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply +{ + // Todo: show user interface for this + dispatch_async(dispatch_get_main_queue(), ^{ + NSLog(@"Found info URL: %@", appcastItem.infoURL); + + reply(SPUDismissInformationalNoticeChoice); + }); +} + - (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData { [self.installUpdateViewController showReleaseNotesWithDownloadData:downloadData]; diff --git a/sparkle-cli/SPUCommandLineUserDriver.m b/sparkle-cli/SPUCommandLineUserDriver.m index 75ef3aa6..a5a5334c 100644 --- a/sparkle-cli/SPUCommandLineUserDriver.m +++ b/sparkle-cli/SPUCommandLineUserDriver.m @@ -153,6 +153,15 @@ }); } +- (void)showInformationalUpdateFoundWithAppcastItem:(SUAppcastItem *)appcastItem userInitiated:(BOOL)__unused userInitiated reply:(void (^)(SPUInformationalUpdateAlertChoice))reply +{ + dispatch_async(dispatch_get_main_queue(), ^{ + fprintf(stderr, "Found information for new update: %s\n", appcastItem.infoURL.absoluteString.UTF8String); + + reply(SPUDismissInformationalNoticeChoice); + }); +} + - (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData { dispatch_async(dispatch_get_main_queue(), ^{