Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display warning if token expired or no token is selected #1013

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,8 @@ AdvSceneSwitcher.twitchToken.request.success.browser="Authentication successful!
AdvSceneSwitcher.twitchToken.request.notSet="Account is not connected!"
AdvSceneSwitcher.twitchToken.permissions="Token permissions:"
AdvSceneSwitcher.twitchToken.permissionsInsufficient="Permissions of selected token are insufficient to perform selected action!"
AdvSceneSwitcher.twitchToken.notValid="Selected token is invalid!"
AdvSceneSwitcher.twitchToken.noSelection="No token selected!"
AdvSceneSwitcher.twitchToken.channel.broadcast.manage="Manage a channel’s broadcast configuration, including updating channel configuration and managing stream markers and stream tags."
AdvSceneSwitcher.twitchToken.channel.subscriptions.read="Read channel's subscribers list and info."
AdvSceneSwitcher.twitchToken.moderator.followers.read="Read the followers of a broadcaster."
Expand Down
48 changes: 37 additions & 11 deletions plugins/twitch/macro-action-twitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,7 @@ MacroActionTwitchEdit::MacroActionTwitchEdit(
_layout(new QHBoxLayout()),
_actions(new FilterComboBox()),
_tokens(new TwitchConnectionSelection()),
_tokenPermissionWarning(new QLabel(obs_module_text(
"AdvSceneSwitcher.twitchToken.permissionsInsufficient"))),
_tokenWarning(new QLabel()),
_streamTitle(new VariableLineEdit(this)),
_category(new TwitchCategoryWidget(this)),
_markerDescription(new VariableLineEdit(this)),
Expand All @@ -496,10 +495,10 @@ MacroActionTwitchEdit::MacroActionTwitchEdit(
mainLayout->addLayout(_layout);
mainLayout->addWidget(_announcementMessage);
mainLayout->addWidget(_chatMessage);
mainLayout->addWidget(_tokenPermissionWarning);
mainLayout->addWidget(_tokenWarning);
setLayout(mainLayout);

_tokenPermissionCheckTimer.start(1000);
_tokenCheckTimer.start(1000);

UpdateEntryData();
_loading = false;
Expand Down Expand Up @@ -541,14 +540,42 @@ void MacroActionTwitchEdit::TwitchTokenChanged(const QString &token)
emit(HeaderInfoChanged(token));
}

void MacroActionTwitchEdit::CheckTokenPermissions()
void MacroActionTwitchEdit::SetTokenWarning(bool visible, const QString &text)
{
_tokenPermissionWarning->setVisible(
_entryData && !_entryData->ActionIsSupportedByToken());
_tokenWarning->setText(text);
_tokenWarning->setVisible(visible);
adjustSize();
updateGeometry();
}

void MacroActionTwitchEdit::CheckToken()
{
if (!_entryData) {
return;
}
if (_entryData->_token.expired()) {
SetTokenWarning(
true,
obs_module_text(
"AdvSceneSwitcher.twitchToken.noSelection"));
return;
}
if (!TokenIsValid(_entryData->_token)) {
SetTokenWarning(
true, obs_module_text(
"AdvSceneSwitcher.twitchToken.notValid"));
return;
}
if (!_entryData->ActionIsSupportedByToken()) {
SetTokenWarning(
true,
obs_module_text(
"AdvSceneSwitcher.twitchToken.permissionsInsufficient"));
return;
}
SetTokenWarning(false);
}

void MacroActionTwitchEdit::StreamTitleChanged()
{
if (_loading || !_entryData) {
Expand Down Expand Up @@ -649,8 +676,8 @@ void MacroActionTwitchEdit::SetWidgetSignalConnections()
SLOT(ActionChanged(int)));
QWidget::connect(_tokens, SIGNAL(SelectionChanged(const QString &)),
this, SLOT(TwitchTokenChanged(const QString &)));
QWidget::connect(&_tokenPermissionCheckTimer, SIGNAL(timeout()), this,
SLOT(CheckTokenPermissions()));
QWidget::connect(&_tokenCheckTimer, SIGNAL(timeout()), this,
SLOT(CheckToken()));
QWidget::connect(_streamTitle, SIGNAL(editingFinished()), this,
SLOT(StreamTitleChanged()));
QWidget::connect(_category,
Expand Down Expand Up @@ -710,8 +737,7 @@ void MacroActionTwitchEdit::SetWidgetVisibility()
AddStretchIfNecessary(_layout);
}

_tokenPermissionWarning->setVisible(
!_entryData->ActionIsSupportedByToken());
CheckToken();

adjustSize();
updateGeometry();
Expand Down
7 changes: 4 additions & 3 deletions plugins/twitch/macro-action-twitch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ class MacroActionTwitchEdit : public QWidget {
private slots:
void ActionChanged(int);
void TwitchTokenChanged(const QString &);
void CheckTokenPermissions();
void CheckToken();
void StreamTitleChanged();
void CategoreyChanged(const TwitchCategory &);
void MarkerDescriptionChanged();
Expand All @@ -228,12 +228,13 @@ private slots:
void SetWidgetSignalConnections();
void SetWidgetLayout();
void SetWidgetVisibility();
void SetTokenWarning(bool visible, const QString &text = "");

QHBoxLayout *_layout;
FilterComboBox *_actions;
TwitchConnectionSelection *_tokens;
QLabel *_tokenPermissionWarning;
QTimer _tokenPermissionCheckTimer;
QLabel *_tokenWarning;
QTimer _tokenCheckTimer;
VariableLineEdit *_streamTitle;
TwitchCategoryWidget *_category;
VariableLineEdit *_markerDescription;
Expand Down
49 changes: 38 additions & 11 deletions plugins/twitch/macro-condition-twitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,8 +1194,7 @@ MacroConditionTwitchEdit::MacroConditionTwitchEdit(
_layout(new QHBoxLayout()),
_conditions(new FilterComboBox()),
_tokens(new TwitchConnectionSelection()),
_tokenPermissionWarning(new QLabel(obs_module_text(
"AdvSceneSwitcher.twitchToken.permissionsInsufficient"))),
_tokenWarning(new QLabel()),
_channel(new TwitchChannelSelection(this)),
_pointsReward(new TwitchPointsRewardWidget(this)),
_streamTitle(new VariableLineEdit(this)),
Expand All @@ -1214,8 +1213,8 @@ MacroConditionTwitchEdit::MacroConditionTwitchEdit(
SLOT(ConditionChanged(int)));
QWidget::connect(_tokens, SIGNAL(SelectionChanged(const QString &)),
this, SLOT(TwitchTokenChanged(const QString &)));
QWidget::connect(&_tokenPermissionCheckTimer, SIGNAL(timeout()), this,
SLOT(CheckTokenPermissions()));
QWidget::connect(&_tokenCheckTimer, SIGNAL(timeout()), this,
SLOT(CheckToken()));
QWidget::connect(_channel,
SIGNAL(ChannelChanged(const TwitchChannel &)), this,
SLOT(ChannelChanged(const TwitchChannel &)));
Expand Down Expand Up @@ -1262,10 +1261,10 @@ MacroConditionTwitchEdit::MacroConditionTwitchEdit(
chatLayout->addWidget(_regexChat);
mainLayout->addLayout(chatLayout);
mainLayout->addLayout(accountLayout);
mainLayout->addWidget(_tokenPermissionWarning);
mainLayout->addWidget(_tokenWarning);
setLayout(mainLayout);

_tokenPermissionCheckTimer.start(1000);
_tokenCheckTimer.start(1000);

_entryData = entryData;
UpdateEntryData();
Expand Down Expand Up @@ -1309,14 +1308,43 @@ void MacroConditionTwitchEdit::TwitchTokenChanged(const QString &token)
emit(HeaderInfoChanged(token));
}

void MacroConditionTwitchEdit::CheckTokenPermissions()
void MacroConditionTwitchEdit::SetTokenWarning(bool visible,
const QString &text)
{
_tokenPermissionWarning->setVisible(
_entryData && !_entryData->ConditionIsSupportedByToken());
_tokenWarning->setText(text);
_tokenWarning->setVisible(visible);
adjustSize();
updateGeometry();
}

void MacroConditionTwitchEdit::CheckToken()
{
if (!_entryData) {
return;
}
if (_entryData->_token.expired()) {
SetTokenWarning(
true,
obs_module_text(
"AdvSceneSwitcher.twitchToken.noSelection"));
return;
}
if (!TokenIsValid(_entryData->_token)) {
SetTokenWarning(
true, obs_module_text(
"AdvSceneSwitcher.twitchToken.notValid"));
return;
}
if (!_entryData->ConditionIsSupportedByToken()) {
SetTokenWarning(
true,
obs_module_text(
"AdvSceneSwitcher.twitchToken.permissionsInsufficient"));
return;
}
SetTokenWarning(false);
}

void MacroConditionTwitchEdit::ChannelChanged(const TwitchChannel &channel)
{
if (_loading || !_entryData) {
Expand Down Expand Up @@ -1428,8 +1456,7 @@ void MacroConditionTwitchEdit::SetWidgetVisibility()
AddStretchIfNecessary(_layout);
}

_tokenPermissionWarning->setVisible(
!_entryData->ConditionIsSupportedByToken());
CheckToken();

adjustSize();
updateGeometry();
Expand Down
7 changes: 4 additions & 3 deletions plugins/twitch/macro-condition-twitch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class MacroConditionTwitchEdit : public QWidget {
private slots:
void ConditionChanged(int);
void TwitchTokenChanged(const QString &);
void CheckTokenPermissions();
void CheckToken();
void ChannelChanged(const TwitchChannel &);
void PointsRewardChanged(const TwitchPointsReward &);
void StreamTitleChanged();
Expand All @@ -169,12 +169,13 @@ private slots:

private:
void SetWidgetVisibility();
void SetTokenWarning(bool visible, const QString &text = "");

QHBoxLayout *_layout;
FilterComboBox *_conditions;
TwitchConnectionSelection *_tokens;
QLabel *_tokenPermissionWarning;
QTimer _tokenPermissionCheckTimer;
QLabel *_tokenWarning;
QTimer _tokenCheckTimer;
TwitchChannelSelection *_channel;
TwitchPointsRewardWidget *_pointsReward;
VariableLineEdit *_streamTitle;
Expand Down
9 changes: 9 additions & 0 deletions plugins/twitch/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,15 @@ std::string GetWeakTwitchTokenName(std::weak_ptr<TwitchToken> token)
return con->Name();
}

bool TokenIsValid(const std::weak_ptr<TwitchToken> &token_)
{
auto token = token_.lock();
if (!token) {
return false;
}
return token->IsValid();
}

static bool ConnectionNameAvailable(const QString &name)
{
return !GetTwitchTokenByName(name);
Expand Down
1 change: 1 addition & 0 deletions plugins/twitch/token.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ TwitchToken *GetTwitchTokenByName(const std::string &);
std::weak_ptr<TwitchToken> GetWeakTwitchTokenByName(const std::string &name);
std::weak_ptr<TwitchToken> GetWeakTwitchTokenByQString(const QString &name);
std::string GetWeakTwitchTokenName(std::weak_ptr<TwitchToken>);
bool TokenIsValid(const std::weak_ptr<TwitchToken> &token);

} // namespace advss

Expand Down
Loading