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