diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 6f3542cf..56862909 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -109,10 +109,9 @@ [connection resume]; [connection.remoteObjectProxy startDownloadWithRequest:request completion:^(NSData * _Nullable appcastData, NSError * _Nullable error) { - [connection invalidate]; - dispatch_async(dispatch_get_main_queue(), ^{ retrievedDownloadResult = YES; + [connection invalidate]; if (appcastData == nil) { [self reportError:error]; diff --git a/Sparkle/SUDownloadDriver.m b/Sparkle/SUDownloadDriver.m index 14b02b13..4a5f8e6f 100644 --- a/Sparkle/SUDownloadDriver.m +++ b/Sparkle/SUDownloadDriver.m @@ -80,7 +80,8 @@ self.connection.invalidationHandler = ^{ dispatch_async(dispatch_get_main_queue(), ^{ - if (!retrievedDownloadResult) { + SUDownloadDriver *strongSelf = weakSelf; + if (!retrievedDownloadResult && strongSelf != nil) { SULog(@"Connection to update downloader was invalidated"); NSDictionary *userInfo = @@ -90,7 +91,7 @@ NSError *downloadError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:userInfo]; - [weakSelf.delegate downloadDriverDidFailToDownloadUpdateWithError:downloadError]; + [strongSelf.delegate downloadDriverDidFailToDownloadUpdateWithError:downloadError]; } }); }; @@ -99,6 +100,10 @@ [self.connection.remoteObjectProxy startDownloadWithRequest:self.request bundleIdentifier:bundleIdentifier desiredFilename:desiredFilename completion:^(BOOL success, NSError * _Nullable error) { dispatch_async(dispatch_get_main_queue(), ^{ retrievedDownloadResult = YES; + SUDownloadDriver *strongSelf = weakSelf; + if (strongSelf == nil) { + return; + } if (!success) { NSURL *failingUrl = error.userInfo[NSURLErrorFailingURLErrorKey]; @@ -115,16 +120,9 @@ } NSError *downloadError = [NSError errorWithDomain:SUSparkleErrorDomain code:SUDownloadError userInfo:userInfo]; - [self.delegate downloadDriverDidFailToDownloadUpdateWithError:downloadError]; + [strongSelf.delegate downloadDriverDidFailToDownloadUpdateWithError:downloadError]; } else { - // If this fails, then we must have already cleaned up / cancelled - SUDownloadDriver *strongSelf = weakSelf; - if (strongSelf.connection != nil) { - [strongSelf.connection invalidate]; - strongSelf.connection = nil; - - [strongSelf.delegate downloadDriverDidDownloadUpdate]; - } + [strongSelf.delegate downloadDriverDidDownloadUpdate]; } }); }]; diff --git a/Sparkle/SUInstallerDriver.m b/Sparkle/SUInstallerDriver.m index 45424a42..7663f981 100644 --- a/Sparkle/SUInstallerDriver.m +++ b/Sparkle/SUInstallerDriver.m @@ -391,10 +391,33 @@ launcherConnection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUInstallerLauncherProtocol)]; [launcherConnection resume]; - [launcherConnection.remoteObjectProxy launchInstallerAtPath:relaunchToolPath withArguments:@[hostBundleIdentifier] completion:^(BOOL success) { - [launcherConnection invalidate]; - + __block BOOL retrievedLaunchStatus = NO; + + __weak NSXPCConnection *weakConnection = launcherConnection; + launcherConnection.interruptionHandler = ^{ dispatch_async(dispatch_get_main_queue(), ^{ + if (!retrievedLaunchStatus) { + [weakConnection invalidate]; + } + }); + }; + + launcherConnection.invalidationHandler = ^{ + dispatch_async(dispatch_get_main_queue(), ^{ + if (!retrievedLaunchStatus) { + NSError *error = + [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedString(@"An error occurred while connecting to the installer. Please try again later.", nil) }]; + + completionHandler(error); + } + }); + }; + + [launcherConnection.remoteObjectProxy launchInstallerAtPath:relaunchToolPath withArguments:@[hostBundleIdentifier] completion:^(BOOL success) { + dispatch_async(dispatch_get_main_queue(), ^{ + retrievedLaunchStatus = YES; + [launcherConnection invalidate]; + if (!success) { NSError *error = [NSError errorWithDomain:SUSparkleErrorDomain code:SUInstallationError userInfo:@{ NSLocalizedDescriptionKey:SULocalizedString(@"An error occurred while launching the installer. Please try again later.", nil) }];