Call update permission prompt delegate method only when needed (#2622)

The delegate method is not called if SUEnableAutomaticChecks is specified in the Info.plist (now) or if the user has responded to a permission prompt request.

Also fixes a respondsToSelector check in legacy SUUpdater adaptor (fixes #2618).
This commit is contained in:
Zorg
2024-09-08 17:21:36 -07:00
committed by GitHub
parent 8f86cad4a2
commit a5c26b5cdf
3 changed files with 10 additions and 7 deletions
+4 -5
View File
@@ -382,19 +382,18 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
id<SPUUpdaterDelegate> delegate = _delegate;
// If the user has been asked about automatic checks, don't bother prompting
// If the user has been asked about automatic checks or the developer has overridden the setting, don't bother prompting
// When the user answers to the permission prompt, this will be set to either @YES or @NO instead of nil
if ([_host objectForUserDefaultsKey:SUEnableAutomaticChecksKey] != nil) {
if ([_host objectForKey:SUEnableAutomaticChecksKey] != nil) {
shouldPrompt = NO;
}
// Does the delegate want to take care of the logic for when we should ask permission to update?
else if ([delegate respondsToSelector:@selector((updaterShouldPromptForPermissionToCheckForUpdates:))]) {
shouldPrompt = [delegate updaterShouldPromptForPermissionToCheckForUpdates:self];
}
// Has the user been asked already? And don't ask if the host has a default value set in its Info.plist.
else if ([_host objectForKey:SUEnableAutomaticChecksKey] == nil) {
else {
// We wait until the second launch of the updater for this host bundle, unless explicitly overridden via SUPromptUserOnFirstLaunchKey.
shouldPrompt = [_host objectForKey:SUPromptUserOnFirstLaunchKey] || hasLaunchedBefore;
shouldPrompt = hasLaunchedBefore || [_host boolForInfoDictionaryKey:SUPromptUserOnFirstLaunchKey];
}
if (!hasLaunchedBefore) {
+5 -1
View File
@@ -137,7 +137,11 @@ SU_EXPORT extern NSString *const SUSystemProfilerPreferredLanguageKey;
/**
Returns whether Sparkle should prompt the user about checking for new updates automatically.
Use this to override the default behavior.
Use this to override the default behavior, which is to prompt for permission to check for updates on second app launch
(if SUEnableAutomaticChecks is not specified).
This method is not called if SUEnableAutomaticChecks is defined in Info.plist or
if the user has responded to a permission prompt before.
@param updater The updater instance.
@return @c YES if the updater should prompt for permission to check for new updates automatically, otherwise @c NO
+1 -1
View File
@@ -292,7 +292,7 @@ static NSMutableDictionary *sharedUpdaters = nil;
- (BOOL)updaterShouldPromptForPermissionToCheckForUpdates:(SPUUpdater *)__unused updater
{
BOOL shouldPrompt = YES;
if ([_delegate respondsToSelector:@selector(updater:didFinishLoadingAppcast:)]) {
if ([_delegate respondsToSelector:@selector(updaterShouldPromptForPermissionToCheckForUpdates:)]) {
shouldPrompt = [_delegate updaterShouldPromptForPermissionToCheckForUpdates:self];
}
return shouldPrompt;