rename codename -> id

This commit is contained in:
Mm2PL 2023-02-14 12:07:22 +01:00
parent 627aafb74b
commit 2629c56d5c
5 changed files with 25 additions and 27 deletions

View file

@ -105,7 +105,7 @@ namespace {
void logHelper(lua_State *L, Plugin *pl, QDebug stream, int argc) void logHelper(lua_State *L, Plugin *pl, QDebug stream, int argc)
{ {
stream.noquote(); stream.noquote();
stream << "[" + pl->codename + ":" + pl->meta.name + "]"; stream << "[" + pl->id + ":" + pl->meta.name + "]";
for (int i = 1; i <= argc; i++) for (int i = 1; i <= argc; i++)
{ {
stream << lua::toString(L, i); stream << lua::toString(L, i);
@ -226,8 +226,8 @@ int g_import(lua_State *L)
auto dir = QUrl(pl->loadDirectory().canonicalPath() + "/"); auto dir = QUrl(pl->loadDirectory().canonicalPath() + "/");
auto file = dir.resolved(fname); auto file = dir.resolved(fname);
qCDebug(chatterinoLua) << "plugin" << pl->codename << "is trying to load" qCDebug(chatterinoLua) << "plugin" << pl->id << "is trying to load" << file
<< file << "(its dir is" << dir << ")"; << "(its dir is" << dir << ")";
if (!dir.isParentOf(file)) if (!dir.isParentOf(file))
{ {
lua_pushnil(L); lua_pushnil(L);

View file

@ -193,13 +193,13 @@ struct PluginMeta {
class Plugin class Plugin
{ {
public: public:
QString codename; QString id;
PluginMeta meta; PluginMeta meta;
bool isDupeName{}; bool isDupeName{};
Plugin(QString codename, lua_State *state, PluginMeta meta, Plugin(QString id, lua_State *state, PluginMeta meta,
const QDir &loadDirectory) const QDir &loadDirectory)
: codename(std::move(codename)) : id(std::move(id))
, meta(std::move(meta)) , meta(std::move(meta))
, loadDirectory_(loadDirectory) , loadDirectory_(loadDirectory)
, state_(state) , state_(state)

View file

@ -202,7 +202,7 @@ void PluginController::load(const QFileInfo &index, const QDir &pluginDir,
auto pluginName = pluginDir.dirName(); auto pluginName = pluginDir.dirName();
auto plugin = std::make_unique<Plugin>(pluginName, l, meta, pluginDir); auto plugin = std::make_unique<Plugin>(pluginName, l, meta, pluginDir);
for (const auto &[codename, other] : this->plugins_) for (const auto &[id, other] : this->plugins_)
{ {
if (other->meta.name == meta.name) if (other->meta.name == meta.name)
{ {
@ -229,9 +229,9 @@ void PluginController::load(const QFileInfo &index, const QDir &pluginDir,
qCInfo(chatterinoLua) << "Loaded" << pluginName << "plugin from" << index; qCInfo(chatterinoLua) << "Loaded" << pluginName << "plugin from" << index;
} }
bool PluginController::reload(const QString &codename) bool PluginController::reload(const QString &id)
{ {
auto it = this->plugins_.find(codename); auto it = this->plugins_.find(id);
if (it == this->plugins_.end()) if (it == this->plugins_.end())
{ {
return false; return false;
@ -247,7 +247,7 @@ bool PluginController::reload(const QString &codename)
} }
it->second->ownedCommands.clear(); it->second->ownedCommands.clear();
QDir loadDir = it->second->loadDirectory_; QDir loadDir = it->second->loadDirectory_;
this->plugins_.erase(codename); this->plugins_.erase(id);
this->tryLoadFromDir(loadDir); this->tryLoadFromDir(loadDir);
return true; return true;
} }
@ -283,14 +283,14 @@ QString PluginController::tryExecPluginCommand(const QString &commandName,
return ""; return "";
} }
bool PluginController::isEnabled(const QString &codename) bool PluginController::isEnabled(const QString &id)
{ {
if (!getSettings()->pluginSupportEnabled) if (!getSettings()->pluginSupportEnabled)
{ {
return false; return false;
} }
auto vec = getSettings()->enabledPlugins.getValue(); auto vec = getSettings()->enabledPlugins.getValue();
auto it = std::find(vec.begin(), vec.end(), codename); auto it = std::find(vec.begin(), vec.end(), id);
return it != vec.end(); return it != vec.end();
} }

View file

@ -51,18 +51,18 @@ public:
} }
/** /**
* @brief Reload plugin given by codename * @brief Reload plugin given by id
* *
* @param codename This is the 'codename' of the plugin, the name of the directory it is in * @param id This is the unique identifier of the plugin, the name of the directory it is in
*/ */
bool reload(const QString &codename); bool reload(const QString &id);
/** /**
* @brief Checks settings to tell if a plugin named by codename. * @brief Checks settings to tell if a plugin named by id.
* *
* It accounts for plugins being enabled/disabled globally. * It accounts for plugins being enabled/disabled globally.
*/ */
static bool isEnabled(const QString &codename); static bool isEnabled(const QString &id);
private: private:
void loadPlugins(); void loadPlugins();

View file

@ -68,7 +68,7 @@ void PluginsPage::rebuildContent()
this->dataFrame_ = frame.getElement(); this->dataFrame_ = frame.getElement();
this->scrollAreaWidget_.append(this->dataFrame_); this->scrollAreaWidget_.append(this->dataFrame_);
auto layout = frame.setLayoutType<QVBoxLayout>(); auto layout = frame.setLayoutType<QVBoxLayout>();
for (const auto &[codename, plugin] : getApp()->plugins->plugins()) for (const auto &[id, plugin] : getApp()->plugins->plugins())
{ {
QString headerText; QString headerText;
if (plugin->isDupeName) if (plugin->isDupeName)
@ -77,7 +77,7 @@ void PluginsPage::rebuildContent()
.arg(plugin->meta.name, .arg(plugin->meta.name,
QString::fromStdString( QString::fromStdString(
plugin->meta.version.to_string()), plugin->meta.version.to_string()),
codename); id);
} }
else else
{ {
@ -146,15 +146,14 @@ void PluginsPage::rebuildContent()
if (plugin->meta.isValid()) if (plugin->meta.isValid())
{ {
QString enableOrDisableStr = "Enable"; QString enableOrDisableStr = "Enable";
if (PluginController::isEnabled(codename)) if (PluginController::isEnabled(id))
{ {
enableOrDisableStr = "Disable"; enableOrDisableStr = "Disable";
} }
auto *enableDisable = new QPushButton(enableOrDisableStr); auto *enableDisable = new QPushButton(enableOrDisableStr);
QObject::connect( QObject::connect(
enableDisable, &QPushButton::pressed, enableDisable, &QPushButton::pressed, [name = id, this]() {
[name = codename, this]() {
std::vector<QString> val = std::vector<QString> val =
getSettings()->enabledPlugins.getValue(); getSettings()->enabledPlugins.getValue();
if (PluginController::isEnabled(name)) if (PluginController::isEnabled(name))
@ -174,8 +173,7 @@ void PluginsPage::rebuildContent()
} }
auto *reload = new QPushButton("Reload"); auto *reload = new QPushButton("Reload");
QObject::connect(reload, &QPushButton::pressed, QObject::connect(reload, &QPushButton::pressed, [name = id, this]() {
[name = codename, this]() {
getApp()->plugins->reload(name); getApp()->plugins->reload(name);
this->rebuildContent(); this->rebuildContent();
}); });