diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cc0c9a2f..278771c62 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ - Minor: Hosting messages are now clickable. (#2655) - Minor: Messages held by automod are now shown to the user. (#2626) - Minor: Load 100 blocked users rather than the default 20. (#2772) +- Bugfix: Fixed a potential crashing issue related to the browser extension. (#2774) - Bugfix: Strip newlines from stream titles to prevent text going off of split header (#2755) - Bugfix: Automod messages now work properly again. (#2682) - Bugfix: `Login expired` message no longer highlights all tabs. (#2735) diff --git a/src/singletons/NativeMessaging.cpp b/src/singletons/NativeMessaging.cpp index c711e4be7..e0fdff803 100644 --- a/src/singletons/NativeMessaging.cpp +++ b/src/singletons/NativeMessaging.cpp @@ -149,31 +149,42 @@ void NativeMessagingServer::start() void NativeMessagingServer::ReceiverThread::run() { - ipc::message_queue::remove("chatterino_gui"); - ipc::message_queue messageQueue(ipc::open_or_create, "chatterino_gui", 100, - MESSAGE_SIZE); - - while (true) + try { - try + ipc::message_queue::remove("chatterino_gui"); + ipc::message_queue messageQueue(ipc::open_or_create, "chatterino_gui", + 100, MESSAGE_SIZE); + + while (true) { - auto buf = std::make_unique(MESSAGE_SIZE); - auto retSize = ipc::message_queue::size_type(); - auto priority = static_cast(0); + try + { + auto buf = std::make_unique(MESSAGE_SIZE); + auto retSize = ipc::message_queue::size_type(); + auto priority = static_cast(0); - messageQueue.receive(buf.get(), MESSAGE_SIZE, retSize, priority); + messageQueue.receive(buf.get(), MESSAGE_SIZE, retSize, + priority); - auto document = QJsonDocument::fromJson( - QByteArray::fromRawData(buf.get(), retSize)); + auto document = QJsonDocument::fromJson( + QByteArray::fromRawData(buf.get(), retSize)); - this->handleMessage(document.object()); - } - catch (ipc::interprocess_exception &ex) - { - qCDebug(chatterinoNativeMessage) - << "received from gui process:" << ex.what(); + this->handleMessage(document.object()); + } + catch (ipc::interprocess_exception &ex) + { + qCDebug(chatterinoNativeMessage) + << "received from gui process:" << ex.what(); + } } } + catch (ipc::interprocess_exception &ex) + { + qCDebug(chatterinoNativeMessage) + << "run ipc message queue:" << ex.what(); + + nmIpcError().set(QString::fromLatin1(ex.what())); + } } void NativeMessagingServer::ReceiverThread::handleMessage( @@ -272,4 +283,10 @@ void NativeMessagingServer::ReceiverThread::handleMessage( } } +Atomic> &nmIpcError() +{ + static Atomic> x; + return x; +} + } // namespace chatterino diff --git a/src/singletons/NativeMessaging.hpp b/src/singletons/NativeMessaging.hpp index 82b201a19..2bb0107b2 100644 --- a/src/singletons/NativeMessaging.hpp +++ b/src/singletons/NativeMessaging.hpp @@ -1,6 +1,9 @@ #pragma once +#include #include +#include +#include namespace chatterino { @@ -10,6 +13,8 @@ class Paths; void registerNmHost(Paths &paths); std::string &getNmQueueName(Paths &paths); +Atomic> &nmIpcError(); + class NativeMessagingClient final { public: diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index ca26258ad..81d41b01d 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -7,6 +7,7 @@ #include "Application.hpp" #include "common/Version.hpp" #include "singletons/Fonts.hpp" +#include "singletons/NativeMessaging.hpp" #include "singletons/Paths.hpp" #include "singletons/Theme.hpp" #include "singletons/WindowManager.hpp" @@ -442,6 +443,16 @@ void GeneralPage::initLayout(GeneralPageView &layout) layout.addDescription("The browser extension replaces the default " "Twitch.tv chat with chatterino."); + { + if (auto err = nmIpcError().get()) + { + layout.addDescription( + "An error happened during initialization of the " + "browser extension: " + + *err); + } + } + layout.addDescription(formatRichNamedLink( CHROME_EXTENSION_LINK, "Download for Google Chrome and similar browsers."));