mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-28 05:14:34 +00:00
Change update permission prompt to prompt after a few hours
The old behavior used to be to prompt on second launch. However, applications can be re-launched in a short amount of time, and Sparkle can be loaded multiple times during a single app launch. So prompting after a certain amount of time after first launch works better.
This commit is contained in:
1 parent
350eba452c
commit
305e33945f
3 files changed
+25
-9
No files matched your search
Vendored
+2
-1
@@ -16,6 +16,7 @@
|
||||
// Misc:
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
extern const NSTimeInterval SUDefaultUpdatePermissionPromptInterval;
|
||||
extern const NSTimeInterval SUMinimumUpdateCheckInterval;
|
||||
extern const NSTimeInterval SUDefaultUpdateCheckInterval;
|
||||
extern const NSTimeInterval SUImpatientUpdateCheckInterval;
|
||||
@@ -33,7 +34,6 @@ extern NSString *const SUTechnicalErrorInformationKey;
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
extern NSString *const SUFeedURLKey;
|
||||
extern NSString *const SUHasLaunchedBeforeKey;
|
||||
extern NSString *const SUShowReleaseNotesKey;
|
||||
extern NSString *const SUSkippedVersionKey;
|
||||
extern NSString *const SUScheduledCheckIntervalKey;
|
||||
@@ -48,6 +48,7 @@ extern NSString *const SUEnableSystemProfilingKey;
|
||||
extern NSString *const SUSendProfileInfoKey;
|
||||
extern NSString *const SULastProfileSubmitDateKey;
|
||||
extern NSString *const SUPromptUserOnFirstLaunchKey;
|
||||
extern NSString *const SUTimeIntervalAtFirstLaunchKey;
|
||||
extern NSString *const SUKeepDownloadOnFailedInstallKey;
|
||||
extern NSString *const SUDefaultsDomainKey;
|
||||
extern NSString *const SUEnableJavaScriptKey;
|
||||
|
||||
Vendored
+4
-1
@@ -21,6 +21,9 @@
|
||||
const NSTimeInterval SUMinimumUpdateCheckInterval = DEBUG ? 60 : (60 * 60);
|
||||
const NSTimeInterval SUDefaultUpdateCheckInterval = DEBUG ? 60 : (60 * 60 * 24);
|
||||
|
||||
// Define the amount of time between Sparkle being started for the first time and before we can prompt the user for permission about checking for updates automatically
|
||||
const NSTimeInterval SUDefaultUpdatePermissionPromptInterval = DEBUG ? (60 * 3) : (60 * 60 * 3);
|
||||
|
||||
// If the update has already been automatically downloaded, we normally don't want to bug the user about the update
|
||||
// However if the user has gone a very long time without quitting an application, we will bug them
|
||||
// This is the time interval for a "week"; it doesn't matter that this measure is imprecise.
|
||||
@@ -30,7 +33,6 @@ NSString *const SUBundleIdentifier = @SPARKLE_BUNDLE_IDENTIFIER;
|
||||
|
||||
NSString *const SUTechnicalErrorInformationKey = @"SUTechnicalErrorInformation";
|
||||
|
||||
NSString *const SUHasLaunchedBeforeKey = @"SUHasLaunchedBefore";
|
||||
NSString *const SUFeedURLKey = @"SUFeedURL";
|
||||
NSString *const SUShowReleaseNotesKey = @"SUShowReleaseNotes";
|
||||
NSString *const SUSkippedVersionKey = @"SUSkippedVersion";
|
||||
@@ -46,6 +48,7 @@ NSString *const SUEnableAutomaticChecksKey = @"SUEnableAutomaticChecks";
|
||||
NSString *const SUSendProfileInfoKey = @"SUSendProfileInfo";
|
||||
NSString *const SULastProfileSubmitDateKey = @"SULastProfileSubmissionDate";
|
||||
NSString *const SUPromptUserOnFirstLaunchKey = @"SUPromptUserOnFirstLaunch";
|
||||
NSString *const SUTimeIntervalAtFirstLaunchKey = @"SUTimeIntervalAtFirstLaunch";
|
||||
NSString *const SUEnableJavaScriptKey = @"SUEnableJavaScript";
|
||||
NSString *const SUFixedHTMLDisplaySizeKey = @"SUFixedHTMLDisplaySize";
|
||||
NSString *const SUKeepDownloadOnFailedInstallKey = @"SUKeepDownloadOnFailedInstall";
|
||||
|
||||
Vendored
+19
-7
@@ -216,7 +216,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
|
||||
- (void)startUpdateCycle
|
||||
{
|
||||
BOOL shouldPrompt = NO;
|
||||
BOOL hasLaunchedBefore = [self.host boolForUserDefaultsKey:SUHasLaunchedBeforeKey];
|
||||
NSNumber *timeIntervalAtFirstLaunch = [self.host objectForUserDefaultsKey:SUTimeIntervalAtFirstLaunchKey];
|
||||
NSDate *currentDate = [NSDate date];
|
||||
|
||||
// If the user has been asked about automatic checks, don't bother prompting
|
||||
if ([self.host objectForUserDefaultsKey:SUEnableAutomaticChecksKey]) {
|
||||
@@ -230,15 +231,26 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification
|
||||
else if ([self.delegate respondsToSelector:@selector(updaterShouldPromptForPermissionToCheckForUpdates:)]) {
|
||||
shouldPrompt = [self.delegate updaterShouldPromptForPermissionToCheckForUpdates:self];
|
||||
}
|
||||
// Has he been asked already? And don't ask if the host has a default value set in its Info.plist.
|
||||
// Has the user been asked already? And don't ask if the host has a default value set in its Info.plist.
|
||||
else if ([self.host objectForKey:SUEnableAutomaticChecksKey] == nil) {
|
||||
// Now, we don't want to ask the user for permission to do a weird thing on the first launch.
|
||||
// We wait until the second launch, unless explicitly overridden via SUPromptUserOnFirstLaunchKey.
|
||||
shouldPrompt = [self.host objectForKey:SUPromptUserOnFirstLaunchKey] || hasLaunchedBefore;
|
||||
// Now, we don't want to ask the user for permission to do a weird thing right when they install the app
|
||||
// We wait until another launch after a few hours have passed, unless explicitly overridden via SUPromptUserOnFirstLaunchKey.
|
||||
|
||||
if ([self.host objectForKey:SUPromptUserOnFirstLaunchKey] != nil) {
|
||||
shouldPrompt = YES;
|
||||
} else if (timeIntervalAtFirstLaunch != nil) {
|
||||
NSDate *firstLaunchDate = [NSDate dateWithTimeIntervalSinceReferenceDate:timeIntervalAtFirstLaunch.doubleValue];
|
||||
NSTimeInterval intervalSinceFirstLaunch = [currentDate timeIntervalSinceDate:firstLaunchDate];
|
||||
// We want to prompt if more than (or equal to) 'SUDefaultUpdatePermissionPromptInterval' seconds have passed since the first launch
|
||||
// If the first launch time is after (or equal to) our current date, then something may have gone wrong in the system - prompt to be on the safe side
|
||||
if (intervalSinceFirstLaunch >= SUDefaultUpdatePermissionPromptInterval || intervalSinceFirstLaunch <= 0) {
|
||||
shouldPrompt = YES;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasLaunchedBefore) {
|
||||
[self.host setBool:YES forUserDefaultsKey:SUHasLaunchedBeforeKey];
|
||||
if (timeIntervalAtFirstLaunch == nil) {
|
||||
[self.host setObject:@([currentDate timeIntervalSinceReferenceDate]) forUserDefaultsKey:SUTimeIntervalAtFirstLaunchKey];
|
||||
}
|
||||
|
||||
if (shouldPrompt) {
|
||||
|
||||
Reference in new issue
Block a user