diff --git a/launcher/ui/themes/ThemeManager.cpp b/launcher/ui/themes/ThemeManager.cpp index c1af63dc8..a7076da5a 100644 --- a/launcher/ui/themes/ThemeManager.cpp +++ b/launcher/ui/themes/ThemeManager.cpp @@ -50,6 +50,11 @@ ThemeManager::ThemeManager() initializeCatPacks(); } +ThemeManager::~ThemeManager() +{ + stopSettingNewWindowColorsOnMac(); +} + /// @brief Adds the Theme to the list of themes /// @param theme The Theme to add /// @return Theme ID @@ -179,6 +184,8 @@ void ThemeManager::setTitlebarColorOnMac(WId windowId, QColor color) {} void ThemeManager::setTitlebarColorOfAllWindowsOnMac(QColor color) {} +void ThemeManager::stopSettingNewWindowColorsOnMac() +{} #endif QList ThemeManager::getValidIconThemes() diff --git a/launcher/ui/themes/ThemeManager.h b/launcher/ui/themes/ThemeManager.h index dd33523d8..8baa88627 100644 --- a/launcher/ui/themes/ThemeManager.h +++ b/launcher/ui/themes/ThemeManager.h @@ -39,6 +39,7 @@ inline auto themeWarningLog() class ThemeManager { public: ThemeManager(); + ~ThemeManager(); QList getValidIconThemes(); QList getValidApplicationThemes(); @@ -86,6 +87,8 @@ class ThemeManager { // This also will set the titlebar color of newly opened windows after this method is called. // On non-Mac systems, this is a no-op. void setTitlebarColorOfAllWindowsOnMac(QColor color); + // On non-Mac systems, this is a no-op. + void stopSettingNewWindowColorsOnMac(); #ifdef Q_OS_MACOS NSObject* m_windowTitlebarObserver = nullptr; #endif diff --git a/launcher/ui/themes/ThemeManager.mm b/launcher/ui/themes/ThemeManager.mm index 21b3d8e35..d9fc291b6 100644 --- a/launcher/ui/themes/ThemeManager.mm +++ b/launcher/ui/themes/ThemeManager.mm @@ -53,10 +53,7 @@ void ThemeManager::setTitlebarColorOfAllWindowsOnMac(QColor color) // There's no notification for when a new window is opened, but we can set the color when a window switches // from occluded to visible, which also fires on open. NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; - if (m_windowTitlebarObserver) { - [center removeObserver:m_windowTitlebarObserver]; - m_windowTitlebarObserver = nil; - } + stopSettingNewWindowColorsOnMac(); m_windowTitlebarObserver = [center addObserverForName:NSWindowDidChangeOcclusionStateNotification object:nil queue:[NSOperationQueue mainQueue] @@ -65,3 +62,12 @@ void ThemeManager::setTitlebarColorOfAllWindowsOnMac(QColor color) setTitlebarColorOnMac((WId)window.contentView, color); }]; } + +void ThemeManager::stopSettingNewWindowColorsOnMac() +{ + if (m_windowTitlebarObserver) { + NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; + [center removeObserver:m_windowTitlebarObserver]; + m_windowTitlebarObserver = nil; + } +}