Replaced progress delegate with a block

This commit is contained in:
Kornel Lesiński committed 2016-12-21 15:23:40 +01:00
1 parent 70f5681797
commit 8103f5fd43
11 files changed
+25 -34

No files matched your search

+1 -1
View File
@@ -13,7 +13,7 @@
#import "SUBasicUpdateDriver.h"
#import "SUAutomaticUpdateAlert.h"
@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver <SUUnarchiverDelegate>
@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver
@end
+1 -1
View File
@@ -15,7 +15,7 @@
#import "SUAppcast.h"
@class SUAppcastItem, SUHost;
@interface SUBasicUpdateDriver : SUUpdateDriver <NSURLDownloadDelegate, SUUnarchiverDelegate>
@interface SUBasicUpdateDriver : SUUpdateDriver <NSURLDownloadDelegate>
@property (strong, readonly) SUAppcastItem *updateItem;
@property (strong, readonly) NSURLDownload *download;
+2 -1
View File
@@ -335,7 +335,6 @@
if (!success) {
[self unarchiverDidFail:nil];
} else {
unarchiver.delegate = self;
[unarchiver unarchiveWithCompletionBlock:^(NSError *err){
if (err) {
[self unarchiverDidFail:err];
@@ -344,6 +343,8 @@
assert(self.updateItem);
[self installWithToolAndRelaunch:YES];
} progressBlock:^(__unused double progress){
}];
}
}
+2 -2
View File
@@ -79,9 +79,9 @@
}
}
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))block
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))block progressBlock:(void (^ _Nullable)(double progress))progress
{
[super unarchiveWithCompletionBlock:block];
[super unarchiveWithCompletionBlock:block progressBlock:progress];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self applyBinaryDelta];
});
+2 -2
View File
@@ -159,9 +159,9 @@
}
}
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))block
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))block progressBlock:(void (^ _Nullable)(double progress))progress
{
[super unarchiveWithCompletionBlock:block];
[super unarchiveWithCompletionBlock:block progressBlock:progress];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self extractDMG];
});
+3 -3
View File
@@ -46,9 +46,9 @@
return NO;
}
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))block
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))block progressBlock:(void (^ _Nullable)(double progress))progress
{
[super unarchiveWithCompletionBlock:block];
[super unarchiveWithCompletionBlock:block progressBlock:progress];
[NSThread detachNewThreadSelector:[[self class] selectorConformingToTypeOfPath:self.archivePath] toTarget:self withObject:nil];
}
@@ -94,7 +94,7 @@
bytesRead += len;
[archiveOutput writeData:data];
dispatch_async(dispatch_get_main_queue(), ^{
[self notifyDelegateOfProgress:(double)bytesRead / (double)expectedLength];
[self notifyProgress:(double)bytesRead / (double)expectedLength];
});
}
while(bytesRead < expectedLength);
+1 -1
View File
@@ -15,7 +15,7 @@
@class SUStatusController;
@interface SUUIBasedUpdateDriver : SUBasicUpdateDriver <SUUnarchiverDelegate>
@interface SUUIBasedUpdateDriver : SUBasicUpdateDriver
- (void)showAlert:(NSAlert *)alert;
- (IBAction)cancelDownload:(id)sender;
+1 -8
View File
@@ -14,27 +14,20 @@
NS_ASSUME_NONNULL_BEGIN
@class SUHost;
@protocol SUUnarchiverDelegate;
@interface SUUnarchiver : NSObject
@property (copy, readonly) NSString *archivePath;
@property (copy, readonly) NSString *_Nullable updateHostBundlePath;
@property (copy, readonly) NSString *_Nullable decryptionPassword;
@property (weak) _Nullable id<SUUnarchiverDelegate> delegate;
+ (nullable SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHostBundlePath:(nullable NSString *)host withPassword:(nullable NSString *)decryptionPassword;
+ (BOOL)unsafeIfArchiveIsNotValidated;
- (void)unarchiveWithCompletionBlock:(void (^_Nonnull)(NSError *_Nullable))block;
- (void)unarchiveWithCompletionBlock:(void (^)(NSError *_Nullable))completion progressBlock:(void (^_Nullable)(double progress))progress;
@end
@protocol SUUnarchiverDelegate <NSObject>
@optional
- (void)unarchiver:(SUUnarchiver *)unarchiver extractedProgress:(double)progress;
@end
NS_ASSUME_NONNULL_END
#endif
+8 -6
View File
@@ -17,15 +17,16 @@
@interface SUUnarchiver ()
@property (strong) void (^completionBlock)(NSError * _Nullable);
@property (strong) void (^progressBlock)(double progress);
@end
@implementation SUUnarchiver
@synthesize archivePath;
@synthesize updateHostBundlePath;
@synthesize delegate;
@synthesize decryptionPassword;
@synthesize completionBlock;
@synthesize completionBlock, progressBlock;
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHostBundlePath:(NSString *)hostPath withPassword:(NSString *)decryptionPassword
{
@@ -39,8 +40,9 @@
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], self.archivePath]; }
- (void)unarchiveWithCompletionBlock:(void (^_Nonnull)(NSError * _Nullable))block {
- (void)unarchiveWithCompletionBlock:(void (^_Nonnull)(NSError * _Nullable))block progressBlock:(void (^_Nullable)(double progress))progress {
self.completionBlock = block;
self.progressBlock = progress;
}
- (instancetype)initWithPath:(NSString *)path hostBundlePath:(NSString *)hostPath password:(NSString *)password
@@ -64,10 +66,10 @@
return NO;
}
- (void)notifyDelegateOfProgress:(double)progress
- (void)notifyProgress:(double)progress
{
if ([self.delegate respondsToSelector:@selector(unarchiver:extractedProgress:)]) {
[self.delegate unarchiver:self extractedProgress:progress];
if (self.progressBlock) {
self.progressBlock(progress);
}
}
+1 -1
View File
@@ -18,7 +18,7 @@
+ (BOOL)canUnarchivePath:(NSString *)path;
- (instancetype)initWithPath:(NSString *)archive hostBundlePath:(NSString *)host;
- (void)notifyDelegateOfProgress:(double)progress;
- (void)notifyProgress:(double)progress;
- (void)unarchiverDidFinish;
- (void)unarchiverDidFailWithError:(NSError *)err;
@end
+3 -8
View File
@@ -8,16 +8,12 @@
import XCTest
class SUUnarchiverTest: XCTestCase, SUUnarchiverDelegate
class SUUnarchiverTest: XCTestCase
{
var password: String? = nil
var unarchivedExpectation: XCTestExpectation? = nil
var unarchivedResult: Bool = false
func unarchiver(_ unarchiver: SUUnarchiver, extractedProgress progress: Double)
{
}
func unarchiveTestAppWithExtension(_ archiveExtension: String)
{
let appName = "SparkleTestCodeSignApp"
@@ -39,11 +35,10 @@ class SUUnarchiverTest: XCTestCase, SUUnarchiverDelegate
let unarchiver = SUUnarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, withPassword: self.password)!
unarchiver.delegate = self
unarchiver.unarchive {(error: Error?) -> Void in
unarchiver.unarchive(completionBlock: {(error: Error?) -> Void in
self.unarchivedResult = nil == error;
self.unarchivedExpectation!.fulfill()
}
}, progressBlock:{(progress: Double) -> Void in });
super.waitForExpectations(timeout: 7.0, handler: nil)