Skip to content

Commit

Permalink
Call update permission prompt delegate method only when needed (#2622)
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
zorgiepoo authored Sep 9, 2024
1 parent 8f86cad commit a5c26b5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 4 additions & 5 deletions Sparkle/SPUUpdater.m
Original file line number Diff line number Diff line change
Expand Up @@ -382,19 +382,18 @@ - (void)startUpdateCycle SPU_OBJC_DIRECT

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) {
Expand Down
6 changes: 5 additions & 1 deletion Sparkle/SPUUpdaterDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Sparkle/SUUpdater.m
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ - (NSString *)feedURLStringForUpdater:(SPUUpdater *)__unused updater
- (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;
Expand Down

0 comments on commit a5c26b5

Please sign in to comment.