mirror of
https://github.com/sparkle-project/Sparkle
synced 2026-11-25 04:47:55 +00:00
Made SUUpdateDriver use notifications instead of KVO to let SUUpdater know it's done.
This commit is contained in:
1 parent
b2145b6838
commit
bc52c0141a
3 files changed
+15
-8
No files matched your search
@@ -11,6 +11,8 @@
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
extern NSString *SUUpdateDriverFinishedNotification;
|
||||
|
||||
@interface SUUpdateDriver : NSObject
|
||||
{
|
||||
BOOL finished;
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#import "SUUpdateDriver.h"
|
||||
|
||||
NSString *SUUpdateDriverFinishedNotification = @"SUUpdateDriverFinished";
|
||||
|
||||
@implementation SUUpdateDriver
|
||||
- (void)checkForUpdatesAtURL:(NSURL *)appcastURL hostBundle:(NSBundle *)hb
|
||||
@@ -18,6 +19,7 @@
|
||||
- (void)abortUpdate
|
||||
{
|
||||
[self setValue:[NSNumber numberWithBool:YES] forKey:@"finished"];
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:SUUpdateDriverFinishedNotification object:self];
|
||||
}
|
||||
|
||||
- (BOOL)finished { return finished; }
|
||||
|
||||
+11
-8
@@ -46,6 +46,7 @@ static SUUpdater *sharedUpdater = nil;
|
||||
sharedUpdater = self;
|
||||
[self setHostBundle:[NSBundle mainBundle]];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidFinishLaunching:) name:NSApplicationDidFinishLaunchingNotification object:NSApp];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(driverDidFinish:) name:SUUpdateDriverFinishedNotification object:nil];
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[@"values." stringByAppendingString:SUScheduledCheckIntervalKey] options:0 context:NULL];
|
||||
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[@"values." stringByAppendingString:SUEnableAutomaticChecksKey] options:0 context:NULL];
|
||||
}
|
||||
@@ -132,19 +133,12 @@ static SUUpdater *sharedUpdater = nil;
|
||||
|
||||
driver = [d retain];
|
||||
if ([driver delegate] == nil) { [driver setDelegate:delegate]; }
|
||||
[driver addObserver:self forKeyPath:@"finished" options:0 context:NULL];
|
||||
[driver checkForUpdatesAtURL:[self feedURL] hostBundle:hostBundle];
|
||||
}
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
||||
{
|
||||
if (object == driver && [keyPath isEqualToString:@"finished"])
|
||||
{
|
||||
[driver removeObserver:self forKeyPath:@"finished"];
|
||||
[driver release]; driver = nil;
|
||||
[self scheduleNextUpdateCheck];
|
||||
}
|
||||
else if (object == [NSUserDefaultsController sharedUserDefaultsController] && ([keyPath hasSuffix:SUScheduledCheckIntervalKey] || [keyPath hasSuffix:SUEnableAutomaticChecksKey]))
|
||||
if (object == [NSUserDefaultsController sharedUserDefaultsController] && ([keyPath hasSuffix:SUScheduledCheckIntervalKey] || [keyPath hasSuffix:SUEnableAutomaticChecksKey]))
|
||||
{
|
||||
[self updatePreferencesChanged];
|
||||
}
|
||||
@@ -247,6 +241,7 @@ static SUUpdater *sharedUpdater = nil;
|
||||
[hostBundle release];
|
||||
[delegate release];
|
||||
if (checkTimer) { [checkTimer invalidate]; }
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
@@ -275,4 +270,12 @@ static SUUpdater *sharedUpdater = nil;
|
||||
return driver && ([driver finished] == NO);
|
||||
}
|
||||
|
||||
- (void)driverDidFinish:(NSNotification *)notification
|
||||
{
|
||||
if ([notification object] != driver) return;
|
||||
[driver release];
|
||||
driver = nil;
|
||||
[self scheduleNextUpdateCheck];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user