Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes 244857

Made a first crack at redifining the SUUpdater delegate protocol. Still not sure about a couple things, so please don't change your delegate methods to conform until this gets merged into trunk.

Also made the SUUpdateDrivers not have the updater's delegate as their delegate (that was really icky). Now they're just coupled with the SUUpdater, which is icky as well, but less icky, at least.
  • Loading branch information...
commit b3f39444958a7e0d63c39b22117e8d3fd5af6aca 1 parent 3146ffb
@andymatuschak andymatuschak authored
View
38 SUBasicUpdateDriver.m
@@ -34,9 +34,10 @@ - (void)checkForUpdatesAtURL:(NSURL *)appcastURL host:(SUHost *)aHost
{
id <SUVersionComparison> comparator = nil;
+ SUUpdater *updater = [SUUpdater updaterForBundle:[host bundle]];
// Give the delegate a chance to provide a custom version comparator
- if ([delegate respondsToSelector:@selector(versionComparatorForHost:)])
- comparator = [delegate versionComparatorForHost:host];
+ if ([[updater delegate] respondsToSelector:@selector(versionComparatorForUpdater:)])
+ comparator = [[updater delegate] versionComparatorForUpdater:updater];
// If we don't get a comparator from the delegate, use the default comparator
if (!comparator)
@@ -70,13 +71,14 @@ - (BOOL)itemContainsValidUpdate:(SUAppcastItem *)ui
- (void)appcastDidFinishLoading:(SUAppcast *)ac
{
- if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:forHost:)])
- [delegate appcastDidFinishLoading:ac forHost:host];
+ SUUpdater *updater = [SUUpdater updaterForBundle:[host bundle]];
+ if ([[updater delegate] respondsToSelector:@selector(updater:didFinishLoadingAppcast:)])
+ [[updater delegate] updater:updater didFinishLoadingAppcast:ac];
// Now we have to find the best valid update in the appcast.
- if ([delegate respondsToSelector:@selector(bestValidUpdateInAppcast:forHost:)]) // Does the delegate want to handle it?
+ if ([[updater delegate] respondsToSelector:@selector(bestValidUpdateInAppcast:forUpdater:)]) // Does the delegate want to handle it?
{
- updateItem = [delegate bestValidUpdateInAppcast:ac forHost:host];
+ updateItem = [[updater delegate] bestValidUpdateInAppcast:ac forUpdater:updater];
}
else // If not, we'll take care of it ourselves.
{
@@ -105,15 +107,17 @@ - (void)appcast:(SUAppcast *)ac failedToLoadWithError:(NSError *)error
- (void)didFindValidUpdate
{
- if ([delegate respondsToSelector:@selector(didFindValidUpdate:toHost:)])
- [delegate didFindValidUpdate:updateItem toHost:host];
+ SUUpdater *updater = [SUUpdater updaterForBundle:[host bundle]];
+ if ([[updater delegate] respondsToSelector:@selector(updater:didFindValidUpdate:)])
+ [[updater delegate] updater:updater didFindValidUpdate:updateItem];
[self downloadUpdate];
}
- (void)didNotFindUpdate
{
- if ([delegate respondsToSelector:@selector(didNotFindUpdateToHost:)])
- [delegate didNotFindUpdateToHost:host];
+ SUUpdater *updater = [SUUpdater updaterForBundle:[host bundle]];
+ if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)])
+ [[updater delegate] updaterDidNotFindUpdate:updater];
[self abortUpdateWithError:[NSError errorWithDomain:SUSparkleErrorDomain code:SUNoUpdateError userInfo:[NSDictionary dictionaryWithObject:[NSString stringWithFormat:SULocalizedString(@"You already have the newest version of %@.", nil), [host name]] forKey:NSLocalizedDescriptionKey]]];
}
@@ -206,8 +210,9 @@ - (BOOL)shouldInstallSynchronously { return NO; }
- (void)installUpdate
{
- if ([delegate respondsToSelector:@selector(updateWillInstall:toHost:)])
- [delegate updateWillInstall:updateItem toHost:host];
+ SUUpdater *updater = [SUUpdater updaterForBundle:[host bundle]];
+ if ([[updater delegate] respondsToSelector:@selector(updater:willInstallUpdate:)])
+ [[updater delegate] updater:updater willInstallUpdate:updateItem];
// 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]];
@@ -229,21 +234,22 @@ - (void)relaunchHostApp
{
// Give the host app an opportunity to postpone the relaunch.
static BOOL postponedOnce = NO;
- if (!postponedOnce && [delegate respondsToSelector:@selector(shouldPostponeRelaunchForUpdate:toHost:untilInvoking:)])
+ SUUpdater *updater = [SUUpdater updaterForBundle:[host bundle]];
+ if (!postponedOnce && [[updater delegate] respondsToSelector:@selector(updater:shouldPostponeRelaunchForUpdate:untilInvoking:)])
{
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[[self class] instanceMethodSignatureForSelector:@selector(relaunchHostApp)] retain]];
[invocation setSelector:@selector(relaunchHostApp)];
[invocation setTarget:self];
postponedOnce = YES;
- if ([delegate shouldPostponeRelaunchForUpdate:updateItem toHost:host untilInvoking:invocation])
+ if ([[updater delegate] updater:updater shouldPostponeRelaunchForUpdate:updateItem untilInvoking:invocation])
return;
}
[self cleanUp]; // Clean up the download and extracted files.
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self];
- if ([delegate respondsToSelector:@selector(updaterWillRelaunchApplication)])
- [delegate updaterWillRelaunchApplication];
+ if ([[updater delegate] respondsToSelector:@selector(updaterWillRelaunchApplication)])
+ [[updater delegate] updaterWillRelaunchApplication:updater];
if(!relaunchPath || ![[NSFileManager defaultManager] fileExistsAtPath:relaunchPath])
{
View
7 SUUIBasedUpdateDriver.m
@@ -28,8 +28,9 @@ - (void)didFindValidUpdate
- (void)didNotFindUpdate
{
- if ([delegate respondsToSelector:@selector(didNotFindUpdateToHost:)])
- [delegate didNotFindUpdateToHost:host];
+ SUUpdater *updater = [SUUpdater updaterForBundle:[host bundle]];
+ if ([[updater delegate] respondsToSelector:@selector(updaterDidNotFindUpdate:)])
+ [[updater delegate] updaterDidNotFindUpdate:updater];
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), [host name], [host displayVersion]];
[alert setIcon:[host icon]];
[alert runModal];
@@ -45,8 +46,6 @@ - (void)applicationDidBecomeActive:(NSNotification *)aNotification
- (void)updateAlert:(SUUpdateAlert *)alert finishedWithChoice:(SUUpdateAlertChoice)choice
{
[updateAlert release]; updateAlert = nil;
- if ([delegate respondsToSelector:@selector(userChoseAction:forUpdate:toHost:)])
- [delegate userChoseAction:choice forUpdate:updateItem toHost:host];
[host setObject:nil forUserDefaultsKey:SUSkippedVersionKey];
switch (choice)
{
View
3  SUUpdateDriver.h
@@ -19,14 +19,11 @@ extern NSString *SUUpdateDriverFinishedNotification;
SUHost *host;
BOOL finished;
- id delegate;
}
- (void)checkForUpdatesAtURL:(NSURL *)appcastURL host:(SUHost *)hb;
- (void)abortUpdate;
- (BOOL)finished;
-- delegate;
-- (void)setDelegate:delegate;
@end
#endif
View
2  SUUpdateDriver.m
@@ -23,6 +23,4 @@ - (void)abortUpdate
}
- (BOOL)finished { return finished; }
-- delegate { return delegate; }
-- (void)setDelegate:del { delegate = del; }
@end
View
27 SUUpdater.h
@@ -23,8 +23,10 @@
+ (SUUpdater *)sharedUpdater;
+ (SUUpdater *)updaterForBundle:(NSBundle *)bundle;
+- (NSBundle *)hostBundle;
- (void)setDelegate:(id)delegate;
+- delegate;
// This IBAction is meant for a main menu item. Hook up any menu item to this action,
// and Sparkle will check for updates and report back its findings verbosely.
@@ -47,40 +49,37 @@
@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 *)feedParametersForHost:(SUHost *)bundle sendingSystemProfile:(BOOL)sendingProfile;
+// Sparkle will also be sending along the system profile. This method should return an array of dictionaries with keys: "key" and "value".
+- (NSArray *)feedParametersForUpdater:(SUUpdater *)updater sendingSystemProfile:(BOOL)sendingProfile;
// Use this to override the default behavior for Sparkle prompting the user about automatic update checks.
-- (BOOL)shouldPromptForPermissionToCheckForUpdatesToHost:(SUHost *)bundle;
+- (BOOL)updaterShouldPromptForPermissionToCheckForUpdates:(SUUpdater *)bundle;
// Implement this if you want to do some special handling with the appcast once it finishes loading.
-- (void)appcastDidFinishLoading:(SUAppcast *)appcast forHost:(SUHost *)bundle;
+- (void)updater:(SUUpdater *)updater didFinishLoadingAppcast:(SUAppcast *)appcast;
// 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 forHost:(SUHost *)bundle;
+- (SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forUpdater:(SUUpdater *)bundle;
// Sent when a valid update is found by the update driver.
-- (void)didFindValidUpdate:(SUAppcastItem *)update toHost:(SUHost *)bundle;
+- (void)updater:(SUUpdater *)updater didFindValidUpdate:(SUAppcastItem *)update;
// Sent when a valid update is not found.
-- (void)didNotFindUpdateToHost:(SUHost *)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 toHost:(SUHost *)bundle;
+- (void)updaterDidNotFindUpdate:(SUUpdater *)update;
// Sent immediately before installing the specified update.
-- (void)updateWillInstall:(SUAppcastItem *)update toHost:(SUHost *)bundle;
+- (void)updater:(SUUpdater *)updater willInstallUpdate:(SUAppcastItem *)update;
// Return YES to delay the relaunch until you do some processing; invoke the given NSInvocation to continue.
-- (BOOL)shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update toHost:(SUHost *)hostBundle untilInvoking:(NSInvocation *)invocation;
+- (BOOL)updater:(SUUpdater *)updater shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update untilInvoking:(NSInvocation *)invocation;
// Called immediately before relaunching.
-- (void)updaterWillRelaunchApplication;
+- (void)updaterWillRelaunchApplication:(SUUpdater *)updater;
// This method allows you to provide a custom version comparator.
// If you don't implement this method or return nil, the standard version comparator will be used.
-- (id <SUVersionComparison>)versionComparatorForHost:(SUHost *)hb;
+- (id <SUVersionComparison>)versionComparatorForUpdater:(SUUpdater *)updater;
@end
View
26 SUUpdater.m
@@ -82,9 +82,9 @@ - (void)applicationDidFinishLaunching:(NSNotification *)note
shouldPrompt = NO;
}
// Does the delegate want to take care of the logic for when we should ask permission to update?
- else if ([delegate respondsToSelector:@selector(shouldPromptForPermissionToCheckForUpdatesToHostBundle:)])
+ else if ([delegate respondsToSelector:@selector(updaterShouldPromptForPermissionToCheckForUpdates:)])
{
- shouldPrompt = [delegate shouldPromptForPermissionToCheckForUpdatesToHost:host];
+ shouldPrompt = [delegate updaterShouldPromptForPermissionToCheckForUpdates:self];
}
// Has he been asked already? And don't ask if the host has a default value set in its Info.plist.
else if ([host objectForUserDefaultsKey:SUEnableAutomaticChecksKey] == nil &&
@@ -175,7 +175,6 @@ - (void)checkForUpdatesWithDriver:(SUUpdateDriver *)d
[NSException raise:@"SUNoFeedURL" format:@"You must specify the URL of the appcast as the SUFeedURLKey in either the Info.plist or the user defaults!"];
driver = [d retain];
- if ([driver delegate] == nil) { [driver setDelegate:delegate]; }
[driver checkForUpdatesAtURL:[self feedURL] host:host];
}
@@ -271,8 +270,8 @@ - (NSURL *)feedURL
// Determine all the parameters we're attaching to the base feed URL.
BOOL sendingSystemProfile = ([host boolForUserDefaultsKey:SUSendProfileInfoKey] == YES);
NSArray *parameters = [NSArray array];
- if ([delegate respondsToSelector:@selector(feedParametersForHostBundle:sendingSystemProfile:)])
- parameters = [parameters arrayByAddingObjectsFromArray:[delegate feedParametersForHost:host sendingSystemProfile:sendingSystemProfile]];
+ if ([delegate respondsToSelector:@selector(feedParametersForUpdater:sendingSystemProfile:)])
+ parameters = [parameters arrayByAddingObjectsFromArray:[delegate feedParametersForUpdater:self sendingSystemProfile:sendingSystemProfile]];
if (sendingSystemProfile)
parameters = [parameters arrayByAddingObjectsFromArray:[host systemProfile]];
if (parameters == nil || [parameters count] == 0) { return baseFeedURL; }
@@ -329,20 +328,7 @@ - (BOOL)updateInProgress
return driver && ([driver finished] == NO);
}
-// Redirect driver delegate methods to our delegate
-/*
-- (void)appcastDidFinishLoading:(SUAppcast *)appcast forHost:(SUHost *)bundle
-{
- if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:forHost:)])
- [delegate appcastDidFinishLoading:ac forHost:bundle];
-}
-
-- (SUAppcastItem *)bestValidUpdateInAppcast:(SUAppcast *)appcast forHost:(SUHost *)bundle
-{
- if ([delegate respondsToSelector:@selector(bestValidUpdateInAppcast:forHost:)]) // Does the delegate want to handle it?
- return [delegate bestValidUpdateInAppcast:ac forHost:bundle];
- else
- return nil;
-}*/
+- delegate { return delegate; }
+- (NSBundle *)hostBundle { return [host bundle]; }
@end
Please sign in to comment.
Something went wrong with that request. Please try again.