Skip to content

Commit 8ed643c

Browse files
authored
Allow impatient update check interval to be configured (#2799)
This is the update check interval used after an update has been downloaded/staged to be installed automatically in the background. By default this is 1 week (in seconds) but this change now allows it to be configured.
1 parent a5401bb commit 8ed643c

File tree

5 files changed

+54
-6
lines changed

5 files changed

+54
-6
lines changed

Sparkle/SPUUpdater.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,15 @@ - (void)scheduleNextUpdateCheckFiringImmediately:(BOOL)firingImmediately usingCu
520520
[SPUProbeInstallStatus probeInstallerUpdateItemForHostBundleIdentifier:hostBundleIdentifier completion:^(SPUInstallationInfo * _Nullable installationInfo) {
521521
dispatch_async(dispatch_get_main_queue(), ^{
522522
NSTimeInterval regularCheckInterval = [self updateCheckInterval];
523+
NSTimeInterval impatientCheckInterval = [self->_updaterSettings impatientUpdateCheckInterval];
523524
if (installationInfo == nil) {
524525
// Proceed as normal if there's no resumable updates
525526
completionHandler(regularCheckInterval);
526527
} else {
527528
if ([installationInfo.appcastItem isCriticalUpdate] || [installationInfo.appcastItem isInformationOnlyUpdate]) {
528-
completionHandler(MIN(regularCheckInterval, SUImpatientUpdateCheckInterval));
529+
completionHandler(MIN(regularCheckInterval, impatientCheckInterval));
529530
} else {
530-
completionHandler(MAX(regularCheckInterval, SUImpatientUpdateCheckInterval));
531+
completionHandler(MAX(regularCheckInterval, impatientCheckInterval));
531532
}
532533
}
533534
});

Sparkle/SPUUpdaterSettings.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ SU_EXPORT @interface SPUUpdaterSettings : NSObject
4646
*/
4747
@property (nonatomic) NSTimeInterval updateCheckInterval;
4848

49+
/**
50+
* The impatient update check interval.
51+
*
52+
* If an update has already been downloaded automatically in the background, Sparkle may not notify users of the update immediately,
53+
* and tries to install the update siliently on quit without notifying the user.
54+
*
55+
* Sparkle uses this long impatient update check interval to decide when to notify the user of the update if they haven't quit the app for a long time.
56+
* By default this check interval is set to 604800 seconds (which is 1 week). This interval must be bigger than the `updateCheckInterval`.
57+
*/
58+
@property (nonatomic, readonly) NSTimeInterval impatientUpdateCheckInterval;
59+
4960
/**
5061
* Indicates whether or not automatically downloading updates is allowed to be turned on by the user.
5162
* If this value is nil, the developer has not explicitly specified this option.

Sparkle/SPUUpdaterSettings.m

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
static NSString *SUAutomaticallyChecksForUpdatesKeyPath = @"automaticallyChecksForUpdates";
1717
static NSString *SUUpdateCheckIntervalKeyPath = @"updateCheckInterval";
18+
static NSString *SUImpatientUpdateCheckIntervalKeyPath = @"impatientUpdateCheckInterval";
1819
static NSString *SUAutomaticallyDownloadsUpdatesKeyPath = @"automaticallyDownloadsUpdates";
1920
static NSString *SUSendsSystemProfileKeyPath = @"sendsSystemProfile";
2021

@@ -25,6 +26,7 @@ @implementation SPUUpdaterSettings
2526

2627
@synthesize automaticallyChecksForUpdates = _automaticallyChecksForUpdates;
2728
@synthesize updateCheckInterval = _updateCheckInterval;
29+
@synthesize impatientUpdateCheckInterval = _impatientUpdateCheckInterval;
2830
@synthesize automaticallyDownloadsUpdates = _automaticallyDownloadsUpdates;
2931
@synthesize sendsSystemProfile = _sendsSystemProfile;
3032

@@ -36,6 +38,7 @@ - (instancetype)initWithHostBundle:(NSBundle *)hostBundle
3638

3739
_automaticallyChecksForUpdates = [self currentAutomaticallyChecksForUpdates];
3840
_updateCheckInterval = [self currentUpdateCheckInterval];
41+
_impatientUpdateCheckInterval = [self currentImpatientUpdateCheckInterval];
3942
_automaticallyDownloadsUpdates = [self currentAutomaticallyDownloadsUpdates];
4043
_sendsSystemProfile = [self currentSendsSystemProfile];
4144

@@ -97,6 +100,21 @@ - (void)processUpdateCheckInterval SPU_OBJC_DIRECT
97100
}
98101
}
99102

103+
- (void)processImpatientUpdateCheckInterval SPU_OBJC_DIRECT
104+
{
105+
NSTimeInterval currentValue = [self currentImpatientUpdateCheckInterval];
106+
107+
if (fabs(currentValue - _impatientUpdateCheckInterval) >= 0.001) {
108+
NSString *updatedKeyPath = SUImpatientUpdateCheckIntervalKeyPath;
109+
110+
[self willChangeValueForKey:updatedKeyPath];
111+
112+
_impatientUpdateCheckInterval = currentValue;
113+
114+
[self didChangeValueForKey:updatedKeyPath];
115+
}
116+
}
117+
100118
- (void)processAutomaticallyDownloadsUpdates SPU_OBJC_DIRECT
101119
{
102120
BOOL currentValue = [self currentAutomaticallyDownloadsUpdates];
@@ -136,6 +154,7 @@ - (void)synchronize:(NSNotification *)notification
136154

137155
[self processCurrentAutomaticallyChecksForUpdates];
138156
[self processUpdateCheckInterval];
157+
[self processImpatientUpdateCheckInterval];
139158
[self processAutomaticallyDownloadsUpdates];
140159
[self processSendsSystemProfile];
141160
}
@@ -199,11 +218,26 @@ - (void)setUpdateCheckInterval:(NSTimeInterval)updateCheckInterval
199218
}
200219
}
201220

221+
- (NSTimeInterval)currentImpatientUpdateCheckInterval SPU_OBJC_DIRECT
222+
{
223+
NSNumber *intervalValue = [_host doubleNumberForInfoDictionaryKey:SUScheduledImpatientCheckIntervalKey];
224+
if (intervalValue == nil) {
225+
return SUDefaultImpatientUpdateCheckInterval;
226+
}
227+
228+
return intervalValue.doubleValue;
229+
}
230+
202231
+ (BOOL)automaticallyNotifiesObserversOfUpdateCheckInterval
203232
{
204233
return NO;
205234
}
206235

236+
+ (BOOL)automaticallyNotifiesObserversOfImpatientUpdateCheckInterval
237+
{
238+
return NO;
239+
}
240+
207241
// For allowing automatic downloaded updates to be turned on or off
208242
- (NSNumber * _Nullable)allowsAutomaticUpdatesOption
209243
{

Sparkle/SUConstants.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ extern const NSTimeInterval SUDefaultUpdatePermissionPromptInterval;
2020
extern const NSTimeInterval SUMinimumUpdateCheckInterval;
2121
extern const NSTimeInterval SUDefaultUpdateCheckInterval;
2222
extern const uint64_t SULeewayUpdateCheckInterval;
23-
extern const NSTimeInterval SUImpatientUpdateCheckInterval;
23+
extern const NSTimeInterval SUDefaultImpatientUpdateCheckInterval;
2424

2525
extern NSString *const SUBundleIdentifier;
2626

@@ -47,6 +47,7 @@ extern NSString *const SUSkippedMinorVersionKey;
4747
extern NSString *const SUSkippedMajorVersionKey;
4848
extern NSString *const SUSkippedMajorSubreleaseVersionKey;
4949
extern NSString *const SUScheduledCheckIntervalKey;
50+
extern NSString *const SUScheduledImpatientCheckIntervalKey;
5051
extern NSString *const SULastCheckTimeKey;
5152
extern NSString *const SUPublicDSAKeyKey;
5253
extern NSString *const SUPublicDSAKeyFileKey;

Sparkle/SUConstants.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
const uint64_t SULeewayUpdateCheckInterval = DEBUG ? 1 : 15;
2323

2424
// If the update has already been automatically downloaded, we normally don't want to bug the user about the update
25-
// However if the user has gone a very long time without quitting an application, we will bug them
26-
// This is the time interval for a "week"; it doesn't matter that this measure is imprecise.
27-
const NSTimeInterval SUImpatientUpdateCheckInterval = DEBUG ? (60 * 2) : (60 * 60 * 24 * 7);
25+
// However if the user has gone a very long time without quitting an application, we will notify them
26+
// By default this is the time interval for a week
27+
const NSTimeInterval SUDefaultImpatientUpdateCheckInterval = DEBUG ? (60 * 2) : (60 * 60 * 24 * 7);
2828

2929
NSString *const SUBundleIdentifier = @SPARKLE_BUNDLE_IDENTIFIER;
3030

@@ -43,6 +43,7 @@
4343
NSString *const SUSkippedMajorVersionKey = @"SUSkippedMajorVersion";
4444
NSString *const SUSkippedMajorSubreleaseVersionKey = @"SUSkippedMajorSubreleaseVersion";
4545
NSString *const SUScheduledCheckIntervalKey = @"SUScheduledCheckInterval";
46+
NSString *const SUScheduledImpatientCheckIntervalKey = @"SUScheduledImpatientCheckInterval";
4647
NSString *const SULastCheckTimeKey = @"SULastCheckTime";
4748
NSString *const SUPublicDSAKeyKey = @"SUPublicDSAKey";
4849
NSString *const SUPublicDSAKeyFileKey = @"SUPublicDSAKeyFile";

0 commit comments

Comments
 (0)