77//
88
99#import " SPUUpdaterSettings.h"
10+ #import " SPUUpdaterSettings+Debug.h"
1011#import " SUHost.h"
1112#import " SUConstants.h"
1213
2223@implementation SPUUpdaterSettings
2324{
2425 SUHost *_host;
26+
27+ #if DEBUG
28+ BOOL _enableDebugUpdateCheckIntervals;
29+ #endif
2530}
2631
2732@synthesize automaticallyChecksForUpdates = _automaticallyChecksForUpdates;
@@ -36,6 +41,12 @@ - (instancetype)initWithHostBundle:(NSBundle *)hostBundle
3641 if (self != nil ) {
3742 _host = [[SUHost alloc ] initWithBundle: hostBundle];
3843
44+ #if DEBUG
45+ // This one must be checked first, before checking the other settings,
46+ // since the others may rely on this
47+ _enableDebugUpdateCheckIntervals = [self currentEnableDebugUpdateCheckIntervals ];
48+ #endif
49+
3950 _automaticallyChecksForUpdates = [self currentAutomaticallyChecksForUpdates ];
4051 _updateCheckInterval = [self currentUpdateCheckInterval ];
4152 _impatientUpdateCheckInterval = [self currentImpatientUpdateCheckInterval ];
@@ -152,6 +163,12 @@ - (void)synchronize:(NSNotification *)notification
152163 return ;
153164 }
154165
166+ #if DEBUG
167+ // This one must be checked first, before checking the other settings,
168+ // since the others may rely on this
169+ _enableDebugUpdateCheckIntervals = [self currentEnableDebugUpdateCheckIntervals ];
170+ #endif
171+
155172 [self processCurrentAutomaticallyChecksForUpdates ];
156173 [self processUpdateCheckInterval ];
157174 [self processImpatientUpdateCheckInterval ];
@@ -180,7 +197,7 @@ - (void)setAutomaticallyChecksForUpdates:(BOOL)automaticallyCheckForUpdates
180197 // Hack to support backwards compatibility with older Sparkle versions, which supported
181198 // disabling updates by setting the check interval to 0.
182199 if (automaticallyCheckForUpdates && (NSInteger )[self currentUpdateCheckInterval ] == 0 ) {
183- [self setUpdateCheckInterval: SUDefaultUpdateCheckInterval ];
200+ [self setUpdateCheckInterval: [ self defaultUpdateCheckInterval ] ];
184201 } else {
185202 [NSNotificationCenter .defaultCenter postNotificationName: SUUpdateAutomaticCheckSettingChangedNotification object: nil userInfo: @{SUUpdateBundlePathUserInfoKey: _host.bundlePath }];
186203 }
@@ -196,7 +213,7 @@ - (NSTimeInterval)currentUpdateCheckInterval SPU_OBJC_DIRECT
196213 // Find the stored check interval. User defaults override Info.plist.
197214 NSNumber *intervalValue = [_host doubleNumberForKey: SUScheduledCheckIntervalKey];
198215 if (intervalValue == nil ) {
199- return SUDefaultUpdateCheckInterval ;
216+ return [ self defaultUpdateCheckInterval ] ;
200217 }
201218
202219 return intervalValue.doubleValue ;
@@ -222,7 +239,7 @@ - (NSTimeInterval)currentImpatientUpdateCheckInterval SPU_OBJC_DIRECT
222239{
223240 NSNumber *intervalValue = [_host doubleNumberForInfoDictionaryKey: SUScheduledImpatientCheckIntervalKey];
224241 if (intervalValue == nil ) {
225- return SUDefaultImpatientUpdateCheckInterval ;
242+ return [ self defaultImpatientUpdateCheckInterval ] ;
226243 }
227244
228245 return intervalValue.doubleValue ;
@@ -295,4 +312,79 @@ + (BOOL)automaticallyNotifiesObserversOfSendsSystemProfile
295312 return NO ;
296313}
297314
315+ #if DEBUG
316+ // This is only used in DEBUG and is meant for the Sparkle Test App
317+ - (BOOL )currentEnableDebugUpdateCheckIntervals
318+ {
319+ return [_host boolForInfoDictionaryKey: @" _SUEnableDebugUpdateCheckIntervals" ];
320+ }
321+ #endif
322+
323+ - (NSTimeInterval )minimumUpdateCheckInterval
324+ {
325+ #if DEBUG
326+ if (_enableDebugUpdateCheckIntervals) {
327+ // 1 minute
328+ return 60 ;
329+ }
330+ #endif
331+
332+ // 1 hour
333+ return (60 * 60 );
334+ }
335+
336+ - (uint64_t )leewayUpdateCheckInterval
337+ {
338+ #if DEBUG
339+ if (_enableDebugUpdateCheckIntervals) {
340+ // 1 second
341+ return 1 ;
342+ }
343+ #endif
344+
345+ // 15 seconds
346+ return 15 ;
347+ }
348+
349+ - (NSTimeInterval )defaultUpdateCheckInterval SPU_OBJC_DIRECT
350+ {
351+ #if DEBUG
352+ if (_enableDebugUpdateCheckIntervals) {
353+ // 1 minute
354+ return 60 ;
355+ }
356+ #endif
357+
358+ // 1 day
359+ return (60 * 60 * 24 );
360+ }
361+
362+ // If the update has already been automatically downloaded, we normally don't want to bug the user about the update
363+ // However if the user has gone a very long time without quitting an application, we will notify them
364+ - (NSTimeInterval )defaultImpatientUpdateCheckInterval SPU_OBJC_DIRECT
365+ {
366+ #if DEBUG
367+ if (_enableDebugUpdateCheckIntervals) {
368+ // 2 minutes
369+ return (60 * 2 );
370+ }
371+ #endif
372+
373+ // 1 week
374+ return (60 * 60 * 24 * 7 );
375+ }
376+
377+ - (NSTimeInterval )standardUIScheduledUpdateIdleEventLeewayInterval
378+ {
379+ #if DEBUG
380+ if (_enableDebugUpdateCheckIntervals) {
381+ // 30 seconds
382+ return 30.0 ;
383+ }
384+ #endif
385+
386+ // 5 minutes
387+ return (5 * 60.0 );
388+ }
389+
298390@end
0 commit comments