From 4cfba2ada4567352a03bc91f012b460df64ae1ea Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 23 Dec 2022 07:17:44 -0800 Subject: [PATCH] Add delegate method to hide showing version history option (#2303) --- Sparkle/SPUStandardUserDriver.m | 47 ++++++++++++++----------- Sparkle/SPUStandardUserDriverDelegate.h | 13 +++++++ 2 files changed, 39 insertions(+), 21 deletions(-) diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index e424093a..e6bddf47 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -580,31 +580,36 @@ static const NSTimeInterval SUScheduledUpdateIdleEventLeewayInterval = DEBUG ? 3 case SPUNoUpdateFoundReasonOnLatestVersion: case SPUNoUpdateFoundReasonOnNewerThanLatestVersion: { // Show the user the past version history if available - NSString *localizedButtonTitle = SULocalizedString(@"Version History", nil); - // Check if the delegate implements a Version History action + // Check if the delegate allows showing the Version History id delegate = self.delegate; + BOOL shouldShowVersionHistory = (![delegate respondsToSelector:@selector(standardUserDriverShouldShowVersionHistoryForAppcastItem:)] || [delegate standardUserDriverShouldShowVersionHistoryForAppcastItem:latestAppcastItem]); - if ([delegate respondsToSelector:@selector(standardUserDriverShowVersionHistoryForAppcastItem:)]) { - [alert addButtonWithTitle:localizedButtonTitle]; + if (shouldShowVersionHistory) { + NSString *localizedButtonTitle = SULocalizedString(@"Version History", nil); - secondaryAction = ^{ - [delegate standardUserDriverShowVersionHistoryForAppcastItem:latestAppcastItem]; - }; - } else if (latestAppcastItem.fullReleaseNotesURL != nil) { - // Open the full release notes URL if informed - [alert addButtonWithTitle:localizedButtonTitle]; - - secondaryAction = ^{ - [[NSWorkspace sharedWorkspace] openURL:(NSURL * _Nonnull)latestAppcastItem.fullReleaseNotesURL]; - }; - } else if (latestAppcastItem.releaseNotesURL != nil) { - // Fall back to opening the release notes URL - [alert addButtonWithTitle:localizedButtonTitle]; - - secondaryAction = ^{ - [[NSWorkspace sharedWorkspace] openURL:(NSURL * _Nonnull)latestAppcastItem.releaseNotesURL]; - }; + // Check if the delegate implements its own Version History action + if ([delegate respondsToSelector:@selector(standardUserDriverShowVersionHistoryForAppcastItem:)]) { + [alert addButtonWithTitle:localizedButtonTitle]; + + secondaryAction = ^{ + [delegate standardUserDriverShowVersionHistoryForAppcastItem:latestAppcastItem]; + }; + } else if (latestAppcastItem.fullReleaseNotesURL != nil) { + // Open the full release notes URL if informed + [alert addButtonWithTitle:localizedButtonTitle]; + + secondaryAction = ^{ + [[NSWorkspace sharedWorkspace] openURL:(NSURL * _Nonnull)latestAppcastItem.fullReleaseNotesURL]; + }; + } else if (latestAppcastItem.releaseNotesURL != nil) { + // Fall back to opening the release notes URL + [alert addButtonWithTitle:localizedButtonTitle]; + + secondaryAction = ^{ + [[NSWorkspace sharedWorkspace] openURL:(NSURL * _Nonnull)latestAppcastItem.releaseNotesURL]; + }; + } } break; diff --git a/Sparkle/SPUStandardUserDriverDelegate.h b/Sparkle/SPUStandardUserDriverDelegate.h index 93448649..b111a4a8 100644 --- a/Sparkle/SPUStandardUserDriverDelegate.h +++ b/Sparkle/SPUStandardUserDriverDelegate.h @@ -42,6 +42,19 @@ SU_EXPORT @protocol SPUStandardUserDriverDelegate */ - (_Nullable id )standardUserDriverRequestsVersionDisplayer; +/** + Decides whether or not the standard user driver should provide an option to show full release notes to the user. + + When a user checks for new updates and no new update is found, Sparkle by default will offer to show the application's version history to the user + by providing a "Version History" button in the no new update available alert. + + If this delegate method is implemented to return `NO`, then Sparkle will not provide an option to show full release notes to the user. + + @param item The appcast item corresponding to the latest version available. + @return @c YES to allow Sparkle to show full release notes to the user, otherwise @c NO to disallow this. + */ +- (BOOL)standardUserDriverShouldShowVersionHistoryForAppcastItem:(SUAppcastItem *)item; + /** Handles showing the full release notes to the user.