|
@@ -138,14 +138,6 @@ bool YoutubeAuth::LoadInternal()
|
|
|
return implicit ? !token.empty() : !refresh_token.empty();
|
|
|
}
|
|
|
|
|
|
-#ifdef BROWSER_AVAILABLE
|
|
|
-static const char *ytchat_script = "\
|
|
|
-const obsCSS = document.createElement('style');\
|
|
|
-obsCSS.innerHTML = \"#panel-pages.yt-live-chat-renderer {display: none;}\
|
|
|
-yt-live-chat-viewer-engagement-message-renderer {display: none;}\";\
|
|
|
-document.querySelector('head').appendChild(obsCSS);";
|
|
|
-#endif
|
|
|
-
|
|
|
void YoutubeAuth::LoadUI()
|
|
|
{
|
|
|
if (uiLoaded)
|
|
@@ -171,7 +163,6 @@ void YoutubeAuth::LoadUI()
|
|
|
|
|
|
browser = cef->create_widget(chat, YOUTUBE_CHAT_PLACEHOLDER_URL,
|
|
|
panel_cookies);
|
|
|
- browser->setStartupScript(ytchat_script);
|
|
|
|
|
|
chat->SetWidget(browser);
|
|
|
main->AddDockWidget(chat, Qt::RightDockWidgetArea);
|
|
@@ -219,6 +210,7 @@ void YoutubeAuth::ResetChat()
|
|
|
{
|
|
|
#ifdef BROWSER_AVAILABLE
|
|
|
if (chat && chat->cefWidget) {
|
|
|
+ chat->SetApiChatId("");
|
|
|
chat->cefWidget->setURL(YOUTUBE_CHAT_PLACEHOLDER_URL);
|
|
|
}
|
|
|
#endif
|
|
@@ -399,13 +391,44 @@ void YoutubeChatDock::SetWidget(QCefWidget *widget_)
|
|
|
setWidget(widget);
|
|
|
|
|
|
cefWidget.reset(widget_);
|
|
|
+
|
|
|
+ QWidget::connect(cefWidget.get(), &QCefWidget::urlChanged, this,
|
|
|
+ &YoutubeChatDock::YoutubeCookieCheck);
|
|
|
}
|
|
|
|
|
|
void YoutubeChatDock::SetApiChatId(const std::string &id)
|
|
|
{
|
|
|
this->apiChatId = id;
|
|
|
- QMetaObject::invokeMethod(this, "EnableChatInput",
|
|
|
- Qt::QueuedConnection);
|
|
|
+ QMetaObject::invokeMethod(this, "EnableChatInput", Qt::QueuedConnection,
|
|
|
+ Q_ARG(bool, !id.empty()));
|
|
|
+}
|
|
|
+
|
|
|
+void YoutubeChatDock::YoutubeCookieCheck()
|
|
|
+{
|
|
|
+ QPointer<YoutubeChatDock> this_ = this;
|
|
|
+ auto cb = [this_](bool currentlyLoggedIn) {
|
|
|
+ bool previouslyLoggedIn = this_->isLoggedIn;
|
|
|
+ this_->isLoggedIn = currentlyLoggedIn;
|
|
|
+ bool loginStateChanged =
|
|
|
+ (currentlyLoggedIn && !previouslyLoggedIn) ||
|
|
|
+ (!currentlyLoggedIn && previouslyLoggedIn);
|
|
|
+ if (loginStateChanged) {
|
|
|
+ QMetaObject::invokeMethod(
|
|
|
+ this_, "EnableChatInput", Qt::QueuedConnection,
|
|
|
+ Q_ARG(bool, !currentlyLoggedIn));
|
|
|
+ OBSBasic *main = OBSBasic::Get();
|
|
|
+ if (main->GetYouTubeAppDock() != nullptr) {
|
|
|
+ QMetaObject::invokeMethod(
|
|
|
+ main->GetYouTubeAppDock(),
|
|
|
+ "SettingsUpdated", Qt::QueuedConnection,
|
|
|
+ Q_ARG(bool, !currentlyLoggedIn));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ if (panel_cookies) {
|
|
|
+ panel_cookies->CheckForCookie("https://www.youtube.com", "SID",
|
|
|
+ cb);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void YoutubeChatDock::SendChatMessage()
|
|
@@ -442,9 +465,10 @@ void YoutubeChatDock::ShowErrorMessage(const QString &error)
|
|
|
QTStr("YouTube.Chat.Error.Text").arg(error));
|
|
|
}
|
|
|
|
|
|
-void YoutubeChatDock::EnableChatInput()
|
|
|
+void YoutubeChatDock::EnableChatInput(bool visible)
|
|
|
{
|
|
|
- lineEdit->setVisible(true);
|
|
|
- sendButton->setVisible(true);
|
|
|
+ bool setVisible = visible && !isLoggedIn;
|
|
|
+ lineEdit->setVisible(setVisible);
|
|
|
+ sendButton->setVisible(setVisible);
|
|
|
}
|
|
|
#endif
|