From bf38b0c9fdf06969ad37aef397c25b0538436134 Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Mon, 10 Oct 2011 10:56:37 -0700 Subject: [PATCH] Adding appcast item element, tag You would use this like: My great update ... The behavior of this tag presently is: rather than waiting for the user to quit the app (or for some large amount of time to pass), the user will be prompted to install the update (with a stronger message) immediately upon its receipt. This behavior could be improved for the manual update case as well. We can also use this new mechanism to create special behavior for e.g. paid updates. --- SUAppcastItem.h | 3 ++- SUAppcastItem.m | 5 +++++ SUAutomaticUpdateAlert.m | 18 ++++++++++++++++-- SUAutomaticUpdateDriver.m | 13 ++++++++++--- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/SUAppcastItem.h b/SUAppcastItem.h index d1067321..5c91b88c 100644 --- a/SUAppcastItem.h +++ b/SUAppcastItem.h @@ -28,7 +28,7 @@ NSDictionary *deltaUpdates; NSDictionary *propertiesDictionary; - + NSURL *infoURL; // UK 2007-08-31 } @@ -47,6 +47,7 @@ - (NSString *)minimumSystemVersion; - (NSDictionary *)deltaUpdates; - (BOOL)isDeltaUpdate; +- (BOOL)isCriticalUpdate; // Returns the dictionary provided in initWithDictionary; this might be useful later for extensions. - (NSDictionary *)propertiesDictionary; diff --git a/SUAppcastItem.m b/SUAppcastItem.m index 57680557..5a46f2ff 100644 --- a/SUAppcastItem.m +++ b/SUAppcastItem.m @@ -130,6 +130,11 @@ return [[propertiesDictionary objectForKey:@"enclosure"] objectForKey:@"sparkle:deltaFrom"] != nil; } +- (BOOL)isCriticalUpdate +{ + return [[propertiesDictionary objectForKey:@"sparkle:tags"] containsObject:@"sparkle:criticalUpdate"]; +} + - initWithDictionary:(NSDictionary *)dict { return [self initWithDictionary:dict failureReason:nil]; diff --git a/SUAutomaticUpdateAlert.m b/SUAutomaticUpdateAlert.m index f055f48d..65f84bed 100644 --- a/SUAutomaticUpdateAlert.m +++ b/SUAutomaticUpdateAlert.m @@ -60,12 +60,26 @@ - (NSString *)titleText { - return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is ready to install!", nil), [host name]]; + if ([updateItem isCriticalUpdate]) + { + return [NSString stringWithFormat:SULocalizedString(@"An important update to %@ is ready to install", nil)]; + } + else + { + return [NSString stringWithFormat:SULocalizedString(@"A new version of %@ is ready to install!", nil), [host name]]; + } } - (NSString *)descriptionText { - return [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?", nil), [host name], [updateItem displayVersionString]]; + if ([updateItem isCriticalUpdate]) + { + return [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! This is an important update; would you like to install it and relaunch %1$@ now?", nil), [host name], [updateItem displayVersionString]]; + } + else + { + return [NSString stringWithFormat:SULocalizedString(@"%1$@ %2$@ has been downloaded and is ready to use! Would you like to install it and relaunch %1$@ now?", nil), [host name], [updateItem displayVersionString]]; + } } @end diff --git a/SUAutomaticUpdateDriver.m b/SUAutomaticUpdateDriver.m index 7bd9d05b..04ccf170 100644 --- a/SUAutomaticUpdateDriver.m +++ b/SUAutomaticUpdateDriver.m @@ -38,9 +38,16 @@ static const NSTimeInterval SUAutomaticUpdatePromptImpatienceTimer = 60 * 60 * 2 - (void)unarchiverDidFinish:(SUUnarchiver *)ua { - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil]; - - showUpdateAlertTimer = [[NSTimer scheduledTimerWithTimeInterval:SUAutomaticUpdatePromptImpatienceTimer target:self selector:@selector(showUpdateAlert) userInfo:nil repeats:NO] retain]; + // If this is marked as a critical update, we'll prompt the user to install it right away. + if ([updateItem isCriticalUpdate]) + { + [self showUpdateAlert]; + } + else + { + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationWillTerminate:) name:NSApplicationWillTerminateNotification object:nil]; + showUpdateAlertTimer = [[NSTimer scheduledTimerWithTimeInterval:SUAutomaticUpdatePromptImpatienceTimer target:self selector:@selector(showUpdateAlert) userInfo:nil repeats:NO] retain]; + } } - (void)stopUpdatingOnTermination