From fa914c152adc6c2fdef9b50bde88436251f64ebe Mon Sep 17 00:00:00 2001 From: Rasmus Karlsson Date: Tue, 30 May 2017 18:24:55 +0200 Subject: [PATCH] you can now log in with username/oauth token from an env variable useful while testing (especially on stream) --- accountmanager.cpp | 31 +++++++++++++++++++++++++++++++ accountmanager.h | 3 +++ ircmanager.cpp | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/accountmanager.cpp b/accountmanager.cpp index 8ab216843..c3873e791 100644 --- a/accountmanager.cpp +++ b/accountmanager.cpp @@ -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 lock(_twitchUsersMutex); + + if (_twitchUsers.size() == 0) { + return _twitchAnon; + } + + return _twitchUsers.front(); +} + std::vector AccountManager::getTwitchUsers() { return std::vector(_twitchUsers); diff --git a/accountmanager.h b/accountmanager.h index e97cdf74c..e706d1c5a 100644 --- a/accountmanager.h +++ b/accountmanager.h @@ -19,6 +19,9 @@ public: twitch::TwitchUser &getTwitchAnon(); + // Returns first user from _twitchUsers, or _twitchAnon if _twitchUsers is empty + twitch::TwitchUser &getTwitchUser(); + std::vector getTwitchUsers(); bool removeTwitchUser(const QString &userName); void addTwitchUser(const twitch::TwitchUser &user); diff --git a/ircmanager.cpp b/ircmanager.cpp index e0a93645c..2df6115c2 100644 --- a/ircmanager.cpp +++ b/ircmanager.cpp @@ -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)