From 19b2102fed17adead8ff803e253c3a377c0c581a Mon Sep 17 00:00:00 2001 From: Leon Richardt Date: Sat, 21 Sep 2019 20:24:52 +0200 Subject: [PATCH 001/136] Fix Version::dateOfBuild_ on Windows The `CHATTERINO_NIGHTLY_VERSION_STRING` defines differ on Windows and MacOS/Linux. (See `appveyor.yml` and `travis.yml`, respectively.) Therefore, the Windows version string looked really messed up but it should be fixed now. --- src/common/Version.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/common/Version.cpp b/src/common/Version.cpp index e6a47ef3..dc3c04d6 100644 --- a/src/common/Version.cpp +++ b/src/common/Version.cpp @@ -16,11 +16,11 @@ Version::Version() this->commitHash_ = QString(FROM_EXTERNAL_DEFINE(CHATTERINO_GIT_HASH)).remove('"'); - // Date of build + // Date of build, this is depended on the format not changing #ifdef CHATTERINO_NIGHTLY_VERSION_STRING this->dateOfBuild_ = QString(FROM_EXTERNAL_DEFINE(CHATTERINO_NIGHTLY_VERSION_STRING)) - .remove('"'); + .remove('"').split(' ')[0]; #endif // "Full" version string, as displayed in window title @@ -31,11 +31,6 @@ Version::Version() } this->fullVersion_ += this->version_; - - if (Modes::getInstance().isNightly) - { - this->fullVersion_ += this->dateOfBuild_; - } } const Version &Version::getInstance() From 5078ecbef1ff86cb7553c514452950d8bca79fb1 Mon Sep 17 00:00:00 2001 From: CommName Date: Sat, 21 Sep 2019 22:19:03 +0200 Subject: [PATCH 002/136] Highlight bug fix --- src/widgets/helper/ChannelView.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index d9dc36a6..d80376a7 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -582,6 +582,11 @@ void ChannelView::setChannel(ChannelPtr channel) this->lastMessageHasAlternateBackground_ = !this->lastMessageHasAlternateBackground_; + if (channel->shouldIgnoreHighlights()) + { + messageLayout->flags.set(MessageLayoutFlag::IgnoreHighlights); + } + this->messages_.pushBack(MessageLayoutPtr(messageLayout), deleted); this->scrollBar_->addHighlight(snapshot[i]->getScrollBarHighlight()); } From 90f3e76c88f1dc03aebb942d7280a9e3031dad41 Mon Sep 17 00:00:00 2001 From: Leon Richardt Date: Sun, 22 Sep 2019 00:03:30 +0200 Subject: [PATCH 003/136] Trying to fix macOS builds I have no idea whether this works and this is the only way to find out. --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 6387df0a..cb0a8c31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -64,7 +64,9 @@ matrix: script: - mkdir build && cd build - dateOfBuild="CHATTERINO_NIGHTLY_VERSION_STRING=\"\\\"$(date +%d.%m.%Y)\\\"\"" - - /usr/local/opt/qt/bin/qmake .. DEFINES+=$dateOfBuild && make -j8 + - /usr/local/opt/qt/bin/qmake .. DEFINES+=$dateOfBuild + - sed -i 's/-framework\\\ /-framework /g' Makefile + - make -j8 - /usr/local/opt/qt/bin/macdeployqt chatterino.app -dmg - mkdir app - hdiutil attach chatterino.dmg From 5e41328f1b0a2f62bf1077abbfbcefe54d4614bc Mon Sep 17 00:00:00 2001 From: Leon Richardt Date: Sun, 22 Sep 2019 00:11:07 +0200 Subject: [PATCH 004/136] Some more trial-and-error --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index cb0a8c31..5e6041b2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -65,7 +65,7 @@ matrix: - mkdir build && cd build - dateOfBuild="CHATTERINO_NIGHTLY_VERSION_STRING=\"\\\"$(date +%d.%m.%Y)\\\"\"" - /usr/local/opt/qt/bin/qmake .. DEFINES+=$dateOfBuild - - sed -i 's/-framework\\\ /-framework /g' Makefile + - sed -ie 's/-framework\\\ /-framework /g' Makefile - make -j8 - /usr/local/opt/qt/bin/macdeployqt chatterino.app -dmg - mkdir app From 1256a7b631a7eda0f38828402871d636170beb6f Mon Sep 17 00:00:00 2001 From: pajlada Date: Sun, 22 Sep 2019 10:42:22 +0200 Subject: [PATCH 005/136] Fix formatting --- src/widgets/helper/ChannelView.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/widgets/helper/ChannelView.cpp b/src/widgets/helper/ChannelView.cpp index d80376a7..e10d670e 100644 --- a/src/widgets/helper/ChannelView.cpp +++ b/src/widgets/helper/ChannelView.cpp @@ -584,7 +584,7 @@ void ChannelView::setChannel(ChannelPtr channel) if (channel->shouldIgnoreHighlights()) { - messageLayout->flags.set(MessageLayoutFlag::IgnoreHighlights); + messageLayout->flags.set(MessageLayoutFlag::IgnoreHighlights); } this->messages_.pushBack(MessageLayoutPtr(messageLayout), deleted); From da4714944d0fe4a0ecdb7011cff4df0d4a56265d Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 22 Sep 2019 10:27:05 +0200 Subject: [PATCH 006/136] small fixes in Image --- src/common/Common.hpp | 19 ++++++++++++++----- src/messages/Image.cpp | 21 +++++++++++---------- src/messages/Image.hpp | 13 +++++++------ src/providers/irc/AbstractIrcServer.hpp | 19 ++++++------------- 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/src/common/Common.hpp b/src/common/Common.hpp index fe5acc56..43b95407 100644 --- a/src/common/Common.hpp +++ b/src/common/Common.hpp @@ -1,16 +1,15 @@ #pragma once -#include "common/Aliases.hpp" -#include "common/Outcome.hpp" -#include "common/ProviderId.hpp" - #include #include #include #include - #include +#include "common/Aliases.hpp" +#include "common/Outcome.hpp" +#include "common/ProviderId.hpp" + namespace chatterino { enum class HighlightState { @@ -46,4 +45,14 @@ enum class CopyMode { OnlyTextAndEmotes, }; +struct DeleteLater { + void operator()(QObject *obj) + { + obj->deleteLater(); + } +}; + +template +using QObjectPtr = std::unique_ptr; + } // namespace chatterino diff --git a/src/messages/Image.cpp b/src/messages/Image.cpp index 675e7d15..412727d0 100644 --- a/src/messages/Image.cpp +++ b/src/messages/Image.cpp @@ -1,5 +1,14 @@ #include "messages/Image.hpp" +#include +#include +#include +#include +#include +#include +#include +#include + #include "Application.hpp" #include "common/Common.hpp" #include "common/NetworkRequest.hpp" @@ -11,15 +20,6 @@ #include "util/DebugCount.hpp" #include "util/PostToThread.hpp" -#include -#include -#include -#include -#include -#include -#include -#include - namespace chatterino { namespace detail { // Frames @@ -324,7 +324,7 @@ int Image::width() const assertInGuiThread(); if (auto pixmap = this->frames_->first()) - return pixmap->width() * this->scale_; + return int(pixmap->width() * this->scale_); else return 16; } @@ -369,6 +369,7 @@ void Image::actuallyLoad() if (!shared) return false; + // fourtf: is this the right thing to do? shared->empty_ = true; return true; diff --git a/src/messages/Image.hpp b/src/messages/Image.hpp index 1cd30d81..7aa184e9 100644 --- a/src/messages/Image.hpp +++ b/src/messages/Image.hpp @@ -13,7 +13,7 @@ #include #include "common/Aliases.hpp" -#include "common/NullablePtr.hpp" +#include "common/Common.hpp" namespace chatterino { namespace detail { @@ -45,6 +45,7 @@ namespace detail { class Image; using ImagePtr = std::shared_ptr; +/// This class is thread safe. class Image : public std::enable_shared_from_this, boost::noncopyable { public: @@ -72,14 +73,14 @@ private: Image(qreal scale); void setPixmap(const QPixmap &pixmap); - void actuallyLoad(); - Url url_{}; - qreal scale_{1}; - bool empty_{false}; + const Url url_{}; + const qreal scale_{1}; + std::atomic_bool empty_{false}; + + // gui thread only bool shouldLoad_{false}; std::unique_ptr frames_{}; - QObject object_{}; }; } // namespace chatterino diff --git a/src/providers/irc/AbstractIrcServer.hpp b/src/providers/irc/AbstractIrcServer.hpp index 9b17d301..20d78249 100644 --- a/src/providers/irc/AbstractIrcServer.hpp +++ b/src/providers/irc/AbstractIrcServer.hpp @@ -1,13 +1,13 @@ #pragma once -#include "providers/irc/IrcConnection2.hpp" - #include +#include +#include #include #include -#include -#include +#include "common/Common.hpp" +#include "providers/irc/IrcConnection2.hpp" namespace chatterino { @@ -73,15 +73,8 @@ protected: private: void initConnection(); - struct Deleter { - void operator()(IrcConnection *conn) - { - conn->deleteLater(); - } - }; - - std::unique_ptr writeConnection_ = nullptr; - std::unique_ptr readConnection_ = nullptr; + QObjectPtr writeConnection_ = nullptr; + QObjectPtr readConnection_ = nullptr; QTimer reconnectTimer_; int falloffCounter_ = 1; From 456065f508b482d1ad92ce9d3f1a22f6dd188849 Mon Sep 17 00:00:00 2001 From: fourtf Date: Sun, 22 Sep 2019 10:53:39 +0200 Subject: [PATCH 007/136] moved resources out of Application --- src/Application.cpp | 8 +++---- src/Application.hpp | 9 +++----- src/RunGui.cpp | 3 +++ src/autogenerated/ResourcesAutogen.cpp | 2 +- src/autogenerated/ResourcesAutogen.hpp | 3 ++- .../moderationactions/ModerationAction.cpp | 6 ++--- src/messages/MessageBuilder.cpp | 2 +- src/providers/twitch/TwitchMessageBuilder.cpp | 20 ++++++++-------- src/singletons/Resources.cpp | 23 +++++++++++++++++++ src/singletons/Resources.hpp | 9 ++++++++ src/widgets/dialogs/UserInfoPopup.cpp | 10 ++++---- src/widgets/splits/SplitHeader.cpp | 14 +++++------ src/widgets/splits/SplitOverlay.cpp | 10 ++++---- 13 files changed, 75 insertions(+), 44 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index c0749037..a5c7e83e 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -1,5 +1,7 @@ #include "Application.hpp" +#include + #include "controllers/accounts/AccountController.hpp" #include "controllers/commands/CommandController.hpp" #include "controllers/highlights/HighlightController.hpp" @@ -31,8 +33,6 @@ #include "util/PostToThread.hpp" #include "widgets/Window.hpp" -#include - namespace chatterino { static std::atomic isAppInitialized{false}; @@ -44,9 +44,7 @@ Application *Application::instance = nullptr; // to each other Application::Application(Settings &_settings, Paths &_paths) - : resources(&this->emplace()) - - , themes(&this->emplace()) + : themes(&this->emplace()) , fonts(&this->emplace()) , emotes(&this->emplace()) , windows(&this->emplace()) diff --git a/src/Application.hpp b/src/Application.hpp index 88cea1ab..fac8ec0f 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -1,11 +1,11 @@ #pragma once -#include "common/Singleton.hpp" -#include "singletons/NativeMessaging.hpp" - #include #include +#include "common/Singleton.hpp" +#include "singletons/NativeMessaging.hpp" + namespace chatterino { class TwitchIrcServer; @@ -28,7 +28,6 @@ class AccountManager; class Emotes; class Settings; class Fonts; -class Resources2; class Toasts; class ChatterinoBadges; @@ -51,8 +50,6 @@ public: friend void test(); - Resources2 *const resources; - Theme *const themes{}; Fonts *const fonts{}; Emotes *const emotes{}; diff --git a/src/RunGui.cpp b/src/RunGui.cpp index 5f86a6a4..190df9d5 100644 --- a/src/RunGui.cpp +++ b/src/RunGui.cpp @@ -8,6 +8,7 @@ #include "Application.hpp" #include "common/NetworkManager.hpp" #include "singletons/Paths.hpp" +#include "singletons/Resources.hpp" #include "singletons/Updates.hpp" #include "util/CombinePath.hpp" #include "widgets/dialogs/LastRunCrashDialog.hpp" @@ -114,6 +115,8 @@ void runGui(QApplication &a, Paths &paths, Settings &settings) { initQt(); + initResources(); + auto thread = std::thread([dir = paths.miscDirectory] { { auto path = combinePath(dir, "Update.exe"); diff --git a/src/autogenerated/ResourcesAutogen.cpp b/src/autogenerated/ResourcesAutogen.cpp index 9629a8f0..e7aab5d5 100644 --- a/src/autogenerated/ResourcesAutogen.cpp +++ b/src/autogenerated/ResourcesAutogen.cpp @@ -50,4 +50,4 @@ Resources2::Resources2() this->twitch.vip = QPixmap(":/twitch/vip.png"); } -} // namespace chatterino \ No newline at end of file +} // namespace chatterino diff --git a/src/autogenerated/ResourcesAutogen.hpp b/src/autogenerated/ResourcesAutogen.hpp index 51a9a573..cb342363 100644 --- a/src/autogenerated/ResourcesAutogen.hpp +++ b/src/autogenerated/ResourcesAutogen.hpp @@ -1,4 +1,5 @@ #include + #include "common/Singleton.hpp" namespace chatterino { @@ -64,4 +65,4 @@ public: } twitch; }; -} // namespace chatterino \ No newline at end of file +} // namespace chatterino diff --git a/src/controllers/moderationactions/ModerationAction.cpp b/src/controllers/moderationactions/ModerationAction.cpp index 1bba03d2..dce01904 100644 --- a/src/controllers/moderationactions/ModerationAction.cpp +++ b/src/controllers/moderationactions/ModerationAction.cpp @@ -65,17 +65,17 @@ ModerationAction::ModerationAction(const QString &action) // line1 = this->line1_; // line2 = this->line2_; // } else { - // this->_moderationActions.emplace_back(app->resources->buttonTimeout, + // this->_moderationActions.emplace_back(getResources().buttonTimeout, // str); // } } else if (action.startsWith("/ban ")) { - this->image_ = Image::fromPixmap(getApp()->resources->buttons.ban); + this->image_ = Image::fromPixmap(getResources().buttons.ban); } else if (action.startsWith("/delete ")) { - this->image_ = Image::fromPixmap(getApp()->resources->buttons.trashCan); + this->image_ = Image::fromPixmap(getResources().buttons.trashCan); } else { diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index c38bf024..e24b22f9 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -33,7 +33,7 @@ std::pair makeAutomodMessage( builder .emplace( - Image::fromPixmap(getApp()->resources->twitch.automod), + Image::fromPixmap(getResources().twitch.automod), MessageElementFlag::BadgeChannelAuthority) ->setTooltip("AutoMod"); builder.emplace("AutoMod:", MessageElementFlag::BoldUsername, diff --git a/src/providers/twitch/TwitchMessageBuilder.cpp b/src/providers/twitch/TwitchMessageBuilder.cpp index 3f94877a..5caa56fb 100644 --- a/src/providers/twitch/TwitchMessageBuilder.cpp +++ b/src/providers/twitch/TwitchMessageBuilder.cpp @@ -1174,21 +1174,21 @@ void TwitchMessageBuilder::appendTwitchBadges() else if (badge == "staff/1") { this->emplace( - Image::fromPixmap(app->resources->twitch.staff), + Image::fromPixmap(getResources().twitch.staff), MessageElementFlag::BadgeGlobalAuthority) ->setTooltip("Twitch Staff"); } else if (badge == "admin/1") { this->emplace( - Image::fromPixmap(app->resources->twitch.admin), + Image::fromPixmap(getResources().twitch.admin), MessageElementFlag::BadgeGlobalAuthority) ->setTooltip("Twitch Admin"); } else if (badge == "global_mod/1") { this->emplace( - Image::fromPixmap(app->resources->twitch.globalmod), + Image::fromPixmap(getResources().twitch.globalmod), MessageElementFlag::BadgeGlobalAuthority) ->setTooltip("Twitch Global Moderator"); } @@ -1203,35 +1203,35 @@ void TwitchMessageBuilder::appendTwitchBadges() continue; } this->emplace( - Image::fromPixmap(app->resources->twitch.moderator), + Image::fromPixmap(getResources().twitch.moderator), MessageElementFlag::BadgeChannelAuthority) ->setTooltip("Twitch Channel Moderator"); } else if (badge == "vip/1") { this->emplace( - Image::fromPixmap(app->resources->twitch.vip), + Image::fromPixmap(getResources().twitch.vip), MessageElementFlag::BadgeChannelAuthority) ->setTooltip("VIP"); } else if (badge == "broadcaster/1") { this->emplace( - Image::fromPixmap(app->resources->twitch.broadcaster), + Image::fromPixmap(getResources().twitch.broadcaster), MessageElementFlag::BadgeChannelAuthority) ->setTooltip("Twitch Broadcaster"); } else if (badge == "turbo/1") { this->emplace( - Image::fromPixmap(app->resources->twitch.turbo), + Image::fromPixmap(getResources().twitch.turbo), MessageElementFlag::BadgeVanity) ->setTooltip("Twitch Turbo Subscriber"); } else if (badge == "premium/1") { this->emplace( - Image::fromPixmap(app->resources->twitch.prime), + Image::fromPixmap(getResources().twitch.prime), MessageElementFlag::BadgeVanity) ->setTooltip("Twitch Prime Subscriber"); } @@ -1243,7 +1243,7 @@ void TwitchMessageBuilder::appendTwitchBadges() case 1: { this->emplace( - Image::fromPixmap(app->resources->twitch.verified, + Image::fromPixmap(getResources().twitch.verified, 0.25), MessageElementFlag::BadgeVanity) ->setTooltip("Twitch Verified"); @@ -1271,7 +1271,7 @@ void TwitchMessageBuilder::appendTwitchBadges() // use default subscriber badge if custom one not found this->emplace( - Image::fromPixmap(app->resources->twitch.subscriber, 0.25), + Image::fromPixmap(getResources().twitch.subscriber, 0.25), MessageElementFlag::BadgeSubscription) ->setTooltip("Twitch Subscriber"); } diff --git a/src/singletons/Resources.cpp b/src/singletons/Resources.cpp index daec74a5..18995dc3 100644 --- a/src/singletons/Resources.cpp +++ b/src/singletons/Resources.cpp @@ -1 +1,24 @@ #include "singletons/Resources.hpp" + +#include "debug/AssertInGuiThread.hpp" + +namespace chatterino { +namespace { + static Resources2 *resources = nullptr; +} + +Resources2 &getResources() +{ + assert(resources); + + return *resources; +} + +void initResources() +{ + assertInGuiThread(); + + resources = new Resources2; +} + +} // namespace chatterino diff --git a/src/singletons/Resources.hpp b/src/singletons/Resources.hpp index 57a1b79a..f4217ca8 100644 --- a/src/singletons/Resources.hpp +++ b/src/singletons/Resources.hpp @@ -1,3 +1,12 @@ #pragma once #include "autogenerated/ResourcesAutogen.hpp" + +namespace chatterino { + +/// This class in thread safe but needs to be initialized from the gui thread +/// first. +Resources2 &getResources(); +void initResources(); + +} // namespace chatterino diff --git a/src/widgets/dialogs/UserInfoPopup.cpp b/src/widgets/dialogs/UserInfoPopup.cpp index 40beaedf..4a7d4f68 100644 --- a/src/widgets/dialogs/UserInfoPopup.cpp +++ b/src/widgets/dialogs/UserInfoPopup.cpp @@ -32,7 +32,7 @@ namespace { { auto label = box.emplace