Permalink
Browse files

Improved delegate names and made SUProbingUpdateDriver use SUUpdater'…

…s delegate methods instead of dumbly having its own.

IF YOU ARE IMPLEMENTING ANY DELEGATE METHODS TO A SPARKLE CLASS, CHECK THESE DIFFS AND ENSURE THAT THE SELECTORS YOU'RE IMPLEMENTING HAVEN'T CHANGED. There's a pretty good chance they have. But for good reason, I promise!
  • Loading branch information...
1 parent d77ca73 commit 7d8ada58e9a119a24139bcb2529f2e6a917d6cf4 @andymatuschak andymatuschak committed Jun 29, 2008
Showing with 33 additions and 33 deletions.
  1. +12 −10 SUBasicUpdateDriver.m
  2. +0 −5 SUProbingUpdateDriver.h
  3. +2 −4 SUProbingUpdateDriver.m
  4. +4 −2 SUUIBasedUpdateDriver.m
  5. +11 −8 SUUpdater.h
  6. +4 −4 SUUpdater.m
View
@@ -58,17 +58,17 @@ - (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui
- (void)appcastDidFinishLoading:(SUAppcast *)ac
{
- if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:)])
- [delegate appcastDidFinishLoading:ac];
+ if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:forHostBundle:)])
+ [delegate appcastDidFinishLoading:ac forHostBundle:hostBundle];
NSArray* updates = [ac items];
if ([updates count] > 0)
[[SUUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:SULastCheckTimeKey];
// Now we have to find the best valid update in the appcast.
- if ([delegate respondsToSelector:@selector(bestValidUpdateInAppcast:)]) // Does the delegate want to handle it?
+ if ([delegate respondsToSelector:@selector(bestValidUpdateInAppcast:forHostBundle:)]) // Does the delegate want to handle it?
{
- updateItem = [delegate bestValidUpdateInAppcast:ac];
+ updateItem = [delegate bestValidUpdateInAppcast:ac forHostBundle:hostBundle];
}
else // If not, we'll take care of it ourselves.
{
@@ -97,13 +97,15 @@ - (void)appcast:(SUAppcast *)ac failedToLoadWithError:(NSError *)error
- (void)didFindValidUpdate
{
- if ([delegate respondsToSelector:@selector(didFindValidUpdate:)])
- [delegate didFindValidUpdate:updateItem];
+ if ([delegate respondsToSelector:@selector(didFindValidUpdate:toHostBundle:)])
+ [delegate didFindValidUpdate:updateItem toHostBundle:hostBundle];
[self downloadUpdate];
}
- (void)didNotFindUpdate
{
+ if ([delegate respondsToSelector:@selector(didNotFindUpdateToHostBundle:)])
+ [delegate didNotFindUpdateToHostBundle:hostBundle];
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNoUpdateError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"You already have the newest version of %@.", nil), [hostBundle name]] forKey:NSLocalizedDescriptionKey]]];
}
@@ -190,8 +192,8 @@ - (BOOL)shouldInstallSynchronously { return NO; }
- (void)installUpdate
{
- if ([delegate respondsToSelector:@selector(updateWillInstall:)])
- [delegate updateWillInstall:updateItem];
+ if ([delegate respondsToSelector:@selector(updateWillInstall:toHostBundle:)])
+ [delegate updateWillInstall:updateItem toHostBundle:hostBundle];
// Copy the relauncher into a temporary directory so we can get to it after the new version's installed.
NSString *relaunchPathToCopy = [[NSBundle bundleForClass:[self class]] pathForResource:@"relaunch" ofType:@""];
NSString *targetPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[relaunchPathToCopy lastPathComponent]];
@@ -213,13 +215,13 @@ - (void)relaunchHostApp
{
// Give the host app an opportunity to postpone the relaunch.
static BOOL postponedOnce = NO;
- if (!postponedOnce && [delegate respondsToSelector:@selector(shouldPostponeRelaunchForUpdate:untilInvoking:)])
+ if (!postponedOnce && [delegate respondsToSelector:@selector(shouldPostponeRelaunchForUpdate:toHostBundle:untilInvoking:)])
{
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[[self class] instanceMethodSignatureForSelector:@selector(relaunchHostApp)] retain]];
[invocation setSelector:@selector(relaunchHostApp)];
[invocation setTarget:self];
postponedOnce = YES;
- if ([delegate shouldPostponeRelaunchForUpdate:updateItem untilInvoking:invocation])
+ if ([delegate shouldPostponeRelaunchForUpdate:updateItem toHostBundle:hostBundle untilInvoking:invocation])
return;
}
@@ -16,9 +16,4 @@
@interface SUProbingUpdateDriver : SUBasicUpdateDriver { }
@end
-@interface NSObject (SUProbeDriverDelegateProtocol)
-- (void)didFindValidUpdate:(SUAppcastItem *)item toHostBundle:(NSBundle *)hb;
-- (void)didNotFindUpdateToHostBundle:(NSBundle *)hb;
-@end
-
#endif
@@ -11,17 +11,15 @@
@implementation SUProbingUpdateDriver
+// Stop as soon as we have an answer! The superclasses will already have taken care of notifying the delegate.
+
- (void)didFindValidUpdate
{
- if ([delegate respondsToSelector:@selector(didFindValidUpdate:toHostBundle:)])
- [delegate didFindValidUpdate:updateItem toHostBundle:hostBundle];
[self abortUpdate];
}
- (void)didNotFindUpdate
{
- if ([delegate respondsToSelector:@selector(didNotFindUpdateToHostBundle:)])
- [delegate didNotFindUpdateToHostBundle:hostBundle];
[self abortUpdate];
}
@@ -29,6 +29,8 @@ - (void)didFindValidUpdate
- (void)didNotFindUpdate
{
+ if ([delegate respondsToSelector:@selector(didNotFindUpdateToHostBundle:)])
+ [delegate didNotFindUpdateToHostBundle:hostBundle];
NSAlert *alert = [NSAlert alertWithMessageText:SULocalizedString(@"You're up to date!", nil) defaultButton:SULocalizedString(@"OK", nil) alternateButton:nil otherButton:nil informativeTextWithFormat:SULocalizedString(@"%@ %@ is currently the newest version available.", nil), [hostBundle name], [hostBundle displayVersion]];
[alert setIcon:[hostBundle icon]];
[alert runModal];
@@ -44,8 +46,8 @@ - (void)applicationDidBecomeActive:(NSNotification *)aNotification
- (void)updateAlert:(SUUpdateAlert *)alert finishedWithChoice:(SUUpdateAlertChoice)choice
{
[updateAlert release]; updateAlert = nil;
- if ([delegate respondsToSelector:@selector(userChoseAction:forUpdate:)])
- [delegate userChoseAction:choice forUpdate:updateItem];
+ if ([delegate respondsToSelector:@selector(userChoseAction:forUpdate:toHostBundle:)])
+ [delegate userChoseAction:choice forUpdate:updateItem toHostBundle:hostBundle];
[[SUUserDefaults standardUserDefaults] setObject:nil forKey:SUSkippedVersionKey];
switch (choice)
{
View
@@ -46,29 +46,32 @@
@interface NSObject (SUUpdaterDelegateInformalProtocol)
// This method allows you to add extra parameters to the appcast URL, potentially based on whether or not
// Sparkle will also be sending along the system profile. This method should return an array of dictionaries with the following keys:
-- (NSArray *)feedParametersForUpdater:(SUUpdater *)updater sendingSystemProfile:(BOOL)sendingProfile;
+- (NSArray *)feedParametersForHostBundle:(NSBundle *)bundle sendingSystemProfile:(BOOL)sendingProfile;
// Use this to override the default behavior for Sparkle prompting the user about automatic update checks.
-- (BOOL)shouldPromptForPermissionToCheckForUpdates;
+- (BOOL)shouldPromptForPermissionToCheckForUpdatesToHostBundle:(NSBundle *)bundle;
// Implement this if you want to do some special handling with the appcast once it finishes loading.
-- (void)appcastDidFinishLoading:(SUAppcast *)appcast;
+- (void)appcastDidFinishLoading:(SUAppcast *)appcast forHostBundle:(NSBundle *)bundle;
// If you're using special logic or extensions in your appcast, implement this to use your own logic for finding
// a valid update, if any, in the given appcast.
-- (SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast;
+- (SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forHostBundle:(NSBundle *)bundle;
// Sent when a valid update is found by the update driver.
-- (void)didFindValidUpdate:(SUAppcastItem *)update;
+- (void)didFindValidUpdate:(SUAppcastItem *)update toHostBundle:(NSBundle *)bundle;
+
+// Sent when a valid update is not found.
+- (void)didNotFindUpdateToHostBundle:(NSBundle *)hb;
// Sent when the user makes a choice in the update alert dialog (install now / remind me later / skip this version).
-- (void)userChoseAction:(SUUpdateAlertChoice)action forUpdate:(SUAppcastItem *)update;
+- (void)userChoseAction:(SUUpdateAlertChoice)action forUpdate:(SUAppcastItem *)update toHostBundle:(NSBundle *)bundle;
// Sent immediately before installing the specified update.
-- (void)updateWillInstall:(SUAppcastItem *)update;
+- (void)updateWillInstall:(SUAppcastItem *)update toHostBundle:(NSBundle *)bundle;
// Return YES to delay the relaunch until you do some processing; invoke the given NSInvocation to continue.
-- (BOOL)shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update untilInvoking:(NSInvocation *)invocation;
+- (BOOL)shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update toHostBundle:(NSBundle *)hostBundle untilInvoking:(NSInvocation *)invocation;
// Called immediately before relaunching.
- (void)updaterWillRelaunchApplication;
View
@@ -58,9 +58,9 @@ - (void)applicationDidFinishLaunching:(NSNotification *)note
[[SUUserDefaults standardUserDefaults] boolForKey:SUEnableAutomaticChecksKey] == NO) { return; }
// Does the delegate want to take care of the logic for when we should ask permission to update?
- if ([delegate respondsToSelector:@selector(shouldPromptForPermissionToCheckForUpdates)])
+ if ([delegate respondsToSelector:@selector(shouldPromptForPermissionToCheckForUpdatesToHostBundle)])
{
- if ([delegate shouldPromptForPermissionToCheckForUpdates])
+ if ([delegate shouldPromptForPermissionToCheckForUpdatesToHostBundle:hostBundle])
[SUUpdatePermissionPrompt promptWithHostBundle:hostBundle delegate:self];
}
// Has he been asked already? And don't ask if the host has a default value set in its Info.plist.
@@ -202,8 +202,8 @@ - (NSArray *)feedParameters
{
BOOL sendingSystemProfile = ([[SUUserDefaults standardUserDefaults] boolForKey:SUSendProfileInfoKey] == YES);
NSArray *parameters = [NSArray array];
- if ([delegate respondsToSelector:@selector(feedParametersForUpdater:sendingSystemProfile:)])
- parameters = [parameters arrayByAddingObjectsFromArray:[delegate feedParametersForUpdater:self sendingSystemProfile:sendingSystemProfile]];
+ if ([delegate respondsToSelector:@selector(feedParametersForHostBundle:sendingSystemProfile:)])
+ parameters = [parameters arrayByAddingObjectsFromArray:[delegate feedParametersForHostBundle:hostBundle sendingSystemProfile:sendingSystemProfile]];
if (sendingSystemProfile)
parameters = [parameters arrayByAddingObjectsFromArray:[hostBundle systemProfile]];
return parameters;

0 comments on commit 7d8ada5

Please sign in to comment.