mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-29 05:24:26 +00:00
Fixes bug 228446
Finally adding real delegate support. The following methods are implemented; the comments document them. If you have suggestions for other methods that would be useful, feel free to suggest them. // Use this to override the default behavior for Sparkle prompting the user about automatic update checks. - (BOOL)shouldPromptForPermissionToCheckForUpdates; // Implement this if you want to do some special handling with the appcast once it finishes loading. - (void)appcastDidFinishLoading:(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; // Sent when a valid update is found by the update driver. - (void)didFindValidUpdate:(SUAppcastItem *)update; // 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; // Sent immediately before installing the specified update. - (void)updateWillInstall:(SUAppcastItem *)update; // Return YES to delay the relaunch until you do some processing; invoke the given NSInvocation to continue. - (BOOL)shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update untilInvoking:(NSInvocation *)invocation; // Called immediately before relaunching. - (void)updaterWillRelaunchApplication;
This commit is contained in:
1 parent
ebb1f01735
commit
5c32832eed
6 files changed
+86
-24
No files matched your search
@@ -23,6 +23,8 @@
|
||||
NSURL *fileURL;
|
||||
NSString *versionString;
|
||||
NSString *displayVersionString;
|
||||
|
||||
NSDictionary *propertiesDictionary;
|
||||
}
|
||||
|
||||
// Initializes with data from a dictionary provided by the RSS class.
|
||||
@@ -38,6 +40,9 @@
|
||||
- (NSString *)DSASignature;
|
||||
- (NSString *)minimumSystemVersion;
|
||||
|
||||
// Returns the dictionary provided in initWithDictionary; this might be useful later for extensions.
|
||||
- (NSDictionary *)propertiesDictionary;
|
||||
|
||||
@end
|
||||
|
||||
#endif
|
||||
@@ -97,6 +97,7 @@
|
||||
self = [super init];
|
||||
if (self)
|
||||
{
|
||||
propertiesDictionary = [dict retain];
|
||||
[self setTitle:[dict objectForKey:@"title"]];
|
||||
[self setDate:[dict objectForKey:@"pubDate"]];
|
||||
[self setDescription:[dict objectForKey:@"description"]];
|
||||
@@ -156,7 +157,13 @@
|
||||
[self setFileURL:nil];
|
||||
[self setVersionString:nil];
|
||||
[self setDisplayVersionString:nil];
|
||||
[propertiesDictionary release];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (NSDictionary *)propertiesDictionary
|
||||
{
|
||||
return propertiesDictionary;
|
||||
}
|
||||
|
||||
@end
|
||||
+37
-8
@@ -58,17 +58,28 @@
|
||||
|
||||
- (void)appcastDidFinishLoading:(SUAppcast *)ac
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(appcastDidFinishLoading:)])
|
||||
[delegate appcastDidFinishLoading:ac];
|
||||
|
||||
NSArray* updates = [ac items];
|
||||
if ([updates count] > 0)
|
||||
[[SUUserDefaults standardUserDefaults] setObject:[NSDate date] forKey:SULastCheckTimeKey];
|
||||
|
||||
// Find the first update we can actually use.
|
||||
NSEnumerator *updateEnumerator = [updates objectEnumerator];
|
||||
do {
|
||||
updateItem = [updateEnumerator nextObject];
|
||||
} while (updateItem && ![self hostSupportsItem:updateItem]);
|
||||
|
||||
[updateItem retain];
|
||||
// Now we have to find the best valid update in the appcast.
|
||||
if ([delegate respondsToSelector:@selector(bestValidUpdateInAppcast:)]) // Does the delegate want to handle it?
|
||||
{
|
||||
updateItem = [delegate bestValidUpdateInAppcast:ac];
|
||||
}
|
||||
else // If not, we'll take care of it ourselves.
|
||||
{
|
||||
// Find the first update we can actually use.
|
||||
NSEnumerator *updateEnumerator = [updates objectEnumerator];
|
||||
do {
|
||||
updateItem = [updateEnumerator nextObject];
|
||||
} while (updateItem && ![self hostSupportsItem:updateItem]);
|
||||
|
||||
[updateItem retain];
|
||||
}
|
||||
CFRelease(ac); // Remember that we're explicitly managing the memory of the appcast.
|
||||
if (updateItem == nil) { [self didNotFindUpdate]; return; }
|
||||
|
||||
@@ -86,6 +97,8 @@
|
||||
|
||||
- (void)didFindValidUpdate
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(didFindValidUpdate:)])
|
||||
[delegate didFindValidUpdate:updateItem];
|
||||
[self downloadUpdate];
|
||||
}
|
||||
|
||||
@@ -168,6 +181,8 @@
|
||||
|
||||
- (void)installUpdate
|
||||
{
|
||||
if ([delegate respondsToSelector:@selector(updateWillInstall:)])
|
||||
[delegate updateWillInstall: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]];
|
||||
@@ -188,8 +203,22 @@
|
||||
|
||||
- (void)relaunchHostApp
|
||||
{
|
||||
// Give the host app an opportunity to postpone the relaunch.
|
||||
static BOOL postponedOnce = NO;
|
||||
if (!postponedOnce && [delegate respondsToSelector:@selector(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 untilInvoking:invocation])
|
||||
return;
|
||||
}
|
||||
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdaterWillRestartNotification object:self];
|
||||
|
||||
if ([delegate respondsToSelector:@selector(updaterWillRelaunchApplication)])
|
||||
[delegate updaterWillRelaunchApplication];
|
||||
|
||||
@try
|
||||
{
|
||||
if(!relaunchPath || ![[NSFileManager defaultManager] fileExistsAtPath:relaunchPath])
|
||||
|
||||
@@ -43,6 +43,8 @@
|
||||
- (void)updateAlert:(SUUpdateAlert *)alert finishedWithChoice:(SUUpdateAlertChoice)choice
|
||||
{
|
||||
[updateAlert release]; updateAlert = nil;
|
||||
if ([delegate respondsToSelector:@selector(userChoseAction:forUpdate:)])
|
||||
[delegate userChoseAction:choice forUpdate:updateItem];
|
||||
[[SUUserDefaults standardUserDefaults] setObject:nil forKey:SUSkippedVersionKey];
|
||||
switch (choice)
|
||||
{
|
||||
|
||||
+28
-15
@@ -33,22 +33,35 @@
|
||||
@end
|
||||
|
||||
@interface NSObject (SUUpdaterDelegateInformalProtocol)
|
||||
/*!
|
||||
@method
|
||||
@abstract Delegate method for host apps to define additional feed parameters
|
||||
@discussion 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:
|
||||
|
||||
key: The key to be used when reporting data to the server
|
||||
|
||||
visibleKey: Alternate version of key to be used in UI displays of profile information
|
||||
|
||||
value: Value to be used when reporting data to the server
|
||||
|
||||
visibleValue: Alternate version of value to be used in UI displays of profile information.
|
||||
*/
|
||||
|
||||
|
||||
// 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;
|
||||
|
||||
// Use this to override the default behavior for Sparkle prompting the user about automatic update checks.
|
||||
- (BOOL)shouldPromptForPermissionToCheckForUpdates;
|
||||
|
||||
// Implement this if you want to do some special handling with the appcast once it finishes loading.
|
||||
- (void)appcastDidFinishLoading:(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;
|
||||
|
||||
// Sent when a valid update is found by the update driver.
|
||||
- (void)didFindValidUpdate:(SUAppcastItem *)update;
|
||||
|
||||
// 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;
|
||||
|
||||
// Sent immediately before installing the specified update.
|
||||
- (void)updateWillInstall:(SUAppcastItem *)update;
|
||||
|
||||
// Return YES to delay the relaunch until you do some processing; invoke the given NSInvocation to continue.
|
||||
- (BOOL)shouldPostponeRelaunchForUpdate:(SUAppcastItem *)update untilInvoking:(NSInvocation *)invocation;
|
||||
|
||||
// Called immediately before relaunching.
|
||||
- (void)updaterWillRelaunchApplication;
|
||||
|
||||
@end
|
||||
|
||||
// Define some minimum intervals to avoid DOS-like checking attacks. These are in seconds.
|
||||
|
||||
+7
-1
@@ -55,8 +55,14 @@ static SUUpdater *sharedUpdater = nil;
|
||||
if ([[SUUserDefaults standardUserDefaults] objectForKey:SUEnableAutomaticChecksKey] &&
|
||||
[[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 shouldPromptForPermissionToCheckForUpdates])
|
||||
[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.
|
||||
if ([[SUUserDefaults standardUserDefaults] objectForKey:SUEnableAutomaticChecksKey] == nil &&
|
||||
else if ([[SUUserDefaults standardUserDefaults] objectForKey:SUEnableAutomaticChecksKey] == nil &&
|
||||
[hostBundle objectForInfoDictionaryKey:SUEnableAutomaticChecksKey] == nil)
|
||||
{
|
||||
if ([[SUUserDefaults standardUserDefaults] objectForKey:SUEnableAutomaticChecksKeyOld])
|
||||
|
||||
Reference in new issue
Block a user