diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index e60816f4..efa1ed51 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -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 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 )updaterDelegate delegate:(id )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; diff --git a/Sparkle/SUDownloadDriver.m b/Sparkle/SUDownloadDriver.m index 2fd87827..06971194 100644 --- a/Sparkle/SUDownloadDriver.m +++ b/Sparkle/SUDownloadDriver.m @@ -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)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) { diff --git a/Sparkle/SUInstallerDriver.m b/Sparkle/SUInstallerDriver.m index 40d93b92..f28985e0 100644 --- a/Sparkle/SUInstallerDriver.m +++ b/Sparkle/SUInstallerDriver.m @@ -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)updaterDelegate delegate:(nullable id)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; diff --git a/Sparkle/SUUserInitiatedUpdateDriver.m b/Sparkle/SUUserInitiatedUpdateDriver.m index d42dd219..209624a2 100644 --- a/Sparkle/SUUserInitiatedUpdateDriver.m +++ b/Sparkle/SUUserInitiatedUpdateDriver.m @@ -19,7 +19,6 @@ @property (nonatomic, readonly) SUUIBasedUpdateDriver *uiDriver; @property (nonatomic, readonly) id 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 )userDriver updaterDelegate:(nullable id )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]; }