From 0b19d8d7fd04ef21b811e6956ca71c52b48b02db Mon Sep 17 00:00:00 2001 From: Zorg Date: Fri, 1 Apr 2016 23:22:52 -0400 Subject: [PATCH] Add error handling cleanup to Appcast Downloader connection --- Sparkle/SUAppcast.m | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/Sparkle/SUAppcast.m b/Sparkle/SUAppcast.m index 38f59572..6f3542cf 100644 --- a/Sparkle/SUAppcast.m +++ b/Sparkle/SUAppcast.m @@ -78,12 +78,42 @@ NSXPCConnection *connection = [[NSXPCConnection alloc] initWithServiceName:@"org.sparkle-project.AppcastDownloader"]; connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(SUAppcastDownloaderProtocol)]; + + __block BOOL retrievedDownloadResult = NO; + + __weak NSXPCConnection *weakConnection = connection; + connection.interruptionHandler = ^{ + dispatch_async(dispatch_get_main_queue(), ^{ + if (!retrievedDownloadResult) { + [weakConnection invalidate]; + } + }); + }; + + connection.invalidationHandler = ^{ + dispatch_async(dispatch_get_main_queue(), ^{ + if (!retrievedDownloadResult) { + SULog(@"Appcast Downloader connection was invalidated"); + + NSDictionary *userInfo = [NSDictionary + dictionaryWithObject: SULocalizedString(@"An error occurred while downloading the update feed.", nil) + forKey: NSLocalizedDescriptionKey]; + + [self reportError:[NSError errorWithDomain:SUSparkleErrorDomain + code:SUDownloadError + userInfo:userInfo]]; + } + }); + }; + [connection resume]; [connection.remoteObjectProxy startDownloadWithRequest:request completion:^(NSData * _Nullable appcastData, NSError * _Nullable error) { [connection invalidate]; dispatch_async(dispatch_get_main_queue(), ^{ + retrievedDownloadResult = YES; + if (appcastData == nil) { [self reportError:error]; } else {