diff --git a/Sparkle/SPUUIBasedUpdateDriver.m b/Sparkle/SPUUIBasedUpdateDriver.m index b58f2ba3..3652e01c 100644 --- a/Sparkle/SPUUIBasedUpdateDriver.m +++ b/Sparkle/SPUUIBasedUpdateDriver.m @@ -204,6 +204,15 @@ validatedChoice = userChoice; } + if ([self.updaterDelegate respondsToSelector:@selector(updater:userDidMakeChoice:forUpdate:state:)]) { + [self.updaterDelegate updater:self.updater userDidMakeChoice:validatedChoice forUpdate:updateItem state:state]; + } else if (validatedChoice == SPUUserUpdateChoiceSkip && [self.updaterDelegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; +#pragma clang diagnostic pop + } + switch (validatedChoice) { case SPUUserUpdateChoiceInstall: { switch (stage) { @@ -222,10 +231,6 @@ case SPUUserUpdateChoiceSkip: { [SPUSkippedUpdate skipUpdate:updateItem host:self.host]; - if ([self.updaterDelegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { - [self.updaterDelegate updater:self.updater userDidSkipThisVersion:updateItem]; - } - switch (stage) { case SPUUserUpdateStageDownloaded: case SPUUserUpdateStageNotDownloaded: diff --git a/Sparkle/SPUUpdaterDelegate.h b/Sparkle/SPUUpdaterDelegate.h index f00b8d6b..a18e967f 100644 --- a/Sparkle/SPUUpdaterDelegate.h +++ b/Sparkle/SPUUpdaterDelegate.h @@ -9,9 +9,10 @@ #import #import #import +#import @protocol SUVersionComparison; -@class SPUUpdater, SUAppcast, SUAppcastItem; +@class SPUUpdater, SUAppcast, SUAppcastItem, SPUUserUpdateState; NS_ASSUME_NONNULL_BEGIN @@ -236,12 +237,23 @@ SU_EXPORT extern NSString *const SUSystemProfilerPreferredLanguageKey; - (BOOL)updater:(SPUUpdater *)updater shouldProceedWithUpdate:(SUAppcastItem *)updateItem updateCheck:(SPUUpdateCheck)updateCheck error:(NSError * __autoreleasing *)error; /** - Called when an update is skipped by the user. + Called when a user makes a choice to install, dismiss, or skip an update. + + If the @c choice is `SPUUserUpdateChoiceDismiss` and @c state.stage is `SPUUserUpdateStageDownloaded` the downloaded update is kept + around until the next time Sparkle reminds the user of the update. + + If the @c choice is `SPUUserUpdateChoiceDismiss` and @c state.stage is `SPUUserUpdateStageInstalling` the update is still set to install on application termination. + + If the @c choice is `SPUUserUpdateChoiceSkip` the user will not be reminded in the future for this update unless they initiate an update check themselves. + + If @c updateItem.isInformationOnlyUpdate is @c YES the @c choice cannot be `SPUUserUpdateChoiceInstall`. @param updater The updater instance. - @param item The appcast item corresponding to the update that the user skipped. + @param choice The choice (install, dismiss, or skip) the user made for this @c updateItem + @param updateItem The appcast item corresponding to the update that the user made a choice on. + @param state The current state for the update which includes if the update has already been downloaded or already installing. */ -- (void)updater:(SPUUpdater *)updater userDidSkipThisVersion:(SUAppcastItem *)item; +- (void)updater:(SPUUpdater *)updater userDidMakeChoice:(SPUUserUpdateChoice)choice forUpdate:(SUAppcastItem *)updateItem state:(SPUUserUpdateState *)state; /** Returns whether the release notes (if available) should be downloaded after an update is found and shown. @@ -446,6 +458,8 @@ SU_EXPORT extern NSString *const SUSystemProfilerPreferredLanguageKey; - (BOOL)updaterMayCheckForUpdates:(SPUUpdater *)updater __deprecated_msg("Please use -[SPUUpdaterDelegate updater:mayPerformUpdateCheck:error:] instead."); +- (void)updater:(SPUUpdater *)updater userDidSkipThisVersion:(SUAppcastItem *)item __deprecated_msg("Please use -[SPUUpdaterDelegate updater:userDidMakeChoice:forUpdate:state:] instead."); + @end NS_ASSUME_NONNULL_END diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index a77d72f9..5a9a1670 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -32,6 +32,9 @@ #pragma clang diagnostic ignored "-Wdeprecated-implementations" @implementation SUUpdater #pragma clang diagnostic pop +{ + BOOL _delayShowingUserUpdate; +} @synthesize updater = _updater; @synthesize delegate = _delegate; @@ -198,7 +201,14 @@ static NSMutableDictionary *sharedUpdaters = nil; - (void)checkForUpdatesInBackground { - [self.updater checkForUpdatesInBackground]; + if (_delayShowingUserUpdate) { + // We don't know if SUUpdater delegate will call checkForUpdates: or checkForUpdatesInBackground + // to bring a deffered update alert back in 1.x. + // So if checkForUpdatesInBackground is called we will bring the update back in focus + [self checkForUpdates:nil]; + } else { + [self.updater checkForUpdatesInBackground]; + } } - (NSDate *)lastUpdateCheckDate @@ -228,7 +238,7 @@ static NSMutableDictionary *sharedUpdaters = nil; SULog(SULogLevelError, @"-[%@ installUpdatesIfAvailable] does not function anymore.. Instead a background scheduled update check will be done.", NSStringFromClass([self class])); self.loggedInstallUpdatesIfAvailableWarning = YES; - } + } [self checkForUpdatesInBackground]; } @@ -325,11 +335,40 @@ static NSMutableDictionary *sharedUpdaters = nil; } } -- (void)updater:(SPUUpdater *)__unused updater userDidSkipThisVersion:(nonnull SUAppcastItem *)item +- (void)updater:(SPUUpdater *)__unused updater userDidMakeChoice:(SPUUserUpdateChoice)choice forUpdate:(SUAppcastItem *)updateItem state:(SPUUserUpdateState *)__unused state { - if ([self.delegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { - [self.delegate updater:self userDidSkipThisVersion:item]; + // This delegate callback matches 1.x behavior (even though -standardUserDriverWillFinishUpdateSession might be a better place for it) + if ([self.delegate respondsToSelector:@selector(updater:didDismissUpdateAlertPermanently:forItem:)]) { + [self.delegate updater:self didDismissUpdateAlertPermanently:(choice == SPUUserUpdateChoiceSkip) forItem:updateItem]; } + + if (choice == SPUUserUpdateChoiceSkip && [self.delegate respondsToSelector:@selector(updater:userDidSkipThisVersion:)]) { + [self.delegate updater:self userDidSkipThisVersion:updateItem]; + } +} + +- (BOOL)standardUserDriverShouldHandleShowingScheduledUpdate:(SUAppcastItem *)update andInImmediateFocus:(BOOL)immediateFocus +{ + if ([self.delegate respondsToSelector:@selector(updaterShouldShowUpdateAlertForScheduledUpdate:forItem:)]) { + // If the delegate returns NO and tries to show the update before + // -standardUserDriverWillHandleShowingUpdate:forUpdate:state: is called, this is technically + // a violation. However it is also unlikely to happen. + return [self.delegate updaterShouldShowUpdateAlertForScheduledUpdate:self forItem:update]; + } else { + return YES; + } +} + +- (void)standardUserDriverWillHandleShowingUpdate:(BOOL)handleShowingUpdate forUpdate:(SUAppcastItem *)update state:(SPUUserUpdateState *)state +{ + if (!handleShowingUpdate) { + _delayShowingUserUpdate = YES; + } +} + +- (void)standardUserDriverWillFinishUpdateSession +{ + _delayShowingUserUpdate = NO; } - (void)updater:(SPUUpdater *)__unused updater willDownloadUpdate:(SUAppcastItem *)item withRequest:(NSMutableURLRequest *)request diff --git a/Sparkle/SUUpdaterDelegate.h b/Sparkle/SUUpdaterDelegate.h index fa49e1fd..466a92a4 100644 --- a/Sparkle/SUUpdaterDelegate.h +++ b/Sparkle/SUUpdaterDelegate.h @@ -120,6 +120,23 @@ __deprecated_msg("Deprecated in Sparkle 2. See SPUUpdaterDelegate instead") */ - (void)updaterDidNotFindUpdate:(SUUpdater *)updater; +/*! + Called just before the scheduled update driver prompts the user to install an update. + + \param updater The SUUpdater instance. + + \return YES to allow the update prompt to be shown (the default behavior), or NO to suppress it. + */ + - (BOOL)updaterShouldShowUpdateAlertForScheduledUpdate:(SUUpdater *)updater forItem:(SUAppcastItem *)item; + + /*! + Called after the user dismisses the update alert. + + \param updater The SUUpdater instance. + \param permanently YES if the alert will not appear again for this update; NO if it may reappear. + */ + - (void)updater:(SUUpdater *)updater didDismissUpdateAlertPermanently:(BOOL)permanently forItem:(SUAppcastItem *)item; + /*! Called immediately before downloading the specified update.