From dc9de3696519fab6403c386a48c84cd6781ab99c Mon Sep 17 00:00:00 2001 From: isanae <14251494+isanae@users.noreply.github.com> Date: Wed, 4 Nov 2020 22:50:51 -0500 Subject: call init() on proxy plugins OrganizerProxy now handles a null OrganizerCore, used for proxy plugins changed appVersion() and pluginDataPath() so they don't need OrganizerCore --- src/plugincontainer.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/plugincontainer.cpp') diff --git a/src/plugincontainer.cpp b/src/plugincontainer.cpp index 0c71e491..3ad3da21 100644 --- a/src/plugincontainer.cpp +++ b/src/plugincontainer.cpp @@ -171,6 +171,22 @@ QObject* PluginContainer::as_qobject(MOBase::IPlugin* plugin) const bool PluginContainer::initPlugin(IPlugin *plugin) { + // when MO has no instance loaded, `init()` is not called on plugins, except + // for proxy plugins + // + // proxy plugins are given an OrganizerProxy that has a null OrganizerCore, + // so there's not a lot it can do, but it can return some information; the + // majority of its functions are no-ops + // + // so initPlugin() (this function) is called for all plugins except proxies, + // and does not call init() if m_Organizer is null; initProxyPlugin() below + // is called only for proxy plugins and will call init() with the crippled + // OrganizerProxy + // + // note that after proxies are initialized, instantiate() is called for all + // the plugins they've discovered, but as for regular plugins, init() won't be + // called on them if m_OrganizerCore is null + if (plugin == nullptr) { return false; } @@ -187,6 +203,22 @@ bool PluginContainer::initPlugin(IPlugin *plugin) return true; } +bool PluginContainer::initProxyPlugin(IPlugin *plugin) +{ + // see initPlugin() above for info + + if (plugin == nullptr) { + return false; + } + + if (!plugin->init(new OrganizerProxy(m_Organizer, this, plugin))) { + log::warn("proxy plugin failed to initialize"); + return false; + } + + return true; +} + void PluginContainer::registerGame(IPluginGame *game) { @@ -272,7 +304,7 @@ bool PluginContainer::registerPlugin(QObject *plugin, const QString &fileName) } { // proxy plugins IPluginProxy *proxy = qobject_cast(plugin); - if (initPlugin(proxy)) { + if (initProxyPlugin(proxy)) { bf::at_key(m_Plugins).push_back(proxy); QStringList pluginNames = proxy->pluginList( QCoreApplication::applicationDirPath() + "/" + ToQString(AppConfig::pluginPath())); -- cgit v1.3.1