Fix loading of JS plugins
This commit is contained in:
parent
b97e4e5b0c
commit
e47a4062ee
@ -1118,21 +1118,40 @@ void DeviceManagerImplementation::loadPlugins()
|
||||
}
|
||||
}
|
||||
|
||||
ScriptDevicePlugin *plugin = new ScriptDevicePlugin(this);
|
||||
bool ret = plugin->loadScript("/home/micha/Develop/nymea-plugin-jstest/devicepluginjstest.js");
|
||||
if (!ret) {
|
||||
delete plugin;
|
||||
qCWarning(dcDeviceManager()) << "JS plugin failed to load";
|
||||
return;
|
||||
}
|
||||
PluginMetadata metaData(plugin->metaData());
|
||||
if (!metaData.isValid()) {
|
||||
qCWarning(dcDeviceManager()) << "Not loading JS plugin. Invalid metadata.";
|
||||
foreach (const QString &error, metaData.validationErrors()) {
|
||||
qCWarning(dcDeviceManager()) << error;
|
||||
foreach (const QString &path, pluginSearchDirs()) {
|
||||
QDir dir(path);
|
||||
qCDebug(dcDeviceManager) << "Loading JS plugins from:" << dir.absolutePath();
|
||||
foreach (const QString &entry, dir.entryList()) {
|
||||
QFileInfo jsFi;
|
||||
QFileInfo jsonFi;
|
||||
|
||||
if (entry.endsWith(".js")) {
|
||||
jsFi.setFile(path + "/" + entry);
|
||||
} else {
|
||||
jsFi.setFile(path + "/" + entry + "/" + entry + ".js");
|
||||
}
|
||||
|
||||
if (!jsFi.exists()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ScriptDevicePlugin *plugin = new ScriptDevicePlugin(this);
|
||||
bool ret = plugin->loadScript("/home/micha/Develop/nymea-plugin-jstest/devicepluginjstest.js");
|
||||
if (!ret) {
|
||||
delete plugin;
|
||||
qCWarning(dcDeviceManager()) << "JS plugin failed to load";
|
||||
continue;
|
||||
}
|
||||
PluginMetadata metaData(plugin->metaData());
|
||||
if (!metaData.isValid()) {
|
||||
qCWarning(dcDeviceManager()) << "Not loading JS plugin. Invalid metadata.";
|
||||
foreach (const QString &error, metaData.validationErrors()) {
|
||||
qCWarning(dcDeviceManager()) << error;
|
||||
}
|
||||
}
|
||||
loadPlugin(plugin, metaData);
|
||||
}
|
||||
}
|
||||
loadPlugin(plugin, metaData);
|
||||
}
|
||||
|
||||
void DeviceManagerImplementation::loadPlugin(DevicePlugin *pluginIface, const PluginMetadata &metaData)
|
||||
|
||||
@ -61,8 +61,9 @@ bool ScriptDevicePlugin::loadScript(const QString &fileName)
|
||||
|
||||
m_engine = new QQmlEngine(this);
|
||||
m_engine->installExtensions(QJSEngine::AllExtensions);
|
||||
m_engine->addImportPath(fi.absoluteDir().path() + "/node_modules/");
|
||||
qCWarning(dcDeviceManager()) << "Engine import path list" << m_engine->importPathList();
|
||||
|
||||
QJSValue deviceMetaObject = m_engine->newQMetaObject(&Device::staticMetaObject);
|
||||
m_engine->globalObject().setProperty("Device", deviceMetaObject);
|
||||
|
||||
m_pluginImport = m_engine->importModule(fileName);
|
||||
if (m_pluginImport.isError()) {
|
||||
@ -70,7 +71,6 @@ bool ScriptDevicePlugin::loadScript(const QString &fileName)
|
||||
return false;
|
||||
}
|
||||
|
||||
qCDebug(dcDeviceManager()) << "Loaded JS plugin" << fileName;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -152,7 +152,6 @@ public:
|
||||
void postSetupDevice(Device *device) override;
|
||||
void deviceRemoved(Device *device) override;
|
||||
void executeAction(DeviceActionInfo *info) override;
|
||||
void browseDevice(BrowseResult *result) override;
|
||||
|
||||
private:
|
||||
QQmlEngine *m_engine = nullptr;
|
||||
|
||||
Reference in New Issue
Block a user