From 6b0d9f0de26f28d5c06ca840cf22f880cc2e1b9a Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 6 Feb 2021 23:26:51 -0800 Subject: [PATCH] Tell user if they are running newer version than latest appcast item This ports https://github.com/sparkle-project/Sparkle/pull/1427 to 2.x --- Sparkle/SPUBasicUpdateDriver.m | 27 ++++++++++++++++++++++++--- Sparkle/SUAppcastDriver.h | 2 +- Sparkle/SUAppcastDriver.m | 3 ++- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Sparkle/SPUBasicUpdateDriver.m b/Sparkle/SPUBasicUpdateDriver.m index 122fc420..9e8fd451 100644 --- a/Sparkle/SPUBasicUpdateDriver.m +++ b/Sparkle/SPUBasicUpdateDriver.m @@ -156,7 +156,7 @@ } } -- (void)didNotFindUpdate +- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult { if (!self.aborted) { if ([self.updaterDelegate respondsToSelector:@selector((updaterDidNotFindUpdate:))]) { @@ -164,13 +164,34 @@ } [[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater]; + NSString *localizedDescription; + NSString *recoverySuggestion; + NSString *recoveryOption; + + if (latestAppcastItem != nil) { // if the appcast was successfully loaded + localizedDescription = SULocalizedString(@"You're up-to-date!", "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates."); + + if (hostToLatestAppcastItemComparisonResult == NSOrderedDescending) { // this means the user is a 'newer than latest' version. give a slight hint to the user instead of wrongly claiming this version is identical to the latest feed version. + recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.\n(You are currently running version %@.)", nil), [self.host name], latestAppcastItem.displayVersionString, [self.host displayVersion]]; + } else { + recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [self.host name], [self.host displayVersion]]; + } + + recoveryOption = @"OK"; + } else { + localizedDescription = SULocalizedString(@"Update Error!", nil); + recoverySuggestion = SULocalizedString(@"No valid update information could be loaded.", nil); + recoveryOption = @"Cancel Update"; + } + NSError *notFoundError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUNoUpdateError userInfo:@{ - NSLocalizedDescriptionKey: SULocalizedString(@"You're up-to-date!", "Status message shown when the user checks for updates but is already current or the feed doesn't contain any updates."), - NSLocalizedRecoverySuggestionErrorKey: [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [self.host name], [self.host displayVersion]] + NSLocalizedDescriptionKey: localizedDescription, + NSLocalizedRecoverySuggestionErrorKey: recoverySuggestion, + NSLocalizedRecoveryOptionsErrorKey: @[recoveryOption] } ]; [self.delegate basicDriverIsRequestingAbortUpdateWithError:notFoundError]; diff --git a/Sparkle/SUAppcastDriver.h b/Sparkle/SUAppcastDriver.h index a032b508..b5b2dbf2 100644 --- a/Sparkle/SUAppcastDriver.h +++ b/Sparkle/SUAppcastDriver.h @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)didFailToFetchAppcastWithError:(NSError *)error; - (void)didFinishLoadingAppcast:(SUAppcast *)appcast; - (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)appcastItem preventsAutoupdate:(BOOL)preventsAutoupdate; -- (void)didNotFindUpdate; +- (void)didNotFindUpdateWithLatestAppcastItem:(nullable SUAppcastItem *)latestAppcastItem hostToLatestAppcastItemComparisonResult:(NSComparisonResult)hostToLatestAppcastItemComparisonResult; @end diff --git a/Sparkle/SUAppcastDriver.m b/Sparkle/SUAppcastDriver.m index a11c9df3..24a0e692 100644 --- a/Sparkle/SUAppcastDriver.m +++ b/Sparkle/SUAppcastDriver.m @@ -110,7 +110,8 @@ self.nonDeltaUpdateItem = nonDeltaUpdateItem; [self.delegate didFindValidUpdateWithAppcastItem:item preventsAutoupdate:[self itemPreventsAutoupdate:item]]; } else { - [self.delegate didNotFindUpdate]; + NSComparisonResult hostToLatestAppcastItemComparisonResult = (item != nil) ? [[self versionComparator] compareVersion:[self.host version] toVersion:[item versionString]] : 0; + [self.delegate didNotFindUpdateWithLatestAppcastItem:item hostToLatestAppcastItemComparisonResult:hostToLatestAppcastItemComparisonResult]; } }