From f15799e9a757773da22f621f7a667266e7807a4b Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Fri, 26 Nov 2021 17:49:20 -0500 Subject: [PATCH] Add plugin::getExactPlugin() and getExactModel() to public API. Fix inability to load plugin that is aliased to another. --- include/plugin.hpp | 6 ++++++ src/app/MenuBar.cpp | 2 +- src/plugin.cpp | 14 +++++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/plugin.hpp b/include/plugin.hpp index e6178fe1..c2711664 100644 --- a/include/plugin.hpp +++ b/include/plugin.hpp @@ -13,10 +13,16 @@ namespace plugin { PRIVATE void init(); PRIVATE void destroy(); + /** Finds a loaded Plugin by slug. */ Plugin* getPlugin(const std::string& pluginSlug); +/** Finds a loaded Plugin by slug, ignoring plugin slug aliases. */ +Plugin* getExactPlugin(const std::string& pluginSlug); /** Finds a loaded Model by plugin and model slug. */ Model* getModel(const std::string& pluginSlug, const std::string& modelSlug); +/** Finds a loaded Model by plugin and model slug, ignoring module slug aliases. */ +Model* getExactModel(const std::string& pluginSlug, const std::string& modelSlug); + /** Creates a Model from a JSON module object. Throws an Exception if the model is not found. */ diff --git a/src/app/MenuBar.cpp b/src/app/MenuBar.cpp index 36b5399d..3785e220 100644 --- a/src/app/MenuBar.cpp +++ b/src/app/MenuBar.cpp @@ -649,7 +649,7 @@ struct SyncUpdateItem : ui::MenuItem { } else { rightText = ""; - plugin::Plugin* p = plugin::getPlugin(slug); + plugin::Plugin* p = plugin::getExactPlugin(slug); if (p) { rightText += "v" + p->version + " → "; } diff --git a/src/plugin.cpp b/src/plugin.cpp index a0163c3c..0d5058b8 100644 --- a/src/plugin.cpp +++ b/src/plugin.cpp @@ -162,7 +162,7 @@ static Plugin* loadPlugin(std::string path) { plugin->fromJson(rootJ); // Reject plugin if slug already exists - Plugin* existingPlugin = getPlugin(plugin->slug); + Plugin* existingPlugin = getExactPlugin(plugin->slug); if (existingPlugin) throw Exception("Plugin %s is already loaded, not attempting to load it again", plugin->slug.c_str()); } @@ -290,7 +290,7 @@ static const std::map pluginSlugFallbacks = { }; -static Plugin* getPluginSimple(const std::string& pluginSlug) { +Plugin* getExactPlugin(const std::string& pluginSlug) { if (pluginSlug.empty()) return NULL; auto it = std::find_if(plugins.begin(), plugins.end(), [=](Plugin* p) { @@ -303,14 +303,14 @@ static Plugin* getPluginSimple(const std::string& pluginSlug) { Plugin* getPlugin(const std::string& pluginSlug) { - Plugin* p = getPluginSimple(pluginSlug); + Plugin* p = getExactPlugin(pluginSlug); if (p) return p; // Use fallback plugin slug auto it = pluginSlugFallbacks.find(pluginSlug); if (it != pluginSlugFallbacks.end()) - return getPluginSimple(it->second); + return getExactPlugin(it->second); return NULL; } @@ -326,7 +326,7 @@ static const std::map moduleSlugFallbacks = }; -static Model* getModelSimple(const std::string& pluginSlug, const std::string& modelSlug) { +Model* getExactModel(const std::string& pluginSlug, const std::string& modelSlug) { if (pluginSlug.empty() || modelSlug.empty()) return NULL; Plugin* p = getPlugin(pluginSlug); @@ -340,14 +340,14 @@ static Model* getModelSimple(const std::string& pluginSlug, const std::string& m Model* getModel(const std::string& pluginSlug, const std::string& modelSlug) { - Model* m = getModelSimple(pluginSlug, modelSlug); + Model* m = getExactModel(pluginSlug, modelSlug); if (m) return m; // Use fallback (module slug, plugin slug) auto it = moduleSlugFallbacks.find(std::make_tuple(pluginSlug, modelSlug)); if (it != moduleSlugFallbacks.end()) { - return getModelSimple(std::get<0>(it->second), std::get<1>(it->second)); + return getExactModel(std::get<0>(it->second), std::get<1>(it->second)); } return NULL; }