Bladeren bron

UI: Use shared cookie manager for YT Control Panel

Use the cookie manager shared by service integration browser docks for
YouTube Control Panel.

This will enable users of the YouTube Chat panel have a better (creator
facing) experience for observed chat message latency, for those users
who sign-in to the YouTube Control Panel or YouTube Live Chat.

NOTE: This commit does not have any migration logic for existing
logged-in users of YTCP, they will need to sign-in again. Based on usage
stats, this is not going to affect a large fraction of OBS users.
Suman Manjunath 1 jaar geleden
bovenliggende
commit
492309c504
4 gewijzigde bestanden met toevoegingen van 41 en 23 verwijderingen
  1. 18 1
      UI/auth-youtube.cpp
  2. 1 0
      UI/auth-youtube.hpp
  3. 21 20
      UI/window-dock-youtube-app.cpp
  4. 1 2
      UI/window-dock-youtube-app.hpp

+ 18 - 1
UI/auth-youtube.cpp

@@ -55,6 +55,14 @@ static inline void OpenBrowser(const QString auth_uri)
 	QDesktopServices::openUrl(url);
 }
 
+static void DeleteCookies()
+{
+	if (panel_cookies) {
+		panel_cookies->DeleteCookies("youtube.com", "");
+		panel_cookies->DeleteCookies("google.com", "");
+	}
+}
+
 void RegisterYoutubeAuth()
 {
 	for (auto &service : youtubeServices) {
@@ -64,7 +72,7 @@ void RegisterYoutubeAuth()
 				return std::make_shared<YoutubeApiWrappers>(
 					service);
 			},
-			YoutubeAuth::Login, []() { return; });
+			YoutubeAuth::Login, DeleteCookies);
 	}
 }
 
@@ -216,6 +224,15 @@ void YoutubeAuth::ResetChat()
 #endif
 }
 
+void YoutubeAuth::ReloadChat()
+{
+#ifdef BROWSER_AVAILABLE
+	if (chat && chat->cefWidget) {
+		chat->cefWidget->reloadPage();
+	}
+#endif
+}
+
 QString YoutubeAuth::GenerateState()
 {
 	char state[YOUTUBE_API_STATE_LENGTH + 1];

+ 1 - 0
UI/auth-youtube.hpp

@@ -60,6 +60,7 @@ public:
 
 	void SetChatId(const QString &chat_id, const std::string &api_chat_id);
 	void ResetChat();
+	void ReloadChat();
 
 	static std::shared_ptr<Auth> Login(QWidget *parent,
 					   const std::string &service);

+ 21 - 20
UI/window-dock-youtube-app.cpp

@@ -33,22 +33,13 @@ static constexpr const char *INGESTION_STOPPED = "INGESTION_STOPPED";
 
 YouTubeAppDock::YouTubeAppDock(const QString &title)
 	: BrowserDock(title),
-	  dockBrowser(nullptr),
-	  cookieManager(nullptr)
+	  dockBrowser(nullptr)
 {
 	cef->init_browser();
 	OBSBasic::InitBrowserPanelSafeBlock();
 	AddYouTubeAppDock();
 }
 
-YouTubeAppDock::~YouTubeAppDock()
-{
-	if (cookieManager) {
-		cookieManager->FlushStore();
-		delete cookieManager;
-	}
-}
-
 bool YouTubeAppDock::IsYTServiceSelected()
 {
 	if (!cef_js_avail)
@@ -78,9 +69,12 @@ void YouTubeAppDock::SettingsUpdated(bool cleanup)
 
 	// definitely cleanup if YT switched off
 	if (!ytservice || cleanup) {
-		if (cookieManager)
-			cookieManager->DeleteCookies("", "");
+		if (panel_cookies) {
+			panel_cookies->DeleteCookies("youtube.com", "");
+			panel_cookies->DeleteCookies("google.com", "");
+		}
 	}
+
 	if (ytservice)
 		Update();
 }
@@ -135,16 +129,9 @@ void YouTubeAppDock::AddYouTubeAppDock()
 
 void YouTubeAppDock::CreateBrowserWidget(const std::string &url)
 {
-	std::string dir_name = std::string("obs_profile_cookies_youtube/") +
-			       config_get_string(OBSBasic::Get()->Config(),
-						 "Panels", "CookieId");
-	if (cookieManager)
-		delete cookieManager;
-	cookieManager = cef->create_cookie_manager(dir_name, true);
-
 	if (dockBrowser)
 		delete dockBrowser;
-	dockBrowser = cef->create_widget(this, url, cookieManager);
+	dockBrowser = cef->create_widget(this, url, panel_cookies);
 	if (!dockBrowser)
 		return;
 
@@ -152,6 +139,10 @@ void YouTubeAppDock::CreateBrowserWidget(const std::string &url)
 		dockBrowser->allowAllPopups(true);
 
 	this->SetWidget(dockBrowser);
+
+	QWidget::connect(dockBrowser.get(), &QCefWidget::urlChanged, this,
+			 &YouTubeAppDock::ReloadChatDock);
+
 	Update();
 }
 
@@ -348,6 +339,16 @@ void YouTubeAppDock::UpdateChannelId()
 	}
 }
 
+void YouTubeAppDock::ReloadChatDock()
+{
+	if (IsUserSignedIntoYT()) {
+		YoutubeApiWrappers *apiYouTube = GetYTApi();
+		if (apiYouTube) {
+			apiYouTube->ReloadChat();
+		}
+	}
+}
+
 void YouTubeAppDock::SetInitEvent(streaming_mode_t mode, const char *event,
 				  const char *video_id, const char *channelId)
 {

+ 1 - 2
UI/window-dock-youtube-app.hpp

@@ -11,7 +11,6 @@ class YouTubeAppDock : public BrowserDock {
 
 public:
 	YouTubeAppDock(const QString &title);
-	~YouTubeAppDock();
 
 	enum streaming_mode_t { YTSM_ACCOUNT, YTSM_STREAM_KEY };
 
@@ -43,11 +42,11 @@ private:
 	void DispatchYTEvent(const char *event, const char *video_id,
 			     streaming_mode_t mode);
 	void UpdateChannelId();
+	void ReloadChatDock();
 	void SetInitEvent(streaming_mode_t mode, const char *event = nullptr,
 			  const char *video_id = nullptr,
 			  const char *channelId = nullptr);
 
 	QString channelId;
 	QPointer<QCefWidget> dockBrowser;
-	QCefCookieManager *cookieManager; // is not a Qt object
 };