From a5c26b5cdfdd39cd289f1047237c4e1c8d86bd97 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 8 Sep 2024 17:21:36 -0700 Subject: [PATCH] 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). --- Sparkle/SPUUpdater.m | 9 ++++----- Sparkle/SPUUpdaterDelegate.h | 6 +++++- Sparkle/SUUpdater.m | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index a219e8b9..6d99d369 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -382,19 +382,18 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification id 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) { diff --git a/Sparkle/SPUUpdaterDelegate.h b/Sparkle/SPUUpdaterDelegate.h index 1b63750e..84af9363 100644 --- a/Sparkle/SPUUpdaterDelegate.h +++ b/Sparkle/SPUUpdaterDelegate.h @@ -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 diff --git a/Sparkle/SUUpdater.m b/Sparkle/SUUpdater.m index c7be1a7a..b151c052 100644 --- a/Sparkle/SUUpdater.m +++ b/Sparkle/SUUpdater.m @@ -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;