From b82189656086beddf1af0542c82201302e7b6807 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Fri, 10 Jun 2022 22:35:51 -0700 Subject: [PATCH] [Visualizer] Constrain SceneKit visualizer events Constrain observer events to the exact context requested, and remove them with the same context specified. Signed-off-by: Christopher Snowhill --- Visualization/SpectrumView.m | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Visualization/SpectrumView.m b/Visualization/SpectrumView.m index 30c9830bd..286438cb4 100644 --- a/Visualization/SpectrumView.m +++ b/Visualization/SpectrumView.m @@ -15,7 +15,7 @@ #define LOWER_BOUND -80 -void *kSpectrumViewContext = &kSpectrumViewContext; +static void *kSpectrumViewContext = &kSpectrumViewContext; extern NSString *CogPlaybackDidBeginNotficiation; extern NSString *CogPlaybackDidPauseNotficiation; @@ -80,9 +80,11 @@ extern NSString *CogPlaybackDidStopNotficiation; change:(NSDictionary *)change context:(void *)context { if(context == kSpectrumViewContext) { - [self updateControls]; - } else if([keyPath isEqualToString:@"self.window.visible"]) { - [self updateVisListening]; + if([keyPath isEqualToString:@"self.window.visible"]) { + [self updateVisListening]; + } else { + [self updateControls]; + } } } @@ -185,7 +187,7 @@ extern NSString *CogPlaybackDidStopNotficiation; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumBarColor" options:0 context:kSpectrumViewContext]; [[NSUserDefaultsController sharedUserDefaultsController] addObserver:self forKeyPath:@"values.spectrumDotColor" options:0 context:kSpectrumViewContext]; - [self addObserver:self forKeyPath:@"self.window.visible" options:0 context:nil]; + [self addObserver:self forKeyPath:@"self.window.visible" options:0 context:kSpectrumViewContext]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidBegin:) @@ -217,11 +219,11 @@ extern NSString *CogPlaybackDidStopNotficiation; - (void)removeObservers { if(observersAdded) { - [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumProjectionMode"]; - [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumBarColor"]; - [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumDotColor"]; + [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumProjectionMode" context:kSpectrumViewContext]; + [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumBarColor" context:kSpectrumViewContext]; + [[NSUserDefaultsController sharedUserDefaultsController] removeObserver:self forKeyPath:@"values.spectrumDotColor" context:kSpectrumViewContext]; - [self removeObserver:self forKeyPath:@"self.window.visible" context:nil]; + [self removeObserver:self forKeyPath:@"self.window.visible" context:kSpectrumViewContext]; [[NSNotificationCenter defaultCenter] removeObserver:self name:CogPlaybackDidBeginNotficiation