From 3ab2ea9e66558cc1cba65684427d36aca32c9831 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sat, 11 May 2024 11:39:28 +0200 Subject: [PATCH] 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 --- plugins/twitch/twitch-tab.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/plugins/twitch/twitch-tab.cpp b/plugins/twitch/twitch-tab.cpp index a1020829..837aaf1e 100644 --- a/plugins/twitch/twitch-tab.cpp +++ b/plugins/twitch/twitch-tab.cpp @@ -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