mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Add markdown support for release notes (#2810)
* Supports Markdown ordered/unordered lists, paragraphs, headers, code blocks, inline styling. Block quotes and thematic breaks are handled in simple manner through indentation and extra newline respectively. Tables are not supported. HTML isn't supported. * Requires macOS 12 or later due to leveraging Foundation / presentation intents for markdown processing. Older OS's and older Sparkle versions >= 2.4.0 will fall back to plain-text interpretation. Additionally, TextKit 2 is now adopted for macOS 12+, and TextKit 1 only code is to be avoided. * Adds delegate method to allow formatting / modifying the presented text before it will be shown for plain-text and markdown release notes. This, for example, can be used to adapting release notes based on currently installed version, but it could also open up styling release notes in other ways. * Adds sparkle:format="markdown" option to <description> element for embedded release notes (in addition to already existingsparkle:format="plain-text" option) * Adds support for generate_appcast to handle markdown release note files and embedded release notes. * Adds a MARKDOWN test mode to Sparkle Test App.
This commit is contained in:
12 files changed
+549
-67
No files matched your search
@@ -58,6 +58,11 @@
|
||||
value = "DELTA"
|
||||
isEnabled = "NO">
|
||||
</EnvironmentVariable>
|
||||
<EnvironmentVariable
|
||||
key = "TEST_MODE"
|
||||
value = "MARKDOWN"
|
||||
isEnabled = "NO">
|
||||
</EnvironmentVariable>
|
||||
</EnvironmentVariables>
|
||||
</LaunchAction>
|
||||
<ProfileAction
|
||||
|
||||
Vendored
+1
-1
@@ -371,7 +371,7 @@
|
||||
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
__weak id<SPUStandardUserDriverDelegate> weakDelegate = delegate;
|
||||
_activeUpdateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:appcastItem state:state host:_host versionDisplayer:versionDisplayer updaterSettings:_updaterSettings completionBlock:^(SPUUserUpdateChoice choice, NSRect windowFrame, BOOL wasKeyWindow) {
|
||||
_activeUpdateAlert = [[SUUpdateAlert alloc] initWithAppcastItem:appcastItem state:state host:_host versionDisplayer:versionDisplayer updaterSettings:_updaterSettings delegate:delegate completionBlock:^(SPUUserUpdateChoice choice, NSRect windowFrame, BOOL wasKeyWindow) {
|
||||
reply(choice);
|
||||
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
|
||||
+16
@@ -188,6 +188,22 @@ SU_EXPORT @protocol SPUStandardUserDriverDelegate <NSObject>
|
||||
*/
|
||||
- (void)standardUserDriverWillFinishUpdateSession;
|
||||
|
||||
/**
|
||||
Called before the standard user driver shows plain-text or markdown release notes text to the user.
|
||||
|
||||
The delegate has the opportunity to return a new attributed string for the release notes text that will be shown to the user.
|
||||
The `bundleDisplayVersion` and `bundleVersion` are supplied in case they're useful for creating a new attributed string.
|
||||
|
||||
This method will not be invoked for HTML release notes. It is only applicable to plain-text and markdown release notes.
|
||||
|
||||
@param releaseNotesAttributedString The release notes text that the standard user driver wants to show to the user.
|
||||
@param update The new update the release notes will be shown for.
|
||||
@param bundleDisplayVersion The current display version (or `CFBundleShortVersionString`) of the bundle that is being updated.
|
||||
@param bundleVersion The current version (or `CFBundleVersion`) of the bundle that is being updated.
|
||||
@return A new attributed string for the release notes text to show, or @c nil if the `releaseNotesAttributedString` should still be used.
|
||||
*/
|
||||
- (NSAttributedString * _Nullable)standardUserDriverWillShowReleaseNotesText:(NSAttributedString *)releaseNotesAttributedString forUpdate:(SUAppcastItem *)update withBundleDisplayVersion:(NSString *)bundleDisplayVersion bundleVersion:(NSString *)bundleVersion;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
+5
-1
@@ -12,11 +12,15 @@
|
||||
|
||||
#import "SUReleaseNotesView.h"
|
||||
|
||||
@protocol SPUStandardUserDriverDelegate;
|
||||
@class SUAppcastItem;
|
||||
@class SUHost;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUPlainTextReleaseNotesView : NSObject <SUReleaseNotesView>
|
||||
|
||||
- (instancetype)initWithFontPointSize:(int)fontPointSize customAllowedURLSchemes:(NSArray<NSString *> *)customAllowedURLSchemes;
|
||||
- (instancetype)initWithFontPointSize:(int)fontPointSize appcastItem:(SUAppcastItem *)appcastItem host:(SUHost *)host delegate:(id<SPUStandardUserDriverDelegate>)delegate prefersMarkdown:(BOOL)prefersMarkdown customAllowedURLSchemes:(NSArray<NSString *> *)customAllowedURLSchemes;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
+339
-14
@@ -10,8 +10,10 @@
|
||||
|
||||
#import "SUPlainTextReleaseNotesView.h"
|
||||
#import "SUReleaseNotesCommon.h"
|
||||
#import "SPUStandardUserDriverDelegate.h"
|
||||
#import "SULog.h"
|
||||
#import "SUErrors.h"
|
||||
#import "SUHost.h"
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
@@ -22,40 +24,330 @@
|
||||
{
|
||||
NSScrollView *_scrollView;
|
||||
NSTextView *_textView;
|
||||
#if DEBUG
|
||||
id _textViewSwitchedToTextKit1Observer;
|
||||
#endif
|
||||
NSArray<NSString *> *_customAllowedURLSchemes;
|
||||
|
||||
SUAppcastItem *_updateItem;
|
||||
SUHost *_host;
|
||||
__weak id<SPUStandardUserDriverDelegate> _delegate;
|
||||
|
||||
int _fontPointSize;
|
||||
BOOL _prefersMarkdown;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFontPointSize:(int)fontPointSize customAllowedURLSchemes:(NSArray<NSString *> *)customAllowedURLSchemes
|
||||
- (instancetype)initWithFontPointSize:(int)fontPointSize appcastItem:(SUAppcastItem *)appcastItem host:(SUHost *)host delegate:(id<SPUStandardUserDriverDelegate>)delegate prefersMarkdown:(BOOL)prefersMarkdown customAllowedURLSchemes:(NSArray<NSString *> *)customAllowedURLSchemes
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_scrollView = [[NSScrollView alloc] initWithFrame:NSZeroRect];
|
||||
_textView = [[NSTextView alloc] initWithFrame:NSZeroRect];
|
||||
_textView.delegate = self;
|
||||
_scrollView.documentView = _textView;
|
||||
_fontPointSize = fontPointSize;
|
||||
_customAllowedURLSchemes = customAllowedURLSchemes;
|
||||
_prefersMarkdown = prefersMarkdown;
|
||||
_scrollView = [[NSScrollView alloc] initWithFrame:NSZeroRect];
|
||||
|
||||
_updateItem = appcastItem;
|
||||
_host = host;
|
||||
|
||||
_delegate = delegate;
|
||||
|
||||
if (@available(macOS 12, *)) {
|
||||
// Create NSTextView using TextKit 2
|
||||
// https://developer.apple.com/documentation/appkit/nstextview/1449347-initwithframe
|
||||
|
||||
NSTextContainer *textContainer = [[NSTextContainer alloc] initWithContainerSize:NSMakeSize(0, (CGFloat)FLT_MAX)];
|
||||
textContainer.widthTracksTextView = YES;
|
||||
|
||||
NSTextLayoutManager *textLayoutManager = [[NSTextLayoutManager alloc] init];
|
||||
textLayoutManager.textContainer = textContainer;
|
||||
|
||||
NSTextContentStorage *textContentStorage = [[NSTextContentStorage alloc] init];
|
||||
[textContentStorage addTextLayoutManager:textLayoutManager];
|
||||
|
||||
_textView = [[NSTextView alloc] initWithFrame:NSZeroRect textContainer:textLayoutManager.textContainer];
|
||||
|
||||
#if DEBUG
|
||||
_textViewSwitchedToTextKit1Observer = [NSNotificationCenter.defaultCenter addObserverForName:NSTextViewDidSwitchToNSLayoutManagerNotification object:_textView queue:nil usingBlock:^(NSNotification * _Nonnull __unused notification) {
|
||||
SULog(SULogLevelError, @"Error: Plain text release notes text view switched to TextKit 1. This should not happen. Was some TextKit 1 API called that is causing this?");
|
||||
}];
|
||||
#endif
|
||||
} else {
|
||||
_textView = [[NSTextView alloc] initWithFrame:NSZeroRect];
|
||||
}
|
||||
|
||||
_textView.delegate = self;
|
||||
_scrollView.documentView = _textView;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
- (void)dealloc
|
||||
{
|
||||
[NSNotificationCenter.defaultCenter removeObserver:_textViewSwitchedToTextKit1Observer];
|
||||
}
|
||||
#endif
|
||||
|
||||
- (NSView *)view
|
||||
{
|
||||
return _scrollView;
|
||||
}
|
||||
|
||||
- (void)_loadString:(NSString *)contents completionHandler:(void (^)(NSError * _Nullable))completionHandler SPU_OBJC_DIRECT
|
||||
static void processMarkdownFragmentAttributedString(NSAttributedString *fragmentAttributedString, NSMutableAttributedString *outputAttributedSubString, NSMutableParagraphStyle *paragraphStyle, BOOL canProcessListItem, NSMutableSet<NSNumber *> *previousVisitedListItemIntents, NSPresentationIntent *intent, NSFont *inputParagraphFont, NSFont *monospacedParagraphFont, NSAttributedString *tabAttributedString, NSAttributedString *newlineAttributedString, NSAttributedString *listBulletAttributedString) API_AVAILABLE(macos(12.0))
|
||||
{
|
||||
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:contents attributes:@{ NSFontAttributeName : [NSFont systemFontOfSize:(CGFloat)_fontPointSize] }];
|
||||
// Pre-pass processing of intent
|
||||
// This info must be computed before processing parent intent
|
||||
BOOL isListItem = NO;
|
||||
NSFont *font = inputParagraphFont;
|
||||
switch (intent.intentKind) {
|
||||
case NSPresentationIntentKindHeader:
|
||||
switch (intent.headerLevel) {
|
||||
case 1:
|
||||
font = [NSFont boldSystemFontOfSize:(CGFloat)inputParagraphFont.pointSize * 1.5];
|
||||
break;
|
||||
case 2:
|
||||
font = [NSFont boldSystemFontOfSize:(CGFloat)inputParagraphFont.pointSize * 1.3];
|
||||
break;
|
||||
case 3:
|
||||
font = [NSFont boldSystemFontOfSize:(CGFloat)inputParagraphFont.pointSize * 1.2];
|
||||
break;
|
||||
default:
|
||||
font = [NSFont boldSystemFontOfSize:(CGFloat)inputParagraphFont.pointSize * 1.1];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case NSPresentationIntentKindListItem:
|
||||
isListItem = YES;
|
||||
break;
|
||||
case NSPresentationIntentKindParagraph:
|
||||
case NSPresentationIntentKindThematicBreak:
|
||||
case NSPresentationIntentKindBlockQuote:
|
||||
case NSPresentationIntentKindCodeBlock:
|
||||
case NSPresentationIntentKindOrderedList:
|
||||
case NSPresentationIntentKindUnorderedList:
|
||||
case NSPresentationIntentKindTable:
|
||||
case NSPresentationIntentKindTableHeaderRow:
|
||||
case NSPresentationIntentKindTableRow:
|
||||
case NSPresentationIntentKindTableCell:
|
||||
break;
|
||||
}
|
||||
|
||||
// Process parent intent if available
|
||||
// A paragraph's intent may be a list item, or a block quote for example. A header's parent intent could be a block quote.
|
||||
// In these cases, we may pre-append attributed string to the output before processing current intent.
|
||||
NSPresentationIntent *parentIntent = intent.parentIntent;
|
||||
if (parentIntent != nil) {
|
||||
processMarkdownFragmentAttributedString(fragmentAttributedString, outputAttributedSubString, paragraphStyle, canProcessListItem && !isListItem, previousVisitedListItemIntents, parentIntent, font, monospacedParagraphFont, tabAttributedString, newlineAttributedString, listBulletAttributedString);
|
||||
}
|
||||
|
||||
// Process the current intent
|
||||
switch (intent.intentKind) {
|
||||
case NSPresentationIntentKindHeader: {
|
||||
CGFloat paragraphSpacing = font.pointSize * 0.8;
|
||||
paragraphStyle.paragraphSpacingBefore += paragraphSpacing;
|
||||
paragraphStyle.paragraphSpacing += paragraphSpacing;
|
||||
|
||||
NSMutableAttributedString *headerAttributedString = [fragmentAttributedString mutableCopy];
|
||||
|
||||
[headerAttributedString addAttributes:@{NSFontAttributeName: font} range:NSMakeRange(0, headerAttributedString.length)];
|
||||
|
||||
[outputAttributedSubString appendAttributedString:headerAttributedString];
|
||||
|
||||
break;
|
||||
}
|
||||
case NSPresentationIntentKindParagraph: {
|
||||
if (parentIntent != nil && parentIntent.intentKind == NSPresentationIntentKindListItem) {
|
||||
// If the parent intent is a list item we don't want to apply paragraphSpacingBefore,
|
||||
// and we'll apply less spacing
|
||||
paragraphStyle.paragraphSpacing += font.pointSize * 0.3;
|
||||
} else {
|
||||
CGFloat paragraphSpacing = font.pointSize * 0.5;
|
||||
paragraphStyle.paragraphSpacing += paragraphSpacing;
|
||||
paragraphStyle.paragraphSpacingBefore += paragraphSpacing;
|
||||
}
|
||||
|
||||
NSMutableAttributedString *contentAttributedString = [fragmentAttributedString mutableCopy];
|
||||
[contentAttributedString addAttributes:@{NSFontAttributeName: font} range:NSMakeRange(0, contentAttributedString.length)];
|
||||
|
||||
[outputAttributedSubString appendAttributedString:contentAttributedString];
|
||||
|
||||
break;
|
||||
}
|
||||
case NSPresentationIntentKindListItem: {
|
||||
// We only process (the innermost first) list item once when we encounter nested lists,
|
||||
// to avoid outputting multiple list bullets
|
||||
// Also avoid processing list items that were processed from previous passes / fragments
|
||||
if (canProcessListItem) {
|
||||
CGFloat firstLineIdentation = intent.indentationLevel * (font.pointSize * 1.5);
|
||||
paragraphStyle.firstLineHeadIndent += firstLineIdentation;
|
||||
|
||||
// Advance subsequent lines and text that wraps to next line by next tab interval past the firstLineIdentation
|
||||
CGFloat defaultTabInterval = paragraphStyle.defaultTabInterval;
|
||||
paragraphStyle.headIndent += ceil(firstLineIdentation / defaultTabInterval) * defaultTabInterval;
|
||||
|
||||
NSNumber *intentIdentity = @(intent.identity);
|
||||
BOOL didVisitListItemFromPreviousPass = [previousVisitedListItemIntents containsObject:intentIdentity];
|
||||
BOOL insertUnorderedBullet = (parentIntent == nil || parentIntent.intentKind == NSPresentationIntentKindUnorderedList);
|
||||
|
||||
if (!didVisitListItemFromPreviousPass) {
|
||||
if (insertUnorderedBullet) {
|
||||
[outputAttributedSubString appendAttributedString:listBulletAttributedString];
|
||||
} else {
|
||||
NSString *ordinalStringWithSpacing = [NSString stringWithFormat:@"%ld.", intent.ordinal];
|
||||
NSAttributedString *listItemAttributedString = [[NSAttributedString alloc] initWithString:ordinalStringWithSpacing attributes:@{NSFontAttributeName: font}];
|
||||
|
||||
[outputAttributedSubString appendAttributedString:listItemAttributedString];
|
||||
}
|
||||
|
||||
[previousVisitedListItemIntents addObject:intentIdentity];
|
||||
}
|
||||
|
||||
[outputAttributedSubString appendAttributedString:tabAttributedString];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case NSPresentationIntentKindBlockQuote: {
|
||||
// Advance text that wraps to next line by this divider width
|
||||
// Multiple levels of block quotes will be advanced mulitiple times
|
||||
// Special rendering via text attachments or decorations is not done because
|
||||
// it's complex and may have tradeoffs
|
||||
|
||||
paragraphStyle.firstLineHeadIndent += paragraphStyle.defaultTabInterval;
|
||||
paragraphStyle.headIndent += paragraphStyle.defaultTabInterval;
|
||||
|
||||
break;
|
||||
}
|
||||
case NSPresentationIntentKindCodeBlock: {
|
||||
paragraphStyle.paragraphSpacing += font.pointSize * 0.25;
|
||||
|
||||
// A parent of a code block could be a block quote or list item
|
||||
// It's more correct to use tab rather than leading paragraph indentation in this case
|
||||
[outputAttributedSubString appendAttributedString:tabAttributedString];
|
||||
// Advance text that wraps to next line by next tab interval
|
||||
paragraphStyle.headIndent += paragraphStyle.defaultTabInterval;
|
||||
|
||||
NSMutableAttributedString *blockquoteAttributedString = [fragmentAttributedString mutableCopy];
|
||||
[blockquoteAttributedString addAttributes:@{NSFontAttributeName: monospacedParagraphFont, NSForegroundColorAttributeName: NSColor.labelColor} range:NSMakeRange(0, blockquoteAttributedString.length)];
|
||||
|
||||
[outputAttributedSubString appendAttributedString:blockquoteAttributedString];
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case NSPresentationIntentKindOrderedList:
|
||||
case NSPresentationIntentKindUnorderedList:
|
||||
// Nothing special is rendered for thematic breaks
|
||||
// Rendering them via text attachments or decorations is complex and has tradeoffs
|
||||
case NSPresentationIntentKindThematicBreak:
|
||||
// Note: TextKit 2 doesn't support NSTextTable
|
||||
// Tables don't show up in release notes often, so they're not that worthwhile supporting
|
||||
case NSPresentationIntentKindTable:
|
||||
case NSPresentationIntentKindTableHeaderRow:
|
||||
case NSPresentationIntentKindTableRow:
|
||||
case NSPresentationIntentKindTableCell:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Note: this function can be called from a background thread and shouldn't use main-thread only APIs
|
||||
// More decorative rendering for blockquotes and line breaks (i.e. rendering dividers) was tried out,
|
||||
// using a. NSTextAttachmentCell based subclass, or b. NSTextAttachmentViewProvider, or c. adopting custom NSTextViewportLayoutControllerDelegate.
|
||||
// This was ultimatily given up on and they all have various tradeoffs. NSCell based text attachments don't work in Catalyst,
|
||||
// view based attachments take up additional space, and TextKit2 CALayer decorations are hard to (re)size/position correctly.
|
||||
// Also each increases code complexity and risk. In the end, changelogs can can live without these.
|
||||
static NSAttributedString *formatMarkdownAttributedString(NSAttributedString *originalAttributedString, CGFloat defaultFontPointSize) API_AVAILABLE(macos(12.0))
|
||||
{
|
||||
// Create our fonts and cache some common attributed strings up front (list bullets, newline)
|
||||
|
||||
NSFont *paragraphFont = [NSFont systemFontOfSize:defaultFontPointSize];
|
||||
NSFont *monospacedParagraphFont = [NSFont monospacedSystemFontOfSize:defaultFontPointSize weight:NSFontWeightRegular];
|
||||
|
||||
NSMutableAttributedString *outputAttributedString = [[NSMutableAttributedString alloc] init];
|
||||
|
||||
NSAttributedString *newlineAttributedString = [[NSAttributedString alloc] initWithString:@"\n"];
|
||||
|
||||
NSAttributedString *listBulletAttributedString;
|
||||
{
|
||||
// The bullet character looks too small in the system font, so switch to another font where it's bigger at same point size
|
||||
NSFont *listBulletPreferredFont = [NSFont fontWithName:@"Menlo Regular" size:defaultFontPointSize];
|
||||
NSFont *listBulletFont = (listBulletPreferredFont != nil) ? listBulletPreferredFont : paragraphFont;
|
||||
|
||||
listBulletAttributedString = [[NSAttributedString alloc] initWithString:@"•" attributes:@{NSFontAttributeName : listBulletFont}];
|
||||
}
|
||||
|
||||
NSAttributedString *tabAttributedString = [[NSAttributedString alloc] initWithString:@"\t" attributes:@{NSFontAttributeName: paragraphFont}];
|
||||
|
||||
NSMutableSet<NSNumber *> *previousVisitedListItemIntents = [[NSMutableSet alloc] init];
|
||||
|
||||
// Enumerate through every presentation intent fragment and create a new attributed string that we append to the output
|
||||
// Foundation handles formatting some things for us already in the attributed string such as bold/itatlics and hyperlinks,
|
||||
// but we need to handle formatting paragraphs, headers, lists, block quotes, etc in the attributed string.
|
||||
[originalAttributedString enumerateAttribute:NSPresentationIntentAttributeName inRange:NSMakeRange(0, originalAttributedString.length) options:0 usingBlock:^(NSPresentationIntent *intent, NSRange presentationIntentRange, BOOL * _Nonnull __unused stopPresentationIntentEnumeration) {
|
||||
|
||||
// Split the presentation intent by lines so we treat every line as a separate paragraph so we present them properly (with correct indentation / tabs)
|
||||
// Normally multiple lines aren't in the same paragraph, but this can happen in some cases like code blocks
|
||||
[originalAttributedString.string enumerateSubstringsInRange:presentationIntentRange options:NSStringEnumerationByLines usingBlock:^(NSString * _Nullable __unused substring, NSRange substringRange, NSRange __unused enclosingRange, BOOL * _Nonnull __unused stopLineEnumeration) {
|
||||
// Insert newline after outputting previous paragraph
|
||||
// This check ensures an extra newline is not inserted after the last outputted paragraph
|
||||
if (outputAttributedString.length > 0) {
|
||||
[outputAttributedString appendAttributedString:newlineAttributedString];
|
||||
}
|
||||
|
||||
NSAttributedString *fragmentAttributedString = [originalAttributedString attributedSubstringFromRange:substringRange];
|
||||
|
||||
// Properties of the paragraph start as 0 and later get incremented based on what is processed
|
||||
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
|
||||
paragraphStyle.paragraphSpacingBefore = 0;
|
||||
paragraphStyle.paragraphSpacing = 0;
|
||||
paragraphStyle.headIndent = 0;
|
||||
paragraphStyle.firstLineHeadIndent = 0;
|
||||
|
||||
// Assume tabs won't be used in headers so we'll just use regular paragraph font size
|
||||
paragraphStyle.tabStops = @[];
|
||||
paragraphStyle.defaultTabInterval = paragraphFont.pointSize * 1.38;
|
||||
|
||||
NSUInteger previousOutputLength = outputAttributedString.length;
|
||||
|
||||
BOOL canProcessListItem = YES;
|
||||
processMarkdownFragmentAttributedString(fragmentAttributedString, outputAttributedString, paragraphStyle, canProcessListItem, previousVisitedListItemIntents, intent, paragraphFont, monospacedParagraphFont, tabAttributedString, newlineAttributedString, listBulletAttributedString);
|
||||
|
||||
[outputAttributedString addAttributes:@{NSParagraphStyleAttributeName: paragraphStyle} range:NSMakeRange(previousOutputLength, outputAttributedString.length - previousOutputLength)];
|
||||
}];
|
||||
}];
|
||||
|
||||
return outputAttributedString;
|
||||
}
|
||||
|
||||
|
||||
- (void)_loadAttributedString:(NSAttributedString * _Nullable)attributedString completionHandler:(void (^)(NSError * _Nullable))completionHandler SPU_OBJC_DIRECT
|
||||
{
|
||||
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];
|
||||
// Give delegate a chance to process and modify the attributed string
|
||||
NSAttributedString *finalAttributedString;
|
||||
id<SPUStandardUserDriverDelegate> delegate = _delegate;
|
||||
if ([(NSObject *)delegate respondsToSelector:@selector(standardUserDriverWillShowReleaseNotesText:forUpdate:withBundleDisplayVersion:bundleVersion:)]) {
|
||||
NSAttributedString *attributedStringFromDelegate = [delegate standardUserDriverWillShowReleaseNotesText:(NSAttributedString * _Nonnull)attributedString forUpdate:_updateItem withBundleDisplayVersion:_host.displayVersion bundleVersion:_host.version];
|
||||
if (attributedStringFromDelegate != nil) {
|
||||
finalAttributedString = attributedStringFromDelegate;
|
||||
} else {
|
||||
finalAttributedString = attributedString;
|
||||
}
|
||||
} else {
|
||||
finalAttributedString = attributedString;
|
||||
}
|
||||
|
||||
[_textView.textStorage setAttributedString:finalAttributedString];
|
||||
|
||||
completionHandler(nil);
|
||||
}
|
||||
|
||||
- (void)_loadString:(NSString *)contents baseURL:(nullable NSURL *)baseURL completionHandler:(void (^)(NSError * _Nullable))completionHandler SPU_OBJC_DIRECT
|
||||
{
|
||||
NSSize contentSize = [_scrollView contentSize];
|
||||
[_textView setFrame:NSMakeRect(0, 0, contentSize.width, contentSize.height)];
|
||||
[_textView setMinSize:NSMakeSize(0.0, contentSize.height)];
|
||||
@@ -63,7 +355,7 @@
|
||||
[_textView setVerticallyResizable:YES];
|
||||
[_textView setHorizontallyResizable:NO];
|
||||
[_textView setAutoresizingMask:NSViewWidthSizable];
|
||||
[_textView setTextContainerInset:NSMakeSize(8, 8)];
|
||||
[_textView setTextContainerInset:NSMakeSize(4, 8)];
|
||||
[_textView setContinuousSpellCheckingEnabled:NO];
|
||||
_textView.usesFontPanel = NO;
|
||||
_textView.editable = NO;
|
||||
@@ -75,12 +367,47 @@
|
||||
[_scrollView setHasVerticalScroller:YES];
|
||||
[_scrollView setHasHorizontalScroller:NO];
|
||||
|
||||
completionHandler(nil);
|
||||
if (_prefersMarkdown) {
|
||||
if (@available(macOS 12, *)) {
|
||||
dispatch_queue_attr_t queuePriority = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INITIATED, 0);
|
||||
|
||||
dispatch_queue_t markdownDispatchQueue = dispatch_queue_create("org.sparkle-project.markdown-loader", queuePriority);
|
||||
|
||||
dispatch_async(markdownDispatchQueue, ^{
|
||||
NSError *loadMarkdownError = nil;
|
||||
NSAttributedString *originalMarkdownAttributedString = [[NSAttributedString alloc] initWithMarkdownString:contents options:nil baseURL:baseURL error:&loadMarkdownError];
|
||||
|
||||
if (originalMarkdownAttributedString == nil) {
|
||||
// Fallback to plain-text
|
||||
|
||||
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:contents attributes:@{ NSFontAttributeName : [NSFont systemFontOfSize:(CGFloat)self->_fontPointSize] }];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self _loadAttributedString:attributedString completionHandler:completionHandler];
|
||||
});
|
||||
} else {
|
||||
NSAttributedString *formattedAttributedString = formatMarkdownAttributedString(originalMarkdownAttributedString, (CGFloat)self->_fontPointSize);
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self _loadAttributedString:formattedAttributedString completionHandler:completionHandler];
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
} else {
|
||||
SULog(SULogLevelDefault, @"Warning: falling back to plain text because markdown support requires macOS 12 or newer");
|
||||
}
|
||||
}
|
||||
|
||||
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithString:contents attributes:@{ NSFontAttributeName : [NSFont systemFontOfSize:(CGFloat)_fontPointSize] }];
|
||||
|
||||
[self _loadAttributedString:attributedString completionHandler:completionHandler];
|
||||
}
|
||||
|
||||
- (void)loadString:(NSString *)contents baseURL:(NSURL * _Nullable)baseURL completionHandler:(void (^)(NSError * _Nullable))completionHandler
|
||||
{
|
||||
[self _loadString:contents completionHandler:completionHandler];
|
||||
[self _loadString:contents baseURL:baseURL completionHandler:completionHandler];
|
||||
}
|
||||
|
||||
- (void)loadData:(NSData *)data MIMEType:(NSString *)MIMEType textEncodingName:(NSString *)textEncodingName baseURL:(NSURL *)baseURL completionHandler:(void (^)(NSError * _Nullable))completionHandler
|
||||
@@ -101,7 +428,7 @@
|
||||
return;
|
||||
}
|
||||
|
||||
[self _loadString:contents completionHandler:completionHandler];
|
||||
[self _loadString:contents baseURL:baseURL completionHandler:completionHandler];
|
||||
}
|
||||
|
||||
- (void)stopLoading
|
||||
@@ -112,8 +439,6 @@
|
||||
{
|
||||
}
|
||||
|
||||
// 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;
|
||||
|
||||
Vendored
+2
-1
@@ -16,11 +16,12 @@
|
||||
#import "SPUUserUpdateState.h"
|
||||
|
||||
@protocol SUUpdateAlertDelegate;
|
||||
@protocol SPUStandardUserDriverDelegate;
|
||||
|
||||
@class SUAppcastItem, SPUDownloadData, SUHost, SPUUpdaterSettings;
|
||||
SPU_OBJC_DIRECT_MEMBERS @interface SUUpdateAlert : NSWindowController
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item state:(SPUUserUpdateState *)state host:(SUHost *)aHost versionDisplayer:(id<SUVersionDisplay>)versionDisplayer updaterSettings:(SPUUpdaterSettings *)updaterSettings completionBlock:(void (^)(SPUUserUpdateChoice, NSRect, BOOL))completionBlock didBecomeKeyBlock:(void (^)(void))didBecomeKeyBlock;
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item state:(SPUUserUpdateState *)state host:(SUHost *)aHost versionDisplayer:(id<SUVersionDisplay>)versionDisplayer updaterSettings:(SPUUpdaterSettings *)updaterSettings delegate:(id<SPUStandardUserDriverDelegate>)delegate completionBlock:(void (^)(SPUUserUpdateChoice, NSRect, BOOL))completionBlock didBecomeKeyBlock:(void (^)(void))didBecomeKeyBlock;
|
||||
|
||||
- (void)showUpdateReleaseNotesWithDownloadData:(SPUDownloadData *)downloadData;
|
||||
- (void)showReleaseNotesFailedToDownload;
|
||||
|
||||
Vendored
+83
-46
@@ -36,6 +36,13 @@ static NSString *const SUAllowsAutomaticUpdatesKeyPath = @"allowsAutomaticUpdate
|
||||
|
||||
static const CGFloat SUUpdateAlertGroupElementSpacing = 12.0;
|
||||
|
||||
typedef NS_ENUM(NSInteger, SUReleaseNotesFormat)
|
||||
{
|
||||
SUReleaseNotesFormatHTML,
|
||||
SUReleaseNotesFormatPlainText,
|
||||
SUReleaseNotesFormatMarkdown
|
||||
};
|
||||
|
||||
@interface SUUpdateAlert () <NSTouchBarDelegate>
|
||||
@end
|
||||
|
||||
@@ -49,6 +56,8 @@ static const CGFloat SUUpdateAlertGroupElementSpacing = 12.0;
|
||||
id<SUReleaseNotesView> _releaseNotesView;
|
||||
id<SUVersionDisplay> _versionDisplayer;
|
||||
|
||||
__weak id<SPUStandardUserDriverDelegate> _delegate;
|
||||
|
||||
IBOutlet NSStackView *_stackView;
|
||||
IBOutlet NSButton *_installButton;
|
||||
IBOutlet NSButton *_laterButton;
|
||||
@@ -64,7 +73,7 @@ static const CGFloat SUUpdateAlertGroupElementSpacing = 12.0;
|
||||
BOOL _windowLoadedAndShowsReleaseNotes;
|
||||
}
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item state:(SPUUserUpdateState *)state host:(SUHost *)aHost versionDisplayer:(id<SUVersionDisplay>)versionDisplayer updaterSettings:(SPUUpdaterSettings *)updaterSettings completionBlock:(void (^)(SPUUserUpdateChoice, NSRect, BOOL))completionBlock didBecomeKeyBlock:(void (^)(void))didBecomeKeyBlock
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item state:(SPUUserUpdateState *)state host:(SUHost *)aHost versionDisplayer:(id<SUVersionDisplay>)versionDisplayer updaterSettings:(SPUUpdaterSettings *)updaterSettings delegate:(id<SPUStandardUserDriverDelegate>)delegate completionBlock:(void (^)(SPUUserUpdateChoice, NSRect, BOOL))completionBlock didBecomeKeyBlock:(void (^)(void))didBecomeKeyBlock
|
||||
{
|
||||
self = [super initWithWindowNibName:@"SUUpdateAlert"];
|
||||
if (self != nil) {
|
||||
@@ -73,6 +82,7 @@ static const CGFloat SUUpdateAlertGroupElementSpacing = 12.0;
|
||||
_versionDisplayer = versionDisplayer;
|
||||
|
||||
_state = state;
|
||||
_delegate = delegate;
|
||||
_completionBlock = [completionBlock copy];
|
||||
_didBecomeKeyBlock = [didBecomeKeyBlock copy];
|
||||
|
||||
@@ -172,12 +182,17 @@ static const CGFloat SUUpdateAlertGroupElementSpacing = 12.0;
|
||||
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];
|
||||
SUReleaseNotesFormat releaseNotesFormat;
|
||||
if ([itemDescriptionFormat isEqualToString:@"plain-text"]) {
|
||||
releaseNotesFormat = SUReleaseNotesFormatPlainText;
|
||||
} else if ([itemDescriptionFormat isEqualToString:@"markdown"]) {
|
||||
releaseNotesFormat = SUReleaseNotesFormatMarkdown;
|
||||
} else {
|
||||
releaseNotesFormat = SUReleaseNotesFormatHTML;
|
||||
}
|
||||
|
||||
[self _createReleaseNotesViewPreferringFormat:releaseNotesFormat];
|
||||
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
[_releaseNotesView loadString:itemDescription baseURL:nil completionHandler:^(NSError * _Nullable error) {
|
||||
@@ -213,15 +228,21 @@ static const CGFloat SUUpdateAlertGroupElementSpacing = 12.0;
|
||||
|
||||
// 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];
|
||||
SUReleaseNotesFormat releaseNotesFormat;
|
||||
// Make sure we test for markdown first because text/plain may be used for MIME type
|
||||
if ([chosenMIMEType isEqualToString:@"text/markdown"] ||
|
||||
[chosenMIMEType isEqualToString:@"text/x-markdown"] ||
|
||||
[pathExtension caseInsensitiveCompare:@"md"] == NSOrderedSame ||
|
||||
[pathExtension caseInsensitiveCompare:@"markdown"] == NSOrderedSame) {
|
||||
releaseNotesFormat = SUReleaseNotesFormatMarkdown;
|
||||
} else if ([chosenMIMEType isEqualToString:@"text/plain"] || [pathExtension caseInsensitiveCompare:@"txt"] == NSOrderedSame) {
|
||||
releaseNotesFormat = SUReleaseNotesFormatPlainText;
|
||||
} else {
|
||||
releaseNotesFormat = SUReleaseNotesFormatHTML;
|
||||
}
|
||||
|
||||
[self _createReleaseNotesViewPreferringFormat:releaseNotesFormat];
|
||||
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
[_releaseNotesView loadData:downloadData.data MIMEType:chosenMIMEType textEncodingName:chosenTextEncodingName baseURL:baseURL completionHandler:^(NSError * _Nullable error) {
|
||||
@@ -255,26 +276,32 @@ static const CGFloat SUUpdateAlertGroupElementSpacing = 12.0;
|
||||
return [shouldShowReleaseNotes boolValue];
|
||||
}
|
||||
|
||||
- (void)_createReleaseNotesViewPreferringPlainText:(BOOL)preferringPlainText SPU_OBJC_DIRECT
|
||||
- (void)_createReleaseNotesViewPreferringFormat:(SUReleaseNotesFormat)preferredReleaseNotesFormat 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);
|
||||
SUReleaseNotesFormat usedReleaseNotesFormat;
|
||||
switch (preferredReleaseNotesFormat) {
|
||||
case SUReleaseNotesFormatPlainText:
|
||||
case SUReleaseNotesFormatMarkdown:
|
||||
usedReleaseNotesFormat = preferredReleaseNotesFormat;
|
||||
break;
|
||||
case SUReleaseNotesFormatHTML:
|
||||
if (@available(macOS 10.15, *)) {
|
||||
if ([[NSProcessInfo processInfo] isMacCatalystApp]) {
|
||||
usedReleaseNotesFormat = SUReleaseNotesFormatPlainText;
|
||||
|
||||
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) or markdown (.md) release notes file. If you are using a <description> element then please specify the %@=\"plain-text\" or %@=\"markdown\" attribute in that element.", SUAppcastAttributeFormat, SUAppcastAttributeFormat);
|
||||
} else {
|
||||
usedReleaseNotesFormat = preferredReleaseNotesFormat;
|
||||
}
|
||||
} else {
|
||||
usedReleaseNotesFormat = preferredReleaseNotesFormat;
|
||||
}
|
||||
} else {
|
||||
usesPlainText = NO;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
NSArray<NSString *> *customAllowedURLSchemes;
|
||||
@@ -297,26 +324,36 @@ static const CGFloat SUUpdateAlertGroupElementSpacing = 12.0;
|
||||
customAllowedURLSchemes = [allowedSchemes copy];
|
||||
}
|
||||
|
||||
if (usesPlainText) {
|
||||
_releaseNotesView = [[SUPlainTextReleaseNotesView alloc] initWithFontPointSize:defaultFontSize customAllowedURLSchemes:customAllowedURLSchemes];
|
||||
} else {
|
||||
NSURL *colorStyleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"ReleaseNotesColorStyle" withExtension:@"css"];
|
||||
|
||||
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).
|
||||
BOOL useWKWebView = !SPUXPCServiceIsEnabled(SUEnableDownloaderServiceKey);
|
||||
if (!useWKWebView) {
|
||||
_releaseNotesView = [[SULegacyWebView alloc] initWithColorStyleSheetLocation:colorStyleURL fontFamily:defaultFontFamily fontPointSize:defaultFontSize javaScriptEnabled:javaScriptEnabled customAllowedURLSchemes:customAllowedURLSchemes];
|
||||
} else
|
||||
#endif
|
||||
id<SPUStandardUserDriverDelegate> delegate = _delegate;
|
||||
switch (usedReleaseNotesFormat) {
|
||||
case SUReleaseNotesFormatPlainText:
|
||||
_releaseNotesView = [[SUPlainTextReleaseNotesView alloc] initWithFontPointSize:defaultFontSize appcastItem:_updateItem host:_host delegate:delegate prefersMarkdown:NO customAllowedURLSchemes:customAllowedURLSchemes];
|
||||
break;
|
||||
case SUReleaseNotesFormatMarkdown:
|
||||
_releaseNotesView = [[SUPlainTextReleaseNotesView alloc] initWithFontPointSize:defaultFontSize appcastItem:_updateItem host:_host delegate:delegate prefersMarkdown:YES customAllowedURLSchemes:customAllowedURLSchemes];
|
||||
break;
|
||||
case SUReleaseNotesFormatHTML:
|
||||
{
|
||||
_releaseNotesView = [[SUWKWebView alloc] initWithColorStyleSheetLocation:colorStyleURL fontFamily:defaultFontFamily fontPointSize:defaultFontSize javaScriptEnabled:javaScriptEnabled customAllowedURLSchemes:customAllowedURLSchemes installedVersion: _host.version];
|
||||
NSURL *colorStyleURL = [[NSBundle bundleForClass:[self class]] URLForResource:@"ReleaseNotesColorStyle" withExtension:@"css"];
|
||||
|
||||
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).
|
||||
BOOL useWKWebView = !SPUXPCServiceIsEnabled(SUEnableDownloaderServiceKey);
|
||||
if (!useWKWebView) {
|
||||
_releaseNotesView = [[SULegacyWebView alloc] initWithColorStyleSheetLocation:colorStyleURL fontFamily:defaultFontFamily fontPointSize:defaultFontSize javaScriptEnabled:javaScriptEnabled customAllowedURLSchemes:customAllowedURLSchemes];
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
_releaseNotesView = [[SUWKWebView alloc] initWithColorStyleSheetLocation:colorStyleURL fontFamily:defaultFontFamily fontPointSize:defaultFontSize javaScriptEnabled:javaScriptEnabled customAllowedURLSchemes:customAllowedURLSchemes installedVersion: _host.version];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,6 +110,8 @@
|
||||
NSString *finalUpdatedVersion;
|
||||
if ([testMode isEqualToString:@"REGULAR"]) {
|
||||
finalUpdatedVersion = @"2.0";
|
||||
} else if ([testMode isEqualToString:@"MARKDOWN"]) {
|
||||
finalUpdatedVersion = @"2.0.1";
|
||||
} else if ([testMode isEqualToString:@"DELTA"]) {
|
||||
finalUpdatedVersion = @"2.1";
|
||||
} else if ([testMode isEqualToString:@"AUTOMATIC"]) {
|
||||
@@ -250,10 +252,10 @@
|
||||
}
|
||||
|
||||
NSUInteger numberOfLengthReplacements = [appcastContents replaceOccurrencesOfString:@"$INSERT_ARCHIVE_LENGTH" withString:[NSString stringWithFormat:@"%llu", archiveFileAttributes.fileSize] options:NSLiteralSearch range:NSMakeRange(0, appcastContents.length)];
|
||||
assert(numberOfLengthReplacements == 2);
|
||||
assert(numberOfLengthReplacements == 3);
|
||||
|
||||
NSUInteger numberOfSignatureReplacements = [appcastContents replaceOccurrencesOfString:@"$INSERT_EDDSA_SIGNATURE" withString:signatureString options:NSLiteralSearch range:NSMakeRange(0, appcastContents.length)];
|
||||
assert(numberOfSignatureReplacements == 2);
|
||||
assert(numberOfSignatureReplacements == 3);
|
||||
|
||||
NSError *writeAppcastError = nil;
|
||||
if (![appcastContents writeToURL:appcastDestinationURL atomically:NO encoding:NSUTF8StringEncoding error:&writeAppcastError]) {
|
||||
@@ -320,6 +322,8 @@
|
||||
return [NSSet setWithObject:@"delta"];
|
||||
} else if ([_testMode isEqualToString:@"AUTOMATIC"]) {
|
||||
return [NSSet setWithObject:@"automatic"];
|
||||
} else if ([_testMode isEqualToString:@"MARKDOWN"]) {
|
||||
return [NSSet setWithObject:@"markdown"];
|
||||
} else {
|
||||
return [NSSet set];
|
||||
}
|
||||
|
||||
@@ -48,6 +48,71 @@
|
||||
</sparkle:deltas>
|
||||
</item>
|
||||
|
||||
<item>
|
||||
<title>Version 2.0.1</title>
|
||||
<sparkle:version>2.0.1</sparkle:version>
|
||||
<link>https://sparkle-project.org</link>
|
||||
<sparkle:fullReleaseNotesLink>releasenotes.html</sparkle:fullReleaseNotesLink>
|
||||
<sparkle:channel>markdown</sparkle:channel>
|
||||
<description sparkle:format="markdown">
|
||||
< because it allows them to blog or write text without having to write all the opening/closing HTML tags. This makes blogging or writing software release notes with markdown a pleasant experience.
|
||||
|
||||
From a good friend:
|
||||
|
||||
> Markdown is also useful for applications that cannot embed WKWebView directly, such as apps without a download client entitlement, or Catalyst applications.
|
||||
>
|
||||
>> In quotes you can also have nested quotes, and the lines in nested quotes can be long enough to span over the next few lines, assuming that the lines are long enough.
|
||||
>>
|
||||
>> And that is how nested quotes can work. A known limitation is properly styling lists in blockquotes so I'd suggest to avoid that.
|
||||
>
|
||||
|
||||
After this paragraph, you should see extra spacing from using a line break.
|
||||
|
||||
---
|
||||
|
||||
Code blocks from markdown are also supported using a monospace font:
|
||||
|
||||
```sh
|
||||
me@Compy ~/D/P/Sparkle> ls
|
||||
Autoupdate/ Carthage-dev.json Configurations/ generate_appcast/ InstallerLauncher/ Package.swift Sparkle/ TestAppHelper/ Vendor/
|
||||
bin/ CHANGELOG DerivedData/ generate_keys/ InstallerStatus/ README.markdown sparkle-cli/ TestApplication/
|
||||
BinaryDelta/ CODE_OF_CONDUCT.md Documentation/ INSTALL LICENSE Resources/ Sparkle.podspec Tests/
|
||||
build/ common_cli/ Downloader/ InstallerConnection/ Makefile sign_update/ Sparkle.xcodeproj/ UITests/
|
||||
```
|
||||
|
||||
Note though, Sparkle's markdown support does not support tables or images. It needs to work without loading additional resources and without switching to TextKit 1.
|
||||
|
||||
## Version 2.0
|
||||
|
||||
* **Redesigned Interface**: Enjoy a refreshed, modern UI that improves navigation and streamlines workflows across the app.
|
||||
* **Cloud Sync Support**: Projects and settings can now be synced securely across multiple devices using your account.
|
||||
* **Customizable Shortcuts**: Create and manage keyboard shortcuts for almost any action.
|
||||
* Improved launch performance and reduced memory usage during startup.
|
||||
* Fixed an issue where notifications could appear twice in some cases.
|
||||
* Addressed several minor visual glitches in dark mode.]]>
|
||||
</description>
|
||||
<pubDate>Sat, 26 Jul 2014 15:20:11 +0000</pubDate>
|
||||
<enclosure url="http://localhost:1337/Sparkle_Test_App.zip" length="$INSERT_ARCHIVE_LENGTH" type="application/octet-stream" sparkle:edSignature="$INSERT_EDDSA_SIGNATURE" />
|
||||
</item>
|
||||
|
||||
<item>
|
||||
<title>Version 2.0</title>
|
||||
<sparkle:version>2.0</sparkle:version>
|
||||
|
||||
@@ -471,12 +471,18 @@ func moveOldUpdatesFromAppcasts(archivesSourceDir: URL, oldFilesDirectory: URL,
|
||||
|
||||
let htmlReleaseNotesFile = archivePath.deletingPathExtension().appendingPathExtension("html")
|
||||
let plainTextReleaseNotesFile = archivePath.deletingPathExtension().appendingPathExtension("txt")
|
||||
let markdownReleaseNotesFile = archivePath.deletingPathExtension().appendingPathExtension("md")
|
||||
let markdownSecondaryReleaseNotesFile = archivePath.deletingPathExtension().appendingPathExtension("markdown")
|
||||
|
||||
let releaseNotesFile: URL?
|
||||
if fileManager.fileExists(atPath: htmlReleaseNotesFile.path) {
|
||||
releaseNotesFile = htmlReleaseNotesFile
|
||||
} else if fileManager.fileExists(atPath: plainTextReleaseNotesFile.path) {
|
||||
releaseNotesFile = plainTextReleaseNotesFile
|
||||
} else if fileManager.fileExists(atPath: markdownReleaseNotesFile.path) {
|
||||
releaseNotesFile = markdownReleaseNotesFile
|
||||
} else if fileManager.fileExists(atPath: markdownSecondaryReleaseNotesFile.path) {
|
||||
releaseNotesFile = markdownSecondaryReleaseNotesFile
|
||||
} else {
|
||||
releaseNotesFile = nil
|
||||
}
|
||||
|
||||
@@ -421,6 +421,16 @@ class ArchiveItem: CustomStringConvertible {
|
||||
return plainTextReleaseNotes
|
||||
}
|
||||
|
||||
let markdownReleaseNotes = basename.appendingPathExtension("md")
|
||||
if FileManager.default.fileExists(atPath: markdownReleaseNotes.path) {
|
||||
return markdownReleaseNotes
|
||||
}
|
||||
|
||||
let markdownSecondaryReleaseNotes = basename.appendingPathExtension("markdown")
|
||||
if FileManager.default.fileExists(atPath: markdownSecondaryReleaseNotes.path) {
|
||||
return markdownSecondaryReleaseNotes
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -429,7 +439,16 @@ class ArchiveItem: CustomStringConvertible {
|
||||
return nil
|
||||
}
|
||||
|
||||
let format = (path.pathExtension.caseInsensitiveCompare("txt") == .orderedSame) ? "plain-text" : "html"
|
||||
let format: String
|
||||
let pathExtension = path.pathExtension
|
||||
switch pathExtension {
|
||||
case "txt":
|
||||
format = "plain-text"
|
||||
case "md", "markdown":
|
||||
format = "markdown"
|
||||
default:
|
||||
format = "html"
|
||||
}
|
||||
|
||||
if embedReleaseNotesAlways {
|
||||
return (content, format)
|
||||
|
||||
@@ -186,7 +186,7 @@ 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 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.
|
||||
.html, .md, 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
|
||||
|
||||
|
||||
Reference in new issue
Block a user