mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-29 05:24:26 +00:00
Use download driver for downloading release notes
This commit is contained in:
1 parent
7cb72238fa
commit
6adb0c3017
3 files changed
+94
-19
No files matched your search
Vendored
+2
-2
@@ -36,9 +36,9 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface SPUDownloadDriver : NSObject
|
||||
|
||||
- (instancetype)initWithRequestURL:(NSURL *)requestURL host:(SUHost *)host userAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders inBackground:(BOOL)background delegate:(id<SPUDownloadDriverDelegate>)delegate;
|
||||
- (instancetype)initWithRequestURL:(NSURL *)requestURL host:(SUHost *)host userAgent:(NSString * _Nullable)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders inBackground:(BOOL)background delegate:(id<SPUDownloadDriverDelegate>)delegate;
|
||||
|
||||
- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem secondaryUpdateItem:(SUAppcastItem * _Nullable)secondaryUpdateItem host:(SUHost *)host userAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders inBackground:(BOOL)background delegate:(id<SPUDownloadDriverDelegate>)delegate;
|
||||
- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem secondaryUpdateItem:(SUAppcastItem * _Nullable)secondaryUpdateItem host:(SUHost *)host userAgent:(NSString * _Nullable)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders inBackground:(BOOL)background delegate:(id<SPUDownloadDriverDelegate>)delegate;
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host;
|
||||
|
||||
|
||||
Vendored
+13
-7
@@ -108,28 +108,34 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithRequestURL:(NSURL *)requestURL host:(SUHost *)host userAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders inBackground:(BOOL)background delegate:(id<SPUDownloadDriverDelegate>)delegate
|
||||
- (instancetype)initWithRequestURL:(NSURL *)requestURL host:(SUHost *)host userAgent:(NSString * _Nullable)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders inBackground:(BOOL)background delegate:(id<SPUDownloadDriverDelegate>)delegate
|
||||
{
|
||||
self = [self initWithHost:host];
|
||||
if (self != nil) {
|
||||
_delegate = delegate;
|
||||
|
||||
_inBackground = background;
|
||||
_request = [NSMutableURLRequest requestWithURL:requestURL];
|
||||
[_request setValue:userAgent forHTTPHeaderField:@"User-Agent"];
|
||||
_request.networkServiceType = background ? NSURLNetworkServiceTypeBackground : NSURLNetworkServiceTypeDefault;
|
||||
|
||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:requestURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
|
||||
|
||||
if (userAgent != nil) {
|
||||
[request setValue:(NSString * _Nonnull)userAgent forHTTPHeaderField:@"User-Agent"];
|
||||
}
|
||||
|
||||
request.networkServiceType = background ? NSURLNetworkServiceTypeBackground : NSURLNetworkServiceTypeDefault;
|
||||
|
||||
if (httpHeaders != nil) {
|
||||
for (NSString *key in httpHeaders) {
|
||||
NSString *value = [httpHeaders objectForKey:key];
|
||||
[_request setValue:value forHTTPHeaderField:key];
|
||||
[request setValue:value forHTTPHeaderField:key];
|
||||
}
|
||||
}
|
||||
|
||||
_request = request;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem secondaryUpdateItem:(SUAppcastItem * _Nullable)secondaryUpdateItem host:(SUHost *)host userAgent:(NSString *)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders inBackground:(BOOL)background delegate:(id<SPUDownloadDriverDelegate>)delegate
|
||||
- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem secondaryUpdateItem:(SUAppcastItem * _Nullable)secondaryUpdateItem host:(SUHost *)host userAgent:(NSString * _Nullable)userAgent httpHeaders:(NSDictionary * _Nullable)httpHeaders inBackground:(BOOL)background delegate:(id<SPUDownloadDriverDelegate>)delegate
|
||||
{
|
||||
self = [self initWithRequestURL:updateItem.fileURL host:host userAgent:userAgent httpHeaders:httpHeaders inBackground:background delegate:delegate];
|
||||
if (self != nil) {
|
||||
|
||||
Vendored
+79
-10
@@ -16,10 +16,63 @@
|
||||
#import "SUErrors.h"
|
||||
#import "SPUDownloadData.h"
|
||||
#import "SPUResumableUpdate.h"
|
||||
#import "SPUDownloadDriver.h"
|
||||
|
||||
|
||||
#include "AppKitPrevention.h"
|
||||
|
||||
// Private class for downloading release notes
|
||||
@interface SPUReleaseNotesDriver: NSObject <SPUDownloadDriverDelegate>
|
||||
|
||||
@property (nonatomic, readonly) SPUDownloadDriver *downloadDriver;
|
||||
@property (nonatomic) void (^completionHandler)(SPUDownloadData * _Nullable, NSError * _Nullable );
|
||||
|
||||
@end
|
||||
|
||||
@implementation SPUReleaseNotesDriver
|
||||
|
||||
@synthesize downloadDriver = _downloadDriver;
|
||||
@synthesize completionHandler = _completionHandler;
|
||||
|
||||
- (instancetype)initWithReleaseNotesURL:(NSURL *)releaseNotesURL host:(SUHost *)host completionHandler:(void (^)(SPUDownloadData * _Nullable, NSError * _Nullable))completionHandler
|
||||
{
|
||||
self = [super init];
|
||||
if (self != nil) {
|
||||
_downloadDriver = [[SPUDownloadDriver alloc] initWithRequestURL:releaseNotesURL host:host userAgent:nil httpHeaders:nil inBackground:NO delegate:self];
|
||||
_completionHandler = [completionHandler copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)startDownload
|
||||
{
|
||||
[self.downloadDriver downloadFile];
|
||||
}
|
||||
|
||||
- (void)downloadDriverDidDownloadData:(SPUDownloadData *)downloadData
|
||||
{
|
||||
if (self.completionHandler != nil) {
|
||||
self.completionHandler(downloadData, nil);
|
||||
self.completionHandler = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)downloadDriverDidFailToDownloadFileWithError:(nonnull NSError *)error
|
||||
{
|
||||
if (self.completionHandler != nil) {
|
||||
self.completionHandler(nil, error);
|
||||
self.completionHandler = nil;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)cleanup:(void (^)(void))cleanupHandler
|
||||
{
|
||||
self.completionHandler = nil;
|
||||
[self.downloadDriver cleanup:cleanupHandler];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@interface SPUUIBasedUpdateDriver() <SPUCoreBasedUpdateDriverDelegate>
|
||||
|
||||
@property (nonatomic, readonly) SPUCoreBasedUpdateDriver *coreDriver;
|
||||
@@ -29,6 +82,7 @@
|
||||
@property (weak, nonatomic, readonly) id<SPUUpdaterDelegate> updaterDelegate;
|
||||
@property (nonatomic, weak, readonly) id<SPUUIBasedUpdateDriverDelegate> delegate;
|
||||
@property (nonatomic, readonly) id<SPUUserDriver> userDriver;
|
||||
@property (nonatomic) SPUReleaseNotesDriver *releaseNotesDriver;
|
||||
@property (nonatomic) BOOL resumingInstallingUpdate;
|
||||
@property (nonatomic) BOOL resumingDownloadedUpdate;
|
||||
@property (nonatomic) BOOL preventsInstallerInteraction;
|
||||
@@ -43,6 +97,7 @@
|
||||
@synthesize userInitiated = _userInitiated;
|
||||
@synthesize updaterDelegate = _updaterDelegate;
|
||||
@synthesize userDriver = _userDriver;
|
||||
@synthesize releaseNotesDriver = _releaseNotesDriver;
|
||||
@synthesize delegate = _delegate;
|
||||
@synthesize resumingInstallingUpdate = _resumingInstallingUpdate;
|
||||
@synthesize resumingDownloadedUpdate = _resumingDownloadedUpdate;
|
||||
@@ -265,16 +320,19 @@
|
||||
}
|
||||
|
||||
if (updateItem.releaseNotesURL != nil && (![updaterDelegate respondsToSelector:@selector(updaterShouldDownloadReleaseNotes:)] || [updaterDelegate updaterShouldDownloadReleaseNotes:self.updater])) {
|
||||
NSURLRequest *request = [NSURLRequest requestWithURL:updateItem.releaseNotesURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30];
|
||||
|
||||
// id <SPUUserDriver> userDriver = self.userDriver;
|
||||
// SPUDownloadURLWithRequest(request, ^(SPUDownloadData * _Nullable downloadData, NSError * _Nullable error) {
|
||||
// if (downloadData != nil) {
|
||||
// [userDriver showUpdateReleaseNotesWithDownloadData:(SPUDownloadData * _Nonnull)downloadData];
|
||||
// } else {
|
||||
// [userDriver showUpdateReleaseNotesFailedToDownloadWithError:(NSError * _Nonnull)error];
|
||||
// }
|
||||
// });
|
||||
__weak __typeof__(self) weakSelf = self;
|
||||
self.releaseNotesDriver = [[SPUReleaseNotesDriver alloc] initWithReleaseNotesURL:updateItem.releaseNotesURL host:self.host completionHandler:^(SPUDownloadData * _Nullable downloadData, NSError * _Nullable error) {
|
||||
__typeof__(self) strongSelf = weakSelf;
|
||||
id <SPUUserDriver> userDriver = strongSelf.userDriver;
|
||||
if (downloadData != nil) {
|
||||
[userDriver showUpdateReleaseNotesWithDownloadData:(SPUDownloadData * _Nonnull)downloadData];
|
||||
} else {
|
||||
[userDriver showUpdateReleaseNotesFailedToDownloadWithError:(NSError * _Nonnull)error];
|
||||
}
|
||||
}];
|
||||
|
||||
[self.releaseNotesDriver startDownload];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -373,7 +431,7 @@
|
||||
[self.delegate coreDriverIsRequestingAbortUpdateWithError:error];
|
||||
}
|
||||
|
||||
- (void)abortUpdateWithError:(nullable NSError *)error
|
||||
- (void)_abortUpdateWithError:(nullable NSError *)error
|
||||
{
|
||||
void (^abortUpdate)(void) = ^{
|
||||
[self.userDriver dismissUpdateInstallation];
|
||||
@@ -415,4 +473,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)abortUpdateWithError:(nullable NSError *)error
|
||||
{
|
||||
if (self.releaseNotesDriver != nil) {
|
||||
[self.releaseNotesDriver cleanup:^{
|
||||
[self _abortUpdateWithError:error];
|
||||
}];
|
||||
} else {
|
||||
[self _abortUpdateWithError:error];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user