mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-28 05:14:34 +00:00
Don't reset impatient check date when superseding an existing update in the background (#2957)
Also we reset the impatient check date whenever the update is presented to the user and use the impatient update interval if an update has started installing (even if it was presented to user before).
This commit is contained in:
3 files changed
+29
-13
No files matched your search
Vendored
+1
-2
@@ -39,8 +39,7 @@ SPU_OBJC_DIRECT_MEMBERS @interface SPUUpdateDriver : NSObject
|
||||
|
||||
- (instancetype)initWithHost:(SUHost *)host applicationBundle:(NSBundle *)applicationBundle updater:(id)updater userDriver:(nullable id <SPUUserDriver>)userDriver updaterDelegate:(nullable id <SPUUpdaterDelegate>)updaterDelegate userInitiated:(BOOL)userInitiated installMode:(SPUUpdateDriverInstallMode)installMode;
|
||||
|
||||
// Only meaningful for a driver constructed with SPUUpdateDriverInstallModeAutomatic.
|
||||
// Must be set (along with impatientUpdateCheckInterval) before starting a check.
|
||||
// Must be set (along with impatientUpdateCheckInterval) before starting a scheduled (automatic or UI) check.
|
||||
@property (nonatomic, copy) NSDate *lastImpatientCheckedDate;
|
||||
@property (nonatomic) NSTimeInterval impatientUpdateCheckInterval;
|
||||
|
||||
|
||||
Vendored
+18
-2
@@ -300,13 +300,23 @@ static BOOL SPUUpdateRequiresUserAttentionBeforeDownloading(SUAppcastItem *updat
|
||||
}
|
||||
|
||||
if (_installMode == SPUUpdateDriverInstallModeShowingUI) {
|
||||
// If we are resuming an update that can be installed silently which was not user initiated, defer showing update until
|
||||
// impatient interval has elapsed.
|
||||
if (resumingExistingUpdate && _startedResumingInstallingUpdate && !_userInitiated && !updateItem.criticalUpdate && !SPUUpdateRequiresUserAttentionBeforeDownloading(updateItem)) {
|
||||
NSTimeInterval intervalSinceImpatientDate = [[NSDate date] timeIntervalSinceDate:_lastImpatientCheckedDate];
|
||||
if (intervalSinceImpatientDate < _impatientUpdateCheckInterval) {
|
||||
[self finishWithError:nil];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[self presentUpdateFoundWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem];
|
||||
return;
|
||||
}
|
||||
|
||||
// For automatic install mode, if we are resuming an installing update we will
|
||||
// check if impatient interval elapsed, otherwise the last impatient update check date
|
||||
// will be refreshed (when downloading a new fresh update or escalating to showing UI)
|
||||
// will be refreshed (when downloading a new fresh update or showing the update through the user driver)
|
||||
if (resumingExistingUpdate) {
|
||||
if (_startedResumingInstallingUpdate) {
|
||||
// The update has already finished preparation from a previous cycle
|
||||
@@ -324,7 +334,10 @@ static BOOL SPUUpdateRequiresUserAttentionBeforeDownloading(SUAppcastItem *updat
|
||||
[self escalateToShowingUI];
|
||||
[self presentUpdateFoundWithAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem];
|
||||
} else {
|
||||
_shouldResetImpatientCheckDate = YES;
|
||||
// If we didn't supersede an existing update, we will want to reset the impatient check date
|
||||
if (!_startedResumingInstallingUpdate && !_startedResumingDownloadedUpdate) {
|
||||
_shouldResetImpatientCheckDate = YES;
|
||||
}
|
||||
[self downloadUpdateFromAppcastItem:updateItem secondaryAppcastItem:secondaryUpdateItem inBackground:YES];
|
||||
}
|
||||
}
|
||||
@@ -583,6 +596,7 @@ static BOOL SPUUpdateRequiresUserAttentionBeforeDownloading(SUAppcastItem *updat
|
||||
}];
|
||||
|
||||
_showingUpdate = YES;
|
||||
_shouldResetImpatientCheckDate = YES;
|
||||
[self fireUpdateShownHandlerIfNeeded];
|
||||
|
||||
NSURL *releaseNotesURL = updateItem.releaseNotesURL;
|
||||
@@ -850,6 +864,8 @@ static BOOL SPUUpdateRequiresUserAttentionBeforeDownloading(SUAppcastItem *updat
|
||||
}];
|
||||
|
||||
_showingUpdate = YES;
|
||||
// If the user driver dismisses the install & relaunch we will want to reset the impatient check date
|
||||
_shouldResetImpatientCheckDate = YES;
|
||||
[self fireUpdateShownHandlerIfNeeded];
|
||||
} else {
|
||||
// Give the delegate a chance to handle installing on quit itself, bypassing Sparkle's own UI entirely -
|
||||
|
||||
Vendored
+10
-9
@@ -594,16 +594,16 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
|
||||
|
||||
SPUUpdateDriver *updateDriver = [[SPUUpdateDriver alloc] initWithHost:_host applicationBundle:_applicationBundle updater:self userDriver:_userDriver updaterDelegate:delegate userInitiated:NO installMode:installMode];
|
||||
|
||||
if (installMode == SPUUpdateDriverInstallModeAutomatic) {
|
||||
if ([_updateLastImpatientCheckedDate timeIntervalSinceNow] > 0) {
|
||||
// Last impatient checked date is bogus (in the future), reset it
|
||||
_updateLastImpatientCheckedDate = [NSDate date];
|
||||
}
|
||||
|
||||
updateDriver.impatientUpdateCheckInterval = _updaterSettings.impatientUpdateCheckInterval;
|
||||
updateDriver.lastImpatientCheckedDate = _updateLastImpatientCheckedDate;
|
||||
if ([_updateLastImpatientCheckedDate timeIntervalSinceNow] > 0) {
|
||||
// Last impatient checked date is bogus (in the future), reset it
|
||||
_updateLastImpatientCheckedDate = [NSDate date];
|
||||
}
|
||||
|
||||
// This may be used even if installMode is not SPUUpdateDriverInstallModeAutomatic
|
||||
// For example, an update that has already started installing prior to this session.
|
||||
updateDriver.impatientUpdateCheckInterval = _updaterSettings.impatientUpdateCheckInterval;
|
||||
updateDriver.lastImpatientCheckedDate = _updateLastImpatientCheckedDate;
|
||||
|
||||
[self checkForUpdatesWithDriver:updateDriver updateCheck:SPUUpdateCheckUpdatesInBackground];
|
||||
}
|
||||
|
||||
@@ -818,7 +818,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
|
||||
[strongSelf updateLastUpdateCheckDate];
|
||||
|
||||
// Track the last downloaded date locally the first time the automatic update driver
|
||||
// downloads an update in the background. This is later used for the impatient update check.
|
||||
// downloads an update in the background, or when an update is shown to the user.
|
||||
// This is later used for the impatient update check.
|
||||
if (shouldResetImpatientCheckDate) {
|
||||
strongSelf->_updateLastImpatientCheckedDate = [strongSelf lastUpdateCheckDate];
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user