diff options
author | Damiano Galassi <[email protected]> | 2020-04-12 09:24:39 +0200 |
---|---|---|
committer | Damiano Galassi <[email protected]> | 2020-04-12 09:24:39 +0200 |
commit | de9b27a42c017fa4ccfe5e3577d6f623a81efe6e (patch) | |
tree | 0f782556d758d0fb2f10af948c4a66d202c22c7f /macosx | |
parent | edf1e2f70090eacae73f22772310cb11afb8a1f5 (diff) |
MacGui: improve some NSNotificationCenter calls to avoid listening to unwanted notifications.
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/HBAddCategoryController.m | 8 | ||||
-rw-r--r-- | macosx/HBController.m | 7 | ||||
-rw-r--r-- | macosx/HBPresetsManager.m | 2 | ||||
-rw-r--r-- | macosx/HBPresetsMenuBuilder.m | 2 | ||||
-rw-r--r-- | macosx/HBQueueDockTileController.m | 11 | ||||
-rw-r--r-- | macosx/HBRenamePresetController.m | 4 |
6 files changed, 22 insertions, 12 deletions
diff --git a/macosx/HBAddCategoryController.m b/macosx/HBAddCategoryController.m index 598f70460..f7d5eb9dc 100644 --- a/macosx/HBAddCategoryController.m +++ b/macosx/HBAddCategoryController.m @@ -36,14 +36,14 @@ { [super windowDidLoad]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(controlTextDidChange:) - name:NSControlTextDidChangeNotification object:nil]; + [NSNotificationCenter.defaultCenter addObserver:self + selector:@selector(controlTextDidChange:) + name:NSControlTextDidChangeNotification object:self.name]; } - (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self name:NSControlTextDidChangeNotification object:nil]; + [NSNotificationCenter.defaultCenter removeObserver:self name:NSControlTextDidChangeNotification object:self.name]; } - (void)controlTextDidChange:(NSNotification *)obj { diff --git a/macosx/HBController.m b/macosx/HBController.m index fe1e07dac..dbca9c863 100644 --- a/macosx/HBController.m +++ b/macosx/HBController.m @@ -1102,8 +1102,11 @@ static void *HBControllerLogLevelContext = &HBControllerLogLevelContext; - (void)removeQueueObservers { - [NSNotificationCenter.defaultCenter removeObserver:self.observerToken]; - self.observerToken = nil; + if (self.observerToken) + { + [NSNotificationCenter.defaultCenter removeObserver:self.observerToken]; + self.observerToken = nil; + } } #pragma mark - Job Handling diff --git a/macosx/HBPresetsManager.m b/macosx/HBPresetsManager.m index d1a11cb56..ebaa5ff4b 100644 --- a/macosx/HBPresetsManager.m +++ b/macosx/HBPresetsManager.m @@ -49,7 +49,7 @@ NSString *HBPresetsChangedNotification = @"HBPresetsChangedNotification"; - (void)nodeDidChange:(HBTreeNode *)node { - [NSNotificationCenter.defaultCenter postNotificationName:HBPresetsChangedNotification object:nil]; + [NSNotificationCenter.defaultCenter postNotificationName:HBPresetsChangedNotification object:self]; } - (void)treeDidRemoveNode:(HBTreeNode *)node diff --git a/macosx/HBPresetsMenuBuilder.m b/macosx/HBPresetsMenuBuilder.m index fa296c228..6045f7468 100644 --- a/macosx/HBPresetsMenuBuilder.m +++ b/macosx/HBPresetsMenuBuilder.m @@ -26,7 +26,7 @@ _manager = manager; _action = action; - [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(build) name:HBPresetsChangedNotification object:nil]; + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(build) name:HBPresetsChangedNotification object:manager]; } return self; diff --git a/macosx/HBQueueDockTileController.m b/macosx/HBQueueDockTileController.m index 2845411c0..2442e274c 100644 --- a/macosx/HBQueueDockTileController.m +++ b/macosx/HBQueueDockTileController.m @@ -44,6 +44,10 @@ [NSNotificationCenter.defaultCenter addObserverForName:HBQueueDidChangeStateNotification object:_queue queue:NSOperationQueue.mainQueue usingBlock:^(NSNotification * _Nonnull note) { [self setUpObservers]; }]; + + [NSNotificationCenter.defaultCenter addObserverForName:HBQueueDidCompleteNotification + object:_queue queue:NSOperationQueue.mainQueue + usingBlock:^(NSNotification * _Nonnull note) { self.dockTile.stringValue = @""; }]; } return self; } @@ -109,8 +113,11 @@ - (void)removeObservers { - [NSNotificationCenter.defaultCenter removeObserver:self.observerToken]; - self.observerToken = nil; + if (self.observerToken) + { + [NSNotificationCenter.defaultCenter removeObserver:self.observerToken]; + self.observerToken = nil; + } } @end diff --git a/macosx/HBRenamePresetController.m b/macosx/HBRenamePresetController.m index 7f95d63b4..4b944f36c 100644 --- a/macosx/HBRenamePresetController.m +++ b/macosx/HBRenamePresetController.m @@ -46,12 +46,12 @@ [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(controlTextDidChange:) - name:NSControlTextDidChangeNotification object:nil]; + name:NSControlTextDidChangeNotification object:self.name]; } - (void)dealloc { - [NSNotificationCenter.defaultCenter removeObserver:self name:NSControlTextDidChangeNotification object:nil]; + [NSNotificationCenter.defaultCenter removeObserver:self name:NSControlTextDidChangeNotification object:self.name]; } - (void)controlTextDidChange:(NSNotification *)obj { |