Tell OS when networking happens without UI

This commit is contained in:
Kornel Lesiński committed 2017-01-10 02:37:00 +00:00
1 parent eafbb2cfad
commit 392cb65716
7 files changed
+31 -5

No files matched your search

+1 -1
View File
@@ -24,7 +24,7 @@ SU_EXPORT @interface SUAppcast : NSObject<NSURLDownloadDelegate>
@property (copy, nullable) NSString *userAgentString;
@property (copy, nullable) NSDictionary *httpHeaders;
- (void)fetchAppcastFromURL:(NSURL *)url completionBlock:(void (^)(NSError *_Nullable))err;
- (void)fetchAppcastFromURL:(NSURL *)url inBackground:(BOOL)bg completionBlock:(void (^)(NSError *_Nullable))err;
- (SUAppcast *)copyWithoutDeltaUpdates;
@property (readonly, copy, nullable) NSArray *items;
+5 -1
View File
@@ -54,11 +54,15 @@
@synthesize download;
@synthesize items;
- (void)fetchAppcastFromURL:(NSURL *)url completionBlock:(void (^)(NSError *))block
- (void)fetchAppcastFromURL:(NSURL *)url inBackground:(BOOL)background completionBlock:(void (^)(NSError *))block
{
self.completionBlock = block;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
if (background) {
request.networkServiceType = NSURLNetworkServiceTypeBackground;
}
if (self.userAgentString) {
[request setValue:self.userAgentString forHTTPHeaderField:@"User-Agent"];
}
+4
View File
@@ -121,6 +121,10 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2
return NO;
}
-(BOOL)downloadsUpdatesInBackground {
return YES;
}
- (void)stopUpdatingOnTermination
{
if (self.willUpdateOnTermination)
+7 -3
View File
@@ -65,7 +65,7 @@
id<SUUpdaterPrivate> updater = self.updater;
[appcast setUserAgentString:[updater userAgentString]];
[appcast setHttpHeaders:[updater httpHeaders]];
[appcast fetchAppcastFromURL:URL completionBlock:^(NSError *error) {
[appcast fetchAppcastFromURL:URL inBackground:self.downloadsAppcastInBackground completionBlock:^(NSError *error) {
if (error) {
[self abortUpdateWithError:error];
} else {
@@ -258,10 +258,14 @@
if ([[NSFileManager defaultManager] fileExistsAtPath:appCachePath]) {
[[NSFileManager defaultManager] removeItemAtPath:appCachePath error:NULL];
}
id<SUUpdaterPrivate> updater = self.updater;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[self.updateItem fileURL]];
if (self.downloadsUpdatesInBackground) {
request.networkServiceType = NSURLNetworkServiceTypeBackground;
}
[request setValue:[updater userAgentString] forHTTPHeaderField:@"User-Agent"];
if ([[updater delegate] respondsToSelector:@selector(updater:willDownloadUpdate:withRequest:)]) {
[[updater delegate] updater:self.updater
+2
View File
@@ -32,6 +32,8 @@ extern NSString *const SUUpdateDriverFinishedNotification;
@property (getter=isInterruptible, readonly) BOOL interruptible;
@property (readonly) BOOL finished;
@property (readonly) BOOL downloadsAppcastInBackground;
@property (readonly) BOOL downloadsUpdatesInBackground;
@property BOOL automaticallyInstallUpdates;
@end
+8
View File
@@ -56,6 +56,14 @@ NSString *const SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished";
return NO;
}
-(BOOL)downloadsAppcastInBackground {
return YES;
}
-(BOOL)downloadsUpdatesInBackground {
return NO;
}
- (void)showAlert:(NSAlert *)alert {
// Only UI-based subclass shows the actual alert
SULog(@"ALERT: %@\n%@", alert.messageText, alert.informativeText);
+4
View File
@@ -80,6 +80,10 @@
[super abortUpdate];
}
-(BOOL)downloadsAppcastInBackground {
return NO;
}
- (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui
{
// We don't check to see if this update's been skipped, because the user explicitly *asked* if he had the latest version.