mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-24 04:38:16 +00:00
71 lines
1.8 KiB
Objective-C
71 lines
1.8 KiB
Objective-C
//
|
|
// SUUnarchiverNotifier.m
|
|
// Sparkle
|
|
//
|
|
// Created by Mayur Pawashe on 12/21/16.
|
|
// Copyright © 2016 Sparkle Project. All rights reserved.
|
|
//
|
|
|
|
#import "SUUnarchiverNotifier.h"
|
|
#import "SULocalizations.h"
|
|
#import "SUErrors.h"
|
|
|
|
|
|
#include "AppKitPrevention.h"
|
|
|
|
@interface SUUnarchiverNotifier ()
|
|
|
|
@property (nonatomic, readonly, copy) void (^completionBlock)(NSError * _Nullable);
|
|
@property (nonatomic, readonly, copy) void (^ _Nullable progressBlock)(double);
|
|
|
|
@end
|
|
|
|
@implementation SUUnarchiverNotifier
|
|
|
|
@synthesize completionBlock = _completionBlock;
|
|
@synthesize progressBlock = _progressBlock;
|
|
|
|
- (instancetype)initWithCompletionBlock:(void (^)(NSError * _Nullable))completionBlock progressBlock:(void (^ _Nullable)(double))progressBlock
|
|
{
|
|
self = [super init];
|
|
if (self != nil) {
|
|
_completionBlock = [completionBlock copy];
|
|
_progressBlock = [progressBlock copy];
|
|
} else {
|
|
assert(false);
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)notifySuccess
|
|
{
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
self.completionBlock(nil);
|
|
});
|
|
}
|
|
|
|
- (void)notifyFailureWithError:(NSError * _Nullable)reason
|
|
{
|
|
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithObject:SULocalizedString(@"An error occurred while extracting the archive. Please try again later.", nil) forKey:NSLocalizedDescriptionKey];
|
|
if (reason) {
|
|
[userInfo setObject:(NSError * _Nonnull)reason forKey:NSUnderlyingErrorKey];
|
|
}
|
|
|
|
NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUUnarchivingError userInfo:userInfo];
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
self.completionBlock(error);
|
|
});
|
|
}
|
|
|
|
- (void)notifyProgress:(double)progress
|
|
{
|
|
if (self.progressBlock != nil) {
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
self.progressBlock(progress);
|
|
});
|
|
}
|
|
}
|
|
|
|
@end
|