Add delegate method for when user makes an update choice (#2257)

Also add gentle reminder support in legacy SUUpdater 1.x methods
This commit is contained in:
Zorg authored and GitHub committed 2022-09-04 15:58:09 -07:00
1 parent 7d68f8f7ae
commit d9c0cc7f53
4 files changed
+88 -13

No files matched your search

+9 -4
View File
@@ -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:
+18 -4
View File
@@ -9,9 +9,10 @@
#import <Foundation/Foundation.h>
#import <Sparkle/SUExport.h>
#import <Sparkle/SPUUpdateCheck.h>
#import <Sparkle/SPUUserUpdateState.h>
@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
+44 -5
View File
@@ -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
+17
View File
@@ -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.