Show remaining time while waiting for Twitch token approval

And increase the timeout to 2 minutes just in case
This commit is contained in:
WarmUpTill
2026-11-09 19:41:52 +01:00
parent b3f47cdb68
commit 1d5fa1752d
3 changed files with 28 additions and 6 deletions

View File

@@ -5,6 +5,7 @@
#include <obs-module-helper.hpp>
#include <algorithm>
#include <QDesktopServices>
#include <QGroupBox>
#include <QScrollArea>
@@ -20,6 +21,7 @@
namespace advss {
static const int tokenGrabberPort = 42171;
static const int tokenTimeoutSeconds = 120;
static std::deque<std::shared_ptr<Item>> twitchTokens;
@@ -684,6 +686,8 @@ TwitchTokenSettingsDialog::TwitchTokenSettingsDialog(
QWidget::connect(&_validationTimer, &QTimer::timeout, this,
&TwitchTokenSettingsDialog::CheckIfTokenValid);
QWidget::connect(&_countdownTimer, &QTimer::timeout, this,
&TwitchTokenSettingsDialog::UpdateWaitingStatus);
_validationTimer.start(10000);
CheckIfTokenValid();
}
@@ -825,12 +829,29 @@ void TwitchTokenSettingsDialog::RequestToken()
_validationTimer.stop();
_tokenGrabber.SetTokenScope(scope);
_tokenGrabber.start();
_tokenStatus->setText(obs_module_text(
"AdvSceneSwitcher.twitchToken.request.waiting"));
_tokenDeadline = std::chrono::steady_clock::now() +
std::chrono::seconds(tokenTimeoutSeconds);
UpdateWaitingStatus();
_countdownTimer.start(1000);
}
void TwitchTokenSettingsDialog::UpdateWaitingStatus()
{
const auto remaining = std::chrono::ceil<std::chrono::seconds>(
_tokenDeadline - std::chrono::steady_clock::now());
const QString remainingText =
QString(obs_module_text(
"AdvSceneSwitcher.twitchToken.request.waiting.remaining"))
.arg(std::max<long long>(remaining.count(), 0));
_tokenStatus->setText(
QString(obs_module_text(
"AdvSceneSwitcher.twitchToken.request.waiting")) +
" " + remainingText);
}
void TwitchTokenSettingsDialog::GotToken(const std::optional<QString> &value)
{
_countdownTimer.stop();
_currentTokenValue->setText(value.value_or(""));
if (!value) {
_tokenStatus->setText(obs_module_text(
@@ -898,8 +919,6 @@ bool TwitchTokenSettingsDialog::AskForSettings(QWidget *parent,
return true;
}
int TokenGrabberThread::_timeout = 15;
TokenGrabberThread::~TokenGrabberThread()
{
_stopWaiting = true;
@@ -1010,7 +1029,7 @@ void TokenGrabberThread::run()
vblog(LOG_INFO, "Token server stopped!");
});
auto time = std::chrono::high_resolution_clock::now() +
std::chrono::seconds(_timeout);
std::chrono::seconds(tokenTimeoutSeconds);
while (!_stopWaiting) {
if (_cv.wait_until(lock, time) == std::cv_status::timeout) {
break;

View File

@@ -96,7 +96,6 @@ private:
QString _scope;
std::optional<QString> _tokenString;
static int _timeout;
std::mutex _mutex;
std::atomic_bool _stopWaiting = {false};
std::condition_variable _cv;
@@ -118,6 +117,7 @@ private slots:
void RequestToken();
void GotToken(const std::optional<QString> &);
void CheckIfTokenValid();
void UpdateWaitingStatus();
private:
std::set<TokenOption> GetEnabledOptions();
@@ -136,6 +136,8 @@ private:
QCheckBox *_validateTimestamps;
QCheckBox *_warnIfInvalid;
QTimer _validationTimer;
QTimer _countdownTimer;
std::chrono::steady_clock::time_point _tokenDeadline;
};
class TwitchConnectionSelection : public ItemSelection {