Only update Twitch tab content when switching to it

This should reduce the potential lag introduced when querying the token
status using the Twitch API
This commit is contained in:
WarmUpTill 2024-05-11 11:39:28 +02:00 committed by WarmUpTill
parent 69b82ee2a3
commit 3ab2ea9e66

View File

@ -29,6 +29,12 @@ static void setTabVisible(QTabWidget *tabWidget, bool visible)
obs_module_text("AdvSceneSwitcher.twitchConnectionTab.title"));
}
static bool twitchTabIsSelected(QTabWidget *tabWidget)
{
return tabWidget->tabText(tabWidget->currentIndex()) ==
obs_module_text("AdvSceneSwitcher.twitchConnectionTab.title");
}
TwitchConnectionsTable *TwitchConnectionsTable::Create()
{
tabWidget = new TwitchConnectionsTable();
@ -211,11 +217,11 @@ static void setupTab(QTabWidget *tab)
}
});
auto timer = new QTimer(tabWidget);
timer->setInterval(1000);
QWidget::connect(timer, &QTimer::timeout,
[]() { updateConnectionStatus(tabWidget->Table()); });
timer->start();
QWidget::connect(tab, &QTabWidget::currentChanged, [tab]() {
if (twitchTabIsSelected(tab)) {
updateConnectionStatus(tabWidget->Table());
}
});
}
} // namespace advss