diff --git a/src/accountmanager.cpp b/src/accountmanager.cpp index 5a70a5653..c5dc51454 100644 --- a/src/accountmanager.cpp +++ b/src/accountmanager.cpp @@ -20,7 +20,8 @@ inline QString getEnvString(const char *target) } // namespace AccountManager::AccountManager() - : twitchAnonymousUser("justinfan64537", "", "") + : currentUser("/accounts/current", "") + , twitchAnonymousUser("justinfan64537", "", "") { } @@ -28,6 +29,8 @@ void AccountManager::load() { auto keys = pajlada::Settings::SettingManager::getObjectKeys("/accounts"); + bool first = true; + for (const auto &uid : keys) { if (uid == "current") { continue; @@ -46,6 +49,11 @@ void AccountManager::load() continue; } + if (first) { + this->setCurrentTwitchUser(qS(username)); + first = false; + } + twitch::TwitchUser user(qS(username), qS(oauthToken), qS(clientID)); this->addTwitchUser(user); @@ -67,9 +75,7 @@ twitch::TwitchUser &AccountManager::getTwitchUser() return this->getTwitchAnon(); } - std::string currentUser = pajlada::Settings::Setting::get("/accounts/current"); - - QString currentUsername = QString::fromStdString(currentUser); + QString currentUsername = QString::fromStdString(this->currentUser); for (auto &user : this->twitchUsers) { if (user.getUserName() == currentUsername) { @@ -82,7 +88,7 @@ twitch::TwitchUser &AccountManager::getTwitchUser() void AccountManager::setCurrentTwitchUser(const QString &username) { - pajlada::Settings::Setting::set("/accounts/current", username.toStdString()); + this->currentUser.setValue(username.toStdString()); } std::vector AccountManager::getTwitchUsers() diff --git a/src/accountmanager.hpp b/src/accountmanager.hpp index 5e2858e64..970e7972c 100644 --- a/src/accountmanager.hpp +++ b/src/accountmanager.hpp @@ -2,6 +2,8 @@ #include "twitch/twitchuser.hpp" +#include + #include #include @@ -37,6 +39,8 @@ public: private: AccountManager(); + pajlada::Settings::Setting currentUser; + twitch::TwitchUser twitchAnonymousUser; std::vector twitchUsers; std::mutex twitchUsersMutex; diff --git a/src/twitch/twitchmessagebuilder.cpp b/src/twitch/twitchmessagebuilder.cpp index ec89a0377..b46eb7a81 100644 --- a/src/twitch/twitchmessagebuilder.cpp +++ b/src/twitch/twitchmessagebuilder.cpp @@ -362,7 +362,7 @@ void TwitchMessageBuilder::parseHighlights() { static auto player = new QMediaPlayer; SettingsManager &settings = SettingsManager::getInstance(); - static pajlada::Settings::Setting currentUser("/accounts/currentUser"); + static pajlada::Settings::Setting currentUser("/accounts/current"); QString currentUsername = QString::fromStdString(currentUser.getValue());