From 54a808c34a1defdafbb6e78ee9a88310ea90ae2c Mon Sep 17 00:00:00 2001 From: Ryan Foster Date: Sun, 21 Nov 2021 10:44:19 -0500 Subject: [PATCH] UI: Set Twitch Panel Dark Mode using OBS theme Check if the current OBS theme is "Dark Mode"-esque and use that to determine if the Twitch browser panel docks should use Twitch's Dark Mode or not. --- UI/auth-twitch.cpp | 12 ++++++++++-- UI/obs-app.cpp | 2 ++ UI/obs-app.hpp | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/UI/auth-twitch.cpp b/UI/auth-twitch.cpp index eac2a72e6..13206ac83 100644 --- a/UI/auth-twitch.cpp +++ b/UI/auth-twitch.cpp @@ -229,7 +229,11 @@ void TwitchAuth::LoadUI() chat->SetWidget(browser); cef->add_force_popup_url(moderation_tools_url, chat.data()); - script = "localStorage.setItem('twilight.theme', 1);"; + if (App()->IsThemeDark()) { + script = "localStorage.setItem('twilight.theme', 1);"; + } else { + script = "localStorage.setItem('twilight.theme', 0);"; + } const int twAddonChoice = config_get_int(main->Config(), service(), "AddonChoice"); @@ -276,7 +280,11 @@ void TwitchAuth::LoadSecondaryUIPanes() QSize size = main->frameSize(); QPoint pos = main->pos(); - script = "localStorage.setItem('twilight.theme', 1);"; + if (App()->IsThemeDark()) { + script = "localStorage.setItem('twilight.theme', 1);"; + } else { + script = "localStorage.setItem('twilight.theme', 0);"; + } script += referrer_script1; script += "https://www.twitch.tv/"; script += name; diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index f9d74edd8..782ff4e38 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -1121,6 +1121,8 @@ bool OBSApp::SetTheme(std::string name, std::string path) setPalette(defaultPalette); ParseExtraThemeData(path.c_str()); setStyleSheet(mpath); + QColor color = palette().text().color(); + themeDarkMode = !(color.redF() < 0.5); emit StyleChanged(); return true; diff --git a/UI/obs-app.hpp b/UI/obs-app.hpp index 6592d5bbc..a534f6d25 100644 --- a/UI/obs-app.hpp +++ b/UI/obs-app.hpp @@ -74,6 +74,7 @@ class OBSApp : public QApplication { private: std::string locale; std::string theme; + bool themeDarkMode = true; ConfigFile globalConfig; TextLookup textLookup; QPointer mainWindow; @@ -127,6 +128,7 @@ public: inline const char *GetTheme() const { return theme.c_str(); } bool SetTheme(std::string name, std::string path = ""); + inline bool IsThemeDark() const { return themeDarkMode; }; inline lookup_t *GetTextLookup() const { return textLookup; }