From e3226d351173dee17dfa6467b28535888c498bed Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 30 Jul 2008 01:30:11 -0700 Subject: [PATCH] A cleaned up and tested version of the one-submit-per-week code --- SUConstants.h | 1 + SUConstants.m | 1 + SUUpdater.m | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/SUConstants.h b/SUConstants.h index c0c427af..acec7483 100644 --- a/SUConstants.h +++ b/SUConstants.h @@ -29,6 +29,7 @@ extern NSString *SUEnableAutomaticChecksKey; extern NSString *SUEnableAutomaticChecksKeyOld; extern NSString *SUEnableSystemProfilingKey; extern NSString *SUSendProfileInfoKey; +extern NSString *SULastProfileSubmitDateKey; extern NSString *SUSparkleErrorDomain; // Appcast phase errors. diff --git a/SUConstants.m b/SUConstants.m index 10984812..20e8bd2b 100644 --- a/SUConstants.m +++ b/SUConstants.m @@ -27,6 +27,7 @@ NSString *SUEnableSystemProfilingKey = @"SUEnableSystemProfiling"; NSString *SUEnableAutomaticChecksKey = @"SUEnableAutomaticChecks"; NSString *SUEnableAutomaticChecksKeyOld = @"SUCheckAtStartup"; NSString *SUSendProfileInfoKey = @"SUSendProfileInfo"; +NSString *SULastProfileSubmitDateKey = @"SULastProfileSubmissionDate"; NSString *SUSparkleErrorDomain = @"SUSparkleErrorDomain"; OSStatus SUAppcastParseError = 1000; diff --git a/SUUpdater.m b/SUUpdater.m index 3fa6e1e6..250aed85 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -282,6 +282,15 @@ static NSString *SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaultsObserv // Determine all the parameters we're attaching to the base feed URL. BOOL sendingSystemProfile = ([host boolForUserDefaultsKey:SUSendProfileInfoKey] == YES); + + NSDate *lastSubmitDate = [host objectForUserDefaultsKey:SULastProfileSubmitDateKey]; + if(!lastSubmitDate) + lastSubmitDate = [NSDate distantPast]; +#define ONE_WEEK (NSTimeInterval)(60 * 60 * 24 * 7) + sendingSystemProfile = sendingSystemProfile && (-[lastSubmitDate timeIntervalSinceNow] >= ONE_WEEK); + if(sendingSystemProfile) + [host setObject:[NSDate date] forUserDefaultsKey:SULastProfileSubmitDateKey]; + NSArray *parameters = [NSArray array]; if ([delegate respondsToSelector:@selector(feedParametersForUpdater:sendingSystemProfile:)]) parameters = [parameters arrayByAddingObjectsFromArray:[delegate feedParametersForUpdater:self sendingSystemProfile:sendingSystemProfile]];