mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
refactor: make Application::plugins private
and add a getter for it
This commit is contained in:
parent
56b8396f77
commit
cd85a1a9de
|
@ -447,6 +447,15 @@ SeventvAPI *Application::getSeventvAPI()
|
|||
return this->seventvAPI;
|
||||
}
|
||||
|
||||
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||
PluginController *Application::getPlugins()
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
||||
return this->plugins;
|
||||
}
|
||||
#endif
|
||||
|
||||
ITwitchIrcServer *Application::getTwitch()
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
|
|
@ -85,6 +85,9 @@ public:
|
|||
virtual TwitchBadges *getTwitchBadges() = 0;
|
||||
virtual ImageUploader *getImageUploader() = 0;
|
||||
virtual SeventvAPI *getSeventvAPI() = 0;
|
||||
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||
virtual PluginController *getPlugins() = 0;
|
||||
#endif
|
||||
virtual Updates &getUpdates() = 0;
|
||||
};
|
||||
|
||||
|
@ -154,12 +157,11 @@ private:
|
|||
std::unique_ptr<TwitchBadges> twitchBadges;
|
||||
std::unique_ptr<ChatterinoBadges> chatterinoBadges;
|
||||
const std::unique_ptr<Logging> logging;
|
||||
|
||||
public:
|
||||
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||
PluginController *const plugins{};
|
||||
#endif
|
||||
|
||||
public:
|
||||
const Paths &getPaths() override
|
||||
{
|
||||
return this->paths_;
|
||||
|
@ -191,6 +193,9 @@ public:
|
|||
IChatterinoBadges *getChatterinoBadges() override;
|
||||
ImageUploader *getImageUploader() override;
|
||||
SeventvAPI *getSeventvAPI() override;
|
||||
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||
PluginController *getPlugins() override;
|
||||
#endif
|
||||
Updates &getUpdates() override
|
||||
{
|
||||
assertInGuiThread();
|
||||
|
|
|
@ -562,7 +562,7 @@ bool CommandController::registerPluginCommand(const QString &commandName)
|
|||
}
|
||||
|
||||
this->commands_[commandName] = [commandName](const CommandContext &ctx) {
|
||||
return getApp()->plugins->tryExecPluginCommand(commandName, ctx);
|
||||
return getIApp()->getPlugins()->tryExecPluginCommand(commandName, ctx);
|
||||
};
|
||||
this->pluginCommands_.append(commandName);
|
||||
return true;
|
||||
|
|
|
@ -38,8 +38,9 @@ void TabCompletionModel::updateResults(const QString &query,
|
|||
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||
// Try plugins first
|
||||
bool done{};
|
||||
std::tie(done, results) = getApp()->plugins->updateCustomCompletions(
|
||||
query, fullTextContent, cursorPosition, isFirstWord);
|
||||
std::tie(done, results) =
|
||||
getIApp()->getPlugins()->updateCustomCompletions(
|
||||
query, fullTextContent, cursorPosition, isFirstWord);
|
||||
if (done)
|
||||
{
|
||||
this->setStringList(results);
|
||||
|
|
|
@ -63,7 +63,7 @@ namespace chatterino::lua::api {
|
|||
|
||||
int c2_register_command(lua_State *L)
|
||||
{
|
||||
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
if (pl == nullptr)
|
||||
{
|
||||
luaL_error(L, "internal error: no plugin");
|
||||
|
@ -97,7 +97,7 @@ int c2_register_command(lua_State *L)
|
|||
|
||||
int c2_register_callback(lua_State *L)
|
||||
{
|
||||
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
if (pl == nullptr)
|
||||
{
|
||||
luaL_error(L, "internal error: no plugin");
|
||||
|
@ -155,7 +155,7 @@ int c2_send_msg(lua_State *L)
|
|||
const auto chn = getApp()->twitch->getChannelOrEmpty(channel);
|
||||
if (chn->isEmpty())
|
||||
{
|
||||
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
|
||||
qCWarning(chatterinoLua)
|
||||
<< "Plugin" << pl->id
|
||||
|
@ -204,7 +204,7 @@ int c2_system_msg(lua_State *L)
|
|||
const auto chn = getApp()->twitch->getChannelOrEmpty(channel);
|
||||
if (chn->isEmpty())
|
||||
{
|
||||
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
qCWarning(chatterinoLua)
|
||||
<< "Plugin" << pl->id
|
||||
<< "tried to show a system message (using system_msg) in channel"
|
||||
|
@ -219,7 +219,7 @@ int c2_system_msg(lua_State *L)
|
|||
|
||||
int c2_log(lua_State *L)
|
||||
{
|
||||
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
if (pl == nullptr)
|
||||
{
|
||||
luaL_error(L, "c2_log: internal error: no plugin?");
|
||||
|
@ -286,7 +286,7 @@ int g_load(lua_State *L)
|
|||
|
||||
int loadfile(lua_State *L, const QString &str)
|
||||
{
|
||||
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
if (pl == nullptr)
|
||||
{
|
||||
return luaL_error(L, "loadfile: internal error: no plugin?");
|
||||
|
@ -328,7 +328,7 @@ int searcherAbsolute(lua_State *L)
|
|||
name = name.replace('.', QDir::separator());
|
||||
|
||||
QString filename;
|
||||
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
if (pl == nullptr)
|
||||
{
|
||||
return luaL_error(L, "searcherAbsolute: internal error: no plugin?");
|
||||
|
@ -369,7 +369,7 @@ int searcherRelative(lua_State *L)
|
|||
|
||||
int g_print(lua_State *L)
|
||||
{
|
||||
auto *pl = getApp()->plugins->getPluginByStatePtr(L);
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
if (pl == nullptr)
|
||||
{
|
||||
luaL_error(L, "c2_print: internal error: no plugin?");
|
||||
|
|
|
@ -80,7 +80,7 @@ void PluginsPage::rebuildContent()
|
|||
this->scrollAreaWidget_.append(this->dataFrame_);
|
||||
auto layout = frame.setLayoutType<QVBoxLayout>();
|
||||
layout->setParent(this->dataFrame_);
|
||||
for (const auto &[id, plugin] : getApp()->plugins->plugins())
|
||||
for (const auto &[id, plugin] : getIApp()->getPlugins()->plugins())
|
||||
{
|
||||
auto groupHeaderText =
|
||||
QString("%1 (%2, from %3)")
|
||||
|
@ -185,7 +185,7 @@ void PluginsPage::rebuildContent()
|
|||
val.push_back(name);
|
||||
}
|
||||
getSettings()->enabledPlugins.setValue(val);
|
||||
getApp()->plugins->reload(name);
|
||||
getIApp()->getPlugins()->reload(name);
|
||||
this->rebuildContent();
|
||||
});
|
||||
pluginEntry->addRow(toggleButton);
|
||||
|
@ -194,7 +194,7 @@ void PluginsPage::rebuildContent()
|
|||
auto *reloadButton = new QPushButton("Reload", this->dataFrame_);
|
||||
QObject::connect(reloadButton, &QPushButton::pressed,
|
||||
[name = id, this]() {
|
||||
getApp()->plugins->reload(name);
|
||||
getIApp()->getPlugins()->reload(name);
|
||||
this->rebuildContent();
|
||||
});
|
||||
pluginEntry->addRow(reloadButton);
|
||||
|
|
Loading…
Reference in a new issue