you can now log in with username/oauth token from an env variable

useful while testing (especially on stream)
This commit is contained in:
Rasmus Karlsson 2017-05-30 18:24:55 +02:00
parent 153fae7c19
commit fa914c152a
3 changed files with 35 additions and 1 deletions

View file

@ -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);

View file

@ -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);

View file

@ -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)