chore: remove Singleton & replace getIApp with getApp (#5514)
This commit is contained in:
@@ -65,7 +65,7 @@ namespace chatterino::lua::api {
|
||||
|
||||
int c2_register_command(lua_State *L)
|
||||
{
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
if (pl == nullptr)
|
||||
{
|
||||
luaL_error(L, "internal error: no plugin");
|
||||
@@ -99,7 +99,7 @@ int c2_register_command(lua_State *L)
|
||||
|
||||
int c2_register_callback(lua_State *L)
|
||||
{
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
if (pl == nullptr)
|
||||
{
|
||||
luaL_error(L, "internal error: no plugin");
|
||||
@@ -133,7 +133,7 @@ int c2_register_callback(lua_State *L)
|
||||
|
||||
int c2_log(lua_State *L)
|
||||
{
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
if (pl == nullptr)
|
||||
{
|
||||
luaL_error(L, "c2_log: internal error: no plugin?");
|
||||
@@ -154,7 +154,7 @@ int c2_log(lua_State *L)
|
||||
|
||||
int c2_later(lua_State *L)
|
||||
{
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
if (pl == nullptr)
|
||||
{
|
||||
return luaL_error(L, "c2.later: internal error: no plugin?");
|
||||
@@ -257,7 +257,7 @@ int g_load(lua_State *L)
|
||||
|
||||
int loadfile(lua_State *L, const QString &str)
|
||||
{
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
if (pl == nullptr)
|
||||
{
|
||||
return luaL_error(L, "loadfile: internal error: no plugin?");
|
||||
@@ -307,7 +307,7 @@ int searcherAbsolute(lua_State *L)
|
||||
name = name.replace('.', QDir::separator());
|
||||
|
||||
QString filename;
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
if (pl == nullptr)
|
||||
{
|
||||
return luaL_error(L, "searcherAbsolute: internal error: no plugin?");
|
||||
@@ -348,7 +348,7 @@ int searcherRelative(lua_State *L)
|
||||
|
||||
int g_print(lua_State *L)
|
||||
{
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
if (pl == nullptr)
|
||||
{
|
||||
luaL_error(L, "c2_print: internal error: no plugin?");
|
||||
|
||||
@@ -197,7 +197,7 @@ bool Plugin::registerCommand(const QString &name, const QString &functionName)
|
||||
return false;
|
||||
}
|
||||
|
||||
auto ok = getIApp()->getCommands()->registerPluginCommand(name);
|
||||
auto ok = getApp()->getCommands()->registerPluginCommand(name);
|
||||
if (!ok)
|
||||
{
|
||||
return false;
|
||||
|
||||
@@ -35,10 +35,8 @@ PluginController::PluginController(const Paths &paths_)
|
||||
{
|
||||
}
|
||||
|
||||
void PluginController::initialize(Settings &settings, const Paths &paths)
|
||||
void PluginController::initialize(Settings &settings)
|
||||
{
|
||||
(void)paths;
|
||||
|
||||
// actuallyInitialize will be called by this connection
|
||||
settings.pluginsEnabled.connect([this](bool enabled) {
|
||||
if (enabled)
|
||||
@@ -354,7 +352,7 @@ bool PluginController::reload(const QString &id)
|
||||
}
|
||||
for (const auto &[cmd, _] : it->second->ownedCommands)
|
||||
{
|
||||
getIApp()->getCommands()->unregisterPluginCommand(cmd);
|
||||
getApp()->getCommands()->unregisterPluginCommand(cmd);
|
||||
}
|
||||
it->second->ownedCommands.clear();
|
||||
QDir loadDir = it->second->loadDirectory_;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#ifdef CHATTERINO_HAVE_PLUGINS
|
||||
|
||||
# include "common/Singleton.hpp"
|
||||
# include "controllers/commands/CommandContext.hpp"
|
||||
# include "controllers/plugins/Plugin.hpp"
|
||||
|
||||
@@ -24,14 +23,14 @@ namespace chatterino {
|
||||
|
||||
class Paths;
|
||||
|
||||
class PluginController : public Singleton
|
||||
class PluginController
|
||||
{
|
||||
const Paths &paths;
|
||||
|
||||
public:
|
||||
explicit PluginController(const Paths &paths_);
|
||||
|
||||
void initialize(Settings &settings, const Paths &paths) override;
|
||||
void initialize(Settings &settings);
|
||||
|
||||
QString tryExecPluginCommand(const QString &commandName,
|
||||
const CommandContext &ctx);
|
||||
|
||||
@@ -174,7 +174,7 @@ int ChannelRef::send_message(lua_State *L)
|
||||
text = text.replace('\n', ' ');
|
||||
if (execcmds)
|
||||
{
|
||||
text = getIApp()->getCommands()->execCommand(text, that, false);
|
||||
text = getApp()->getCommands()->execCommand(text, that, false);
|
||||
}
|
||||
that->sendMessage(text);
|
||||
return 0;
|
||||
@@ -300,7 +300,7 @@ int ChannelRef::get_by_name(lua_State *L)
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
auto chn = getIApp()->getTwitchAbstract()->getChannelOrEmpty(name);
|
||||
auto chn = getApp()->getTwitchAbstract()->getChannelOrEmpty(name);
|
||||
lua::push(L, chn);
|
||||
return 1;
|
||||
}
|
||||
@@ -324,7 +324,7 @@ int ChannelRef::get_by_twitch_id(lua_State *L)
|
||||
lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
auto chn = getIApp()->getTwitch()->getChannelOrEmptyByID(id);
|
||||
auto chn = getApp()->getTwitch()->getChannelOrEmptyByID(id);
|
||||
|
||||
lua::push(L, chn);
|
||||
return 1;
|
||||
|
||||
@@ -309,7 +309,7 @@ int HTTPRequest::create(lua_State *L)
|
||||
L, "cannot get method (1st argument of HTTPRequest.create, "
|
||||
"expected a string)");
|
||||
}
|
||||
auto *pl = getIApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
auto *pl = getApp()->getPlugins()->getPluginByStatePtr(L);
|
||||
if (!pl->hasHTTPPermissionFor(parsedurl))
|
||||
{
|
||||
return luaL_error(
|
||||
|
||||
Reference in New Issue
Block a user