1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

ScopedNotificationCenterObserver: Fix dark mode detection regression on macOS

This commit is contained in:
reuk 2023-01-04 18:56:45 +00:00
parent 4e68af7fde
commit c9ebb167a3
No known key found for this signature in database
GPG key ID: FCB43929F012EE5C
2 changed files with 21 additions and 12 deletions

View file

@ -535,22 +535,26 @@ class ScopedNotificationCenterObserver
public:
ScopedNotificationCenterObserver() = default;
ScopedNotificationCenterObserver (id observerIn, SEL selector, NSNotificationName nameIn, id objectIn)
: observer (observerIn), name (nameIn), object (objectIn)
ScopedNotificationCenterObserver (id observerIn,
SEL selector,
NSNotificationName nameIn,
id objectIn,
Class klassIn = [NSNotificationCenter class])
: observer (observerIn), name (nameIn), object (objectIn), klass (klassIn)
{
[[NSNotificationCenter defaultCenter] addObserver: observer
selector: selector
name: name
object: object];
[[klass defaultCenter] addObserver: observer
selector: selector
name: name
object: object];
}
~ScopedNotificationCenterObserver()
{
if (observer != nullptr && name != nullptr)
{
[[NSNotificationCenter defaultCenter] removeObserver: observer
name: name
object: object];
[[klass defaultCenter] removeObserver: observer
name: name
object: object];
}
}
@ -561,8 +565,7 @@ public:
ScopedNotificationCenterObserver& operator= (ScopedNotificationCenterObserver&& other) noexcept
{
auto moved = std::move (other);
swap (moved);
ScopedNotificationCenterObserver (std::move (other)).swap (*this);
return *this;
}
@ -575,11 +578,13 @@ private:
std::swap (other.observer, observer);
std::swap (other.name, name);
std::swap (other.object, object);
std::swap (other.klass, klass);
}
id observer = nullptr;
NSNotificationName name = nullptr;
id object = nullptr;
Class klass = nullptr;
};
} // namespace juce

View file

@ -513,7 +513,11 @@ public:
{
static DelegateClass delegateClass;
delegate.reset ([delegateClass.createInstance() init]);
observer.emplace (delegate.get(), darkModeSelector, @"AppleInterfaceThemeChangedNotification", nil);
observer.emplace (delegate.get(),
darkModeSelector,
@"AppleInterfaceThemeChangedNotification",
nil,
[NSDistributedNotificationCenter class]);
}
private: