From 9119d287abcee1c6d6ff630c0c40e26c1eaaa3cd Mon Sep 17 00:00:00 2001 From: Dmytro Tretiakov Date: Mon, 10 Feb 2014 18:31:42 +0200 Subject: [PATCH] Added delegate methods that interacts with DevMate (beta updates, test mode). --- SUUpdater.h | 15 +++++++++++++++ SUUpdater.m | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/SUUpdater.h b/SUUpdater.h index 71e09ff1..e29daad1 100644 --- a/SUUpdater.h +++ b/SUUpdater.h @@ -142,6 +142,21 @@ @end +// ----------------------------------------------------------------------------- +// SUUpdater Delegate: DevMate Interaction +// ----------------------------------------------------------------------------- + +// NOTE!!! Implemented delegate methods have higher priority than values saved in user preferences + +FOUNDATION_EXPORT NSString *const SUUpdaterChecksForBetaUpdatesPrefKey; // bool value +FOUNDATION_EXPORT NSString *const SUUpdaterIsInTestModePrefKey; // bool value + +@interface NSObject (SUUpdaterDelegate_DevMateInteraction) + +- (BOOL)updaterShouldCheckForBetaUpdates:(SUUpdater *)updater; +- (BOOL)isUpdaterInTestMode:(SUUpdater *)updater; + +@end // ----------------------------------------------------------------------------- // Constants: diff --git a/SUUpdater.m b/SUUpdater.m index c0f99353..ece93c91 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -479,7 +479,7 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault const NSTimeInterval oneWeek = 60 * 60 * 24 * 7; sendingSystemProfile &= (-[lastSubmitDate timeIntervalSinceNow] >= oneWeek); - NSArray *parameters = [NSArray array]; + NSArray *parameters = [self devmateFeedParameters]; if ([delegate respondsToSelector:@selector(feedParametersForUpdater:sendingSystemProfile:)]) parameters = [parameters arrayByAddingObjectsFromArray:[delegate feedParametersForUpdater:self sendingSystemProfile:sendingSystemProfile]]; if (sendingSystemProfile) @@ -564,4 +564,36 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault return [[NSFileManager defaultManager] fileExistsAtPath:[xpcServicePrefixPath stringByAppendingPathComponent:xpcServiceSuffixPath]]; } +#pragma mark - DevMate Interaction + +NSString *const SUUpdaterChecksForBetaUpdatesPrefKey = @"SUUpdaterChecksForBetaUpdates"; +NSString *const SUUpdaterIsInTestModePrefKey = @"SUUpdaterIsInTestMode"; + +- (NSArray *)devmateFeedParameters +{ + NSMutableArray *parameters = [NSMutableArray array]; + + BOOL isInTestMode = [host boolForUserDefaultsKey:SUUpdaterIsInTestModePrefKey]; + if ([delegate respondsToSelector:@selector(isUpdaterInTestMode:)]) + { + isInTestMode = [delegate isUpdaterInTestMode:self]; + } + if (isInTestMode) + { + [parameters addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"test", @"key", @"1", @"value", nil]]; + } + + BOOL shouldCheckBeta = [host boolForUserDefaultsKey:SUUpdaterChecksForBetaUpdatesPrefKey]; + if ([delegate respondsToSelector:@selector(updaterShouldCheckForBetaUpdates:)]) + { + shouldCheckBeta = [delegate updaterShouldCheckForBetaUpdates:self]; + } + if (shouldCheckBeta) + { + [parameters addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"beta", @"key", @"1", @"value", nil]]; + } + + return parameters; +} + @end