Add support for plain text release notes view (#2315)

This also allows embedded release notes to be plain text using sparkle:format="plain-text" attribute.

Also, Catalyst apps only support plain text release notes (compared to before where release notes weren't supported for Catalyst apps).
This commit is contained in:
Zorg authored and GitHub committed 2023-02-11 19:34:26 -08:00
1 parent 348c3a9658
commit ffc203b89a
24 files changed
+503 -160

No files matched your search

+23 -15
View File
@@ -185,13 +185,13 @@
723ABD6C259A9CBC00BDB4FA /* SUUpdatePermissionPrompt.xib in Resources */ = {isa = PBXBuildFile; fileRef = 723ABD6A259A9CBB00BDB4FA /* SUUpdatePermissionPrompt.xib */; };
723ABDDB259A9E8600BDB4FA /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 723ABDD9259A9E8600BDB4FA /* InfoPlist.strings */; };
723ABE02259A9E9E00BDB4FA /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 723ABE00259A9E9E00BDB4FA /* MainMenu.xib */; };
723ABF1B259D055E00BDB4FA /* SUWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = 723ABF1A259D055E00BDB4FA /* SUWebView.h */; };
723ABF1B259D055E00BDB4FA /* SUReleaseNotesView.h in Headers */ = {isa = PBXBuildFile; fileRef = 723ABF1A259D055E00BDB4FA /* SUReleaseNotesView.h */; };
723ABF30259D062F00BDB4FA /* SULegacyWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = 723ABF2E259D062F00BDB4FA /* SULegacyWebView.h */; };
723ABF31259D062F00BDB4FA /* SULegacyWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 723ABF2F259D062F00BDB4FA /* SULegacyWebView.m */; };
723ABFC4259D4CB300BDB4FA /* SUWKWebView.h in Headers */ = {isa = PBXBuildFile; fileRef = 723ABFC2259D4CB300BDB4FA /* SUWKWebView.h */; };
723ABFC5259D4CB300BDB4FA /* SUWKWebView.m in Sources */ = {isa = PBXBuildFile; fileRef = 723ABFC3259D4CB300BDB4FA /* SUWKWebView.m */; };
723AC010259DBDAA00BDB4FA /* SUWebViewCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 723AC00E259DBDAA00BDB4FA /* SUWebViewCommon.h */; };
723AC011259DBDAA00BDB4FA /* SUWebViewCommon.m in Sources */ = {isa = PBXBuildFile; fileRef = 723AC00F259DBDAA00BDB4FA /* SUWebViewCommon.m */; };
723AC010259DBDAA00BDB4FA /* SUReleaseNotesCommon.h in Headers */ = {isa = PBXBuildFile; fileRef = 723AC00E259DBDAA00BDB4FA /* SUReleaseNotesCommon.h */; };
723AC011259DBDAA00BDB4FA /* SUReleaseNotesCommon.m in Sources */ = {isa = PBXBuildFile; fileRef = 723AC00F259DBDAA00BDB4FA /* SUReleaseNotesCommon.m */; };
723AD12F29922B5F006BB02F /* test-dangerous-link.xml in Resources */ = {isa = PBXBuildFile; fileRef = 723AD12E29922B5F006BB02F /* test-dangerous-link.xml */; };
723B5DA71CF7AB0100365F95 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 723B5DA01CF7AB0100365F95 /* main.m */; };
723B5DA91CF7AB0100365F95 /* SPUDownloader.m in Sources */ = {isa = PBXBuildFile; fileRef = 723B5DA31CF7AB0100365F95 /* SPUDownloader.m */; };
@@ -337,6 +337,8 @@
728337A61C9E6FF40085AA99 /* SPUProbeInstallStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = 728337A41C9E6FF40085AA99 /* SPUProbeInstallStatus.h */; };
728337A71C9E6FF40085AA99 /* SPUProbeInstallStatus.m in Sources */ = {isa = PBXBuildFile; fileRef = 728337A51C9E6FF40085AA99 /* SPUProbeInstallStatus.m */; };
728638ED1CAF50CE00783084 /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; };
7286EE5F28CEC84900163C1D /* SUPlainTextReleaseNotesView.h in Headers */ = {isa = PBXBuildFile; fileRef = 7286EE5D28CEC84900163C1D /* SUPlainTextReleaseNotesView.h */; };
7286EE6028CEC84900163C1D /* SUPlainTextReleaseNotesView.m in Sources */ = {isa = PBXBuildFile; fileRef = 7286EE5E28CEC84900163C1D /* SUPlainTextReleaseNotesView.m */; };
728ED34A277DA23400D9238F /* SPUSparkleDeltaArchive.m in Sources */ = {isa = PBXBuildFile; fileRef = 728ED349277DA23400D9238F /* SPUSparkleDeltaArchive.m */; };
728ED34B277DA23400D9238F /* SPUSparkleDeltaArchive.m in Sources */ = {isa = PBXBuildFile; fileRef = 728ED349277DA23400D9238F /* SPUSparkleDeltaArchive.m */; };
728ED34C277DA23400D9238F /* SPUSparkleDeltaArchive.m in Sources */ = {isa = PBXBuildFile; fileRef = 728ED349277DA23400D9238F /* SPUSparkleDeltaArchive.m */; };
@@ -1166,13 +1168,13 @@
723ABE37259A9F2900BDB4FA /* th */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = th; path = th.lproj/MainMenu.strings; sourceTree = "<group>"; };
723ABE38259A9F2B00BDB4FA /* tr */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = tr; path = tr.lproj/MainMenu.strings; sourceTree = "<group>"; };
723ABE39259A9F2E00BDB4FA /* uk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = uk; path = uk.lproj/MainMenu.strings; sourceTree = "<group>"; };
723ABF1A259D055E00BDB4FA /* SUWebView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUWebView.h; sourceTree = "<group>"; };
723ABF1A259D055E00BDB4FA /* SUReleaseNotesView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUReleaseNotesView.h; sourceTree = "<group>"; };
723ABF2E259D062F00BDB4FA /* SULegacyWebView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SULegacyWebView.h; sourceTree = "<group>"; };
723ABF2F259D062F00BDB4FA /* SULegacyWebView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SULegacyWebView.m; sourceTree = "<group>"; };
723ABFC2259D4CB300BDB4FA /* SUWKWebView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUWKWebView.h; sourceTree = "<group>"; };
723ABFC3259D4CB300BDB4FA /* SUWKWebView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SUWKWebView.m; sourceTree = "<group>"; };
723AC00E259DBDAA00BDB4FA /* SUWebViewCommon.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUWebViewCommon.h; sourceTree = "<group>"; };
723AC00F259DBDAA00BDB4FA /* SUWebViewCommon.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SUWebViewCommon.m; sourceTree = "<group>"; };
723AC00E259DBDAA00BDB4FA /* SUReleaseNotesCommon.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUReleaseNotesCommon.h; sourceTree = "<group>"; };
723AC00F259DBDAA00BDB4FA /* SUReleaseNotesCommon.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SUReleaseNotesCommon.m; sourceTree = "<group>"; };
723AD12E29922B5F006BB02F /* test-dangerous-link.xml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xml; path = "test-dangerous-link.xml"; sourceTree = "<group>"; };
723B5D9F1CF7AB0100365F95 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = Downloader/Info.plist; sourceTree = SOURCE_ROOT; };
723B5DA01CF7AB0100365F95 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = Downloader/main.m; sourceTree = SOURCE_ROOT; };
@@ -1317,6 +1319,8 @@
728337A41C9E6FF40085AA99 /* SPUProbeInstallStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPUProbeInstallStatus.h; sourceTree = "<group>"; };
728337A51C9E6FF40085AA99 /* SPUProbeInstallStatus.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUProbeInstallStatus.m; sourceTree = "<group>"; };
728638EE1CAF589C00783084 /* ConfigDownloader.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = ConfigDownloader.xcconfig; sourceTree = "<group>"; };
7286EE5D28CEC84900163C1D /* SUPlainTextReleaseNotesView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SUPlainTextReleaseNotesView.h; sourceTree = "<group>"; };
7286EE5E28CEC84900163C1D /* SUPlainTextReleaseNotesView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SUPlainTextReleaseNotesView.m; sourceTree = "<group>"; };
728ED348277DA23400D9238F /* SPUSparkleDeltaArchive.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SPUSparkleDeltaArchive.h; path = Autoupdate/SPUSparkleDeltaArchive.h; sourceTree = SOURCE_ROOT; };
728ED349277DA23400D9238F /* SPUSparkleDeltaArchive.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SPUSparkleDeltaArchive.m; path = Autoupdate/SPUSparkleDeltaArchive.m; sourceTree = SOURCE_ROOT; };
729924921DF4A45000DBCDF5 /* SUUpdateValidator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SUUpdateValidator.h; path = Sparkle/SUUpdateValidator.h; sourceTree = SOURCE_ROOT; };
@@ -1966,7 +1970,7 @@
6196CFE409C71ADE000DC222 /* SUStatusController.m */,
61B5FCA009C5228F00B25A18 /* SUUpdateAlert.h */,
61B5FCA109C5228F00B25A18 /* SUUpdateAlert.m */,
723AC036259DBF1B00BDB4FA /* Web View */,
723AC036259DBF1B00BDB4FA /* Release Notes Views */,
612DCBAD0D488BC60015DBEA /* SUUpdatePermissionPrompt.h */,
612DCBAE0D488BC60015DBEA /* SUUpdatePermissionPrompt.m */,
723C8A521E2D60DB00C14942 /* SUTouchBarButtonGroup.h */,
@@ -2162,18 +2166,20 @@
name = Internal;
sourceTree = "<group>";
};
723AC036259DBF1B00BDB4FA /* Web View */ = {
723AC036259DBF1B00BDB4FA /* Release Notes Views */ = {
isa = PBXGroup;
children = (
723ABF1A259D055E00BDB4FA /* SUWebView.h */,
723AC00E259DBDAA00BDB4FA /* SUWebViewCommon.h */,
723AC00F259DBDAA00BDB4FA /* SUWebViewCommon.m */,
723ABF1A259D055E00BDB4FA /* SUReleaseNotesView.h */,
723AC00E259DBDAA00BDB4FA /* SUReleaseNotesCommon.h */,
723AC00F259DBDAA00BDB4FA /* SUReleaseNotesCommon.m */,
723ABFC2259D4CB300BDB4FA /* SUWKWebView.h */,
723ABFC3259D4CB300BDB4FA /* SUWKWebView.m */,
723ABF2E259D062F00BDB4FA /* SULegacyWebView.h */,
723ABF2F259D062F00BDB4FA /* SULegacyWebView.m */,
7286EE5D28CEC84900163C1D /* SUPlainTextReleaseNotesView.h */,
7286EE5E28CEC84900163C1D /* SUPlainTextReleaseNotesView.m */,
);
name = "Web View";
name = "Release Notes Views";
sourceTree = "<group>";
};
724BB36D1D31D0B7005D534A /* InstallerConnection */ = {
@@ -2488,6 +2494,7 @@
721BC20E1D1CDE55002BC71E /* SPULocalCacheDirectory.h in Headers */,
7267E5B11D3D8AD500D1BF90 /* SPUMessageTypes.h in Headers */,
728337A61C9E6FF40085AA99 /* SPUProbeInstallStatus.h in Headers */,
7286EE5F28CEC84900163C1D /* SUPlainTextReleaseNotesView.h in Headers */,
723C8A541E2D60DB00C14942 /* SUTouchBarButtonGroup.h in Headers */,
72B767D21C9C7B9300A07552 /* SPUProbingUpdateDriver.h in Headers */,
7229E1B91C97CC4D00CB50D0 /* SPUScheduledUpdateDriver.h in Headers */,
@@ -2527,11 +2534,11 @@
7267E5E51D3D90AA00D1BF90 /* SUFileManager.h in Headers */,
72B3DEC91E23472200457642 /* SPUDownloadedUpdate.h in Headers */,
61EF67590E25C5B400F754E0 /* SUHost.h in Headers */,
723AC010259DBDAA00BDB4FA /* SUWebViewCommon.h in Headers */,
723AC010259DBDAA00BDB4FA /* SUReleaseNotesCommon.h in Headers */,
72162B081C82C9600013C1C5 /* SULocalizations.h in Headers */,
55C14F06136EF6DB00649790 /* SULog.h in Headers */,
EA1E286E22B665F0004AA304 /* SUSignatures.h in Headers */,
723ABF1B259D055E00BDB4FA /* SUWebView.h in Headers */,
723ABF1B259D055E00BDB4FA /* SUReleaseNotesView.h in Headers */,
72B3DECD1E23479000457642 /* SPUInformationalUpdate.h in Headers */,
726F2CE51BC9C33D001971A4 /* SUOperatingSystem.h in Headers */,
61A225A40D1C4AC000430CCD /* SUStandardVersionComparator.h in Headers */,
@@ -3604,6 +3611,7 @@
61A225A50D1C4AC000430CCD /* SUStandardVersionComparator.m in Sources */,
727F340B2605321D00020E85 /* SULog+NSError.m in Sources */,
EA1E287022B66621004AA304 /* SUSignatures.m in Sources */,
7286EE6028CEC84900163C1D /* SUPlainTextReleaseNotesView.m in Sources */,
6196CFFA09C72149000DC222 /* SUStatusController.m in Sources */,
72B3DECA1E23472200457642 /* SPUDownloadedUpdate.m in Sources */,
61A2279D0D1CEE7600430CCD /* SUSystemProfiler.m in Sources */,
@@ -3614,7 +3622,7 @@
72F9EBE31D517E2F004AC8B6 /* SUUpdater.m in Sources */,
724BB3881D32A167005D534A /* SUXPCInstallerConnection.m in Sources */,
724BB3A91D33461B005D534A /* SUXPCInstallerStatus.m in Sources */,
723AC011259DBDAA00BDB4FA /* SUWebViewCommon.m in Sources */,
723AC011259DBDAA00BDB4FA /* SUReleaseNotesCommon.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
+22 -14
View File
@@ -80,7 +80,7 @@
NSUInteger options = NSXMLNodeLoadExternalEntitiesNever; // Prevent inclusion from file://
NSXMLDocument *document = [[NSXMLDocument alloc] initWithData:appcastData options:options error:errorp];
if (nil == document) {
if (nil == document) {
return nil;
}
@@ -93,7 +93,7 @@
NSEnumerator *nodeEnum = [xmlItems objectEnumerator];
NSXMLNode *node;
while((node = [nodeEnum nextObject])) {
while((node = [nodeEnum nextObject])) {
NSMutableDictionary *nodesDict = [NSMutableDictionary dictionary];
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
@@ -120,8 +120,7 @@
// These are flattened as a separate dictionary for some reason
NSDictionary *innerDict = [self attributesOfNode:(NSXMLElement *)node];
[dict setObject:innerDict forKey:name];
}
else if ([name isEqualToString:SURSSElementPubDate]) {
} else if ([name isEqualToString:SURSSElementPubDate]) {
// We don't want to parse and create a NSDate instance -
// that's a risk we can avoid. We don't use the date anywhere other
// than it being accessible from SUAppcastItem
@@ -129,8 +128,21 @@
if (dateString) {
[dict setObject:dateString forKey:name];
}
}
else if ([name isEqualToString:SUAppcastElementDeltas]) {
} else if ([name isEqualToString:SURSSElementDescription]) {
NSString *description = node.stringValue;
if (description != nil) {
NSDictionary *attributes = [self attributesOfNode:(NSXMLElement *)node];
NSString *descriptionFormat = attributes[SUAppcastAttributeFormat];
NSMutableDictionary *descriptionDict = [NSMutableDictionary dictionary];
[descriptionDict setObject:description forKey:@"content"];
if (descriptionFormat != nil) {
[descriptionDict setObject:descriptionFormat forKey:@"format"];
}
[dict setObject:descriptionDict forKey:SURSSElementDescription];
}
} else if ([name isEqualToString:SUAppcastElementDeltas]) {
NSMutableArray *deltas = [NSMutableArray array];
NSEnumerator *childEnum = [[node children] objectEnumerator];
for (NSXMLNode *child in childEnum) {
@@ -139,8 +151,7 @@
}
}
[dict setObject:deltas forKey:name];
}
else if ([name isEqualToString:SUAppcastElementTags]) {
} else if ([name isEqualToString:SUAppcastElementTags]) {
NSMutableArray *names = [NSMutableArray array];
NSEnumerator *childEnum = [[node children] objectEnumerator];
for (NSXMLNode *child in childEnum) {
@@ -150,8 +161,7 @@
}
}
[dict setObject:names forKey:name];
}
else if ([name isEqualToString:SUAppcastElementInformationalUpdate]) {
} else if ([name isEqualToString:SUAppcastElementInformationalUpdate]) {
NSMutableSet *informationalUpdateVersions = [NSMutableSet set];
NSEnumerator *childEnum = [[node children] objectEnumerator];
for (NSXMLNode *child in childEnum) {
@@ -169,8 +179,7 @@
}
}
[dict setObject:[informationalUpdateVersions copy] forKey:name];
}
else if (name != nil) {
} else if (name != nil) {
// add all other values as strings
NSString *theValue = [[node stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if (theValue != nil) {
@@ -184,8 +193,7 @@
if (anItem) {
[appcastItems addObject:anItem];
}
else {
} else {
SULog(SULogLevelError, @"Sparkle Updater: Failed to parse appcast item: %@.\nAppcast dictionary was: %@", errString, dict);
if (errorp) *errorp = [NSError errorWithDomain:SUSparkleErrorDomain
code:SUAppcastParseError
+15
View File
@@ -155,6 +155,21 @@ SU_EXPORT @interface SUAppcastItem : NSObject<NSSecureCoding>
*/
@property (nonatomic, copy, readonly, nullable) NSString *itemDescription;
/**
The format of the `itemDescription` for inline/embedded release notes if provided.
This may be:
- @c html
- @c plain-text
This is extracted from the @c sparkle:descriptionFormat attribute in the @c <description> element.
If the format is not provided in the @c <description> element of the appcast item, then this property may default to `html`.
If the @c <description> element of the appcast item is not available, this property is `nil`.
*/
@property (nonatomic, readonly, nullable) NSString *itemDescriptionFormat;
/**
The full release notes URL of the appcast item if provided.
+54 -1
View File
@@ -28,6 +28,7 @@ static NSString *SUAppcastItemFileURLKey = @"fileURL";
static NSString *SUAppcastItemInfoURLKey = @"infoURL";
static NSString *SUAppcastItemContentLengthKey = @"contentLength";
static NSString *SUAppcastItemDescriptionKey = @"itemDescription";
static NSString *SUAppcastItemDescriptionFormatKey = @"itemDescriptionFormat";
static NSString *SUAppcastItemMaximumSystemVersionKey = @"maximumSystemVersion";
static NSString *SUAppcastItemMinimumSystemVersionKey = @"minimumSystemVersion";
static NSString *SUAppcastItemReleaseNotesURLKey = @"releaseNotesURL";
@@ -68,6 +69,7 @@ static NSString *SUAppcastItemDeltaFromSparkleLocalesKey = @"SUAppcastItemDeltaF
@synthesize contentLength = _contentLength;
@synthesize infoURL = _infoURL;
@synthesize itemDescription = _itemDescription;
@synthesize itemDescriptionFormat = _itemDescriptionFormat;
@synthesize maximumSystemVersion = _maximumSystemVersion;
@synthesize minimumSystemVersion = _minimumSystemVersion;
@synthesize releaseNotesURL = _releaseNotesURL;
@@ -120,6 +122,7 @@ static NSString *SUAppcastItemDeltaFromSparkleLocalesKey = @"SUAppcastItemDeltaF
_installationType = [installationType copy];
_itemDescription = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemDescriptionKey] copy];
_itemDescriptionFormat = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemDescriptionFormatKey] copy];
_maximumSystemVersion = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemMaximumSystemVersionKey] copy];
_minimumSystemVersion = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastItemMinimumSystemVersionKey] copy];
_minimumAutoupdateVersion = [(NSString *)[decoder decodeObjectOfClass:[NSString class] forKey:SUAppcastElementMinimumAutoupdateVersion] copy];
@@ -188,6 +191,10 @@ static NSString *SUAppcastItemDeltaFromSparkleLocalesKey = @"SUAppcastItemDeltaF
[encoder encodeObject:_itemDescription forKey:SUAppcastItemDescriptionKey];
}
if (_itemDescriptionFormat != nil) {
[encoder encodeObject:_itemDescriptionFormat forKey:SUAppcastItemDescriptionFormatKey];
}
if (_maximumSystemVersion != nil) {
[encoder encodeObject:_maximumSystemVersion forKey:SUAppcastItemMaximumSystemVersionKey];
}
@@ -399,7 +406,53 @@ static NSString *SUAppcastItemDeltaFromSparkleLocalesKey = @"SUAppcastItemDeltaF
_propertiesDictionary = [[NSDictionary alloc] initWithDictionary:dict];
_dateString = [(NSString *)[dict objectForKey:SURSSElementPubDate] copy];
_itemDescription = [(NSString *)[dict objectForKey:SURSSElementDescription] copy];
id itemDescription = [dict objectForKey:SURSSElementDescription];
if (itemDescription != nil) {
if ([(NSObject *)itemDescription isKindOfClass:[NSDictionary class]]) {
NSString *descriptionContent = itemDescription[@"content"];
NSString *itemDescriptionString;
if ([descriptionContent isKindOfClass:[NSString class]]) {
itemDescriptionString = [descriptionContent copy];
} else {
itemDescriptionString = nil;
}
id descriptionFormat = itemDescription[@"format"];
NSString *descriptionFormatString;
if ([(NSObject *)descriptionFormat isKindOfClass:[NSString class]]) {
descriptionFormatString = [(NSString *)descriptionFormat lowercaseString];
} else {
descriptionFormatString = nil;
}
_itemDescription = itemDescriptionString;
if (itemDescriptionString != nil) {
if (descriptionFormatString != nil) {
if (![descriptionFormatString isEqualToString:@"plain-text"] &&
![descriptionFormatString isEqualToString:@"markdown"] &&
![descriptionFormatString isEqualToString:@"html"]) {
SULog(SULogLevelError, @"warning: Item '%@' has unknown format '%@' in '<%@>'. Ignoring and using 'html' instead.", _title, descriptionFormatString, SUAppcastItemDescriptionKey);
_itemDescriptionFormat = @"html";
} else {
_itemDescriptionFormat = descriptionFormatString;
}
} else {
_itemDescriptionFormat = @"html";
}
} else {
_itemDescriptionFormat = nil;
}
} else if ([(NSObject *)itemDescription isKindOfClass:[NSString class]]) {
// Legacy path
_itemDescription = [(NSString *)itemDescription copy];
_itemDescriptionFormat = @"html";
}
} else {
_itemDescription = nil;
_itemDescriptionFormat = nil;
}
NSString *theInfoURL = [dict objectForKey:SURSSElementLink];
if (theInfoURL) {
+1
View File
@@ -84,6 +84,7 @@ extern NSString *const SUAppcastAttributeShortVersionString;
extern NSString *const SUAppcastAttributeVersion;
extern NSString *const SUAppcastAttributeOsType;
extern NSString *const SUAppcastAttributeInstallationType;
extern NSString *const SUAppcastAttributeFormat;
extern NSString *const SUAppcastElementVersion;
extern NSString *const SUAppcastElementShortVersionString;
+1
View File
@@ -83,6 +83,7 @@ NSString *const SUAppcastAttributeShortVersionString = @"sparkle:shortVersionStr
NSString *const SUAppcastAttributeVersion = @"sparkle:version";
NSString *const SUAppcastAttributeOsType = @"sparkle:os";
NSString *const SUAppcastAttributeInstallationType = @"sparkle:installationType";
NSString *const SUAppcastAttributeFormat = @"sparkle:format";
NSString *const SUAppcastElementVersion = SUAppcastAttributeVersion;
NSString *const SUAppcastElementShortVersionString = SUAppcastAttributeShortVersionString;
+1
View File
@@ -44,6 +44,7 @@ typedef NS_ENUM(OSStatus, SUError) {
SUResumeAppcastError = 1004,
SURunningTranslocated = 1005,
SUWebKitTerminationError = 1006,
SUReleaseNotesError = 1007,
// Download phase errors.
SUTemporaryDirectoryError = 2000,
+2 -2
View File
@@ -9,11 +9,11 @@
#if SPARKLE_BUILD_UI_BITS && DOWNLOADER_XPC_SERVICE_EMBEDDED
#import <Foundation/Foundation.h>
#import "SUWebView.h"
#import "SUReleaseNotesView.h"
NS_ASSUME_NONNULL_BEGIN
SPU_OBJC_DIRECT_MEMBERS @interface SULegacyWebView : NSObject <SUWebView>
SPU_OBJC_DIRECT_MEMBERS @interface SULegacyWebView : NSObject <SUReleaseNotesView>
- (instancetype)initWithColorStyleSheetLocation:(NSURL *)colorStyleSheetLocation fontFamily:(NSString *)fontFamily fontPointSize:(int)fontPointSize javaScriptEnabled:(BOOL)javaScriptEnabled;
+3 -3
View File
@@ -9,7 +9,7 @@
#if SPARKLE_BUILD_UI_BITS && DOWNLOADER_XPC_SERVICE_EMBEDDED
#import "SULegacyWebView.h"
#import "SUWebViewCommon.h"
#import "SUReleaseNotesCommon.h"
#import "SULog.h"
#import <WebKit/WebKit.h>
@@ -62,7 +62,7 @@
return _webView;
}
- (void)loadHTMLString:(NSString *)htmlString baseURL:(NSURL * _Nullable)baseURL completionHandler:(void (^)(NSError * _Nullable))completionHandler
- (void)loadString:(NSString *)htmlString baseURL:(NSURL * _Nullable)baseURL completionHandler:(void (^)(NSError * _Nullable))completionHandler
{
_completionHandler = [completionHandler copy];
[[_webView mainFrame] loadHTMLString:htmlString baseURL:baseURL];
@@ -110,7 +110,7 @@
{
NSURL *requestURL = request.URL;
BOOL isAboutBlank = NO;
BOOL safeURL = SUWebViewIsSafeURL(requestURL, &isAboutBlank);
BOOL safeURL = SUReleaseNotesIsSafeURL(requestURL, &isAboutBlank);
// Do not allow redirects to dangerous protocols such as file://
if (!safeURL) {
+25
View File
@@ -0,0 +1,25 @@
//
// SUPlainTextReleaseNotesView.h
// Sparkle
//
// Created on 9/11/22.
// Copyright © 2022 Sparkle Project. All rights reserved.
//
#if SPARKLE_BUILD_UI_BITS
#import <Foundation/Foundation.h>
#import "SUReleaseNotesView.h"
NS_ASSUME_NONNULL_BEGIN
SPU_OBJC_DIRECT_MEMBERS @interface SUPlainTextReleaseNotesView : NSObject <SUReleaseNotesView>
- (instancetype)initWithFontPointSize:(int)fontPointSize;
@end
NS_ASSUME_NONNULL_END
#endif
+141
View File
@@ -0,0 +1,141 @@
//
// SUPlainReleaseNotesView.m
// Sparkle
//
// Created on 9/11/22.
// Copyright © 2022 Sparkle Project. All rights reserved.
//
#if SPARKLE_BUILD_UI_BITS
#import "SUPlainTextReleaseNotesView.h"
#import "SUReleaseNotesCommon.h"
#import "SULog.h"
#import "SUErrors.h"
#import <AppKit/AppKit.h>
@interface SUPlainTextReleaseNotesView () <NSTextViewDelegate>
@end
@implementation SUPlainTextReleaseNotesView
{
NSScrollView *_scrollView;
NSTextView *_textView;
int _fontPointSize;
}
- (instancetype)initWithFontPointSize:(int)fontPointSize
{
self = [super init];
if (self != nil) {
_scrollView = [[NSScrollView alloc] initWithFrame:NSZeroRect];
_textView = [[NSTextView alloc] initWithFrame:NSZeroRect];
_textView.delegate = self;
_scrollView.documentView = _textView;
_fontPointSize = fontPointSize;
}
return self;
}
- (NSView *)view
{
return _scrollView;
}
- (void)_loadString:(NSString *)contents completionHandler:(void (^)(NSError * _Nullable))completionHandler SPU_OBJC_DIRECT
{
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:contents attributes:@{ NSFontAttributeName : [NSFont systemFontOfSize:(CGFloat)_fontPointSize] }];
if (attributedString == nil) {
completionHandler([NSError errorWithDomain:SUSparkleErrorDomain code:SUReleaseNotesError userInfo:@{NSLocalizedDescriptionKey: @"Failed to create attributed string of contents to load"}]);
return;
}
[_textView.textStorage setAttributedString:attributedString];
NSSize contentSize = [_scrollView contentSize];
[_textView setFrame:NSMakeRect(0, 0, contentSize.width, contentSize.height)];
[_textView setMinSize:NSMakeSize(0.0, contentSize.height)];
[_textView setMaxSize:NSMakeSize(DBL_MAX, DBL_MAX)];
[_textView setVerticallyResizable:YES];
[_textView setHorizontallyResizable:NO];
[_textView setAutoresizingMask:NSViewWidthSizable];
[_textView setTextContainerInset:NSMakeSize(8, 8)];
[_textView setContinuousSpellCheckingEnabled:NO];
_textView.usesFontPanel = NO;
_textView.editable = NO;
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_14
if (@available(macOS 10.14, *))
#endif
{
_textView.usesAdaptiveColorMappingForDarkAppearance = YES;
}
[_scrollView setHasVerticalScroller:YES];
[_scrollView setHasHorizontalScroller:NO];
completionHandler(nil);
}
- (void)loadString:(NSString *)contents baseURL:(NSURL * _Nullable)baseURL completionHandler:(void (^)(NSError * _Nullable))completionHandler
{
[self _loadString:contents completionHandler:completionHandler];
}
- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL completionHandler:(void (^)(NSError * _Nullable))completionHandler
{
CFStringEncoding cfEncoding = CFStringConvertIANACharSetNameToEncoding((CFStringRef)textEncodingName);
NSStringEncoding encoding;
if (cfEncoding != kCFStringEncodingInvalidId) {
encoding = CFStringConvertEncodingToNSStringEncoding(cfEncoding);
} else {
encoding = NSUTF8StringEncoding;
}
NSString *contents = [[NSString alloc] initWithData:data encoding:encoding];
if (contents == nil) {
completionHandler([NSError errorWithDomain:SUSparkleErrorDomain code:SUReleaseNotesError userInfo:@{NSLocalizedDescriptionKey: @"Failed to convert data contents to string"}]);
return;
}
[self _loadString:contents completionHandler:completionHandler];
}
- (void)stopLoading
{
}
- (void)setDrawsBackground:(BOOL)drawsBackground
{
}
// Links are not insertable yet but this is useful in case we support them in the future
// This is also a defence in case links are somehow insertable
- (BOOL)textView:(NSTextView *)textView clickedOnLink:(id)link atIndex:(NSUInteger)charIndex
{
NSURL *linkURL;
if ([(NSObject *)link isKindOfClass:[NSURL class]]) {
linkURL = link;
} else if ([(NSObject *)link isKindOfClass:[NSString class]]) {
linkURL = [NSURL URLWithString:link];
} else {
SULog(SULogLevelDefault, @"Blocked display of %@ link of unknown type", link);
return YES;
}
BOOL isAboutBlankURL;
if (!SUReleaseNotesIsSafeURL(linkURL, &isAboutBlankURL)) {
SULog(SULogLevelDefault, @"Blocked display of %@ URL which may be dangerous", linkURL.scheme);
return YES;
}
return NO;
}
@end
#endif
@@ -1,5 +1,5 @@
//
// SUWebViewCommon.h
// SUReleaseNotesCommon.h
// Sparkle
//
// Created by Mayur Pawashe on 12/31/20.
@@ -12,7 +12,7 @@
NS_ASSUME_NONNULL_BEGIN
BOOL SUWebViewIsSafeURL(NSURL *url, BOOL *isAboutBlankURL);
BOOL SUReleaseNotesIsSafeURL(NSURL *url, BOOL *isAboutBlankURL);
NS_ASSUME_NONNULL_END
@@ -1,5 +1,5 @@
//
// SUWebViewCommon.m
// SUReleaseNotesCommon.m
// Sparkle
//
// Created by Mayur Pawashe on 12/31/20.
@@ -8,12 +8,12 @@
#if SPARKLE_BUILD_UI_BITS
#import "SUWebViewCommon.h"
#import "SUReleaseNotesCommon.h"
#include "AppKitPrevention.h"
BOOL SUWebViewIsSafeURL(NSURL *url, BOOL *isAboutBlankURL)
BOOL SUReleaseNotesIsSafeURL(NSURL *url, BOOL *isAboutBlankURL)
{
NSString *scheme = url.scheme;
BOOL isAboutBlank = [url.absoluteString isEqualToString:@"about:blank"] || [url.absoluteString isEqualToString:@"about:srcdoc"];
+3 -3
View File
@@ -1,5 +1,5 @@
//
// SUWebView.h
// SUReleaseNotesView.h
// Sparkle
//
// Created by Mayur Pawashe on 12/30/20.
@@ -14,11 +14,11 @@
NS_ASSUME_NONNULL_BEGIN
@protocol SUWebView <NSObject>
@protocol SUReleaseNotesView <NSObject>
@property (nonatomic, readonly) NSView *view;
- (void)loadHTMLString:(NSString *)htmlString baseURL:(NSURL * _Nullable)baseURL completionHandler:(void (^)(NSError * _Nullable))completionHandler;
- (void)loadString:(NSString *)string baseURL:(NSURL * _Nullable)baseURL completionHandler:(void (^)(NSError * _Nullable))completionHandler;
- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL completionHandler:(void (^)(NSError * _Nullable))completionHandler;
+105 -68
View File
@@ -15,9 +15,10 @@
#import "SUUpdateAlert.h"
#import "SUHost.h"
#import "SUWebView.h"
#import "SUReleaseNotesView.h"
#import "SUWKWebView.h"
#import "SULegacyWebView.h"
#import "SUPlainTextReleaseNotesView.h"
#import "SUConstants.h"
#import "SULog.h"
@@ -42,7 +43,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE
SPUUserUpdateState *_state;
NSProgressIndicator *_releaseNotesSpinner;
NSBox *_darkBackgroundView;
id<SUWebView> _webView;
id<SUReleaseNotesView> _releaseNotesView;
__weak id <SUVersionDisplay> _versionDisplayer;
@@ -109,8 +110,8 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE
- (void)endWithSelection:(SPUUserUpdateChoice)choice SPU_OBJC_DIRECT
{
[_webView stopLoading];
[_webView.view removeFromSuperview]; // Otherwise it gets sent Esc presses (why?!) and gets very confused.
[_releaseNotesView stopLoading];
[_releaseNotesView.view removeFromSuperview]; // Otherwise it gets sent Esc presses (why?!) and gets very confused.
NSWindow *window = self.window;
BOOL wasKeyWindow = window.keyWindow;
@@ -149,35 +150,31 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE
[self endWithSelection:SPUUserUpdateChoiceDismiss];
}
- (void)displayReleaseNotes SPU_OBJC_DIRECT
- (void)displayReleaseNotesSpinner SPU_OBJC_DIRECT
{
[self adaptReleaseNotesAppearance];
#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_14
if (@available(macOS 10.14, *))
#endif
{
if (!_observingAppearance) {
[_webView.view addObserver:self forKeyPath:@"effectiveAppearance" options:0 context:nil];
_observingAppearance = YES;
}
}
// Stick a nice big spinner in the middle of the web view until the page is loaded.
NSRect frame = [[_webView.view superview] frame];
NSView *boxContentView = _releaseNotesBoxView.contentView;
NSRect frame = boxContentView.frame;
_releaseNotesSpinner = [[NSProgressIndicator alloc] initWithFrame:NSMakeRect(NSMidX(frame) - 16, NSMidY(frame) - 16, 32, 32)];
[_releaseNotesSpinner setStyle:NSProgressIndicatorStyleSpinning];
[_releaseNotesSpinner startAnimation:self];
[[_webView.view superview] addSubview:_releaseNotesSpinner];
[boxContentView addSubview:_releaseNotesSpinner];
// If there's no release notes URL, just stick the contents of the description into the web view
// Otherwise we'll wait until the client wants us to show release notes
if (_updateItem.releaseNotesURL == nil)
{
if (_updateItem.releaseNotesURL == nil) {
NSString *itemDescription = _updateItem.itemDescription;
if (itemDescription != nil) {
NSString *itemDescriptionFormat = _updateItem.itemDescriptionFormat;
// We don't support markdown but prepare for the future in case we support it one day
BOOL prefersPlainText =
([itemDescriptionFormat isEqualToString:@"plain-text"] ||
[itemDescriptionFormat isEqualToString:@"markdown"]);
[self _createReleaseNotesViewPreferringPlainText:prefersPlainText];
__weak __typeof__(self) weakSelf = self;
[_webView loadHTMLString:itemDescription baseURL:nil completionHandler:^(NSError * _Nullable error) {
[_releaseNotesView loadString:itemDescription baseURL:nil completionHandler:^(NSError * _Nullable error) {
if (error != nil) {
SULog(SULogLevelError, @"Failed to load HTML string from web view: %@", error);
}
@@ -192,7 +189,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE
if (@available(macOS 10.14, *))
#endif
{
if (object == _webView.view && [keyPath isEqualToString:@"effectiveAppearance"]) {
if (object == _releaseNotesView.view && [keyPath isEqualToString:@"effectiveAppearance"]) {
[self adaptReleaseNotesAppearance];
}
}
@@ -204,7 +201,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE
#endif
{
if (_observingAppearance) {
[_webView.view removeObserver:self forKeyPath:@"effectiveAppearance"];
[_releaseNotesView.view removeObserver:self forKeyPath:@"effectiveAppearance"];
_observingAppearance = NO;
}
}
@@ -216,21 +213,21 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE
if (@available(macOS 10.14, *))
#endif
{
NSAppearanceName bestAppearance = [_webView.view.effectiveAppearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
NSAppearanceName bestAppearance = [_releaseNotesView.view.effectiveAppearance bestMatchFromAppearancesWithNames:@[NSAppearanceNameAqua, NSAppearanceNameDarkAqua]];
if ([bestAppearance isEqualToString:NSAppearanceNameDarkAqua])
{
// Remove web view background...
[_webView setDrawsBackground:NO];
[_releaseNotesView setDrawsBackground:NO];
// ... and use NSBox to get the dynamically colored background
if (_darkBackgroundView == nil)
{
_darkBackgroundView = [[NSBox alloc] initWithFrame:_webView.view.frame];
_darkBackgroundView = [[NSBox alloc] initWithFrame:_releaseNotesView.view.frame];
_darkBackgroundView.boxType = NSBoxCustom;
_darkBackgroundView.fillColor = [NSColor textBackgroundColor];
_darkBackgroundView.borderColor = [NSColor clearColor];
// Using auto-resizing mask instead of contraints works well enough
_darkBackgroundView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
[_webView.view.superview addSubview:_darkBackgroundView positioned:NSWindowBelow relativeTo:_webView.view];
[_releaseNotesView.view.superview addSubview:_darkBackgroundView positioned:NSWindowBelow relativeTo:_releaseNotesView.view];
// The release note user stylesheet will not adjust to the user changing the theme until adaptReleaseNoteAppearance is called again.
// So lock the appearance of the background to keep the text readable if the system theme changes.
@@ -242,21 +239,39 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE
// Restore standard dark on light appearance
[_darkBackgroundView removeFromSuperview];
_darkBackgroundView = nil;
[_webView setDrawsBackground:YES];
[_releaseNotesView setDrawsBackground:YES];
}
if (!_observingAppearance) {
[_releaseNotesView.view addObserver:self forKeyPath:@"effectiveAppearance" options:0 context:nil];
_observingAppearance = YES;
}
}
}
- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData
{
NSURL *baseURL = _updateItem.releaseNotesURL.URLByDeletingLastPathComponent;
NSURL *releaseNotesURL = _updateItem.releaseNotesURL;
NSURL *baseURL = releaseNotesURL.URLByDeletingLastPathComponent;
// If a MIME type isn't provided, we will pick html as the default, as opposed to plain text. Questionable decision..
NSString *chosenMIMEType = (downloadData.MIMEType != nil) ? downloadData.MIMEType : @"text/html";
// We'll pick utf-8 as the default text encoding name if one isn't provided which I think is reasonable
NSString *chosenTextEncodingName = (downloadData.textEncodingName != nil) ? downloadData.textEncodingName : @"utf-8";
// We don't support markdown but prepare for the future in case we support it one day
NSString *pathExtension = releaseNotesURL.pathExtension;
BOOL preferringPlainText =
([chosenMIMEType isEqualToString:@"text/plain"] ||
[pathExtension caseInsensitiveCompare:@"txt"] == NSOrderedSame ||
[chosenMIMEType isEqualToString:@"text/markdown"] ||
[chosenMIMEType isEqualToString:@"text/x-markdown"] ||
[pathExtension caseInsensitiveCompare:@"md"] == NSOrderedSame ||
[pathExtension caseInsensitiveCompare:@"markdown"] == NSOrderedSame);
[self _createReleaseNotesViewPreferringPlainText:preferringPlainText];
__weak __typeof__(self) weakSelf = self;
[_webView loadData:downloadData.data MIMEType:chosenMIMEType textEncodingName:chosenTextEncodingName baseURL:baseURL completionHandler:^(NSError * _Nullable error) {
[_releaseNotesView loadData:downloadData.data MIMEType:chosenMIMEType textEncodingName:chosenTextEncodingName baseURL:baseURL completionHandler:^(NSError * _Nullable error) {
if (error != nil) {
SULog(SULogLevelError, @"Failed to load data from web view: %@", error);
}
@@ -278,54 +293,76 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE
- (BOOL)showsReleaseNotes
{
NSNumber *shouldShowReleaseNotes = [_host objectForInfoDictionaryKey:SUShowReleaseNotesKey];
if (shouldShowReleaseNotes == nil)
{
if (shouldShowReleaseNotes == nil) {
// Don't show release notes if RSS item contains no description and no release notes URL:
return (([_updateItem itemDescription] != nil
&& [[[_updateItem itemDescription] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] length] > 0)
|| [_updateItem releaseNotesURL] != nil);
}
else
}
else
return [shouldShowReleaseNotes boolValue];
}
- (void)_createReleaseNotesViewPreferringPlainText:(BOOL)preferringPlainText SPU_OBJC_DIRECT
{
// "-apple-system-font" is a reference to the system UI font. "-apple-system" is the new recommended token, but for backward compatibility we can't use it.
NSString *defaultFontFamily = @"-apple-system-font";
int defaultFontSize = (int)[NSFont systemFontSize];
BOOL usesPlainText;
if (preferringPlainText) {
usesPlainText = YES;
} else {
if (@available(macOS 10.15, *)) {
usesPlainText = [[NSProcessInfo processInfo] isMacCatalystApp];
if (usesPlainText && !preferringPlainText) {
SULog(SULogLevelError, @"Error: Showing HTML release notes for Catalyst apps is not supported. The release notes will be interpreted as plain text. Please serve a plain-text (.txt) release notes file. If you are using a <description> element then please specify the %@=\"plain-text\" attribute in that element.", SUAppcastAttributeFormat);
}
} else {
usesPlainText = NO;
}
}
if (usesPlainText) {
_releaseNotesView = [[SUPlainTextReleaseNotesView alloc] initWithFontPointSize:defaultFontSize];
} else {
NSURL *colorStyleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"ReleaseNotesColorStyle" withExtension:@"css"];
BOOL javaScriptEnabled = [_host boolForInfoDictionaryKey:SUEnableJavaScriptKey];
// WKWebView has a bug where it won't work in loading local HTML content in sandboxed apps that do not have an outgoing network entitlement
// FB6993802: https://twitter.com/sindresorhus/status/1160577243929878528 | https://github.com/feedback-assistant/reports/issues/1
// If the developer is using the downloader XPC service, they are very most likely are a) sandboxed b) do not use outgoing network entitlement.
// In this case, fall back to legacy WebKit view.
// (In theory it is possible for a non-sandboxed app or sandboxed app with outgoing network entitlement to use the XPC service, it's just pretty unlikely. And falling back to a legacy web view would not be too harmful in those cases).
BOOL useWKWebView = !SPUXPCServiceIsEnabled(SUEnableDownloaderServiceKey);
if (useWKWebView) {
_releaseNotesView = [[SUWKWebView alloc] initWithColorStyleSheetLocation:colorStyleURL fontFamily:defaultFontFamily fontPointSize:defaultFontSize javaScriptEnabled:javaScriptEnabled];
} else {
_releaseNotesView = [[SULegacyWebView alloc] initWithColorStyleSheetLocation:colorStyleURL fontFamily:defaultFontFamily fontPointSize:defaultFontSize javaScriptEnabled:javaScriptEnabled];
}
}
NSView *boxContentView = _releaseNotesBoxView.contentView;
assert(_releaseNotesSpinner != nil);
[boxContentView addSubview:_releaseNotesView.view positioned:NSWindowBelow relativeTo:_releaseNotesSpinner];
_releaseNotesView.view.frame = boxContentView.bounds;
_releaseNotesView.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
[self adaptReleaseNotesAppearance];
}
- (void)windowDidLoad
{
NSWindow *window = self.window;
BOOL showReleaseNotes = [self showsReleaseNotes];
if (showReleaseNotes) {
window.frameAutosaveName = @"SUUpdateAlert";
NSURL *colorStyleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"ReleaseNotesColorStyle" withExtension:@"css"];
// "-apple-system-font" is a reference to the system UI font. "-apple-system" is the new recommended token, but for backward compatibility we can't use it.
NSString *defaultFontFamily = @"-apple-system-font";
int defaultFontSize = (int)[NSFont systemFontSize];
BOOL javaScriptEnabled = [_host boolForInfoDictionaryKey:SUEnableJavaScriptKey];
#if DOWNLOADER_XPC_SERVICE_EMBEDDED
// WKWebView has a bug where it won't work in loading local HTML content in sandboxed apps that do not have an outgoing network entitlement
// FB6993802: https://twitter.com/sindresorhus/status/1160577243929878528 | https://github.com/feedback-assistant/reports/issues/1
// If the developer is using the downloader XPC service, they are very most likely are a) sandboxed b) do not use outgoing network entitlement.
// In this case, fall back to legacy WebKit view.
// (In theory it is possible for a non-sandboxed app or sandboxed app with outgoing network entitlement to use the XPC service, it's just pretty unlikely. And falling back to a legacy web view would not be too harmful in those cases).
if (SPUXPCServiceIsEnabled(SUEnableDownloaderServiceKey)) {
_webView = [[SULegacyWebView alloc] initWithColorStyleSheetLocation:colorStyleURL fontFamily:defaultFontFamily fontPointSize:defaultFontSize javaScriptEnabled:javaScriptEnabled];
} else
#endif
{
_webView = [[SUWKWebView alloc] initWithColorStyleSheetLocation:colorStyleURL fontFamily:defaultFontFamily fontPointSize:defaultFontSize javaScriptEnabled:javaScriptEnabled];
}
NSView *boxContentView = _releaseNotesBoxView.contentView;
[boxContentView addSubview:_webView.view];
_webView.view.frame = boxContentView.bounds;
_webView.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
} else {
// Update alert should not be resizable when no release notes are available
window.styleMask &= ~NSWindowStyleMaskResizable;
@@ -339,7 +376,7 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE
BOOL allowsAutomaticUpdates = _allowsAutomaticUpdates;
if (showReleaseNotes) {
[self displayReleaseNotes];
[self displayReleaseNotesSpinner];
} else {
// When automatic updates aren't allowed we won't show the automatic install updates button
// This button is removed later below
@@ -404,8 +441,8 @@ static NSString *const SUUpdateAlertTouchBarIndentifier = @"" SPARKLE_BUNDLE_IDE
- (BOOL)windowShouldClose:(NSNotification *) __unused note
{
[self endWithSelection:SPUUserUpdateChoiceDismiss];
return YES;
[self endWithSelection:SPUUserUpdateChoiceDismiss];
return YES;
}
- (NSImage *)applicationIcon
+2 -2
View File
@@ -9,11 +9,11 @@
#if SPARKLE_BUILD_UI_BITS
#import <Foundation/Foundation.h>
#import "SUWebView.h"
#import "SUReleaseNotesView.h"
NS_ASSUME_NONNULL_BEGIN
SPU_OBJC_DIRECT_MEMBERS @interface SUWKWebView : NSObject <SUWebView>
SPU_OBJC_DIRECT_MEMBERS @interface SUWKWebView : NSObject <SUReleaseNotesView>
- (instancetype)initWithColorStyleSheetLocation:(NSURL *)colorStyleSheetLocation fontFamily:(NSString *)fontFamily fontPointSize:(int)fontPointSize javaScriptEnabled:(BOOL)javaScriptEnabled;
+3 -3
View File
@@ -9,7 +9,7 @@
#if SPARKLE_BUILD_UI_BITS
#import "SUWKWebView.h"
#import "SUWebViewCommon.h"
#import "SUReleaseNotesCommon.h"
#import "SULog.h"
#import "SUErrors.h"
#import <WebKit/WebKit.h>
@@ -105,7 +105,7 @@ static WKUserScript *_userScriptWithInjectedStyleSource(NSString *styleSource)
return _webView;
}
- (void)loadHTMLString:(NSString *)htmlString baseURL:(NSURL * _Nullable)baseURL completionHandler:(void (^)(NSError * _Nullable))completionHandler
- (void)loadString:(NSString *)htmlString baseURL:(NSURL * _Nullable)baseURL completionHandler:(void (^)(NSError * _Nullable))completionHandler
{
_completionHandler = [completionHandler copy];
@@ -179,7 +179,7 @@ static WKUserScript *_userScriptWithInjectedStyleSource(NSString *styleSource)
NSURLRequest *request = navigationAction.request;
NSURL *requestURL = request.URL;
BOOL isAboutBlank = NO;
BOOL safeURL = SUWebViewIsSafeURL(requestURL, &isAboutBlank);
BOOL safeURL = SUReleaseNotesIsSafeURL(requestURL, &isAboutBlank);
// Do not allow redirects to dangerous protocols such as file://
if (!safeURL) {
+2 -1
View File
@@ -4,7 +4,7 @@
<title>For unit test only</title>
<item>
<title>Version 2.0</title>
<description>desc</description>
<description sparkle:format="plain-text">desc</description>
<pubDate>Sat, 26 Jul 2014 15:20:11 +0000</pubDate>
<!-- Test sparkle:version in enclosure -->
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" sparkle:version="2.0" />
@@ -15,6 +15,7 @@
<title>Version 3.0</title>
<sparkle:version>3.0</sparkle:version>
<sparkle:phasedRolloutInterval>86400</sparkle:phasedRolloutInterval>
<description>desc3</description>
<!-- Test legacy critical update tag -->
<sparkle:tags><sparkle:criticalUpdate /></sparkle:tags>
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" length="1346234" />
+3 -1
View File
@@ -27,13 +27,15 @@ class SUAppcastTest: XCTestCase {
XCTAssertEqual("Version 2.0", items[0].title)
XCTAssertEqual("desc", items[0].itemDescription)
XCTAssertEqual("plain-text", items[0].itemDescriptionFormat)
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)
XCTAssertNil(items[1].itemDescription)
XCTAssertEqual("desc3", items[1].itemDescription)
XCTAssertEqual("html", items[1].itemDescriptionFormat)
XCTAssertNil(items[1].dateString)
XCTAssertTrue(items[1].isCriticalUpdate)
XCTAssertEqual(items[1].phasedRolloutInterval, 86400)
+13 -2
View File
@@ -441,8 +441,19 @@ func moveOldUpdatesFromAppcasts(archivesSourceDir: URL, oldFilesDirectory: URL,
print("Warning: failed to move \(archivePath.lastPathComponent) to \(oldFilesDirectory.lastPathComponent): \(error)")
}
let releaseNotesFile = archivePath.deletingPathExtension().appendingPathExtension("html")
if fileManager.fileExists(atPath: releaseNotesFile.path) {
let htmlReleaseNotesFile = archivePath.deletingPathExtension().appendingPathExtension("html")
let plainTextReleaseNotesFile = archivePath.deletingPathExtension().appendingPathExtension("txt")
let releaseNotesFile: URL?
if fileManager.fileExists(atPath: htmlReleaseNotesFile.path) {
releaseNotesFile = htmlReleaseNotesFile
} else if fileManager.fileExists(atPath: plainTextReleaseNotesFile.path) {
releaseNotesFile = plainTextReleaseNotesFile
} else {
releaseNotesFile = nil
}
if let releaseNotesFile = releaseNotesFile {
do {
try suFileManager.updateModificationAndAccessTimeOfItem(at: releaseNotesFile)
} catch {
+45 -19
View File
@@ -295,37 +295,50 @@ class ArchiveItem: CustomStringConvertible {
if basename.pathExtension == "tar" { // tar.gz
basename = basename.deletingPathExtension()
}
let releaseNotes = basename.appendingPathExtension("html")
if !FileManager.default.fileExists(atPath: releaseNotes.path) {
return nil
let htmlReleaseNotes = basename.appendingPathExtension("html")
if FileManager.default.fileExists(atPath: htmlReleaseNotes.path) {
return htmlReleaseNotes
}
return releaseNotes
let plainTextReleaseNotes = basename.appendingPathExtension("txt")
if FileManager.default.fileExists(atPath: plainTextReleaseNotes.path) {
return plainTextReleaseNotes
}
return nil
}
private func getReleaseNotesAsHTMLFragment(_ path: URL, _ maxCDATAThreshold: Int) -> String? {
if let html = try? String(contentsOf: path) {
if html.utf8.count <= maxCDATAThreshold &&
!html.localizedCaseInsensitiveContains("<!DOCTYPE") &&
!html.localizedCaseInsensitiveContains("<body") {
return html
}
private func getReleaseNotesAsFragment(_ path: URL, _ embedReleaseNotesAlways: Bool) -> (content: String, format: String)? {
guard let content = try? String(contentsOf: path) else {
return nil
}
let format = (path.pathExtension.caseInsensitiveCompare("txt") == .orderedSame) ? "plain-text" : "html"
if embedReleaseNotesAlways {
return (content, format)
} else if path.pathExtension.caseInsensitiveCompare("html") == .orderedSame && !content.localizedCaseInsensitiveContains("<!DOCTYPE") && !content.localizedCaseInsensitiveContains("<body") {
// HTML fragments should always be embedded
return (content, format)
} else {
return nil
}
return nil
}
func releaseNotesHTML(maxCDATAThreshold: Int) -> String? {
func releaseNotesContent(embedReleaseNotesAlways: Bool) -> (content: String, format: String)? {
if let path = self.releaseNotesPath {
return self.getReleaseNotesAsHTMLFragment(path, maxCDATAThreshold)
return self.getReleaseNotesAsFragment(path, embedReleaseNotesAlways)
}
return nil
}
func releaseNotesURL(maxCDATAThreshold: Int) -> URL? {
func releaseNotesURL(embedReleaseNotesAlways: Bool) -> URL? {
guard let path = self.releaseNotesPath else {
return nil
}
// The file is already used as inline description
if self.getReleaseNotesAsHTMLFragment(path, maxCDATAThreshold) != nil {
if self.getReleaseNotesAsFragment(path, embedReleaseNotesAlways) != nil {
return nil
}
return self.releaseNoteURL(for: path.lastPathComponent)
@@ -352,10 +365,23 @@ class ArchiveItem: CustomStringConvertible {
}
var localizedReleaseNotes = [(String, URL)]()
for languageCode in Locale.isoLanguageCodes {
let localizedReleaseNoteURL = basename
let baseLocalizedReleaseNoteURL = basename
.appendingPathExtension(languageCode)
.appendingPathExtension("html")
if (try? localizedReleaseNoteURL.checkResourceIsReachable()) ?? false,
let htmlLocalizedReleaseNoteURL = baseLocalizedReleaseNoteURL.appendingPathExtension("html")
let plainTextLocalizedReleaseNoteURL = baseLocalizedReleaseNoteURL.appendingPathExtension("txt")
let localizedReleaseNoteURL: URL?
if (try? htmlLocalizedReleaseNoteURL.checkResourceIsReachable()) ?? false {
localizedReleaseNoteURL = htmlLocalizedReleaseNoteURL
} else if (try? plainTextLocalizedReleaseNoteURL.checkResourceIsReachable()) ?? false {
localizedReleaseNoteURL = plainTextLocalizedReleaseNoteURL
} else {
localizedReleaseNoteURL = nil
}
if let localizedReleaseNoteURL = localizedReleaseNoteURL,
let localizedReleaseNoteRemoteURL = self.releaseNoteURL(for: localizedReleaseNoteURL.lastPathComponent)
{
localizedReleaseNotes.append((languageCode, localizedReleaseNoteRemoteURL))
+26 -13
View File
@@ -16,13 +16,17 @@ func findElement(name: String, parent: XMLElement) -> XMLElement? {
return nil
}
func createElement(name: String, parent: XMLElement) -> XMLElement {
let element = XMLElement(name: name)
parent.addChild(element)
return element
}
func findOrCreateElement(name: String, parent: XMLElement) -> XMLElement {
if let element = findElement(name: name, parent: parent) {
return element
}
let element = XMLElement(name: name)
parent.addChild(element)
return element
return createElement(name: name, parent: parent)
}
func text(_ text: String) -> XMLNode {
@@ -132,7 +136,7 @@ func readAppcast(archives: [String: ArchiveItem], appcastURL: URL) throws -> [St
return updateBranches
}
func writeAppcast(appcastDestPath: URL, appcast: Appcast, fullReleaseNotesLink: String?, maxCDATAThreshold: Int, link: String?, newChannel: String?, majorVersion: String?, ignoreSkippedUpgradesBelowVersion: String?, phasedRolloutInterval: Int?, criticalUpdateVersion: String?, informationalUpdateVersions: [String]?) throws -> (numNewUpdates: Int, numExistingUpdates: Int, numUpdatesRemoved: Int) {
func writeAppcast(appcastDestPath: URL, appcast: Appcast, fullReleaseNotesLink: String?, preferToEmbedReleaseNotes: Bool, link: String?, newChannel: String?, majorVersion: String?, ignoreSkippedUpgradesBelowVersion: String?, phasedRolloutInterval: Int?, criticalUpdateVersion: String?, informationalUpdateVersions: [String]?) throws -> (numNewUpdates: Int, numExistingUpdates: Int, numUpdatesRemoved: Int) {
let appBaseName = appcast.inferredAppName
let sparkleNS = "http://www.andymatuschak.org/xml-namespaces/sparkle"
@@ -358,13 +362,6 @@ func writeAppcast(appcastDestPath: URL, appcast: Appcast, fullReleaseNotesLink:
item.addChild(shortVersionElement!)
}
shortVersionElement?.setChildren([text(update.shortVersion)])
if let html = update.releaseNotesHTML(maxCDATAThreshold: maxCDATAThreshold) {
let descElement = findOrCreateElement(name: "description", parent: item)
let cdata = XMLNode(kind: .text, options: .nodeIsCDATA)
cdata.stringValue = html
descElement.setChildren([cdata])
}
// Override the minimum system version with the version from the archive,
// only if an existing item doesn't specify one
@@ -379,7 +376,7 @@ func writeAppcast(appcastDestPath: URL, appcast: Appcast, fullReleaseNotesLink:
minimumSystemVersion = update.minimumSystemVersion
}
minVer?.setChildren([text(minimumSystemVersion)])
// Look for an existing release notes element
let releaseNotesXpath = "\(SUAppcastElementReleaseNotesLink)"
let results = ((try? item.nodes(forXPath: releaseNotesXpath)) as? [XMLElement])?
@@ -387,7 +384,23 @@ func writeAppcast(appcastDestPath: URL, appcast: Appcast, fullReleaseNotesLink:
.contains(where: { $0.name == SUXMLLanguage }) }
let relElement = results?.first
if let url = update.releaseNotesURL(maxCDATAThreshold: maxCDATAThreshold) {
// If an existing item has a release notes item, don't automatically embed release notes even if the user
// prefers to embed release notes (we only respect this choice for updates without a release notes item or a new item)
let embedReleaseNotesAlways = preferToEmbedReleaseNotes && (relElement == nil)
if let (descriptionContents, descriptionFormat) = update.releaseNotesContent(embedReleaseNotesAlways: embedReleaseNotesAlways) {
let descElement = findOrCreateElement(name: "description", parent: item)
let cdata = XMLNode(kind: .text, options: .nodeIsCDATA)
cdata.stringValue = descriptionContents
descElement.setChildren([cdata])
if descriptionFormat != "html" {
descElement.addAttribute(XMLNode.attribute(withName: SUAppcastAttributeFormat, stringValue: descriptionFormat) as! XMLNode)
}
} else if let existingDescriptionElement = findElement(name: "description", parent: item) {
// The update doesn't include embedded release notes. Remove it.
item.removeChild(at: existingDescriptionElement.index)
}
if let url = update.releaseNotesURL(embedReleaseNotesAlways: embedReleaseNotesAlways) {
// The update includes a valid release notes URL
if let existingReleaseNotesElement = relElement {
// The existing item includes a release notes element. Update it.
+1 -1
View File
@@ -56,7 +56,7 @@ func unarchiveUpdates(archivesSourceDir: URL, archivesDestDir: URL, disableNeste
let dir = try fileManager.contentsOfDirectory(atPath: archivesSourceDir.path)
var running = 0
for item in dir.filter({ !$0.hasPrefix(".") && !$0.hasSuffix(".delta") && !$0.hasSuffix(".xml") && !$0.hasSuffix(".html") }) {
for item in dir.filter({ !$0.hasPrefix(".") && !$0.hasSuffix(".delta") && !$0.hasSuffix(".xml") && !$0.hasSuffix(".html") && !$0.hasSuffix(".txt") }) {
let itemPath = archivesSourceDir.appendingPathComponent(item)
var isDir: ObjCBool = false
if fileManager.fileExists(atPath: itemPath.path, isDirectory: &isDir) && isDir.boolValue {
+7 -7
View File
@@ -81,6 +81,9 @@ struct GenerateAppcast: ParsableCommand {
@Option(name: .customLong("release-notes-url-prefix"), help: ArgumentHelp("A URL that will be used as prefix for constructing URLs for release notes.", valueName: "url"), transform: { URL(string: $0) })
var releaseNotesURLPrefix : URL?
@Flag(name: .customLong("embed-release-notes"), help: ArgumentHelp("Embed release notes in a new update's description. By default, release note files are only embedded if they are HTML and do not include DOCTYPE or body tags. This flag forces release note files for newly created updates to always be embedded."))
var embedReleaseNotes : Bool = false
@Option(name: .customLong("full-release-notes-url"), help: ArgumentHelp("A URL that will be used for the full release notes.", valueName: "url"))
var fullReleaseNotesURL: String?
@@ -138,10 +141,6 @@ struct GenerateAppcast: ParsableCommand {
@Flag(help: .hidden)
var verbose: Bool = false
// CDATA text must contain <= this number of characters
@Option(name: .customLong("max-cdata-threshold"), help: .hidden)
var maxCDATAThreshold: Int = DEFAULT_MAX_CDATA_THRESHOLD
@Flag(name: .customLong("disable-nested-code-check"), help: .hidden)
var disableNestedCodeCheck: Bool = false
@@ -160,8 +159,9 @@ struct GenerateAppcast: ParsableCommand {
Use the --versions option if you need to insert an update that is older than the latest update in your feed, or
if you need to insert only a specific new version with certain parameters.
.html files that have the same filename as an archive (except for the file extension) will be used for release notes for that item.
If the contents of these files are short (< \(DEFAULT_MAX_CDATA_THRESHOLD) characters) and do not include a DOCTYPE or body tags, they will be treated as embedded CDATA release notes.
.html or .txt files that have the same filename as an archive (except for the file extension) will be used for release notes for that item.
For HTML release notes, if the contents of these files do not include a DOCTYPE or body tags, they will be treated as embedded CDATA release notes.
Release notes for new items can be forced to be embedded by passing --embed-release-notes
For new update entries, Sparkle infers the minimum system OS requirement based on your update's LSMinimumSystemVersion provided
by your application's Info.plist. If none is found, \(programName) defaults to Sparkle's own minimum system requirement (macOS 10.13).
@@ -286,7 +286,7 @@ struct GenerateAppcast: ParsableCommand {
relativeTo: archivesSourceDir)
// Write the appcast
let (numNewUpdates, numExistingUpdates, numUpdatesRemoved) = try writeAppcast(appcastDestPath: appcastDestPath, appcast: appcast, fullReleaseNotesLink: fullReleaseNotesURL, maxCDATAThreshold: maxCDATAThreshold, link: link, newChannel: channel, majorVersion: majorVersion, ignoreSkippedUpgradesBelowVersion: ignoreSkippedUpgradesBelowVersion, phasedRolloutInterval: phasedRolloutInterval, criticalUpdateVersion: criticalUpdateVersion, informationalUpdateVersions: informationalUpdateVersions)
let (numNewUpdates, numExistingUpdates, numUpdatesRemoved) = try writeAppcast(appcastDestPath: appcastDestPath, appcast: appcast, fullReleaseNotesLink: fullReleaseNotesURL, preferToEmbedReleaseNotes: embedReleaseNotes, link: link, newChannel: channel, majorVersion: majorVersion, ignoreSkippedUpgradesBelowVersion: ignoreSkippedUpgradesBelowVersion, phasedRolloutInterval: phasedRolloutInterval, criticalUpdateVersion: criticalUpdateVersion, informationalUpdateVersions: informationalUpdateVersions)
// Inform the user, pluralizing "update" if necessary
let pluralizeUpdates = { pluralizeWord($0, "update") }