added debug logs and code to assert that we are in the gui thread

This commit is contained in:
fourtf 2018-04-26 18:10:26 +02:00
parent b176dc5295
commit d078ef5fe0
22 changed files with 81 additions and 13 deletions

View file

@ -312,7 +312,8 @@ HEADERS += \
src/widgets/attachedwindow.hpp \ src/widgets/attachedwindow.hpp \
src/util/tupletablemodel.hpp \ src/util/tupletablemodel.hpp \
src/widgets/settingspages/externaltoolspage.hpp \ src/widgets/settingspages/externaltoolspage.hpp \
src/util/removescrollareabackground.hpp src/util/removescrollareabackground.hpp \
src/util/assertinguithread.h
RESOURCES += \ RESOURCES += \
resources/resources.qrc resources/resources.qrc

View file

@ -69,7 +69,7 @@ void AbstractIrcServer::connect()
} }
this->onConnected(); this->onConnected();
this->connected.invoke(); // this->connected.invoke();
} }
void AbstractIrcServer::disconnect() void AbstractIrcServer::disconnect()

View file

@ -9,8 +9,8 @@ namespace providers {
namespace twitch { namespace twitch {
TwitchAccountManager::TwitchAccountManager() TwitchAccountManager::TwitchAccountManager()
: anonymousUser(new TwitchAccount(ANONYMOUS_USERNAME, "", "", ""))
{ {
this->anonymousUser.reset(new TwitchAccount(ANONYMOUS_USERNAME, "", "", ""));
} }
std::shared_ptr<TwitchAccount> TwitchAccountManager::getCurrent() std::shared_ptr<TwitchAccount> TwitchAccountManager::getCurrent()

View file

@ -21,9 +21,10 @@ TwitchServer::TwitchServer()
, mentionsChannel(new Channel("/mentions", Channel::TwitchMentions)) , mentionsChannel(new Channel("/mentions", Channel::TwitchMentions))
, watchingChannel(Channel::getEmpty(), Channel::TwitchWatching) , watchingChannel(Channel::getEmpty(), Channel::TwitchWatching)
{ {
AccountManager::getInstance().Twitch.userChanged.connect([this]() { // qDebug() << "init TwitchServer";
util::postToThread([this] { this->connect(); });
}); AccountManager::getInstance().Twitch.userChanged.connect(
[this]() { util::postToThread([this] { this->connect(); }); });
} }
TwitchServer &TwitchServer::getInstance() TwitchServer &TwitchServer::getInstance()
@ -36,6 +37,8 @@ void TwitchServer::initializeConnection(IrcConnection *connection, bool isRead,
{ {
std::shared_ptr<TwitchAccount> account = AccountManager::getInstance().Twitch.getCurrent(); std::shared_ptr<TwitchAccount> account = AccountManager::getInstance().Twitch.getCurrent();
qDebug() << "logging in as" << account->getUserName();
QString username = account->getUserName(); QString username = account->getUserName();
// QString oauthClient = account->getOAuthClient(); // QString oauthClient = account->getOAuthClient();
QString oauthToken = account->getOAuthToken(); QString oauthToken = account->getOAuthToken();

View file

@ -17,6 +17,11 @@ inline QString getEnvString(const char *target)
} // namespace } // namespace
AccountManager::AccountManager()
{
qDebug() << "init AccountManager";
}
AccountManager &AccountManager::getInstance() AccountManager &AccountManager::getInstance()
{ {
static AccountManager instance; static AccountManager instance;

View file

@ -7,7 +7,7 @@ namespace singletons {
class AccountManager class AccountManager
{ {
AccountManager() = default; AccountManager();
public: public:
static AccountManager &getInstance(); static AccountManager &getInstance();

View file

@ -17,6 +17,11 @@ using namespace chatterino::providers::twitch;
namespace chatterino { namespace chatterino {
namespace singletons { namespace singletons {
CommandManager::CommandManager()
{
qDebug() << "init CommandManager";
}
CommandManager &CommandManager::getInstance() CommandManager &CommandManager::getInstance()
{ {
static CommandManager instance; static CommandManager instance;

View file

@ -16,7 +16,7 @@ namespace singletons {
class CommandManager class CommandManager
{ {
CommandManager() = default; CommandManager();
public: public:
static CommandManager &getInstance(); static CommandManager &getInstance();

View file

@ -79,6 +79,7 @@ void FillInFFZEmoteData(const QJsonObject &urls, const QString &code, const QStr
EmoteManager::EmoteManager() EmoteManager::EmoteManager()
: findShortCodesRegex(":([-+\\w]+):") : findShortCodesRegex(":([-+\\w]+):")
{ {
qDebug() << "init EmoteManager";
auto &accountManager = AccountManager::getInstance(); auto &accountManager = AccountManager::getInstance();
accountManager.Twitch.userChanged.connect([this] { accountManager.Twitch.userChanged.connect([this] {

View file

@ -24,6 +24,8 @@ FontManager::FontManager()
, currentFontSize("/appearance/currentFontSize", DEFAULT_FONT_SIZE) , currentFontSize("/appearance/currentFontSize", DEFAULT_FONT_SIZE)
// , currentFont(this->currentFontFamily.getValue().c_str(), currentFontSize.getValue()) // , currentFont(this->currentFontFamily.getValue().c_str(), currentFontSize.getValue())
{ {
qDebug() << "init FontManager";
this->currentFontFamily.connect([this](const std::string &newValue, auto) { this->currentFontFamily.connect([this](const std::string &newValue, auto) {
this->incGeneration(); this->incGeneration();
// this->currentFont.setFamily(newValue.c_str()); // this->currentFont.setFamily(newValue.c_str());
@ -41,7 +43,6 @@ FontManager::FontManager()
FontManager &FontManager::getInstance() FontManager &FontManager::getInstance()
{ {
static FontManager instance; static FontManager instance;
return instance; return instance;
} }

View file

@ -14,6 +14,7 @@ namespace singletons {
LoggingManager::LoggingManager() LoggingManager::LoggingManager()
: pathManager(PathManager::getInstance()) : pathManager(PathManager::getInstance())
{ {
qDebug() << "init LoggingManager";
} }
LoggingManager &LoggingManager::getInstance() LoggingManager &LoggingManager::getInstance()

View file

@ -32,6 +32,7 @@ namespace singletons {
NativeMessagingManager::NativeMessagingManager() NativeMessagingManager::NativeMessagingManager()
{ {
qDebug() << "init NativeMessagingManager";
} }
NativeMessagingManager &NativeMessagingManager::getInstance() NativeMessagingManager &NativeMessagingManager::getInstance()

View file

@ -8,6 +8,11 @@
namespace chatterino { namespace chatterino {
namespace singletons { namespace singletons {
PathManager::PathManager()
{
qDebug() << "init PathManager";
}
PathManager &PathManager::getInstance() PathManager &PathManager::getInstance()
{ {
static PathManager instance; static PathManager instance;

View file

@ -7,7 +7,7 @@ namespace singletons {
class PathManager class PathManager
{ {
PathManager() = default; PathManager();
public: public:
static PathManager &getInstance(); static PathManager &getInstance();

View file

@ -172,6 +172,8 @@ bool PubSubClient::Send(const char *payload)
PubSubManager::PubSubManager() PubSubManager::PubSubManager()
{ {
qDebug() << "init PubSubManager";
this->moderationActionHandlers["clear"] = [this](const auto &data, const auto &roomID) { this->moderationActionHandlers["clear"] = [this](const auto &data, const auto &roomID) {
ClearChatAction action(data, roomID); ClearChatAction action(data, roomID);
@ -444,7 +446,6 @@ void PubSubManager::AddClient()
PubSubManager &PubSubManager::getInstance() PubSubManager &PubSubManager::getInstance()
{ {
static PubSubManager instance; static PubSubManager instance;
return instance; return instance;
} }

View file

@ -288,6 +288,8 @@ ResourceManager::ResourceManager()
, buttonBan(lli(":/images/button_ban.png", 0.25)) , buttonBan(lli(":/images/button_ban.png", 0.25))
, buttonTimeout(lli(":/images/button_timeout.png", 0.25)) , buttonTimeout(lli(":/images/button_timeout.png", 0.25))
{ {
qDebug() << "init ResourceManager";
this->loadDynamicTwitchBadges(); this->loadDynamicTwitchBadges();
this->loadChatterinoBadges(); this->loadChatterinoBadges();

View file

@ -20,6 +20,8 @@ SettingManager::SettingManager()
: snapshot(nullptr) : snapshot(nullptr)
, _ignoredKeywords(new std::vector<QString>) , _ignoredKeywords(new std::vector<QString>)
{ {
qDebug() << "init SettingManager";
this->wordFlagsListener.addSetting(this->showTimestamps); this->wordFlagsListener.addSetting(this->showTimestamps);
this->wordFlagsListener.addSetting(this->showBadges); this->wordFlagsListener.addSetting(this->showBadges);
this->wordFlagsListener.addSetting(this->enableBttvEmotes); this->wordFlagsListener.addSetting(this->enableBttvEmotes);

View file

@ -38,6 +38,8 @@ ThemeManager::ThemeManager()
: themeName("/appearance/theme/name", "Dark") : themeName("/appearance/theme/name", "Dark")
, themeHue("/appearance/theme/hue", 0.0) , themeHue("/appearance/theme/hue", 0.0)
{ {
qDebug() << "init ThemeManager";
this->update(); this->update();
this->themeName.connectSimple([this](auto) { this->update(); }); this->themeName.connectSimple([this](auto) { this->update(); });

View file

@ -9,6 +9,7 @@ namespace singletons {
UpdateManager::UpdateManager() UpdateManager::UpdateManager()
: currentVersion(CHATTERINO_VERSION) : currentVersion(CHATTERINO_VERSION)
{ {
qDebug() << "init UpdateManager";
} }
UpdateManager &UpdateManager::getInstance() UpdateManager &UpdateManager::getInstance()

View file

@ -4,6 +4,7 @@
#include "singletons/fontmanager.hpp" #include "singletons/fontmanager.hpp"
#include "singletons/pathmanager.hpp" #include "singletons/pathmanager.hpp"
#include "singletons/thememanager.hpp" #include "singletons/thememanager.hpp"
#include "util/assertinguithread.h"
#include "widgets/accountswitchpopupwidget.hpp" #include "widgets/accountswitchpopupwidget.hpp"
#include "widgets/settingsdialog.hpp" #include "widgets/settingsdialog.hpp"
@ -55,6 +56,7 @@ void WindowManager::showAccountSelectPopup(QPoint point)
WindowManager::WindowManager(ThemeManager &_themeManager) WindowManager::WindowManager(ThemeManager &_themeManager)
: themeManager(_themeManager) : themeManager(_themeManager)
{ {
qDebug() << "init WindowManager";
_themeManager.repaintVisibleChatWidgets.connect([this] { this->repaintVisibleChatWidgets(); }); _themeManager.repaintVisibleChatWidgets.connect([this] { this->repaintVisibleChatWidgets(); });
} }
@ -84,16 +86,22 @@ void WindowManager::repaintGifEmotes()
widgets::Window &WindowManager::getMainWindow() widgets::Window &WindowManager::getMainWindow()
{ {
util::assertInGuiThread();
return *this->mainWindow; return *this->mainWindow;
} }
widgets::Window &WindowManager::getSelectedWindow() widgets::Window &WindowManager::getSelectedWindow()
{ {
util::assertInGuiThread();
return *this->selectedWindow; return *this->selectedWindow;
} }
widgets::Window &WindowManager::createWindow(widgets::Window::WindowType type) widgets::Window &WindowManager::createWindow(widgets::Window::WindowType type)
{ {
util::assertInGuiThread();
auto *window = new widgets::Window(this->themeManager, type); auto *window = new widgets::Window(this->themeManager, type);
this->windows.push_back(window); this->windows.push_back(window);
window->show(); window->show();
@ -121,6 +129,8 @@ int WindowManager::windowCount()
widgets::Window *WindowManager::windowAt(int index) widgets::Window *WindowManager::windowAt(int index)
{ {
util::assertInGuiThread();
if (index < 0 || (size_t)index >= this->windows.size()) { if (index < 0 || (size_t)index >= this->windows.size()) {
return nullptr; return nullptr;
} }
@ -131,6 +141,8 @@ widgets::Window *WindowManager::windowAt(int index)
void WindowManager::initialize() void WindowManager::initialize()
{ {
util::assertInGuiThread();
assert(!this->initialized); assert(!this->initialized);
// load file // load file
@ -217,6 +229,8 @@ void WindowManager::initialize()
void WindowManager::save() void WindowManager::save()
{ {
util::assertInGuiThread();
QJsonDocument document; QJsonDocument document;
// "serialize" // "serialize"
@ -296,6 +310,8 @@ void WindowManager::save()
void WindowManager::encodeChannel(IndirectChannel channel, QJsonObject &obj) void WindowManager::encodeChannel(IndirectChannel channel, QJsonObject &obj)
{ {
util::assertInGuiThread();
switch (channel.getType()) { switch (channel.getType()) {
case Channel::Twitch: { case Channel::Twitch: {
obj.insert("type", "twitch"); obj.insert("type", "twitch");
@ -315,6 +331,8 @@ void WindowManager::encodeChannel(IndirectChannel channel, QJsonObject &obj)
IndirectChannel WindowManager::decodeChannel(const QJsonObject &obj) IndirectChannel WindowManager::decodeChannel(const QJsonObject &obj)
{ {
util::assertInGuiThread();
QString type = obj.value("type").toString(); QString type = obj.value("type").toString();
if (type == "twitch") { if (type == "twitch") {
return providers::twitch::TwitchServer::getInstance().getOrAddChannel( return providers::twitch::TwitchServer::getInstance().getOrAddChannel(
@ -332,6 +350,8 @@ IndirectChannel WindowManager::decodeChannel(const QJsonObject &obj)
void WindowManager::closeAll() void WindowManager::closeAll()
{ {
util::assertInGuiThread();
for (widgets::Window *window : windows) { for (widgets::Window *window : windows) {
window->close(); window->close();
} }

View file

@ -0,0 +1,18 @@
#pragma once
#include <QCoreApplication>
#include <QThread>
#include <cassert>
namespace chatterino {
namespace util {
void assertInGuiThread()
{
#ifdef _DEBUG
assert(QCoreApplication::instance()->thread() == QThread::currentThread());
#endif
}
} // namespace util
} // namespace chatterino

View file

@ -16,8 +16,7 @@
#include <QShortcut> #include <QShortcut>
#include <QVBoxLayout> #include <QVBoxLayout>
#include <QTableView> #include <QStandardItemModel>
#include "util/tupletablemodel.hpp"
namespace chatterino { namespace chatterino {
namespace widgets { namespace widgets {