From b5ace2d037392500107a14530567aaabd8119a91 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sat, 13 Aug 2016 18:03:16 -0400 Subject: [PATCH] Save the NSDate into user defaults for first launch instead of the interval This is more consistent with how the last update check logic works. I changed the value of SUTimeIntervalAtFirstLaunchKey for backwards compatibility purposes. --- Sparkle/SPUUpdater.m | 12 ++++++------ Sparkle/SUConstants.m | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Sparkle/SPUUpdater.m b/Sparkle/SPUUpdater.m index f7087d7b..04583aef 100644 --- a/Sparkle/SPUUpdater.m +++ b/Sparkle/SPUUpdater.m @@ -250,11 +250,12 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification - (void)startUpdateCycle { BOOL shouldPrompt = NO; - NSNumber *timeIntervalAtFirstLaunch = [self.host objectForUserDefaultsKey:SUTimeIntervalAtFirstLaunchKey]; + NSDate *firstLaunchDate = [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]) { + // When the user answers to the permission prompt, this will be set to either @YES or @NO instead of nil + if ([self.host objectForUserDefaultsKey:SUEnableAutomaticChecksKey] != nil) { shouldPrompt = NO; } // If the developer wants to check for updates, we shouldn't bug the user about a prompt yet @@ -272,8 +273,7 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification if ([self.host objectForKey:SUPromptUserOnFirstLaunchKey] != nil) { shouldPrompt = YES; - } else if (timeIntervalAtFirstLaunch != nil) { - NSDate *firstLaunchDate = [NSDate dateWithTimeIntervalSinceReferenceDate:timeIntervalAtFirstLaunch.doubleValue]; + } else if (firstLaunchDate != nil) { 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 @@ -283,8 +283,8 @@ NSString *const SUUpdaterAppcastNotificationKey = @"SUUpdaterAppCastNotification } } - if (timeIntervalAtFirstLaunch == nil) { - [self.host setObject:@([currentDate timeIntervalSinceReferenceDate]) forUserDefaultsKey:SUTimeIntervalAtFirstLaunchKey]; + if (firstLaunchDate == nil) { + [self.host setObject:currentDate forUserDefaultsKey:SUTimeIntervalAtFirstLaunchKey]; } if (shouldPrompt) { diff --git a/Sparkle/SUConstants.m b/Sparkle/SUConstants.m index 8e892e0e..229f1ef0 100644 --- a/Sparkle/SUConstants.m +++ b/Sparkle/SUConstants.m @@ -48,7 +48,7 @@ NSString *const SUEnableAutomaticChecksKey = @"SUEnableAutomaticChecks"; NSString *const SUSendProfileInfoKey = @"SUSendProfileInfo"; NSString *const SULastProfileSubmitDateKey = @"SULastProfileSubmissionDate"; NSString *const SUPromptUserOnFirstLaunchKey = @"SUPromptUserOnFirstLaunch"; -NSString *const SUTimeIntervalAtFirstLaunchKey = @"SUTimeIntervalAtFirstLaunch"; +NSString *const SUTimeIntervalAtFirstLaunchKey = @"SUTimeIntervalAtTheFirstLaunch"; NSString *const SUEnableJavaScriptKey = @"SUEnableJavaScript"; NSString *const SUFixedHTMLDisplaySizeKey = @"SUFixedHTMLDisplaySize"; NSString *const SUKeepDownloadOnFailedInstallKey = @"SUKeepDownloadOnFailedInstall";