mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
you can now log in with username/oauth token from an env variable
useful while testing (especially on stream)
This commit is contained in:
parent
153fae7c19
commit
fa914c152a
3 changed files with 35 additions and 1 deletions
|
@ -2,11 +2,31 @@
|
|||
|
||||
namespace chatterino {
|
||||
|
||||
namespace {
|
||||
|
||||
inline QString getEnvString(const char *target)
|
||||
{
|
||||
char *val = std::getenv(target);
|
||||
if (val == nullptr) {
|
||||
return QString();
|
||||
}
|
||||
|
||||
return QString(val);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
AccountManager::AccountManager()
|
||||
: _twitchAnon("justinfan64537", "", "")
|
||||
, _twitchUsers()
|
||||
, _twitchUsersMutex()
|
||||
{
|
||||
QString envUsername = getEnvString("CHATTERINO2_USERNAME");
|
||||
QString envOauthToken = getEnvString("CHATTERINO2_OAUTH");
|
||||
|
||||
if (!envUsername.isEmpty() && !envOauthToken.isEmpty()) {
|
||||
this->addTwitchUser(twitch::TwitchUser(envUsername, envOauthToken, ""));
|
||||
}
|
||||
}
|
||||
|
||||
twitch::TwitchUser &AccountManager::getTwitchAnon()
|
||||
|
@ -14,6 +34,17 @@ twitch::TwitchUser &AccountManager::getTwitchAnon()
|
|||
return _twitchAnon;
|
||||
}
|
||||
|
||||
twitch::TwitchUser &AccountManager::getTwitchUser()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_twitchUsersMutex);
|
||||
|
||||
if (_twitchUsers.size() == 0) {
|
||||
return _twitchAnon;
|
||||
}
|
||||
|
||||
return _twitchUsers.front();
|
||||
}
|
||||
|
||||
std::vector<twitch::TwitchUser> AccountManager::getTwitchUsers()
|
||||
{
|
||||
return std::vector<twitch::TwitchUser>(_twitchUsers);
|
||||
|
|
|
@ -19,6 +19,9 @@ public:
|
|||
|
||||
twitch::TwitchUser &getTwitchAnon();
|
||||
|
||||
// Returns first user from _twitchUsers, or _twitchAnon if _twitchUsers is empty
|
||||
twitch::TwitchUser &getTwitchUser();
|
||||
|
||||
std::vector<twitch::TwitchUser> getTwitchUsers();
|
||||
bool removeTwitchUser(const QString &userName);
|
||||
void addTwitchUser(const twitch::TwitchUser &user);
|
||||
|
|
|
@ -28,7 +28,7 @@ IrcManager IrcManager::instance;
|
|||
const QString IrcManager::defaultClientId("7ue61iz46fz11y3cugd0l3tawb4taal");
|
||||
|
||||
IrcManager::IrcManager()
|
||||
: _account(AccountManager::getInstance().getTwitchAnon())
|
||||
: _account(AccountManager::getInstance().getTwitchUser())
|
||||
, _connection()
|
||||
, _connectionMutex()
|
||||
, _connectionGeneration(0)
|
||||
|
|
Loading…
Reference in a new issue