From 3dc73e9b84f0f3c0a5974ef73659c05c12d89f93 Mon Sep 17 00:00:00 2001 From: MiguVT <71216796+MiguVT@users.noreply.github.com> Date: Tue, 4 Mar 2025 22:26:20 +0100 Subject: [PATCH] feat: allow extra user-defined extension IDs to interact with Chatterino (#5997) --- CHANGELOG.md | 1 + src/singletons/NativeMessaging.cpp | 26 +++++++++++++++++++++++ src/singletons/Settings.hpp | 2 ++ src/widgets/settingspages/GeneralPage.cpp | 21 ++++++++++++++++++ 4 files changed, 50 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26f42cdf..812e9593 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unversioned +- Minor: Added an option to allow multiple user-selected extensions to interact with Chatterino. (#5997) - Minor: Add `Set highlight sounds` and `Open subscription page` split hotkeys. (#5856) - Minor: `/clear` messages are now stacked like timeouts. (#5806) - Minor: Treat all browsers starting with `firefox` as a Firefox browser. (#5805) diff --git a/src/singletons/NativeMessaging.cpp b/src/singletons/NativeMessaging.cpp index 5406fb4d..ec4421ca 100644 --- a/src/singletons/NativeMessaging.cpp +++ b/src/singletons/NativeMessaging.cpp @@ -7,6 +7,7 @@ #include "debug/AssertInGuiThread.hpp" #include "providers/twitch/TwitchIrcServer.hpp" #include "singletons/Paths.hpp" +#include "singletons/Settings.hpp" #include "util/IpcQueue.hpp" #include "util/PostToThread.hpp" @@ -55,11 +56,26 @@ void registerNmHost(const Paths &paths) }; }; + QStringList extensionIDs = + getSettings()->additionalExtensionIDs.getValue().split( + ';', Qt::SkipEmptyParts); + // chrome { auto obj = getBaseDocument(); QJsonArray allowedOriginsArr = { u"chrome-extension://%1/"_s.arg(EXTENSION_ID)}; + + for (const auto &id : extensionIDs) + { + QString trimmedID = id.trimmed(); + if (!trimmedID.isEmpty()) + { + allowedOriginsArr.append( + u"chrome-extension://%1/"_s.arg(trimmedID)); + } + } + obj.insert("allowed_origins", allowedOriginsArr); registerNmManifest(paths, "/native-messaging-manifest-chrome.json", @@ -72,6 +88,16 @@ void registerNmHost(const Paths &paths) { auto obj = getBaseDocument(); QJsonArray allowedExtensions = {"chatterino_native@chatterino.com"}; + + for (const auto &id : extensionIDs) + { + QString trimmedID = id.trimmed(); + if (!trimmedID.isEmpty()) + { + allowedExtensions.append(trimmedID); + } + } + obj.insert("allowed_extensions", allowedExtensions); registerNmManifest(paths, "/native-messaging-manifest-firefox.json", diff --git a/src/singletons/Settings.hpp b/src/singletons/Settings.hpp index fbfa024a..df94504c 100644 --- a/src/singletons/Settings.hpp +++ b/src/singletons/Settings.hpp @@ -658,6 +658,8 @@ public: false, }; + QStringSetting additionalExtensionIDs{"/misc/additionalExtensionIDs", ""}; + private: ChatterinoSetting> highlightedMessagesSetting = {"/highlighting/highlights"}; diff --git a/src/widgets/settingspages/GeneralPage.cpp b/src/widgets/settingspages/GeneralPage.cpp index ea2b346c..6a6f9f7f 100644 --- a/src/widgets/settingspages/GeneralPage.cpp +++ b/src/widgets/settingspages/GeneralPage.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -876,6 +877,26 @@ void GeneralPage::initLayout(GeneralPageView &layout) s.attachExtensionToAnyProcess, false, "Attempt to force the Chatterino Browser Extension to work in certain " "browsers that do not work automatically.\ne.g. Librewolf"); + + { + auto *note = new QLabel( + "A semicolon-separated list of Chrome or Firefox extension IDs" + "allowed to interact with Chatterino's browser integration " + "(requires restart).\n" + "Using multiple extension IDs from different browsers may cause " + "issues."); + note->setWordWrap(true); + note->setStyleSheet("color: #bbb"); + + layout.addWidget(note); + auto *extraIDs = this->createLineEdit(s.additionalExtensionIDs); + extraIDs->setPlaceholderText("Extension;IDs;separated;by;semicolons"); + + auto form = new QFormLayout(); + form->addRow("Extra extension IDs:", extraIDs); + + layout.addLayout(form); + } #endif layout.addTitle("AppData & Cache");