Browse Source

UI: Cache YouTube channel name

This prevents having to look up the YouTube channel every time the
settings window is opened.

Closes obsproject/obs-studio#5154
jp9000 4 years ago
parent
commit
a6fdc47535
2 changed files with 20 additions and 27 deletions
  1. 9 0
      UI/auth-youtube.cpp
  2. 11 27
      UI/window-basic-settings-stream.cpp

+ 9 - 0
UI/auth-youtube.cpp

@@ -287,5 +287,14 @@ std::shared_ptr<Auth> YoutubeAuth::Login(QWidget *owner,
 		return nullptr;
 	}
 
+	config_t *config = OBSBasic::Get()->Config();
+	config_remove_value(config, "YouTube", "ChannelName");
+
+	ChannelDescription cd;
+	if (auth->GetChannelDescription(cd))
+		config_set_string(config, "YouTube", "ChannelName",
+				  QT_TO_UTF8(cd.title));
+
+	config_save_safe(config, "tmp", nullptr);
 	return auth;
 }

+ 11 - 27
UI/window-basic-settings-stream.cpp

@@ -412,23 +412,17 @@ static void reset_service_ui_fields(Ui::OBSBasicSettings *ui,
 }
 
 #if YOUTUBE_ENABLED
-static void get_yt_ch_title(Ui::OBSBasicSettings *ui,
-			    YoutubeApiWrappers *ytAuth)
+static void get_yt_ch_title(Ui::OBSBasicSettings *ui)
 {
-	if (ytAuth) {
-		ChannelDescription cd;
-		if (ytAuth->GetChannelDescription(cd)) {
-			ui->connectedAccountText->setText(cd.title);
-		} else {
-			// if we still not changed the service page
-			if (IsYouTubeService(
-				    QT_TO_UTF8(ui->service->currentText()))) {
-				ui->connectedAccountText->setText(
-					ytAuth->GetLastError().isEmpty()
-						? QTStr("Auth.LoadingChannel.Error")
-						: QTStr("YouTube.AuthError.Text")
-							  .arg(ytAuth->GetLastError()));
-			}
+	const char *name = config_get_string(OBSBasic::Get()->Config(),
+					     "YouTube", "ChannelName");
+	if (name) {
+		ui->connectedAccountText->setText(name);
+	} else {
+		// if we still not changed the service page
+		if (IsYouTubeService(QT_TO_UTF8(ui->service->currentText()))) {
+			ui->connectedAccountText->setText(
+				QTStr("Auth.LoadingChannel.Error"));
 		}
 	}
 }
@@ -615,17 +609,7 @@ void OBSBasicSettings::OnOAuthStreamKeyConnected()
 			ui->connectedAccountText->setText(
 				QTStr("Auth.LoadingChannel.Title"));
 
-			std::string a_service = a->service();
-			std::shared_ptr<YoutubeApiWrappers> ytAuth =
-				std::dynamic_pointer_cast<YoutubeApiWrappers>(
-					auth);
-			auto act = [&]() {
-				get_yt_ch_title(ui.get(), ytAuth.get());
-			};
-
-			QScopedPointer<QThread> thread(CreateQThread(act));
-			thread->start();
-			thread->wait();
+			get_yt_ch_title(ui.get());
 		}
 #endif
 		ui->bandwidthTestEnable->setChecked(false);