We used to not register SUUpdater as an observer of the shared user defaults controller if we were running as a bundle. The performance win is minimal, and if I stop doing that, we won't accidentally try to unregister as an observer and bother developers who break on [NSException raise].

This commit is contained in:
Andy Matuschak committed 2010-09-10 17:16:31 -07:00
1 parent b3ac18f173
commit fba7231261
1 file changed
+5 -5
+5 -5
View File
@@ -210,22 +210,22 @@ static NSString * const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefault
- (void)registerAsObserver
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDriverDidFinish:) name:SUUpdateDriverFinishedNotification object:nil];
// No sense observing the shared NSUserDefaultsController when we're not updating the main bundle.
if ([host bundle] != [NSBundle mainBundle]) return;
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[@"values." stringByAppendingString:SUScheduledCheckIntervalKey] options:0 context:SUUpdaterDefaultsObservationContext];
[[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[@"values." stringByAppendingString:SUEnableAutomaticChecksKey] options:0 context:SUUpdaterDefaultsObservationContext];
}
- (void)unregisterAsObserver
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
// Removing self as a KVO observer if no observer was registered leads to an NSException. But we don't care.
@try
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[@"values." stringByAppendingString:SUScheduledCheckIntervalKey]];
[[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[@"values." stringByAppendingString:SUEnableAutomaticChecksKey]];
}
@catch (NSException *e) { }
@catch (NSException *e)
{
NSLog(@"Sparkle Error: [SUUpdater unregisterAsObserver] called, but the updater wasn't registered as an observer.");
}
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context