Put preventive measures for aborting update more than once.

This resolves issues with canceling not taking complete effect.
This commit is contained in:
Zorg committed 2016-07-24 20:13:06 -04:00
1 parent 8d93513813
commit da8065f67e
4 files changed
+56 -40

No files matched your search

+39 -26
View File
@@ -28,6 +28,8 @@
@property (nonatomic, readonly, weak) id updater; // if we didn't have legacy support, I'd remove this..
@property (nullable, nonatomic, readonly, weak) id <SUUpdaterDelegate>updaterDelegate;
@property (nonatomic) BOOL aborted;
@end
@implementation SUBasicUpdateDriver
@@ -38,6 +40,7 @@
@synthesize delegate = _delegate;
@synthesize appcastDriver = _appcastDriver;
@synthesize completionBlock = _completionBlock;
@synthesize aborted = _aborted;
- (instancetype)initWithHost:(SUHost *)host updater:(id)updater updaterDelegate:(id <SUUpdaterDelegate>)updaterDelegate delegate:(id <SUBasicUpdateDriverDelegate>)delegate
{
@@ -103,7 +106,9 @@
- (void)didFailToFetchAppcastWithError:(NSError *)error
{
[self.delegate basicDriverIsRequestingAbortUpdateWithError:error];
if (!self.aborted) {
[self.delegate basicDriverIsRequestingAbortUpdateWithError:error];
}
}
- (void)notifyFinishLoadingAppcast
@@ -115,46 +120,54 @@
- (void)didFinishLoadingAppcast:(SUAppcast *)appcast
{
if ([self.updaterDelegate respondsToSelector:@selector(updater:didFinishLoadingAppcast:)]) {
[self.updaterDelegate updater:self.updater didFinishLoadingAppcast:appcast];
if (!self.aborted) {
if ([self.updaterDelegate respondsToSelector:@selector(updater:didFinishLoadingAppcast:)]) {
[self.updaterDelegate updater:self.updater didFinishLoadingAppcast:appcast];
}
[self notifyFinishLoadingAppcast];
}
[self notifyFinishLoadingAppcast];
}
- (void)didFindValidUpdateWithAppcastItem:(SUAppcastItem *)updateItem
{
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification
object:self.updater
userInfo:@{ SUUpdaterAppcastItemNotificationKey: updateItem }];
if ([self.updaterDelegate respondsToSelector:@selector(updater:didFindValidUpdate:)]) {
[self.updaterDelegate updater:self.updater didFindValidUpdate:updateItem];
if (!self.aborted) {
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidFindValidUpdateNotification
object:self.updater
userInfo:@{ SUUpdaterAppcastItemNotificationKey: updateItem }];
if ([self.updaterDelegate respondsToSelector:@selector(updater:didFindValidUpdate:)]) {
[self.updaterDelegate updater:self.updater didFindValidUpdate:updateItem];
}
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
}
[self.delegate basicDriverDidFindUpdateWithAppcastItem:updateItem];
}
- (void)didNotFindUpdate
{
if ([self.updaterDelegate respondsToSelector:@selector(updaterDidNotFindUpdate:)]) {
[self.updaterDelegate updaterDidNotFindUpdate:self.updater];
if (!self.aborted) {
if ([self.updaterDelegate respondsToSelector:@selector(updaterDidNotFindUpdate:)]) {
[self.updaterDelegate updaterDidNotFindUpdate:self.updater];
}
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater];
NSError *notFoundError =
[NSError
errorWithDomain:SUSparkleErrorDomain
code:SUNoUpdateError
userInfo:@{
NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"You already have the newest version of %@.", "'Error' message when the user checks for updates but is already current or the feed doesn't contain any updates. (not necessarily shown in UI)"), self.host.name]
}
];
[self.delegate basicDriverIsRequestingAbortUpdateWithError:notFoundError];
}
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterDidNotFindUpdateNotification object:self.updater];
NSError *notFoundError =
[NSError
errorWithDomain:SUSparkleErrorDomain
code:SUNoUpdateError
userInfo:@{
NSLocalizedDescriptionKey: [NSString stringWithFormat:SULocalizedString(@"You already have the newest version of %@.", "'Error' message when the user checks for updates but is already current or the feed doesn't contain any updates. (not necessarily shown in UI)"), self.host.name]
}
];
[self.delegate basicDriverIsRequestingAbortUpdateWithError:notFoundError];
}
- (void)abortUpdateAndShowNextUpdateImmediately:(BOOL)shouldShowUpdateImmediately downloadedUpdate:(SUDownloadedUpdate * _Nullable)downloadedUpdate error:(nullable NSError *)error
{
self.aborted = YES;
if (error != nil) {
if (error.code != SUNoUpdateError && error.code != SUInstallationCancelledError && error.code != SUInstallationAuthorizeLaterError) { // Let's not bother logging this.
NSError *errorToDisplay = error;
+7 -6
View File
@@ -35,6 +35,7 @@
@property (nonatomic) BOOL retrievedDownloadResult;
@property (nonatomic) BOOL retrievedDownloadResponse;
@property (nonatomic) NSUInteger expectedContentLength;
@property (nonatomic) BOOL cleaningUp;
@end
@@ -51,6 +52,7 @@
@synthesize retrievedDownloadResult = _retrievedDownloadResult;
@synthesize retrievedDownloadResponse = _retrievedDownloadResponse;
@synthesize expectedContentLength = _expectedContentLength;
@synthesize cleaningUp = _cleaningUp;
- (instancetype)initWithUpdateItem:(SUAppcastItem *)updateItem host:(SUHost *)host userAgent:(NSString *)userAgent delegate:(id<SUDownloadDriverDelegate>)delegate
{
@@ -98,7 +100,7 @@
self.connection.invalidationHandler = ^{
dispatch_async(dispatch_get_main_queue(), ^{
SUDownloadDriver *strongSelf = weakSelf;
if (strongSelf != nil && !strongSelf.retrievedDownloadResult) {
if (strongSelf != nil && !strongSelf.retrievedDownloadResult && !strongSelf.cleaningUp) {
SULog(@"Connection to update downloader was invalidated");
NSDictionary *userInfo =
@@ -119,15 +121,14 @@
[self.downloader startDownloadWithRequest:[SUURLRequest URLRequestWithRequest:self.request] bundleIdentifier:bundleIdentifier desiredFilename:desiredFilename];
}
- (void)dealloc
{
[self cleanup];
}
- (void)cleanup
{
// It's very crucial to wait until they are done with completion before invalidating our XPC connection (if there is one)
// Otherwise we can run into some unfortunate crashes
// Edit: I think this was an issue because -dealloc was implemented to invoke this method. I have since removed -dealloc
// Will have to test around with this later
self.cleaningUp = YES;
[self.downloader cleanupWithCompletion:^{
dispatch_async(dispatch_get_main_queue(), ^{
if (self.connection != nil) {
+5 -1
View File
@@ -53,6 +53,8 @@
@property (nonatomic, copy) NSString *downloadName;
@property (nonatomic, copy) NSString *temporaryDirectory;
@property (nonatomic) BOOL aborted;
@end
@implementation SUInstallerDriver
@@ -72,6 +74,7 @@
@synthesize updateItem = _updateItem;
@synthesize downloadName = _downloadName;
@synthesize temporaryDirectory = _temporaryDirectory;
@synthesize aborted = _aborted;
- (instancetype)initWithHost:(SUHost *)host cachePath:(NSString *)cachePath sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater updaterDelegate:(id<SUUpdaterDelegate>)updaterDelegate delegate:(nullable id<SUInstallerDriverDelegate>)delegate
{
@@ -106,7 +109,7 @@
[self.installerConnection setInvalidationHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
SUInstallerDriver *strongSelf = weakSelf;
if (strongSelf.installerConnection != nil) {
if (strongSelf.installerConnection != nil && !strongSelf.aborted) {
NSError *remoteError =
[NSError
errorWithDomain:SUSparkleErrorDomain
@@ -527,6 +530,7 @@
- (void)abortInstall
{
self.aborted = YES;
if (self.installerConnection != nil) {
[self.installerConnection invalidate];
self.installerConnection = nil;
+5 -7
View File
@@ -19,7 +19,6 @@
@property (nonatomic, readonly) SUUIBasedUpdateDriver *uiDriver;
@property (nonatomic, readonly) id<SUUserDriver> userDriver;
@property (nonatomic) BOOL showingUserInitiatedProgress;
@property (nonatomic) BOOL canceledCheckForUpdates;
@end
@@ -28,7 +27,6 @@
@synthesize uiDriver = _uiDriver;
@synthesize userDriver = _userDriver;
@synthesize showingUserInitiatedProgress = _showingUserInitiatedProgress;
@synthesize canceledCheckForUpdates = _canceledCheckForUpdates;
- (instancetype)initWithHost:(SUHost *)host sparkleBundle:(NSBundle *)sparkleBundle updater:(id)updater userDriver:(id <SUUserDriver>)userDriver updaterDelegate:(nullable id <SUUpdaterDelegate>)updaterDelegate
{
@@ -50,8 +48,9 @@
break;
case SUUserInitiatedCheckCancelled:
dispatch_async(dispatch_get_main_queue(), ^{
self.canceledCheckForUpdates = YES;
[self.userDriver dismissUserInitiatedUpdateCheck];
if (self.showingUserInitiatedProgress) {
[self abortUpdate];
}
});
break;
}
@@ -82,9 +81,7 @@
- (void)basicDriverDidFinishLoadingAppcast
{
if (self.canceledCheckForUpdates) {
[self abortUpdate];
} else if (self.showingUserInitiatedProgress) {
if (self.showingUserInitiatedProgress) {
self.showingUserInitiatedProgress = NO;
[self.userDriver dismissUserInitiatedUpdateCheck];
}
@@ -99,6 +96,7 @@
{
if (self.showingUserInitiatedProgress) {
[self.userDriver dismissUserInitiatedUpdateCheck];
self.showingUserInitiatedProgress = NO;
}
[self.uiDriver abortUpdateWithError:error];
}