From fba7231261d29fcc2d3acd2754dc7794411e3aca Mon Sep 17 00:00:00 2001 From: Andy Matuschak Date: Fri, 10 Sep 2010 17:12:45 -0700 Subject: [PATCH] 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]. --- SUUpdater.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/SUUpdater.m b/SUUpdater.m index 2a1bdf70..00e2f7ff 100644 --- a/SUUpdater.m +++ b/SUUpdater.m @@ -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