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
This commit is contained in:
parent
083461698d
commit
a6fdc47535
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user