From 5d27dc6fb3255da14d0d23277b3655b703fe1233 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 26 Jun 2021 16:06:39 -0700 Subject: [PATCH 1/7] Expose the reason and latest appcast item when update is not found --- Sparkle/SPUBasicUpdateDriver.m | 34 +++++++++++++++++++++++++++------- Sparkle/SPUUserDriver.h | 8 ++++++++ Sparkle/SUConstants.m | 2 ++ Sparkle/SUErrors.h | 11 +++++++++++ 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/Sparkle/SPUBasicUpdateDriver.m b/Sparkle/SPUBasicUpdateDriver.m index 859e9eb7..3aaade2f 100644 --- a/Sparkle/SPUBasicUpdateDriver.m +++ b/Sparkle/SPUBasicUpdateDriver.m @@ -171,6 +171,7 @@ NSString *recoverySuggestion; NSString *recoveryOption; + SPUNoUpdateFoundReason reason; if (latestAppcastItem != nil) { switch (hostToLatestAppcastItemComparisonResult) { case NSOrderedDescending: @@ -178,12 +179,16 @@ 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."); 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]]; + + reason = SPUNoUpdateFoundReasonOnNewerThanLatestVersion; break; case NSOrderedSame: // No new update is available and we're on the latest 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."); recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [self.host name], [self.host displayVersion]]; + + reason = SPUNoUpdateFoundReasonOnLatestVersion; break; case NSOrderedAscending: // This means a new update doesn't match the OS requirements @@ -191,20 +196,26 @@ localizedDescription = SULocalizedString(@"Your macOS version is too old", nil); recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ is available but your macOS version is too old to install it. At least macOS %3$@ is required.", nil), [self.host name], latestAppcastItem.versionString, latestAppcastItem.minimumSystemVersion]; + + reason = SPUNoUpdateFoundReasonSystemIsTooOld; } else if (!latestAppcastItem.maximumOperatingSystemVersionIsOK) { localizedDescription = SULocalizedString(@"Your macOS version is too new", nil); recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ is available but your macOS version is too new for this update. This update only supports up to macOS %3$@.", nil), [self.host name], latestAppcastItem.versionString, latestAppcastItem.maximumSystemVersion]; + + reason = SPUNoUpdateFoundReasonSystemIsTooNew; } else { // We shouldn't realistically get here 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."); recoverySuggestion = [NSString stringWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [self.host name], [self.host displayVersion]]; + + reason = SPUNoUpdateFoundReasonUnknown; } break; } - recoveryOption = @"OK"; + recoveryOption = SULocalizedString(@"OK", nil); } else { // When no updates are found in the appcast, or latest appcast item info // was not provided (i.e, for a background update check) @@ -212,18 +223,27 @@ localizedDescription = SULocalizedString(@"Update Error!", nil); recoverySuggestion = SULocalizedString(@"No valid update information could be loaded.", nil); recoveryOption = SULocalizedString(@"Cancel Update", nil); + + reason = SPUNoUpdateFoundReasonUnknown; + } + + NSMutableDictionary *userInfo = + [NSMutableDictionary dictionaryWithDictionary:@{ + NSLocalizedDescriptionKey: localizedDescription, + NSLocalizedRecoverySuggestionErrorKey: recoverySuggestion, + NSLocalizedRecoveryOptionsErrorKey: @[recoveryOption], + SPUNoUpdateFoundReasonKey: @(reason), + }]; + + if (latestAppcastItem != nil) { + userInfo[SPULatestAppcastItemFoundKey] = latestAppcastItem; } NSError *notFoundError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUNoUpdateError - userInfo:@{ - NSLocalizedDescriptionKey: localizedDescription, - NSLocalizedRecoverySuggestionErrorKey: recoverySuggestion, - NSLocalizedRecoveryOptionsErrorKey: @[recoveryOption] - } - ]; + userInfo:[userInfo copy]]; [self.delegate basicDriverIsRequestingAbortUpdateWithError:notFoundError]; } } diff --git a/Sparkle/SPUUserDriver.h b/Sparkle/SPUUserDriver.h index c8086eb5..450496e7 100644 --- a/Sparkle/SPUUserDriver.h +++ b/Sparkle/SPUUserDriver.h @@ -116,6 +116,14 @@ SU_EXPORT @protocol SPUUserDriver * Before this point, -showUserInitiatedUpdateCheckWithCancellation: may be called. * * @param error The error associated with why a new update was not found. + * There are various reasons a new update is unavailable and can't be installed. + * This error object is populated with recovery and suggestion strings suitable to be shown in an alert. + * + * The userInfo dictionary is also populated with two keys: + * SPULatestAppcastItemFoundKey: if available, this may provide the latest SUAppcastItem that was found. + * SPUNoUpdateFoundReasonKey: if available, this will provide the SUNoUpdateFoundReason. For example the reason could be because + * the latest version in the feed requires a newer OS version or could be because the user is already on the latest version. + * * @param acknowledgement Acknowledge to the updater that no update found error was shown. */ - (void)showUpdateNotFoundWithError:(NSError *)error acknowledgement:(void (^)(void))acknowledgement; diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index 0a60324e..f1aad287 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -57,6 +57,8 @@ NSString *const SUEnableJavaScriptKey = @"SUEnableJavaScript"; NSString *const SUFixedHTMLDisplaySizeKey = @"SUFixedHTMLDisplaySize"; NSString *const SUDefaultsDomainKey = @"SUDefaultsDomain"; NSString *const SUSparkleErrorDomain = @"SUSparkleErrorDomain"; +NSString *const SPUNoUpdateFoundReasonKey = @"SUNoUpdateFoundReason"; +NSString *const SPULatestAppcastItemFoundKey = @"SULatestAppcastItemFound"; NSString *const SUAppendVersionNumberKey = @"SUAppendVersionNumber"; NSString *const SUEnableAutomatedDowngradesKey = @"SUEnableAutomatedDowngrades"; diff --git a/Sparkle/SUErrors.h b/Sparkle/SUErrors.h index af6e105b..4b5a2eae 100644 --- a/Sparkle/SUErrors.h +++ b/Sparkle/SUErrors.h @@ -78,4 +78,15 @@ typedef NS_ENUM(OSStatus, SUError) { SUIncorrectAPIUsageError = 5000 }; +typedef NS_ENUM(OSStatus, SPUNoUpdateFoundReason) { + SPUNoUpdateFoundReasonUnknown, + SPUNoUpdateFoundReasonOnLatestVersion, + SPUNoUpdateFoundReasonOnNewerThanLatestVersion, + SPUNoUpdateFoundReasonSystemIsTooOld, + SPUNoUpdateFoundReasonSystemIsTooNew +}; + +SU_EXPORT extern NSString *const SPUNoUpdateFoundReasonKey; +SU_EXPORT extern NSString *const SPULatestAppcastItemFoundKey; + #endif From aa867a0cb93d45ee3de296554fae2540d21118e8 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 26 Jun 2021 18:18:44 -0700 Subject: [PATCH 2/7] Expose reason why new update is not available to user When user is on version >= latest appcast feed item, we give them an option to view version history. When user can't update because of a min/max OS requirement, we give them an option to view product's website. --- Sparkle/SPUStandardUserDriver.m | 52 +++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/Sparkle/SPUStandardUserDriver.m b/Sparkle/SPUStandardUserDriver.m index 3275958a..ab5d6bac 100644 --- a/Sparkle/SPUStandardUserDriver.m +++ b/Sparkle/SPUStandardUserDriver.m @@ -20,6 +20,7 @@ #import "SUApplicationInfo.h" #import "SUOperatingSystem.h" #import "SPUUserUpdateState.h" +#import "SUErrors.h" #import @@ -250,7 +251,7 @@ alert.messageText = SULocalizedString(@"Update Error!", nil); alert.informativeText = [NSString stringWithFormat:@"%@", [error localizedDescription]]; [alert addButtonWithTitle:SULocalizedString(@"Cancel Update", nil)]; - [self showAlert:alert]; + [self showAlert:alert secondaryAction:nil]; acknowledgement(); } @@ -263,12 +264,49 @@ NSAlert *alert = [NSAlert alertWithError:error]; alert.alertStyle = NSAlertStyleInformational; - [self showAlert:alert]; + + // Can we give more information to the user? + SPUNoUpdateFoundReason reason = (SPUNoUpdateFoundReason)[(NSNumber *)error.userInfo[SPUNoUpdateFoundReasonKey] integerValue]; + + void (^secondaryAction)(void) = nil; + SUAppcastItem *latestAppcastItem = error.userInfo[SPULatestAppcastItemFoundKey]; + if (latestAppcastItem != nil) { + 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)]; + + secondaryAction = ^{ + [[NSWorkspace sharedWorkspace] openURL:(NSURL * _Nonnull)latestAppcastItem.releaseNotesURL]; + }; + } + + break; + } + case SPUNoUpdateFoundReasonSystemIsTooOld: + case SPUNoUpdateFoundReasonSystemIsTooNew: + if (latestAppcastItem.infoURL != nil) { + // Show the user the product's link if available + [alert addButtonWithTitle:SULocalizedString(@"Learn More...", nil)]; + + secondaryAction = ^{ + [[NSWorkspace sharedWorkspace] openURL:(NSURL * _Nonnull)latestAppcastItem.infoURL]; + }; + } + break; + case SPUNoUpdateFoundReasonUnknown: + break; + } + } + + [self showAlert:alert secondaryAction:secondaryAction]; acknowledgement(); } -- (void)showAlert:(NSAlert *)alert +- (void)showAlert:(NSAlert *)alert secondaryAction:(void (^ _Nullable)(void))secondaryAction { id delegate = self.delegate; @@ -281,7 +319,11 @@ if ([SUApplicationInfo isBackgroundApplication:[NSApplication sharedApplication]]) { [[NSApplication sharedApplication] activateIgnoringOtherApps:YES]; } [alert setIcon:[SUApplicationInfo bestIconForHost:self.host]]; - [alert runModal]; + + NSModalResponse response = [alert runModal]; + if (response == NSAlertSecondButtonReturn && secondaryAction != nil) { + secondaryAction(); + } if ([delegate respondsToSelector:@selector(standardUserDriverDidShowModalAlert)]) { [delegate standardUserDriverDidShowModalAlert]; @@ -435,7 +477,7 @@ } else { alert.informativeText = [NSString stringWithFormat:SULocalizedString(@"%@ is now updated!", nil), hostName]; } - [self showAlert:alert]; + [self showAlert:alert secondaryAction:nil]; } acknowledgement(); From ed3e331f56dedeffafff9b0ead9605245c1da2e8 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 26 Jun 2021 18:21:47 -0700 Subject: [PATCH 3/7] Update SampleAppcast.xml with links to Sparkle's website --- Resources/SampleAppcast.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Resources/SampleAppcast.xml b/Resources/SampleAppcast.xml index 39c176bd..2a4a2df5 100755 --- a/Resources/SampleAppcast.xml +++ b/Resources/SampleAppcast.xml @@ -9,6 +9,7 @@ http://you.com/app/2.0.html + http://sparkle-project.org Wed, 09 Jan 2006 19:20:11 +0000 10.11 @@ -19,6 +20,7 @@ http://you.com/app/1.5.html + http://sparkle-project.org Wed, 01 Jan 2006 12:20:11 +0000 10.11 @@ -30,6 +32,7 @@ http://you.com/app/1.4.html + http://sparkle-project.org Wed, 25 Dec 2005 12:20:11 +0000 10.11 From 1c1b7416ba0d9d10ee9b0ba14712b5456af1ef2c Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 26 Jun 2021 18:33:00 -0700 Subject: [PATCH 4/7] Add Version History string to localization file --- Sparkle/Base.lproj/Sparkle.strings | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sparkle/Base.lproj/Sparkle.strings b/Sparkle/Base.lproj/Sparkle.strings index 86423b2a..7d903471 100644 --- a/Sparkle/Base.lproj/Sparkle.strings +++ b/Sparkle/Base.lproj/Sparkle.strings @@ -146,6 +146,9 @@ "%1$@ %2$@ is available but your macOS version is too new for this update. This update only supports up to macOS %3$@." = "%1$@ %2$@ is available but your macOS version is too new for this update. This update only supports up to macOS %3$@."; +/* Used when a new update is not found */ +"Version History" = "Version History"; + /* Authorization message shown when app wants permission to update itself. */ "%1$@ wants permission to update." = "%1$@ wants permission to update."; From ccd8886bfd3dd032edbc578bd0f923ce6aa1f5ba Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 26 Jun 2021 19:05:24 -0700 Subject: [PATCH 5/7] Adopt sparkle:version and sparkle:shortVersionString elements We should recommend using sparkle:version and sparkle:shortVersionString elements inside the appcast item instead of inside the enclosure for consistency. Delta updates do not need to specify sparkle:version, and can inherit the top level element. This clears up some confusion and reduces duplication (and reduces error proneness / saves me work when testing delta / info-only features). This is also consistent with informational updates. Regardless whether you want to make an update informational only or not, the sparkle:version stays in the same top-level place. This is a backwards compatible change. Very old versions of Sparkle (possibly up to a decade or more ago) have supported specifying sparkle:version as a top level item. Winsparkle supports it as well because it's needed for info-only updates. This is only changing what we recommend / standardize. The attribute variants are still usable. External tools relying on Sparkle's feed format may have to adapt to this standardization (they have always needed to support info-only updates with a missing enclosure which apps do leverage anyway). I updated generate_appcast to prefer the element variants and updated the tool so it understands them (this was a bug). --- Resources/SampleAppcast.xml | 10 ++++--- Sparkle/SUAppcastItem.m | 16 +++++++----- Sparkle/SUConstants.h | 2 ++ Sparkle/SUConstants.m | 2 ++ TestApplication/sparkletestcast.xml | 3 ++- Tests/Resources/testappcast.xml | 12 +++++---- Tests/Resources/testappcast_info_updates.xml | 9 +++---- .../testappcast_minimumAutoupdateVersion.xml | 6 +++-- .../testlocalizedreleasenotesappcast.xml | 3 ++- Tests/SUAppcastTest.swift | 3 +++ generate_appcast/FeedXML.swift | 26 +++++++++++++++---- 11 files changed, 64 insertions(+), 28 deletions(-) diff --git a/Resources/SampleAppcast.xml b/Resources/SampleAppcast.xml index 39c176bd..83fa8293 100755 --- a/Resources/SampleAppcast.xml +++ b/Resources/SampleAppcast.xml @@ -6,21 +6,23 @@ en Version 2.0 (2 bugs fixed; 3 new features) + 2.0 http://you.com/app/2.0.html Wed, 09 Jan 2006 19:20:11 +0000 - + 10.11 Version 1.5 (8 bugs fixed; 2 new features) + 1.5 http://you.com/app/1.5.html Wed, 01 Jan 2006 12:20:11 +0000 - + 10.11 @@ -30,8 +32,10 @@ http://you.com/app/1.4.html + 241 + 1.4 Wed, 25 Dec 2005 12:20:11 +0000 - + 10.11 diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index b7aaee47..77829da2 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -312,23 +312,28 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; { self = [super init]; if (self) { + _title = [(NSString *)[dict objectForKey:SURSSElementTitle] copy]; + NSDictionary *enclosure = [dict objectForKey:SURSSElementEnclosure]; // Try to find a version string. - // Finding the new version number from the RSS feed is a little bit hacky. There are two ways: + // Finding the new version number from the RSS feed is a little bit hacky. There are a few ways: // 1. A "sparkle:version" attribute on the enclosure tag, an extension from the RSS spec. - // 2. If there isn't a version attribute, Sparkle will parse the path in the enclosure, expecting + // 2. If there isn't a version attribute, see if there is a version element (this is now the recommended path). + // 3. If there isn't a version element, Sparkle will parse the path in the enclosure, expecting // that it will look like this: http://something.com/YourApp_0.5.zip. It'll read whatever's between the last // underscore and the last period as the version number. So name your packages like this: APPNAME_VERSION.extension. // The big caveat with this is that you can't have underscores in your version strings, as that'll confuse Sparkle. // Feel free to change the separator string to a hyphen or something more suited to your needs if you like. NSString *newVersion = [enclosure objectForKey:SUAppcastAttributeVersion]; if (newVersion == nil) { - newVersion = [dict objectForKey:SUAppcastAttributeVersion]; // Get version from the item, in case it's a download-less item (i.e. paid upgrade). + // Get version from the item + newVersion = [dict objectForKey:SUAppcastElementVersion]; } - if (newVersion == nil) // no sparkle:version attribute anywhere? + if (newVersion == nil) { - SULog(SULogLevelError, @"warning: <%@> for URL '%@' is missing %@ attribute. Version comparison may be unreliable. Please always specify %@", SURSSElementEnclosure, [enclosure objectForKey:SURSSAttributeURL], SUAppcastAttributeVersion, SUAppcastAttributeVersion); + // No sparkle:version element/attribute anywhere? + SULog(SULogLevelError, @"warning: Item '%@' is missing '<%@>' element. Version comparison may be unreliable. Please always specify %@", _title, SUAppcastElementVersion, SUAppcastElementVersion); // Separate the url by underscores and take the last component, as that'll be closest to the end, // then we remove the extension. Hopefully, this will be the version. @@ -346,7 +351,6 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; } _propertiesDictionary = [[NSDictionary alloc] initWithDictionary:dict]; - _title = [(NSString *)[dict objectForKey:SURSSElementTitle] copy]; _dateString = [(NSString *)[dict objectForKey:SURSSElementPubDate] copy]; _itemDescription = [(NSString *)[dict objectForKey:SURSSElementDescription] copy]; diff --git a/Sparkle/SUConstants.h b/Sparkle/SUConstants.h index a1e65b66..a1f2669c 100644 --- a/Sparkle/SUConstants.h +++ b/Sparkle/SUConstants.h @@ -77,6 +77,8 @@ extern NSString *const SUAppcastAttributeVersion; extern NSString *const SUAppcastAttributeOsType; extern NSString *const SUAppcastAttributeInstallationType; +extern NSString *const SUAppcastElementVersion; +extern NSString *const SUAppcastElementShortVersionString; extern NSString *const SUAppcastElementCriticalUpdate; extern NSString *const SUAppcastElementDeltas; extern NSString *const SUAppcastElementMinimumAutoupdateVersion; diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index 0a60324e..ee3b9b96 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -71,6 +71,8 @@ NSString *const SUAppcastAttributeVersion = @"sparkle:version"; NSString *const SUAppcastAttributeOsType = @"sparkle:os"; NSString *const SUAppcastAttributeInstallationType = @"sparkle:installationType"; +NSString *const SUAppcastElementVersion = SUAppcastAttributeVersion; +NSString *const SUAppcastElementShortVersionString = SUAppcastAttributeShortVersionString; NSString *const SUAppcastElementCriticalUpdate = @"sparkle:criticalUpdate"; NSString *const SUAppcastElementDeltas = @"sparkle:deltas"; NSString *const SUAppcastElementMinimumAutoupdateVersion = @"sparkle:minimumAutoupdateVersion"; diff --git a/TestApplication/sparkletestcast.xml b/TestApplication/sparkletestcast.xml index b74b0220..ebb17b93 100644 --- a/TestApplication/sparkletestcast.xml +++ b/TestApplication/sparkletestcast.xml @@ -6,6 +6,7 @@ en Version 2.0 + 2.0 @@ -17,7 +18,7 @@ ]]> Sat, 26 Jul 2014 15:20:11 +0000 - + diff --git a/Tests/Resources/testappcast.xml b/Tests/Resources/testappcast.xml index f78862d1..5922b830 100644 --- a/Tests/Resources/testappcast.xml +++ b/Tests/Resources/testappcast.xml @@ -6,26 +6,26 @@ Version 2.0 desc Sat, 26 Jul 2014 15:20:11 +0000 + Version 3.0 + 3.0 86400 - + Version 4.0 + 4.0 Sat, 26 Jul 2014 15:20:13 +0000 - + 17.0.0 Version 5.0 - + 5.0 + 2.0.0 diff --git a/Tests/Resources/testappcast_info_updates.xml b/Tests/Resources/testappcast_info_updates.xml index e1e5074e..a8a86a3d 100644 --- a/Tests/Resources/testappcast_info_updates.xml +++ b/Tests/Resources/testappcast_info_updates.xml @@ -23,19 +23,18 @@ Version 4.0 Sat, 26 Jul 2014 15:20:13 +0000 - + 4.0 + http://sparkle-project.org - - For unit test only Version 3.0 + 3.0 2.0 - + Version 2.0 - + 2.0 + diff --git a/Tests/Resources/testlocalizedreleasenotesappcast.xml b/Tests/Resources/testlocalizedreleasenotesappcast.xml index ee21cd0a..5e0d3f7e 100644 --- a/Tests/Resources/testlocalizedreleasenotesappcast.xml +++ b/Tests/Resources/testlocalizedreleasenotesappcast.xml @@ -5,8 +5,9 @@ Version 6.0 + 6.0 Sat, 26 Jul 2019 15:20:13 +0000 - + https://sparkle-project.org/#works https://sparkle-project.org/#localized_notes_link_works diff --git a/Tests/SUAppcastTest.swift b/Tests/SUAppcastTest.swift index d3c25fd9..b593a098 100644 --- a/Tests/SUAppcastTest.swift +++ b/Tests/SUAppcastTest.swift @@ -30,6 +30,7 @@ class SUAppcastTest: XCTestCase { XCTAssertEqual("desc", items[0].itemDescription) XCTAssertEqual("Sat, 26 Jul 2014 15:20:11 +0000", items[0].dateString) XCTAssertTrue(items[0].isCriticalUpdate) + XCTAssertEqual(items[0].versionString, "2.0") // This is the best release matching our system version XCTAssertEqual("Version 3.0", items[1].title) @@ -37,6 +38,7 @@ class SUAppcastTest: XCTestCase { XCTAssertNil(items[1].dateString) XCTAssertTrue(items[1].isCriticalUpdate) XCTAssertEqual(items[1].phasedRolloutInterval, 86400) + XCTAssertEqual(items[1].versionString, "3.0") XCTAssertEqual("Version 4.0", items[2].title) XCTAssertNil(items[2].itemDescription) @@ -58,6 +60,7 @@ class SUAppcastTest: XCTestCase { XCTAssertEqual(bestAppcastItem, items[1]) XCTAssertEqual(deltaItem!.fileURL!.lastPathComponent, "3.0_from_1.0.patch") + XCTAssertEqual(deltaItem!.versionString, "3.0") // Test latest delta update item available var latestDeltaItem: SUAppcastItem? diff --git a/generate_appcast/FeedXML.swift b/generate_appcast/FeedXML.swift index f84f12a3..8159fa47 100644 --- a/generate_appcast/FeedXML.swift +++ b/generate_appcast/FeedXML.swift @@ -71,7 +71,13 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { var numItems = 0 for update in updates { var item: XMLElement - let existingItems = try channel.nodes(forXPath: "item[enclosure[@sparkle:version=\"\(update.version)\"]]") + + var existingItems = try channel.nodes(forXPath: "item[enclosure[@\(SUAppcastAttributeVersion)=\"\(update.version)\"]]") + if existingItems.count == 0 { + // Fall back to see if any items are using the element version variant + existingItems = try channel.nodes(forXPath: "item[\(SUAppcastElementVersion)=\"\(update.version)\"]") + } + let createNewItem = existingItems.count == 0 // Update all old items, but aim for less than 5 in new feeds @@ -93,6 +99,20 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { if nil == findElement(name: "pubDate", parent: item) { item.addChild(XMLElement.element(withName: "pubDate", stringValue: update.pubDate) as! XMLElement) } + + var versionElement = findElement(name: SUAppcastElementVersion, parent: item) + if nil == versionElement { + versionElement = XMLElement.element(withName: SUAppcastElementVersion, uri: sparkleNS) as? XMLElement + item.addChild(versionElement!) + } + versionElement?.setChildren([text(update.version)]) + + var shortVersionElement = findElement(name: SUAppcastElementShortVersionString, parent: item) + if nil == shortVersionElement { + shortVersionElement = XMLElement.element(withName: SUAppcastElementShortVersionString, uri: sparkleNS) as? XMLElement + item.addChild(shortVersionElement!) + } + shortVersionElement?.setChildren([text(update.shortVersion)]) if let html = update.releaseNotesHTML { let descElement = findOrCreateElement(name: "description", parent: item) @@ -157,8 +177,6 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { } var attributes = [ XMLNode.attribute(withName: "url", stringValue: archiveURL) as! XMLNode, - XMLNode.attribute(withName: SUAppcastAttributeVersion, uri: sparkleNS, stringValue: update.version) as! XMLNode, - XMLNode.attribute(withName: SUAppcastAttributeShortVersionString, uri: sparkleNS, stringValue: update.shortVersion) as! XMLNode, XMLNode.attribute(withName: "length", stringValue: String(update.fileSize)) as! XMLNode, XMLNode.attribute(withName: "type", stringValue: update.mimeType) as! XMLNode, ] @@ -181,8 +199,6 @@ func writeAppcast(appcastDestPath: URL, updates: [ArchiveItem]) throws { for delta in update.deltas { var attributes = [ XMLNode.attribute(withName: "url", stringValue: URL(string: delta.archivePath.lastPathComponent.addingPercentEncoding(withAllowedCharacters: CharacterSet.urlPathAllowed)!, relativeTo: update.archiveURL)!.absoluteString) as! XMLNode, - XMLNode.attribute(withName: SUAppcastAttributeVersion, uri: sparkleNS, stringValue: update.version) as! XMLNode, - XMLNode.attribute(withName: SUAppcastAttributeShortVersionString, uri: sparkleNS, stringValue: update.shortVersion) as! XMLNode, XMLNode.attribute(withName: SUAppcastAttributeDeltaFrom, uri: sparkleNS, stringValue: delta.fromVersion) as! XMLNode, XMLNode.attribute(withName: "length", stringValue: String(delta.fileSize)) as! XMLNode, XMLNode.attribute(withName: "type", stringValue: "application/octet-stream") as! XMLNode, From c631a52b48d70e0e1dbb2d0677dcda7f14d0ed82 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 27 Jun 2021 15:17:11 -0700 Subject: [PATCH 6/7] Re-order where link element is in sample appcast --- Resources/SampleAppcast.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Resources/SampleAppcast.xml b/Resources/SampleAppcast.xml index 2aadac48..dfc2b3db 100755 --- a/Resources/SampleAppcast.xml +++ b/Resources/SampleAppcast.xml @@ -6,11 +6,11 @@ en Version 2.0 (2 bugs fixed; 3 new features) + http://sparkle-project.org 2.0 http://you.com/app/2.0.html - http://sparkle-project.org Wed, 09 Jan 2006 19:20:11 +0000 10.11 @@ -18,11 +18,11 @@ Version 1.5 (8 bugs fixed; 2 new features) + http://sparkle-project.org 1.5 http://you.com/app/1.5.html - http://sparkle-project.org Wed, 01 Jan 2006 12:20:11 +0000 10.11 @@ -31,12 +31,12 @@ Version 1.4 (5 bugs fixed; 2 new features) + http://sparkle-project.org http://you.com/app/1.4.html 241 1.4 - http://sparkle-project.org Wed, 25 Dec 2005 12:20:11 +0000 10.11 From 8997bad17e424c57b852d318e3e80113b939b376 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 27 Jun 2021 15:19:46 -0700 Subject: [PATCH 7/7] Update error message to lacking version element instead of attribute --- Sparkle/SUAppcastItem.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sparkle/SUAppcastItem.m b/Sparkle/SUAppcastItem.m index 77829da2..e1fd3b89 100644 --- a/Sparkle/SUAppcastItem.m +++ b/Sparkle/SUAppcastItem.m @@ -345,7 +345,7 @@ static NSString *SUAppcastItemStateKey = @"SUAppcastItemState"; if (!newVersion) { if (error) { - *error = [NSString stringWithFormat:@"Feed item lacks %@ attribute, and version couldn't be deduced from file name (would have used last component of a file name like AppName_1.3.4.zip)", SUAppcastAttributeVersion]; + *error = [NSString stringWithFormat:@"Feed item lacks %@ element, and version couldn't be deduced from file name (would have used last component of a file name like AppName_1.3.4.zip)", SUAppcastElementVersion]; } return nil; }