|
43 | 43 | #import "Beardie-Swift.h" |
44 | 44 |
|
45 | 45 | #define VOLUME_RELAXING_TIMEOUT 2 //seconds |
| 46 | +#define AUTOUPDATE_COMPATIBILITY_INTERVAL 3600*24 // 24 hours |
46 | 47 |
|
47 | 48 | NSString *const InUpdatingStrategiesState = @"InUpdatingStrategiesState"; |
48 | 49 |
|
@@ -120,8 +121,7 @@ - (void)applicationWillFinishLaunching:(NSNotification *)aNotification |
120 | 121 |
|
121 | 122 | #if !DEBUG_STRATEGY |
122 | 123 | /* Check for strategy updates from the master github repo */ |
123 | | - if ([[NSUserDefaults standardUserDefaults] boolForKey:BeardedSpiceUpdateAtLaunch]) |
124 | | - [self checkForCompUpdates:self]; |
| 124 | + [self setAutoCompUpdates]; |
125 | 125 | #endif |
126 | 126 | } |
127 | 127 |
|
@@ -966,6 +966,22 @@ - (void)repairLaunchAtLogin { |
966 | 966 |
|
967 | 967 | } |
968 | 968 |
|
| 969 | +- (void)setAutoCompUpdates { |
| 970 | + static dispatch_source_t updateTimer; |
| 971 | + static dispatch_once_t onceToken; |
| 972 | + dispatch_once(&onceToken, ^{ |
| 973 | + updateTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue()); |
| 974 | + int64_t begin = [[NSUserDefaults standardUserDefaults] boolForKey:BeardedSpiceUpdateAtLaunch] ? 0 : AUTOUPDATE_COMPATIBILITY_INTERVAL; |
| 975 | + dispatch_source_set_timer(updateTimer, dispatch_time(DISPATCH_TIME_NOW, begin * NSEC_PER_SEC), |
| 976 | + AUTOUPDATE_COMPATIBILITY_INTERVAL * NSEC_PER_SEC, |
| 977 | + AUTOUPDATE_COMPATIBILITY_INTERVAL * NSEC_PER_SEC); |
| 978 | + dispatch_source_set_event_handler(updateTimer, ^{ |
| 979 | + [self checkForCompUpdates:self]; |
| 980 | + }); |
| 981 | + dispatch_resume(updateTimer); |
| 982 | + }); |
| 983 | +} |
| 984 | + |
969 | 985 | ///////////////////////////////////////////////////////////////////////// |
970 | 986 | #pragma mark Notifications methods |
971 | 987 | ///////////////////////////////////////////////////////////////////////// |
|
0 commit comments