mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-28 05:14:34 +00:00
Replaced progress delegate with a block
This commit is contained in:
1 parent
70f5681797
commit
8103f5fd43
11 files changed
+25
-34
No files matched your search
Vendored
+1
-1
@@ -13,7 +13,7 @@
|
||||
#import "SUBasicUpdateDriver.h"
|
||||
#import "SUAutomaticUpdateAlert.h"
|
||||
|
||||
@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver <SUUnarchiverDelegate>
|
||||
@interface SUAutomaticUpdateDriver : SUBasicUpdateDriver
|
||||
|
||||
@end
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -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;
|
||||
|
||||
Vendored
+2
-1
@@ -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){
|
||||
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -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];
|
||||
});
|
||||
|
||||
Vendored
+2
-2
@@ -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];
|
||||
});
|
||||
|
||||
Vendored
+3
-3
@@ -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);
|
||||
|
||||
Vendored
+1
-1
@@ -15,7 +15,7 @@
|
||||
|
||||
@class SUStatusController;
|
||||
|
||||
@interface SUUIBasedUpdateDriver : SUBasicUpdateDriver <SUUnarchiverDelegate>
|
||||
@interface SUUIBasedUpdateDriver : SUBasicUpdateDriver
|
||||
|
||||
- (void)showAlert:(NSAlert *)alert;
|
||||
- (IBAction)cancelDownload:(id)sender;
|
||||
|
||||
Vendored
+1
-8
@@ -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
|
||||
Vendored
+8
-6
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-1
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in new issue
Block a user