From 528c6f25ed0a243929a9a65ca539be4b8fcd3fd8 Mon Sep 17 00:00:00 2001 From: Zorg Date: Sun, 27 Mar 2016 15:46:40 -0400 Subject: [PATCH] Remove user defaults observing in standard updater controller If these settings are changed, they should be changed through SUUpdater, honestly. Morever, this user defaults code retains the controller. --- Sparkle/SUStandardUpdaterController.m | 44 +-------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/Sparkle/SUStandardUpdaterController.m b/Sparkle/SUStandardUpdaterController.m index ab7a145e..ee114dd9 100644 --- a/Sparkle/SUStandardUpdaterController.m +++ b/Sparkle/SUStandardUpdaterController.m @@ -34,7 +34,7 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults - (instancetype)initWithUpdater:(SUUpdater *)updater userDriver:(id)userDriver { - self = [self init]; // note: call our own init here rather than super's + self = [super init]; if (self != nil) { self.updater = updater; self.userDriver = userDriver; @@ -43,17 +43,6 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults return self; } -// Invoked from being instantiated in a nib -- (instancetype)init -{ - self = [super init]; - if (self != nil) { - // Register as an observer here to match unregistering in -dealloc - [self registerAsObserver]; - } - return self; -} - - (void)awakeFromNib { // awakeFromNib might be called more than once; guard against that @@ -69,11 +58,6 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults } } -- (void)dealloc -{ - [self unregisterAsObserver]; -} - - (IBAction)checkForUpdates:(id)__unused sender { [self.updater checkForUpdates]; @@ -87,30 +71,4 @@ static NSString *const SUUpdaterDefaultsObservationContext = @"SUUpdaterDefaults return YES; } -- (void)registerAsObserver -{ - [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[@"values." stringByAppendingString:SUScheduledCheckIntervalKey] options:(NSKeyValueObservingOptions)0 context:(__bridge void *)(SUUpdaterDefaultsObservationContext)]; - - [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:[@"values." stringByAppendingString:SUEnableAutomaticChecksKey] options:(NSKeyValueObservingOptions)0 context:(__bridge void *)(SUUpdaterDefaultsObservationContext)]; -} - -- (void)unregisterAsObserver -{ - [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[@"values." stringByAppendingString:SUScheduledCheckIntervalKey]]; - [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:[@"values." stringByAppendingString:SUEnableAutomaticChecksKey]]; -} - -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context -{ - if (context == (__bridge void *)(SUUpdaterDefaultsObservationContext)) { - // Allow a small delay, because perhaps the user or developer wants to change both preferences. This allows the developer to interpret a zero check interval as a sign to disable automatic checking. - // Or we may get this from the developer and from our own KVO observation, this will effectively coalesce them. - [self.updater resetUpdateCycleAfterShortDelay]; - } else { - if ([super respondsToSelector:@selector(observeValueForKeyPath:ofObject:change:context:)]) { - [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; - } - } -} - @end