mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
Use completion block for unarchiving
This commit is contained in:
1 parent
5ee02e954e
commit
70f5681797
8 files changed
+38
-40
No files matched your search
Vendored
-2
@@ -37,8 +37,6 @@
|
||||
- (void)download:(NSURLDownload *)download didFailWithError:(NSError *)error;
|
||||
|
||||
- (void)extractUpdate;
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)ua;
|
||||
- (void)unarchiverDidFail:(SUUnarchiver *)ua;
|
||||
- (void)failedToApplyDeltaUpdate;
|
||||
|
||||
- (void)installWithToolAndRelaunch:(BOOL)relaunch;
|
||||
|
||||
Vendored
+9
-8
@@ -336,7 +336,15 @@
|
||||
[self unarchiverDidFail:nil];
|
||||
} else {
|
||||
unarchiver.delegate = self;
|
||||
[unarchiver start];
|
||||
[unarchiver unarchiveWithCompletionBlock:^(NSError *err){
|
||||
if (err) {
|
||||
[self unarchiverDidFail:err];
|
||||
return;
|
||||
}
|
||||
|
||||
assert(self.updateItem);
|
||||
[self installWithToolAndRelaunch:YES];
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -349,13 +357,6 @@
|
||||
[self downloadUpdate];
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)__unused ua
|
||||
{
|
||||
assert(self.updateItem);
|
||||
|
||||
[self installWithToolAndRelaunch:YES];
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFail:(NSError *)err
|
||||
{
|
||||
// No longer needed
|
||||
|
||||
Vendored
+2
-1
@@ -79,8 +79,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)start
|
||||
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))block
|
||||
{
|
||||
[super unarchiveWithCompletionBlock:block];
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
[self applyBinaryDelta];
|
||||
});
|
||||
|
||||
Vendored
+2
-1
@@ -159,8 +159,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
- (void)start
|
||||
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))block
|
||||
{
|
||||
[super unarchiveWithCompletionBlock:block];
|
||||
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
[self extractDMG];
|
||||
});
|
||||
|
||||
Vendored
+2
-1
@@ -46,8 +46,9 @@
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void)start
|
||||
- (void)unarchiveWithCompletionBlock:(void (^)(NSError * _Nullable))block
|
||||
{
|
||||
[super unarchiveWithCompletionBlock:block];
|
||||
[NSThread detachNewThreadSelector:[[self class] selectorConformingToTypeOfPath:self.archivePath] toTarget:self withObject:nil];
|
||||
}
|
||||
|
||||
|
||||
Vendored
+1
-3
@@ -27,13 +27,11 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
+ (BOOL)unsafeIfArchiveIsNotValidated;
|
||||
|
||||
- (void)start;
|
||||
- (void)unarchiveWithCompletionBlock:(void (^_Nonnull)(NSError *_Nullable))block;
|
||||
|
||||
@end
|
||||
|
||||
@protocol SUUnarchiverDelegate <NSObject>
|
||||
- (void)unarchiverDidFinish:(SUUnarchiver *)unarchiver;
|
||||
- (void)unarchiverDidFail:(SUUnarchiver *)unarchiver;
|
||||
@optional
|
||||
- (void)unarchiver:(SUUnarchiver *)unarchiver extractedProgress:(double)progress;
|
||||
@end
|
||||
|
||||
Vendored
+16
-9
@@ -15,12 +15,17 @@
|
||||
#import "SUUnarchiver.h"
|
||||
#import "SUUnarchiver_Private.h"
|
||||
|
||||
@interface SUUnarchiver ()
|
||||
@property (strong) void (^completionBlock)(NSError * _Nullable);
|
||||
@end
|
||||
|
||||
@implementation SUUnarchiver
|
||||
|
||||
@synthesize archivePath;
|
||||
@synthesize updateHostBundlePath;
|
||||
@synthesize delegate;
|
||||
@synthesize decryptionPassword;
|
||||
@synthesize completionBlock;
|
||||
|
||||
+ (SUUnarchiver *)unarchiverForPath:(NSString *)path updatingHostBundlePath:(NSString *)hostPath withPassword:(NSString *)decryptionPassword
|
||||
{
|
||||
@@ -34,9 +39,8 @@
|
||||
|
||||
- (NSString *)description { return [NSString stringWithFormat:@"%@ <%@>", [self class], self.archivePath]; }
|
||||
|
||||
- (void)start
|
||||
{
|
||||
// No-op
|
||||
- (void)unarchiveWithCompletionBlock:(void (^_Nonnull)(NSError * _Nullable))block {
|
||||
self.completionBlock = block;
|
||||
}
|
||||
|
||||
- (instancetype)initWithPath:(NSString *)path hostBundlePath:(NSString *)hostPath password:(NSString *)password
|
||||
@@ -70,18 +74,21 @@
|
||||
- (void)unarchiverDidFinish
|
||||
{
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if ([self.delegate respondsToSelector:@selector(unarchiverDidFinish:)]) {
|
||||
[self.delegate unarchiverDidFinish:self];
|
||||
}
|
||||
self.completionBlock(nil);
|
||||
});
|
||||
}
|
||||
|
||||
- (void)unarchiverDidFail:(NSError *)reason
|
||||
{
|
||||
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil) forKey:NSLocalizedDescriptionKey];
|
||||
if (reason) {
|
||||
[userInfo setObject:reason forKey:NSUnderlyingErrorKey];
|
||||
}
|
||||
|
||||
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:userInfo];
|
||||
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if ([self.delegate respondsToSelector:@selector(unarchiverDidFail:)]) {
|
||||
[self.delegate unarchiverDidFail:self];
|
||||
}
|
||||
self.completionBlock(error);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -18,18 +18,6 @@ class SUUnarchiverTest: XCTestCase, SUUnarchiverDelegate
|
||||
{
|
||||
}
|
||||
|
||||
func unarchiverDidFail(_ unarchiver: SUUnarchiver)
|
||||
{
|
||||
self.unarchivedResult = false
|
||||
self.unarchivedExpectation!.fulfill()
|
||||
}
|
||||
|
||||
func unarchiverDidFinish(_ unarchiver: SUUnarchiver)
|
||||
{
|
||||
self.unarchivedResult = true
|
||||
self.unarchivedExpectation!.fulfill()
|
||||
}
|
||||
|
||||
func unarchiveTestAppWithExtension(_ archiveExtension: String)
|
||||
{
|
||||
let appName = "SparkleTestCodeSignApp"
|
||||
@@ -49,10 +37,13 @@ class SUUnarchiverTest: XCTestCase, SUUnarchiverDelegate
|
||||
|
||||
self.unarchivedExpectation = super.expectation(description: "Unarchived Application (format: \(archiveExtension))")
|
||||
|
||||
let unarchiver = SUUnarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, withPassword: self.password)
|
||||
let unarchiver = SUUnarchiver(forPath: tempArchiveURL.path, updatingHostBundlePath: nil, withPassword: self.password)!
|
||||
|
||||
unarchiver?.delegate = self
|
||||
unarchiver?.start()
|
||||
unarchiver.delegate = self
|
||||
unarchiver.unarchive {(error: Error?) -> Void in
|
||||
self.unarchivedResult = nil == error;
|
||||
self.unarchivedExpectation!.fulfill()
|
||||
}
|
||||
|
||||
super.waitForExpectations(timeout: 7.0, handler: nil)
|
||||
|
||||
|
||||
Reference in new issue
Block a user