mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-25 04:47:55 +00:00
Pass text encoding and MIME type to user driver for release notes
This fixes issues where the user driver may not be displaying release notes properly because it doesn't know what kind of data was downloaded (eg: html vs plain text).
This commit is contained in:
1 parent
085724322f
commit
65d78d5129
16 files changed
+177
-28
No files matched your search
@@ -325,6 +325,10 @@
|
||||
72F9EBE31D517E2F004AC8B6 /* SUUpdater.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EBE11D517E2F004AC8B6 /* SUUpdater.m */; };
|
||||
72F9EC341D5BF542004AC8B6 /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5E41D3D90AA00D1BF90 /* SUFileManager.m */; };
|
||||
72F9EC351D5BF54E004AC8B6 /* SUFileManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 7267E5E41D3D90AA00D1BF90 /* SUFileManager.m */; };
|
||||
72F9EC381D5C04A9004AC8B6 /* SPUTemporaryDownload.h in Headers */ = {isa = PBXBuildFile; fileRef = 72F9EC361D5C04A9004AC8B6 /* SPUTemporaryDownload.h */; };
|
||||
72F9EC3A1D5C04A9004AC8B6 /* SPUTemporaryDownload.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EC371D5C04A9004AC8B6 /* SPUTemporaryDownload.m */; };
|
||||
72F9EC3B1D5C15D0004AC8B6 /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; };
|
||||
72F9EC3C1D5C15EF004AC8B6 /* SPUTemporaryDownload.m in Sources */ = {isa = PBXBuildFile; fileRef = 72F9EC371D5C04A9004AC8B6 /* SPUTemporaryDownload.m */; };
|
||||
C23E885B1BE7B24F0050BB73 /* SparkleTestCodeSignApp.enc.dmg in Resources */ = {isa = PBXBuildFile; fileRef = C23E88591BE7AF890050BB73 /* SparkleTestCodeSignApp.enc.dmg */; };
|
||||
F8761EB11ADC5068000C9034 /* SUCodeSigningVerifierTest.m in Sources */ = {isa = PBXBuildFile; fileRef = F8761EB01ADC5068000C9034 /* SUCodeSigningVerifierTest.m */; };
|
||||
F8761EB31ADC50EB000C9034 /* SparkleTestCodeSignApp.zip in Resources */ = {isa = PBXBuildFile; fileRef = F8761EB21ADC50EB000C9034 /* SparkleTestCodeSignApp.zip */; };
|
||||
@@ -1023,6 +1027,8 @@
|
||||
72F94F571CC44DE1002DEE68 /* SPUXPCServiceInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPUXPCServiceInfo.m; sourceTree = "<group>"; };
|
||||
72F9EBE01D517E2F004AC8B6 /* SUUpdater.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUUpdater.h; sourceTree = "<group>"; };
|
||||
72F9EBE11D517E2F004AC8B6 /* SUUpdater.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdater.m; sourceTree = "<group>"; };
|
||||
72F9EC361D5C04A9004AC8B6 /* SPUTemporaryDownload.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SPUTemporaryDownload.h; path = TemporaryDownloader/SPUTemporaryDownload.h; sourceTree = SOURCE_ROOT; };
|
||||
72F9EC371D5C04A9004AC8B6 /* SPUTemporaryDownload.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SPUTemporaryDownload.m; path = TemporaryDownloader/SPUTemporaryDownload.m; sourceTree = SOURCE_ROOT; };
|
||||
8DC2EF5A0486A6940098B216 /* Sparkle-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Sparkle-Info.plist"; sourceTree = "<group>"; };
|
||||
8DC2EF5B0486A6940098B216 /* Sparkle.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Sparkle.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
A5BF4F1B1BC7668B007A052A /* SUTestWebServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SUTestWebServer.h; sourceTree = "<group>"; };
|
||||
@@ -1720,6 +1726,8 @@
|
||||
724A0A351CF7AEEA00D8C3D5 /* main.m */,
|
||||
724A0A371CF7AEEA00D8C3D5 /* SUTemporaryDownloader.h */,
|
||||
724A0A381CF7AEEA00D8C3D5 /* SUTemporaryDownloader.m */,
|
||||
72F9EC361D5C04A9004AC8B6 /* SPUTemporaryDownload.h */,
|
||||
72F9EC371D5C04A9004AC8B6 /* SPUTemporaryDownload.m */,
|
||||
724A0A391CF7AEEA00D8C3D5 /* SUTemporaryDownloaderProtocol.h */,
|
||||
);
|
||||
name = TemporaryDownloader;
|
||||
@@ -1898,6 +1906,7 @@
|
||||
61B5F8ED09C4CE3C00B25A18 /* SPUUpdater.h in Headers */,
|
||||
61A2259E0D1C495D00430CCD /* SUVersionComparisonProtocol.h in Headers */,
|
||||
3772FEA913DE0B6B00F79537 /* SUVersionDisplayProtocol.h in Headers */,
|
||||
72F9EC381D5C04A9004AC8B6 /* SPUTemporaryDownload.h in Headers */,
|
||||
7267E5E51D3D90AA00D1BF90 /* SUFileManager.h in Headers */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
@@ -2734,6 +2743,8 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
72F9EC3B1D5C15D0004AC8B6 /* SUConstants.m in Sources */,
|
||||
72F9EC3A1D5C04A9004AC8B6 /* SPUTemporaryDownload.m in Sources */,
|
||||
724A0A3B1CF7AEEA00D8C3D5 /* main.m in Sources */,
|
||||
7293A1B01CEE9B9800B957A7 /* SPUURLRequest.m in Sources */,
|
||||
724A0A3D1CF7AEEA00D8C3D5 /* SUTemporaryDownloader.m in Sources */,
|
||||
@@ -2794,6 +2805,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
72F9EC3C1D5C15EF004AC8B6 /* SPUTemporaryDownload.m in Sources */,
|
||||
7267E5DF1D3D8FFA00D1BF90 /* SPUInstallationInputData.m in Sources */,
|
||||
724BB3B01D3482BA005D534A /* SPUSystemAuthorization.m in Sources */,
|
||||
724BB3AA1D3347C2005D534A /* SUInstallerStatus.m in Sources */,
|
||||
|
||||
Vendored
+2
-2
@@ -188,10 +188,10 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)showUpdateReleaseNotes:(NSData *)releaseNotes
|
||||
- (void)showUpdateReleaseNotesWithData:(NSData *)releaseNotesData textEncodingName:(NSString * _Nullable)textEncodingName MIMEType:(NSString * _Nullable)MIMEType
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[self.activeUpdateAlert showReleaseNotes:releaseNotes];
|
||||
[self.activeUpdateAlert showUpdateReleaseNotesWithData:releaseNotesData textEncodingName:textEncodingName MIMEType:MIMEType];
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Vendored
+3
-1
@@ -10,8 +10,10 @@
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class SPUTemporaryDownload;
|
||||
|
||||
// From the completion block, either data or error can be nil, but not both
|
||||
// The completion block returns on the main queue
|
||||
void SPUDownloadURLWithRequest(NSURLRequest * request, void (^completionBlock)(NSData * _Nullable data, NSError * _Nullable error));
|
||||
void SPUDownloadURLWithRequest(NSURLRequest * request, void (^completionBlock)(SPUTemporaryDownload * _Nullable download, NSError * _Nullable error));
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
Vendored
+5
-4
@@ -11,9 +11,10 @@
|
||||
#import "SUTemporaryDownloader.h"
|
||||
#import "SUTemporaryDownloaderProtocol.h"
|
||||
#import "SPUURLRequest.h"
|
||||
#import "SPUTemporaryDownload.h"
|
||||
#import "SUErrors.h"
|
||||
|
||||
void SPUDownloadURLWithRequest(NSURLRequest * request, void (^completionBlock)(NSData * _Nullable, NSError * _Nullable))
|
||||
void SPUDownloadURLWithRequest(NSURLRequest * request, void (^completionBlock)(SPUTemporaryDownload * _Nullable, NSError * _Nullable))
|
||||
{
|
||||
id<SUTemporaryDownloaderProtocol> downloader = nil;
|
||||
NSXPCConnection *connection = nil;
|
||||
@@ -57,15 +58,15 @@ void SPUDownloadURLWithRequest(NSURLRequest * request, void (^completionBlock)(N
|
||||
downloader = connection.remoteObjectProxy;
|
||||
}
|
||||
|
||||
[downloader startDownloadWithRequest:[SPUURLRequest URLRequestWithRequest:request] completion:^(NSData * _Nullable data, NSError * _Nullable error) {
|
||||
[downloader startDownloadWithRequest:[SPUURLRequest URLRequestWithRequest:request] completion:^(SPUTemporaryDownload * _Nullable download, NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
retrievedDownloadResult = YES;
|
||||
[connection invalidate];
|
||||
|
||||
if (data == nil) {
|
||||
if (download == nil || download.data == nil) {
|
||||
completionBlock(nil, error);
|
||||
} else {
|
||||
completionBlock(data, nil);
|
||||
completionBlock(download, nil);
|
||||
}
|
||||
});
|
||||
}];
|
||||
|
||||
Vendored
+4
-2
@@ -161,11 +161,13 @@ SU_EXPORT @protocol SPUUserDriver <NSObject>
|
||||
* This is only applicable if the release notes are linked from the appcast, and are not directly embedded inside of the appcast file.
|
||||
* That is, this may be invoked if the releaseNotesURL from the appcast item is non-nil.
|
||||
*
|
||||
* @param releaseNotes The data for the release notes that was downloaded from the new update's appcast.
|
||||
* @param releaseNotesData The data for the release notes that was downloaded from the new update's appcast.
|
||||
* @param textEncodingName The text encoding name (eg: "utf-8"). This may be nil if one wasn't retrieved.
|
||||
* @param MIMEType The MIME type that was retrieved from the download. This may be nil if one wasn't retrieved.
|
||||
*
|
||||
* This can be called from any thread
|
||||
*/
|
||||
- (void)showUpdateReleaseNotes:(NSData *)releaseNotes;
|
||||
- (void)showUpdateReleaseNotesWithData:(NSData *)releaseNotesData textEncodingName:(NSString * _Nullable)textEncodingName MIMEType:(NSString * _Nullable)MIMEType;
|
||||
|
||||
/*!
|
||||
* Show the user that the new update's release notes could not be downloaded
|
||||
|
||||
Vendored
+4
-3
@@ -15,6 +15,7 @@
|
||||
#import "SULocalizations.h"
|
||||
#import "SPUXPCServiceInfo.h"
|
||||
#import "SPUURLDownload.h"
|
||||
#import "SPUTemporaryDownload.h"
|
||||
|
||||
#ifdef _APPKITDEFINES_H
|
||||
#error This is a "core" class and should NOT import AppKit
|
||||
@@ -76,10 +77,10 @@
|
||||
|
||||
[request setValue:@"application/rss+xml,*/*;q=0.1" forHTTPHeaderField:@"Accept"];
|
||||
|
||||
SPUDownloadURLWithRequest(request, ^(NSData * _Nullable data, NSError * _Nullable error) {
|
||||
if (data != nil) {
|
||||
SPUDownloadURLWithRequest(request, ^(SPUTemporaryDownload * _Nullable download, NSError * _Nullable error) {
|
||||
if (download != nil) {
|
||||
NSError *parseError = nil;
|
||||
NSArray *appcastItems = [self parseAppcastItemsFromXMLData:data error:&parseError];
|
||||
NSArray *appcastItems = [self parseAppcastItemsFromXMLData:download.data error:&parseError];
|
||||
|
||||
if (appcastItems != nil) {
|
||||
self.items = appcastItems;
|
||||
|
||||
Vendored
+5
-3
@@ -15,6 +15,7 @@
|
||||
#import "SUAppcastItem.h"
|
||||
#import "SUErrors.h"
|
||||
#import "SPUURLDownload.h"
|
||||
#import "SPUTemporaryDownload.h"
|
||||
|
||||
#ifdef _APPKITDEFINES_H
|
||||
#error This is a "core" class and should NOT import AppKit
|
||||
@@ -144,9 +145,10 @@
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:updateItem.releaseNotesURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];
|
||||
|
||||
id <SPUUserDriver> userDriver = self.userDriver;
|
||||
SPUDownloadURLWithRequest(request, ^(NSData * _Nullable data, NSError * _Nullable error) {
|
||||
if (data != nil) {
|
||||
[userDriver showUpdateReleaseNotes:(NSData * _Nonnull)data];
|
||||
SPUDownloadURLWithRequest(request, ^(SPUTemporaryDownload * _Nullable download, NSError * _Nullable error) {
|
||||
if (download != nil) {
|
||||
SPUTemporaryDownload *nonnullDownload = download;
|
||||
[userDriver showUpdateReleaseNotesWithData:nonnullDownload.data textEncodingName:nonnullDownload.textEncoding MIMEType:nonnullDownload.MIMEType];
|
||||
} else {
|
||||
[userDriver showUpdateReleaseNotesFailedToDownloadWithError:(NSError * _Nonnull)error];
|
||||
}
|
||||
|
||||
Vendored
+1
-1
@@ -24,7 +24,7 @@
|
||||
|
||||
- (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)aHost versionDisplayer:(id <SUVersionDisplay>)aVersionDisplayer resumableCompletionBlock:(void (^)(SUInstallUpdateStatus))block;
|
||||
|
||||
- (void)showReleaseNotes:(NSData *)releaseNotes;
|
||||
- (void)showUpdateReleaseNotesWithData:(NSData *)releaseNotesData textEncodingName:(NSString *)textEncodingName MIMEType:(NSString *)MIMEType;
|
||||
- (void)showReleaseNotesFailedToDownload;
|
||||
|
||||
- (IBAction)installUpdate:sender;
|
||||
|
||||
Vendored
+7
-2
@@ -199,11 +199,16 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)showReleaseNotes:(NSData *)releaseNotes
|
||||
- (void)showUpdateReleaseNotesWithData:(NSData *)releaseNotesData textEncodingName:(NSString * _Nullable)textEncodingName MIMEType:(NSString * _Nullable)MIMEType
|
||||
{
|
||||
if (!self.webViewFinishedLoading) {
|
||||
NSURL *baseURL = self.updateItem.releaseNotesURL.URLByDeletingLastPathComponent;
|
||||
[[self.releaseNotesView mainFrame] loadData:releaseNotes MIMEType:@"text/html" textEncodingName:@"utf-8" baseURL:baseURL];
|
||||
// If a MIME type isn't provided, we will pick html as the default, as opposed to plain text. Questionable decision..
|
||||
NSString *chosenMIMEType = (MIMEType != nil) ? 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 = (textEncodingName != nil) ? textEncodingName : @"utf-8";
|
||||
|
||||
[[self.releaseNotesView mainFrame] loadData:releaseNotesData MIMEType:chosenMIMEType textEncodingName:chosenTextEncodingName baseURL:baseURL];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// SPUTemporaryDownload.h
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 8/10/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SPUTemporaryDownload : NSObject <NSSecureCoding>
|
||||
|
||||
- (instancetype)initWithData:(NSData *)data textEncoding:(NSString * _Nullable)textEncoding MIMEType:(NSString * _Nullable)MIMEType;
|
||||
|
||||
@property (nonatomic, readonly) NSData *data;
|
||||
@property (nonatomic, readonly, nullable, copy) NSString *textEncoding;
|
||||
@property (nonatomic, readonly, nullable, copy) NSString *MIMEType;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// SPUTemporaryDownload.m
|
||||
// Sparkle
|
||||
//
|
||||
// Created by Mayur Pawashe on 8/10/16.
|
||||
// Copyright © 2016 Sparkle Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SPUTemporaryDownload.h"
|
||||
|
||||
static NSString *SPUTemporaryDownloadDataKey = @"SPUTemporaryDownloadData";
|
||||
static NSString *SPUTemporaryDownloadTextEncodingKey = @"SPUTemporaryDownloadTextEncoding";
|
||||
static NSString *SPUTemporaryDownloadMIMETypeKey = @"SPUTemporaryDownloadMIMEType";
|
||||
|
||||
@implementation SPUTemporaryDownload
|
||||
|
||||
@synthesize data = _data;
|
||||
@synthesize textEncoding = _textEncoding;
|
||||
@synthesize MIMEType = _MIMEType;
|
||||
|
||||
+ (BOOL)supportsSecureCoding
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (instancetype)initWithData:(NSData *)data textEncoding:(NSString * _Nullable)textEncoding MIMEType:(NSString *)MIMEType
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_data = data;
|
||||
_textEncoding = textEncoding;
|
||||
_MIMEType = MIMEType;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(NSCoder *)coder
|
||||
{
|
||||
[coder encodeObject:self.data forKey:SPUTemporaryDownloadDataKey];
|
||||
|
||||
if (self.textEncoding != nil) {
|
||||
[coder encodeObject:self.textEncoding forKey:SPUTemporaryDownloadTextEncodingKey];
|
||||
}
|
||||
|
||||
if (self.MIMEType != nil) {
|
||||
[coder encodeObject:self.MIMEType forKey:SPUTemporaryDownloadMIMETypeKey];
|
||||
}
|
||||
}
|
||||
|
||||
- (nullable instancetype)initWithCoder:(NSCoder *)decoder
|
||||
{
|
||||
NSData *data = [decoder decodeObjectOfClass:[NSData class] forKey:SPUTemporaryDownloadDataKey];
|
||||
if (data == nil) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
NSString *textEncoding = [decoder decodeObjectOfClass:[NSString class] forKey:SPUTemporaryDownloadTextEncodingKey];
|
||||
NSString *MIMEType = [decoder decodeObjectOfClass:[NSString class] forKey:SPUTemporaryDownloadMIMETypeKey];
|
||||
|
||||
return [self initWithData:data textEncoding:textEncoding MIMEType:MIMEType];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -7,13 +7,17 @@
|
||||
//
|
||||
|
||||
#import "SUTemporaryDownloader.h"
|
||||
#import "SPUTemporaryDownload.h"
|
||||
#import "SPUURLRequest.h"
|
||||
#import "SUErrors.h"
|
||||
#import "SUConstants.h"
|
||||
|
||||
@interface SUTemporaryDownloader () <NSURLDownloadDelegate>
|
||||
|
||||
@property (nonatomic, copy) void (^completionBlock)(NSData * _Nullable data, NSError * _Nullable error);
|
||||
@property (nonatomic, copy) void (^completionBlock)(SPUTemporaryDownload * _Nullable download, NSError * _Nullable error);
|
||||
@property (nonatomic) NSURLDownload *download;
|
||||
@property (nonatomic, copy) NSString *downloadFilename;
|
||||
@property (nonatomic) NSURLResponse *response;
|
||||
|
||||
@end
|
||||
|
||||
@@ -22,8 +26,9 @@
|
||||
@synthesize completionBlock = _completionBlock;
|
||||
@synthesize download = _download;
|
||||
@synthesize downloadFilename = _downloadFilename;
|
||||
@synthesize response = _response;
|
||||
|
||||
- (void)startDownloadWithRequest:(SPUURLRequest *)request completion:(void (^)(NSData * _Nullable data, NSError * _Nullable error))completionBlock
|
||||
- (void)startDownloadWithRequest:(SPUURLRequest *)request completion:(void (^)(SPUTemporaryDownload * _Nullable download, NSError * _Nullable error))completionBlock
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
self.completionBlock = completionBlock;
|
||||
@@ -60,9 +65,24 @@
|
||||
self.downloadFilename = path;
|
||||
}
|
||||
|
||||
- (void)download:(NSURLDownload *)__unused download didReceiveResponse:(NSURLResponse *)response
|
||||
{
|
||||
self.response = response;
|
||||
}
|
||||
|
||||
- (void)downloadDidFinish:(NSURLDownload *)__unused aDownload
|
||||
{
|
||||
self.completionBlock([NSData dataWithContentsOfFile:self.downloadFilename], nil);
|
||||
assert(self.response != nil);
|
||||
assert(self.downloadFilename != nil);
|
||||
|
||||
NSData *data = [NSData dataWithContentsOfFile:self.downloadFilename];
|
||||
if (data != nil) {
|
||||
// See SUPersistentDownloader as to why sending the NSURLResponse object over is not a good idea
|
||||
SPUTemporaryDownload *download = [[SPUTemporaryDownload alloc] initWithData:data textEncoding:self.response.textEncodingName MIMEType:self.response.MIMEType];
|
||||
self.completionBlock(download, nil);
|
||||
} else {
|
||||
self.completionBlock(nil, [NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:@"Failed to read temporary downloaded data from %@", self.downloadFilename] }]);
|
||||
}
|
||||
self.completionBlock = nil;
|
||||
[self cleanup];
|
||||
}
|
||||
|
||||
@@ -11,11 +11,12 @@
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class SPUURLRequest;
|
||||
@class SPUTemporaryDownload;
|
||||
|
||||
// The protocol that this service will vend as its API. This header file will also need to be visible to the process hosting the service.
|
||||
@protocol SUTemporaryDownloaderProtocol
|
||||
|
||||
- (void)startDownloadWithRequest:(SPUURLRequest *)request completion:(void (^)(NSData * _Nullable data, NSError * _Nullable error))completionBlock;
|
||||
- (void)startDownloadWithRequest:(SPUURLRequest *)request completion:(void (^)(SPUTemporaryDownload * _Nullable download, NSError * _Nullable error))completionBlock;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -211,7 +211,7 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (void)showUpdateReleaseNotes:(NSData *)__unused releaseNotes
|
||||
- (void)showUpdateReleaseNotesWithData:(NSData *)__unused releaseNotesData textEncodingName:(NSString * _Nullable)__unused textEncodingName MIMEType:(NSString * _Nullable)__unused MIMEType
|
||||
{
|
||||
// todo: this should really be implemented
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
|
||||
- (void)showResumableUpdateFoundWithAppcastItem:(SUAppcastItem *)__unused appcastItem reply:(void (^)(SUInstallUpdateStatus))__unused reply {}
|
||||
|
||||
- (void)showUpdateReleaseNotes:(NSData *)__unused releaseNotes {}
|
||||
- (void)showUpdateReleaseNotesWithData:(NSData *)__unused releaseNotesData textEncodingName:(NSString * _Nullable)__unused textEncodingName MIMEType:(NSString * _Nullable)__unused MIMEType {}
|
||||
|
||||
- (void)showUpdateReleaseNotesFailedToDownloadWithError:(NSError *)__unused error {}
|
||||
|
||||
|
||||
@@ -120,13 +120,20 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (void)displayReleaseNotes:(NSData *)releaseNotes
|
||||
- (void)displayHTMLReleaseNotes:(NSData *)releaseNotes
|
||||
{
|
||||
NSAttributedString *attributedString = [[NSAttributedString alloc] initWithHTML:releaseNotes documentAttributes:NULL];
|
||||
fprintf(stderr, "Release notes:\n");
|
||||
fprintf(stderr, "%s\n", attributedString.string.UTF8String);
|
||||
}
|
||||
|
||||
- (void)displayPlainTextReleaseNotes:(NSData *)releaseNotes encoding:(NSStringEncoding)encoding
|
||||
{
|
||||
NSString *string = [[NSString alloc] initWithData:releaseNotes encoding:encoding];
|
||||
fprintf(stderr, "Release notes:\n");
|
||||
fprintf(stderr, "%s\n", string.UTF8String);
|
||||
}
|
||||
|
||||
- (void)showUpdateWithAppcastItem:(SUAppcastItem *)appcastItem updateAdjective:(NSString *)updateAdjective
|
||||
{
|
||||
if (self.verbose) {
|
||||
@@ -135,7 +142,7 @@
|
||||
if (appcastItem.itemDescription != nil) {
|
||||
NSData *descriptionData = [appcastItem.itemDescription dataUsingEncoding:NSUTF8StringEncoding];
|
||||
if (descriptionData != nil) {
|
||||
[self displayReleaseNotes:descriptionData];
|
||||
[self displayHTMLReleaseNotes:descriptionData];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -174,11 +181,21 @@
|
||||
});
|
||||
}
|
||||
|
||||
- (void)showUpdateReleaseNotes:(NSData *)releaseNotes
|
||||
- (void)showUpdateReleaseNotesWithData:(NSData *)releaseNotesData textEncodingName:(NSString * _Nullable)textEncodingName MIMEType:(NSString * _Nullable)MIMEType
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self.verbose) {
|
||||
[self displayReleaseNotes:releaseNotes];
|
||||
if ([MIMEType isEqualToString:@"text/plain"]) {
|
||||
NSStringEncoding encoding;
|
||||
if (textEncodingName == nil) {
|
||||
encoding = NSUTF8StringEncoding;
|
||||
} else {
|
||||
encoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)textEncodingName));
|
||||
}
|
||||
[self displayPlainTextReleaseNotes:releaseNotesData encoding:encoding];
|
||||
} else {
|
||||
[self displayHTMLReleaseNotes:releaseNotesData];
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user