From e48edc6856b60ef46aa50f59757ce4d91672cc20 Mon Sep 17 00:00:00 2001 From: Billy Gray Date: Fri, 29 Oct 2021 19:59:48 -0400 Subject: [PATCH] Adds standard user driver delegate method for responding to Version History button (#1989) --- Sparkle/SPUStandardUserDriver.m | 18 +++++++++++++++--- Sparkle/SPUStandardUserDriverDelegate.h | 9 +++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index ab5d6bac..000cb6ac 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -274,9 +274,21 @@ switch (reason) { case SPUNoUpdateFoundReasonOnLatestVersion: case SPUNoUpdateFoundReasonOnNewerThanLatestVersion: { - if (latestAppcastItem.releaseNotesURL != nil) { - // Show the user the past version history if available - [alert addButtonWithTitle:SULocalizedString(@"Version History", nil)]; + // Show the user the past version history if available + NSString *localizedButtonTitle = SULocalizedString(@"Version History", nil); + + // Check if the delegate implements a Version History action + id delegate = self.delegate; + + if ([delegate respondsToSelector:@selector(standardUserDriverShowVersionHistoryForAppcastItem:)]) { + [alert addButtonWithTitle:localizedButtonTitle]; + + secondaryAction = ^{ + [delegate standardUserDriverShowVersionHistoryForAppcastItem:latestAppcastItem]; + }; + } else if (latestAppcastItem.releaseNotesURL != nil) { + // Fall back to opening the release notes URL (or forthcoming full version history link attr!) + [alert addButtonWithTitle:localizedButtonTitle]; secondaryAction = ^{ [[NSWorkspace sharedWorkspace] openURL:(NSURL * _Nonnull)latestAppcastItem.releaseNotesURL]; diff --git a/Sparkle/SPUStandardUserDriverDelegate.h b/Sparkle/SPUStandardUserDriverDelegate.h index 3bf1e315..4bed89cc 100644 --- a/Sparkle/SPUStandardUserDriverDelegate.h +++ b/Sparkle/SPUStandardUserDriverDelegate.h @@ -45,4 +45,13 @@ SU_EXPORT @protocol SPUStandardUserDriverDelegate */ - (_Nullable id )standardUserDriverRequestsVersionDisplayer; +/** + Called if implemented when the Version History button is chosen by the user. Otherwise, + the `fullReleaseNotesLink` or `releaseNotesLink` in the appcast's latest item will be be + opened. + + @param item The appcast item corresponding to the latest version available. + */ +- (void)standardUserDriverShowVersionHistoryForAppcastItem:(SUAppcastItem *_Nonnull)item; + @end