From a6fdc47535eac73bfcef56fdb552c447a95f919f Mon Sep 17 00:00:00 2001 From: jp9000 Date: Tue, 24 Aug 2021 18:42:54 -0700 Subject: [PATCH] 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 --- UI/auth-youtube.cpp | 9 +++++++ UI/window-basic-settings-stream.cpp | 38 +++++++++-------------------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/UI/auth-youtube.cpp b/UI/auth-youtube.cpp index f1fbd5e4e..5bd66d306 100644 --- a/UI/auth-youtube.cpp +++ b/UI/auth-youtube.cpp @@ -287,5 +287,14 @@ std::shared_ptr 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; } diff --git a/UI/window-basic-settings-stream.cpp b/UI/window-basic-settings-stream.cpp index 8775a07d0..4715eb7b7 100644 --- a/UI/window-basic-settings-stream.cpp +++ b/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 ytAuth = - std::dynamic_pointer_cast( - auth); - auto act = [&]() { - get_yt_ch_title(ui.get(), ytAuth.get()); - }; - - QScopedPointer thread(CreateQThread(act)); - thread->start(); - thread->wait(); + get_yt_ch_title(ui.get()); } #endif ui->bandwidthTestEnable->setChecked(false);