diff --git a/chatterino.pro b/chatterino.pro index 645a3bf57..9cb48cafb 100644 --- a/chatterino.pro +++ b/chatterino.pro @@ -312,7 +312,8 @@ HEADERS += \ src/widgets/attachedwindow.hpp \ src/util/tupletablemodel.hpp \ src/widgets/settingspages/externaltoolspage.hpp \ - src/util/removescrollareabackground.hpp + src/util/removescrollareabackground.hpp \ + src/util/assertinguithread.h RESOURCES += \ resources/resources.qrc diff --git a/src/providers/irc/abstractircserver.cpp b/src/providers/irc/abstractircserver.cpp index 266279cc3..aad9f8c79 100644 --- a/src/providers/irc/abstractircserver.cpp +++ b/src/providers/irc/abstractircserver.cpp @@ -69,7 +69,7 @@ void AbstractIrcServer::connect() } this->onConnected(); - this->connected.invoke(); + // this->connected.invoke(); } void AbstractIrcServer::disconnect() diff --git a/src/providers/twitch/twitchaccountmanager.cpp b/src/providers/twitch/twitchaccountmanager.cpp index b651a8b2e..47c556203 100644 --- a/src/providers/twitch/twitchaccountmanager.cpp +++ b/src/providers/twitch/twitchaccountmanager.cpp @@ -9,8 +9,8 @@ namespace providers { namespace twitch { TwitchAccountManager::TwitchAccountManager() + : anonymousUser(new TwitchAccount(ANONYMOUS_USERNAME, "", "", "")) { - this->anonymousUser.reset(new TwitchAccount(ANONYMOUS_USERNAME, "", "", "")); } std::shared_ptr TwitchAccountManager::getCurrent() diff --git a/src/providers/twitch/twitchserver.cpp b/src/providers/twitch/twitchserver.cpp index 3fe7e07a9..db084de7c 100644 --- a/src/providers/twitch/twitchserver.cpp +++ b/src/providers/twitch/twitchserver.cpp @@ -21,9 +21,10 @@ TwitchServer::TwitchServer() , mentionsChannel(new Channel("/mentions", Channel::TwitchMentions)) , watchingChannel(Channel::getEmpty(), Channel::TwitchWatching) { - AccountManager::getInstance().Twitch.userChanged.connect([this]() { // - util::postToThread([this] { this->connect(); }); - }); + qDebug() << "init TwitchServer"; + + AccountManager::getInstance().Twitch.userChanged.connect( + [this]() { util::postToThread([this] { this->connect(); }); }); } TwitchServer &TwitchServer::getInstance() @@ -36,6 +37,8 @@ void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead, { std::shared_ptr account = AccountManager::getInstance().Twitch.getCurrent(); + qDebug() << "logging in as" << account->getUserName(); + QString username = account->getUserName(); // QString oauthClient = account->getOAuthClient(); QString oauthToken = account->getOAuthToken(); diff --git a/src/singletons/accountmanager.cpp b/src/singletons/accountmanager.cpp index 089ea4208..236aea1dd 100644 --- a/src/singletons/accountmanager.cpp +++ b/src/singletons/accountmanager.cpp @@ -17,6 +17,11 @@ inline QString getEnvString(const char *target) } // namespace +AccountManager::AccountManager() +{ + qDebug() << "init AccountManager"; +} + AccountManager &AccountManager::getInstance() { static AccountManager instance; diff --git a/src/singletons/accountmanager.hpp b/src/singletons/accountmanager.hpp index 9528e3911..774ebb6fc 100644 --- a/src/singletons/accountmanager.hpp +++ b/src/singletons/accountmanager.hpp @@ -7,7 +7,7 @@ namespace singletons { class AccountManager { - AccountManager() = default; + AccountManager(); public: static AccountManager &getInstance(); diff --git a/src/singletons/commandmanager.cpp b/src/singletons/commandmanager.cpp index d509c7605..3818e6dd4 100644 --- a/src/singletons/commandmanager.cpp +++ b/src/singletons/commandmanager.cpp @@ -17,6 +17,11 @@ using namespace chatterino::providers::twitch; namespace chatterino { namespace singletons { +CommandManager::CommandManager() +{ + qDebug() << "init CommandManager"; +} + CommandManager &CommandManager::getInstance() { static CommandManager instance; diff --git a/src/singletons/commandmanager.hpp b/src/singletons/commandmanager.hpp index 20c56cc25..4904bb656 100644 --- a/src/singletons/commandmanager.hpp +++ b/src/singletons/commandmanager.hpp @@ -16,7 +16,7 @@ namespace singletons { class CommandManager { - CommandManager() = default; + CommandManager(); public: static CommandManager &getInstance(); diff --git a/src/singletons/emotemanager.cpp b/src/singletons/emotemanager.cpp index 83fdf9a37..98c6f92d7 100644 --- a/src/singletons/emotemanager.cpp +++ b/src/singletons/emotemanager.cpp @@ -79,6 +79,7 @@ void FillInFFZEmoteData(const QJsonObject &urls, const QString &code, const QStr EmoteManager::EmoteManager() : findShortCodesRegex(":([-+\\w]+):") { + qDebug() << "init EmoteManager"; auto &accountManager = AccountManager::getInstance(); accountManager.Twitch.userChanged.connect([this] { diff --git a/src/singletons/fontmanager.cpp b/src/singletons/fontmanager.cpp index 452149176..61060cc10 100644 --- a/src/singletons/fontmanager.cpp +++ b/src/singletons/fontmanager.cpp @@ -24,6 +24,8 @@ FontManager::FontManager() , currentFontSize("/appearance/currentFontSize", DEFAULT_FONT_SIZE) // , currentFont(this->currentFontFamily.getValue().c_str(), currentFontSize.getValue()) { + qDebug() << "init FontManager"; + this->currentFontFamily.connect([this](const std::string &newValue, auto) { this->incGeneration(); // this->currentFont.setFamily(newValue.c_str()); @@ -41,7 +43,6 @@ FontManager::FontManager() FontManager &FontManager::getInstance() { static FontManager instance; - return instance; } diff --git a/src/singletons/loggingmanager.cpp b/src/singletons/loggingmanager.cpp index 943077a1a..d25a9ace5 100644 --- a/src/singletons/loggingmanager.cpp +++ b/src/singletons/loggingmanager.cpp @@ -14,6 +14,7 @@ namespace singletons { LoggingManager::LoggingManager() : pathManager(PathManager::getInstance()) { + qDebug() << "init LoggingManager"; } LoggingManager &LoggingManager::getInstance() diff --git a/src/singletons/nativemessagingmanager.cpp b/src/singletons/nativemessagingmanager.cpp index 9c3bb907d..c0e0dbdd9 100644 --- a/src/singletons/nativemessagingmanager.cpp +++ b/src/singletons/nativemessagingmanager.cpp @@ -32,6 +32,7 @@ namespace singletons { NativeMessagingManager::NativeMessagingManager() { + qDebug() << "init NativeMessagingManager"; } NativeMessagingManager &NativeMessagingManager::getInstance() diff --git a/src/singletons/pathmanager.cpp b/src/singletons/pathmanager.cpp index 3fd3f6dc6..0e893df34 100644 --- a/src/singletons/pathmanager.cpp +++ b/src/singletons/pathmanager.cpp @@ -8,6 +8,11 @@ namespace chatterino { namespace singletons { +PathManager::PathManager() +{ + qDebug() << "init PathManager"; +} + PathManager &PathManager::getInstance() { static PathManager instance; diff --git a/src/singletons/pathmanager.hpp b/src/singletons/pathmanager.hpp index 10ba3ab62..b0fb8243f 100644 --- a/src/singletons/pathmanager.hpp +++ b/src/singletons/pathmanager.hpp @@ -7,7 +7,7 @@ namespace singletons { class PathManager { - PathManager() = default; + PathManager(); public: static PathManager &getInstance(); diff --git a/src/singletons/pubsubmanager.cpp b/src/singletons/pubsubmanager.cpp index 044c205b9..bc84ede1b 100644 --- a/src/singletons/pubsubmanager.cpp +++ b/src/singletons/pubsubmanager.cpp @@ -172,6 +172,8 @@ bool PubSubClient::Send(const char *payload) PubSubManager::PubSubManager() { + qDebug() << "init PubSubManager"; + this->moderationActionHandlers["clear"] = [this](const auto &data, const auto &roomID) { ClearChatAction action(data, roomID); @@ -444,7 +446,6 @@ void PubSubManager::AddClient() PubSubManager &PubSubManager::getInstance() { static PubSubManager instance; - return instance; } diff --git a/src/singletons/resourcemanager.cpp b/src/singletons/resourcemanager.cpp index 5ae369f1f..c394f8149 100644 --- a/src/singletons/resourcemanager.cpp +++ b/src/singletons/resourcemanager.cpp @@ -288,6 +288,8 @@ ResourceManager::ResourceManager() , buttonBan(lli(":/images/button_ban.png", 0.25)) , buttonTimeout(lli(":/images/button_timeout.png", 0.25)) { + qDebug() << "init ResourceManager"; + this->loadDynamicTwitchBadges(); this->loadChatterinoBadges(); diff --git a/src/singletons/settingsmanager.cpp b/src/singletons/settingsmanager.cpp index 5f2eed2d3..56ca824fe 100644 --- a/src/singletons/settingsmanager.cpp +++ b/src/singletons/settingsmanager.cpp @@ -20,6 +20,8 @@ SettingManager::SettingManager() : snapshot(nullptr) , _ignoredKeywords(new std::vector) { + qDebug() << "init SettingManager"; + this->wordFlagsListener.addSetting(this->showTimestamps); this->wordFlagsListener.addSetting(this->showBadges); this->wordFlagsListener.addSetting(this->enableBttvEmotes); diff --git a/src/singletons/thememanager.cpp b/src/singletons/thememanager.cpp index e7d3a6be2..87329ccaa 100644 --- a/src/singletons/thememanager.cpp +++ b/src/singletons/thememanager.cpp @@ -38,6 +38,8 @@ ThemeManager::ThemeManager() : themeName("/appearance/theme/name", "Dark") , themeHue("/appearance/theme/hue", 0.0) { + qDebug() << "init ThemeManager"; + this->update(); this->themeName.connectSimple([this](auto) { this->update(); }); diff --git a/src/singletons/updatemanager.cpp b/src/singletons/updatemanager.cpp index 87f312525..73b99717e 100644 --- a/src/singletons/updatemanager.cpp +++ b/src/singletons/updatemanager.cpp @@ -9,6 +9,7 @@ namespace singletons { UpdateManager::UpdateManager() : currentVersion(CHATTERINO_VERSION) { + qDebug() << "init UpdateManager"; } UpdateManager &UpdateManager::getInstance() diff --git a/src/singletons/windowmanager.cpp b/src/singletons/windowmanager.cpp index 50d66e503..e5908aa7b 100644 --- a/src/singletons/windowmanager.cpp +++ b/src/singletons/windowmanager.cpp @@ -4,6 +4,7 @@ #include "singletons/fontmanager.hpp" #include "singletons/pathmanager.hpp" #include "singletons/thememanager.hpp" +#include "util/assertinguithread.h" #include "widgets/accountswitchpopupwidget.hpp" #include "widgets/settingsdialog.hpp" @@ -55,6 +56,7 @@ void WindowManager::showAccountSelectPopup(QPoint point) WindowManager::WindowManager(ThemeManager &_themeManager) : themeManager(_themeManager) { + qDebug() << "init WindowManager"; _themeManager.repaintVisibleChatWidgets.connect([this] { this->repaintVisibleChatWidgets(); }); } @@ -84,16 +86,22 @@ void WindowManager::repaintGifEmotes() widgets::Window &WindowManager::getMainWindow() { + util::assertInGuiThread(); + return *this->mainWindow; } widgets::Window &WindowManager::getSelectedWindow() { + util::assertInGuiThread(); + return *this->selectedWindow; } widgets::Window &WindowManager::createWindow(widgets::Window::WindowType type) { + util::assertInGuiThread(); + auto *window = new widgets::Window(this->themeManager, type); this->windows.push_back(window); window->show(); @@ -121,6 +129,8 @@ int WindowManager::windowCount() widgets::Window *WindowManager::windowAt(int index) { + util::assertInGuiThread(); + if (index < 0 || (size_t)index >= this->windows.size()) { return nullptr; } @@ -131,6 +141,8 @@ widgets::Window *WindowManager::windowAt(int index) void WindowManager::initialize() { + util::assertInGuiThread(); + assert(!this->initialized); // load file @@ -217,6 +229,8 @@ void WindowManager::initialize() void WindowManager::save() { + util::assertInGuiThread(); + QJsonDocument document; // "serialize" @@ -296,6 +310,8 @@ void WindowManager::save() void WindowManager::encodeChannel(IndirectChannel channel, QJsonObject &obj) { + util::assertInGuiThread(); + switch (channel.getType()) { case Channel::Twitch: { obj.insert("type", "twitch"); @@ -315,6 +331,8 @@ void WindowManager::encodeChannel(IndirectChannel channel, QJsonObject &obj) IndirectChannel WindowManager::decodeChannel(const QJsonObject &obj) { + util::assertInGuiThread(); + QString type = obj.value("type").toString(); if (type == "twitch") { return providers::twitch::TwitchServer::getInstance().getOrAddChannel( @@ -332,6 +350,8 @@ IndirectChannel WindowManager::decodeChannel(const QJsonObject &obj) void WindowManager::closeAll() { + util::assertInGuiThread(); + for (widgets::Window *window : windows) { window->close(); } diff --git a/src/util/assertinguithread.h b/src/util/assertinguithread.h new file mode 100644 index 000000000..f9ce99fde --- /dev/null +++ b/src/util/assertinguithread.h @@ -0,0 +1,18 @@ +#pragma once + +#include +#include +#include + +namespace chatterino { +namespace util { + +void assertInGuiThread() +{ +#ifdef _DEBUG + assert(QCoreApplication::instance()->thread() == QThread::currentThread()); +#endif +} + +} // namespace util +} // namespace chatterino diff --git a/src/widgets/window.cpp b/src/widgets/window.cpp index 7c7504c29..974a3165d 100644 --- a/src/widgets/window.cpp +++ b/src/widgets/window.cpp @@ -16,8 +16,7 @@ #include #include -#include -#include "util/tupletablemodel.hpp" +#include namespace chatterino { namespace widgets {