diff --git a/External/libDMCore.a b/External/libDMCore.a new file mode 100644 index 00000000..84fb9471 Binary files /dev/null and b/External/libDMCore.a differ diff --git a/Sparkle.xcodeproj/project.pbxproj b/Sparkle.xcodeproj/project.pbxproj index 4ba21aa8..5aca1833 100644 --- a/Sparkle.xcodeproj/project.pbxproj +++ b/Sparkle.xcodeproj/project.pbxproj @@ -49,6 +49,7 @@ 14950073195FCE4E00BC5B5B /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0867D6A5FE840307C02AAC07 /* AppKit.framework */; }; 14958C6E19AEBC950061B14F /* signed-test-file.txt in Resources */ = {isa = PBXBuildFile; fileRef = 14958C6B19AEBC530061B14F /* signed-test-file.txt */; }; 14958C6F19AEBC980061B14F /* test-pubkey.pem in Resources */ = {isa = PBXBuildFile; fileRef = 14958C6C19AEBC610061B14F /* test-pubkey.pem */; }; + 331726611B4ABAEB008B2D77 /* libDMCore.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 331726601B4ABABD008B2D77 /* libDMCore.a */; }; 33545B8D1B4679080059250D /* com.devmate.UpdateInstaller.xpc in Embed XPC Services */ = {isa = PBXBuildFile; fileRef = 33545B811B4679080059250D /* com.devmate.UpdateInstaller.xpc */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; }; 33545B921B4679810059250D /* install_service.m in Sources */ = {isa = PBXBuildFile; fileRef = 33545B771B46774D0059250D /* install_service.m */; }; 33545B931B4687CD0059250D /* SUConstants.m in Sources */ = {isa = PBXBuildFile; fileRef = 61299A5F09CA6EB100B7442F /* SUConstants.m */; }; @@ -371,6 +372,7 @@ 14950074195FDF5900BC5B5B /* SUUpdaterTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SUUpdaterTest.m; sourceTree = ""; usesTabs = 0; }; 14958C6B19AEBC530061B14F /* signed-test-file.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "signed-test-file.txt"; sourceTree = ""; }; 14958C6C19AEBC610061B14F /* test-pubkey.pem */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "test-pubkey.pem"; sourceTree = ""; }; + 331726601B4ABABD008B2D77 /* libDMCore.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libDMCore.a; path = External/libDMCore.a; sourceTree = ""; }; 33545B771B46774D0059250D /* install_service.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = install_service.m; sourceTree = ""; }; 33545B781B46774D0059250D /* install_service.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = install_service.pch; sourceTree = ""; }; 33545B791B46774D0059250D /* SandboxService.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = SandboxService.plist; sourceTree = ""; }; @@ -682,6 +684,7 @@ 61B5F8F709C4CEB300B25A18 /* Security.framework in Frameworks */, 55C14F32136EFC2400649790 /* SystemConfiguration.framework in Frameworks */, 61B5FC4C09C4FD5E00B25A18 /* WebKit.framework in Frameworks */, + 331726611B4ABAEB008B2D77 /* libDMCore.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -722,6 +725,7 @@ 0867D69AFE84028FC02AAC07 /* Frameworks */ = { isa = PBXGroup; children = ( + 331726601B4ABABD008B2D77 /* libDMCore.a */, 0867D6A5FE840307C02AAC07 /* AppKit.framework */, 525A278F133D6AE900FD8D70 /* Cocoa.framework */, 0867D69BFE84028FC02AAC07 /* Foundation.framework */, @@ -1891,6 +1895,10 @@ isa = XCBuildConfiguration; baseConfigurationReference = FA1941CA0D94A70100DD942E /* ConfigFrameworkDebug.xcconfig */; buildSettings = { + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/External", + ); }; name = Debug; }; @@ -1898,6 +1906,10 @@ isa = XCBuildConfiguration; baseConfigurationReference = FA1941D50D94A70100DD942E /* ConfigFrameworkRelease.xcconfig */; buildSettings = { + LIBRARY_SEARCH_PATHS = ( + "$(inherited)", + "$(PROJECT_DIR)/External", + ); }; name = Release; }; diff --git a/Sparkle/SUAutomaticUpdateDriver.m b/Sparkle/SUAutomaticUpdateDriver.m index 45b3d546..7b4991c2 100644 --- a/Sparkle/SUAutomaticUpdateDriver.m +++ b/Sparkle/SUAutomaticUpdateDriver.m @@ -60,6 +60,31 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidBecomeActive:) name:NSApplicationDidBecomeActiveNotification object:NSApp]; } +- (void)downloadReleaseNotesAndWaitUntilDone +{ + NSURL *releaseNotesURL = self.updateItem.releaseNotesURL; + if (nil == releaseNotesURL || [releaseNotesURL isFileURL]) + return; + + static NSString * const kSUAutomaticUpdateParamName = @"autoupdate"; + + NSString *URLString = releaseNotesURL.absoluteString; + URLString = [URLString stringByAppendingFormat:@"%@%@=1", (releaseNotesURL.query != nil) ? @"&" : @"?", kSUAutomaticUpdateParamName]; + releaseNotesURL = [NSURL URLWithString:URLString]; + + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:releaseNotesURL]; + [request setCachePolicy:NSURLRequestReloadIgnoringCacheData]; + [self updateURLRequestHTTPHeaders:request]; + [NSURLConnection sendSynchronousRequest:request returningResponse:NULL error:NULL]; +} + +- (void)didFindValidUpdate +{ + // For correct DevMate statistics need to send request for Release Notes. + [self downloadReleaseNotesAndWaitUntilDone]; + [super didFindValidUpdate]; +} + - (void)unarchiverDidFinish:(SUUnarchiver *)__unused ua { [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil]; diff --git a/Sparkle/SUBasicUpdateDriver.h b/Sparkle/SUBasicUpdateDriver.h index 8c6960d8..b218984d 100644 --- a/Sparkle/SUBasicUpdateDriver.h +++ b/Sparkle/SUBasicUpdateDriver.h @@ -31,6 +31,7 @@ - (void)didFindValidUpdate; - (void)didNotFindUpdate; +- (void)updateURLRequestHTTPHeaders:(NSMutableURLRequest *)request; - (void)downloadUpdate; - (void)download:(NSURLDownload *)d decideDestinationWithSuggestedFilename:(NSString *)name; - (void)downloadDidFinish:(NSURLDownload *)d; diff --git a/Sparkle/SUBasicUpdateDriver.m b/Sparkle/SUBasicUpdateDriver.m index 02f518e7..8bd9de23 100644 --- a/Sparkle/SUBasicUpdateDriver.m +++ b/Sparkle/SUBasicUpdateDriver.m @@ -22,6 +22,8 @@ #import "SUUpdater_Private.h" #import "SUXPCInstaller.h" +CF_EXPORT CFDictionaryRef DMCopyHTTPRequestHeaders(CFBundleRef appBundle, CFDataRef httpBodyData); + @interface SUBasicUpdateDriver () @property (strong) SUAppcastItem *updateItem; @@ -53,10 +55,14 @@ return; } + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL]; + request.allHTTPHeaderFields = [self.updater httpHeaders]; + [self updateURLRequestHTTPHeaders:request]; + SUAppcast *appcast = [[SUAppcast alloc] init]; [appcast setUserAgentString:[self.updater userAgentString]]; - [appcast setHttpHeaders:[self.updater httpHeaders]]; + [appcast setHttpHeaders:request.allHTTPHeaderFields]; [appcast fetchAppcastFromURL:URL completionBlock:^(NSError *error) { if (error) { [self abortUpdateWithError:error]; @@ -188,10 +194,26 @@ }]]; } +- (void)updateURLRequestHTTPHeaders:(NSMutableURLRequest *)request +{ + CFBundleRef hostBundle = CFBundleCreate(kCFAllocatorDefault, (__bridge CFURLRef)[NSURL fileURLWithPath:self.host.bundlePath]); + NSDictionary *devmateHeaders = (__bridge_transfer NSDictionary *)DMCopyHTTPRequestHeaders(hostBundle, NULL); + if (devmateHeaders.count) + { + [request setAllHTTPHeaderFields:devmateHeaders]; + } + + if (NULL != hostBundle) + { + CFRelease(hostBundle); + } +} + - (void)downloadUpdate { NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[self.updateItem fileURL]]; [request setValue:[self.updater userAgentString] forHTTPHeaderField:@"User-Agent"]; + [self updateURLRequestHTTPHeaders:request]; self.download = [[NSURLDownload alloc] initWithRequest:request delegate:self]; } diff --git a/Sparkle/SUUIBasedUpdateDriver.m b/Sparkle/SUUIBasedUpdateDriver.m index b1e09370..4b0d6b8e 100644 --- a/Sparkle/SUUIBasedUpdateDriver.m +++ b/Sparkle/SUUIBasedUpdateDriver.m @@ -32,6 +32,11 @@ [self updateAlertFinishedWithChoice:choice]; }]; + __weak SUUIBasedUpdateDriver *weakSelf = self; + self.updateAlert.releaseNotesRequestModifier = ^(NSMutableURLRequest *request) { + [weakSelf updateURLRequestHTTPHeaders:request]; + }; + id versDisp = nil; if ([[self.updater delegate] respondsToSelector:@selector(versionDisplayerForUpdater:)]) { versDisp = [[self.updater delegate] versionDisplayerForUpdater:self.updater]; diff --git a/Sparkle/SUUpdateAlert.h b/Sparkle/SUUpdateAlert.h index 2db57bf4..61725f53 100644 --- a/Sparkle/SUUpdateAlert.h +++ b/Sparkle/SUUpdateAlert.h @@ -25,6 +25,7 @@ typedef NS_ENUM(NSInteger, SUUpdateAlertChoice) { @interface SUUpdateAlert : SUWindowController @property (weak) id versionDisplayer; +@property (copy) void (^releaseNotesRequestModifier)(NSMutableURLRequest *request); - (instancetype)initWithAppcastItem:(SUAppcastItem *)item host:(SUHost *)host completionBlock:(void(^)(SUUpdateAlertChoice))c; diff --git a/Sparkle/SUUpdateAlert.m b/Sparkle/SUUpdateAlert.m index 61ca768c..61c260cd 100644 --- a/Sparkle/SUUpdateAlert.m +++ b/Sparkle/SUUpdateAlert.m @@ -135,7 +135,14 @@ } else { - [[self.releaseNotesView mainFrame] loadRequest:[NSURLRequest requestWithURL:[self.updateItem releaseNotesURL] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30]]; + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:self.updateItem.releaseNotesURL + cachePolicy:NSURLRequestReloadIgnoringCacheData + timeoutInterval:30]; + if (self.releaseNotesRequestModifier != nil) + { + self.releaseNotesRequestModifier(request); + } + [[self.releaseNotesView mainFrame] loadRequest:request]; } } else