diff --git a/CMakeLists.txt b/CMakeLists.txt index c7bc9cd4f..90a1be3de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,6 +24,12 @@ option(CHATTERINO_GENERATE_COVERAGE "Generate coverage files" OFF) option(BUILD_TRANSLATIONS "" OFF) option(BUILD_SHARED_LIBS "" OFF) option(CHATTERINO_LTO "Enable LTO for all targets" OFF) +option(CHATTERINO_PLUGINS "Enable EXPERIMENTAL plugin support in Chatterino" OFF) + +if(CHATTERINO_PLUGINS) + add_definitions(-DCHATTERINO_HAVE_PLUGINS) + message(STATUS "Building Chatterino with lua plugin support enabled.") +endif() if(CHATTERINO_LTO) include(CheckIPOSupported) @@ -148,9 +154,10 @@ else() add_subdirectory("${CMAKE_SOURCE_DIR}/lib/settings" EXCLUDE_FROM_ALL) endif() - -set(LUA_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/lib/lua/src") -add_subdirectory(lib/lua) +if (CHATTERINO_PLUGINS) + set(LUA_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/lib/lua/src") + add_subdirectory(lib/lua) +endif() set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) diff --git a/src/Application.cpp b/src/Application.cpp index 6df7ef647..1990165f9 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -10,7 +10,9 @@ #include "controllers/hotkeys/HotkeyController.hpp" #include "controllers/ignores/IgnoreController.hpp" #include "controllers/notifications/NotificationController.hpp" -#include "controllers/plugins/PluginController.hpp" +#ifdef CHATTERINO_HAVE_PLUGINS +# include "controllers/plugins/PluginController.hpp" +#endif #include "controllers/sound/SoundController.hpp" #include "controllers/userdata/UserDataController.hpp" #include "debug/AssertInGuiThread.hpp" @@ -85,7 +87,9 @@ Application::Application(Settings &_settings, Paths &_paths) , seventvBadges(&this->emplace()) , userData(&this->emplace()) , sound(&this->emplace()) +#ifdef CHATTERINO_HAVE_PLUGINS , plugins(&this->emplace()) +#endif , logging(&this->emplace()) { this->instance = this; diff --git a/src/Application.hpp b/src/Application.hpp index a4d1de114..7c5525505 100644 --- a/src/Application.hpp +++ b/src/Application.hpp @@ -20,7 +20,9 @@ class HotkeyController; class IUserDataController; class UserDataController; class SoundController; +#ifdef CHATTERINO_HAVE_PLUGINS class PluginController; +#endif class Theme; class WindowManager; @@ -96,7 +98,9 @@ public: UserDataController *const userData{}; SoundController *const sound{}; +#ifdef CHATTERINO_HAVE_PLUGINS PluginController *const plugins{}; +#endif /*[[deprecated]]*/ Logging *const logging{}; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3b9230fcf..72fefca53 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -625,8 +625,10 @@ target_link_libraries(${LIBRARY_PROJECT} RapidJSON::RapidJSON LRUCache MagicEnum - lua ) +if (CHATTERINO_PLUGINS) + target_link_libraries(${LIBRARY_PROJECT} PUBLIC lua) +endif() if (BUILD_WITH_QTKEYCHAIN) target_link_libraries(${LIBRARY_PROJECT} diff --git a/src/common/CompletionModel.cpp b/src/common/CompletionModel.cpp index b7f2f879f..9b123aa4c 100644 --- a/src/common/CompletionModel.cpp +++ b/src/common/CompletionModel.cpp @@ -230,11 +230,12 @@ void CompletionModel::refresh(const QString &prefix, bool isFirstWord) { addString(emote.first.string, TaggedString::Type::BTTVGlobalEmote); } - +#ifdef CHATTERINO_HAVE_PLUGINS for (const auto &command : getApp()->commands->pluginCommands()) { addString(command, TaggedString::PluginCommand); } +#endif // Custom Chatterino commands for (const auto &command : getApp()->commands->items) { diff --git a/src/common/CompletionModel.hpp b/src/common/CompletionModel.hpp index a1b1c882b..5b46fb2de 100644 --- a/src/common/CompletionModel.hpp +++ b/src/common/CompletionModel.hpp @@ -34,7 +34,9 @@ class CompletionModel : public QAbstractListModel CustomCommand, ChatterinoCommand, TwitchCommand, +#ifdef CHATTERINO_HAVE_PLUGINS PluginCommand, +#endif }; TaggedString(QString _string, Type type); diff --git a/src/controllers/commands/CommandController.cpp b/src/controllers/commands/CommandController.cpp index 6e3a41350..e8f4f6b35 100644 --- a/src/controllers/commands/CommandController.cpp +++ b/src/controllers/commands/CommandController.cpp @@ -3220,7 +3220,7 @@ QString CommandController::execCommand(const QString &textNoEmoji, return text; } - +#ifdef CHATTERINO_HAVE_PLUGINS bool CommandController::registerPluginCommand(const QString &commandName) { if (this->commands_.contains(commandName)) @@ -3244,6 +3244,7 @@ bool CommandController::unregisterPluginCommand(const QString &commandName) this->pluginCommands_.removeAll(commandName); return this->commands_.erase(commandName) != 0; } +#endif void CommandController::registerCommand(const QString &commandName, CommandFunctionVariants commandFunction) diff --git a/src/controllers/commands/CommandController.hpp b/src/controllers/commands/CommandController.hpp index ee4b2f9e2..ca8a820ff 100644 --- a/src/controllers/commands/CommandController.hpp +++ b/src/controllers/commands/CommandController.hpp @@ -42,7 +42,7 @@ public: const QStringList &words, const Command &command, bool dryRun, ChannelPtr channel, const Message *message = nullptr, std::unordered_map context = {}); - +#ifdef CHATTERINO_HAVE_PLUGINS bool registerPluginCommand(const QString &commandName); bool unregisterPluginCommand(const QString &commandName); @@ -50,6 +50,7 @@ public: { return this->pluginCommands_; } +#endif private: void load(Paths &paths); @@ -81,7 +82,9 @@ private: commandsSetting_; QStringList defaultChatterinoCommandAutoCompletions_; +#ifdef CHATTERINO_HAVE_PLUGINS QStringList pluginCommands_; +#endif }; } // namespace chatterino diff --git a/src/controllers/plugins/LuaUtilities.cpp b/src/controllers/plugins/LuaUtilities.cpp index 99977a79b..0440ffe9a 100644 --- a/src/controllers/plugins/LuaUtilities.cpp +++ b/src/controllers/plugins/LuaUtilities.cpp @@ -1,12 +1,13 @@ #include "LuaUtilities.hpp" +#ifdef CHATTERINO_HAVE_PLUGINS -#include "common/Channel.hpp" -#include "controllers/commands/CommandContext.hpp" -#include "lauxlib.h" -#include "lua.h" +# include "common/Channel.hpp" +# include "controllers/commands/CommandContext.hpp" +# include "lauxlib.h" +# include "lua.h" -#include -#include +# include +# include namespace chatterino::lua { @@ -109,3 +110,4 @@ bool peek(lua_State *L, QString *out, StackIdx idx) return true; } } // namespace chatterino::lua +#endif diff --git a/src/controllers/plugins/LuaUtilities.hpp b/src/controllers/plugins/LuaUtilities.hpp index 0ecf25c36..5530a7f59 100644 --- a/src/controllers/plugins/LuaUtilities.hpp +++ b/src/controllers/plugins/LuaUtilities.hpp @@ -1,10 +1,11 @@ #pragma once -#include "lua.h" +#ifdef CHATTERINO_HAVE_PLUGINS +# include "lua.h" -#include +# include -#include +# include struct lua_State; class QJsonObject; namespace chatterino { @@ -73,3 +74,4 @@ bool pop(lua_State *L, T *out, StackIdx idx = -1) } } // namespace chatterino::lua +#endif diff --git a/src/controllers/plugins/Plugin.cpp b/src/controllers/plugins/Plugin.cpp index d75c3f19d..5d3400a79 100644 --- a/src/controllers/plugins/Plugin.cpp +++ b/src/controllers/plugins/Plugin.cpp @@ -1,4 +1,5 @@ #include "Plugin.hpp" +#ifdef CHATTERINO_HAVE_PLUGINS namespace chatterino { bool Plugin::registerCommand(const QString &name, const QString &functionName) @@ -27,3 +28,4 @@ std::set Plugin::listRegisteredCommands() return out; } } // namespace chatterino +#endif diff --git a/src/controllers/plugins/PluginController.cpp b/src/controllers/plugins/PluginController.cpp index dbcef9e9f..6a1313cb1 100644 --- a/src/controllers/plugins/PluginController.cpp +++ b/src/controllers/plugins/PluginController.cpp @@ -1,28 +1,26 @@ #include "PluginController.hpp" +#ifdef CHATTERINO_HAVE_PLUGINS -#include "Application.hpp" -#include "common/QLogging.hpp" -#include "controllers/commands/CommandContext.hpp" -#include "controllers/plugins/LuaUtilities.hpp" -#include "messages/MessageBuilder.hpp" -#include "providers/twitch/TwitchIrcServer.hpp" -#include "singletons/Paths.hpp" -#include "singletons/Settings.hpp" -#include "singletons/WindowManager.hpp" -#include "widgets/Notebook.hpp" -#include "widgets/splits/Split.hpp" -#include "widgets/Window.hpp" +# include "Application.hpp" +# include "common/QLogging.hpp" +# include "controllers/commands/CommandContext.hpp" +# include "controllers/plugins/LuaUtilities.hpp" +# include "lauxlib.h" +# include "lua.h" +# include "lualib.h" +# include "messages/MessageBuilder.hpp" +# include "providers/twitch/TwitchIrcServer.hpp" +# include "singletons/Paths.hpp" +# include "singletons/Settings.hpp" +# include "singletons/WindowManager.hpp" +# include "widgets/Notebook.hpp" +# include "widgets/splits/Split.hpp" +# include "widgets/Window.hpp" -#include +# include -#include -#include - -//extern "C" { -#include "lauxlib.h" -#include "lua.h" -#include "lualib.h" -//} +# include +# include namespace chatterino { @@ -362,3 +360,4 @@ bool PluginController::isEnabled(const QString &codename) } }; // namespace chatterino +#endif diff --git a/src/controllers/plugins/PluginController.hpp b/src/controllers/plugins/PluginController.hpp index d024dd801..e4eedd128 100644 --- a/src/controllers/plugins/PluginController.hpp +++ b/src/controllers/plugins/PluginController.hpp @@ -1,20 +1,22 @@ #pragma once -#include "common/Singleton.hpp" -#include "controllers/plugins/Plugin.hpp" -#include "singletons/Paths.hpp" +#ifdef CHATTERINO_HAVE_PLUGINS -#include -#include -#include -#include -#include +# include "common/Singleton.hpp" +# include "controllers/plugins/Plugin.hpp" +# include "singletons/Paths.hpp" -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include + +# include +# include +# include +# include +# include struct lua_State; @@ -68,3 +70,4 @@ private: }; }; // namespace chatterino +#endif diff --git a/src/widgets/dialogs/SettingsDialog.cpp b/src/widgets/dialogs/SettingsDialog.cpp index cd3a52107..fff147099 100644 --- a/src/widgets/dialogs/SettingsDialog.cpp +++ b/src/widgets/dialogs/SettingsDialog.cpp @@ -216,7 +216,9 @@ void SettingsDialog::addTabs() this->addTab([]{return new ModerationPage;}, "Moderation", ":/settings/moderation.svg", SettingsTabId::Moderation); this->addTab([]{return new NotificationPage;}, "Live Notifications", ":/settings/notification2.svg"); this->addTab([]{return new ExternalToolsPage;}, "External tools", ":/settings/externaltools.svg"); +#ifdef CHATTERINO_HAVE_PLUGINS this->addTab([]{return new PluginsPage;}, "Plugins", ":/settings/externaltools.svg"); +#endif this->ui_.tabContainer->addStretch(1); this->addTab([]{return new AboutPage;}, "About", ":/settings/about.svg", SettingsTabId(), Qt::AlignBottom); // clang-format on diff --git a/src/widgets/settingspages/PluginsPage.cpp b/src/widgets/settingspages/PluginsPage.cpp index 96471e1e9..d37aea254 100644 --- a/src/widgets/settingspages/PluginsPage.cpp +++ b/src/widgets/settingspages/PluginsPage.cpp @@ -1,21 +1,22 @@ #include "PluginsPage.hpp" +#ifdef CHATTERINO_HAVE_PLUGINS -#include "Application.hpp" -#include "controllers/plugins/PluginController.hpp" -#include "singletons/Paths.hpp" -#include "singletons/Settings.hpp" -#include "util/Helpers.hpp" -#include "util/LayoutCreator.hpp" -#include "util/RemoveScrollAreaBackground.hpp" +# include "Application.hpp" +# include "controllers/plugins/PluginController.hpp" +# include "singletons/Paths.hpp" +# include "singletons/Settings.hpp" +# include "util/Helpers.hpp" +# include "util/LayoutCreator.hpp" +# include "util/RemoveScrollAreaBackground.hpp" -#include -#include -#include -#include -#include -#include -#include -#include +# include +# include +# include +# include +# include +# include +# include +# include namespace chatterino { @@ -163,3 +164,4 @@ void PluginsPage::rebuildContent() } } // namespace chatterino +#endif diff --git a/src/widgets/settingspages/PluginsPage.hpp b/src/widgets/settingspages/PluginsPage.hpp index 1d6685035..08fbd8690 100644 --- a/src/widgets/settingspages/PluginsPage.hpp +++ b/src/widgets/settingspages/PluginsPage.hpp @@ -1,11 +1,12 @@ #pragma once -#include "util/LayoutCreator.hpp" -#include "widgets/settingspages/SettingsPage.hpp" +#ifdef CHATTERINO_HAVE_PLUGINS +# include "util/LayoutCreator.hpp" +# include "widgets/settingspages/SettingsPage.hpp" -#include -#include -#include -#include +# include +# include +# include +# include namespace chatterino { class Plugin; @@ -23,3 +24,4 @@ private: QFrame *dataFrame_; }; } // namespace chatterino +#endif