Browse Source

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.
Ryan Foster 3 năm trước cách đây
mục cha
commit
54a808c34a
3 tập tin đã thay đổi với 14 bổ sung2 xóa
  1. 10 2
      UI/auth-twitch.cpp
  2. 2 0
      UI/obs-app.cpp
  3. 2 0
      UI/obs-app.hpp

+ 10 - 2
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;

+ 2 - 0
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;

+ 2 - 0
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<OBSMainWindow> 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; }