Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions src/global_util/plugin_manager/modules_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ ModulesLoader::~ModulesLoader()
{
quit();
wait();

QMutexLocker locker(&m_mutex);
for (auto &loader : m_pluginLoaders) {
cleanupPluginLoader(loader);
}
m_pluginLoaders.clear();
}

ModulesLoader& ModulesLoader::instance()
Expand Down Expand Up @@ -78,7 +84,7 @@ void ModulesLoader::findModule(const QString& path)
}

qCInfo(DDE_SHELL) << "About to process " << module;
auto loader = new QPluginLoader(path);
auto loader = std::unique_ptr<QPluginLoader>(new QPluginLoader(path));

// 检查兼容性
const QJsonObject meta = loader->metaData().value("MetaData").toObject();
Expand Down Expand Up @@ -134,7 +140,8 @@ void ModulesLoader::findModule(const QString& path)
loader->moveToThread(qApp->thread());

QMutexLocker locker(&m_mutex);
m_pluginLoaders.insert(moduleInstance->key(), QPointer<QPluginLoader>(loader));
m_pluginLoaders.insert(moduleInstance->key(), QPointer<QPluginLoader>(loader.get()));
loader.release(); // 释放所有权,防止 QPluginLoader 被析构
PluginManager::instance()->addPlugin(moduleInstance, version);
}
m_loadLoginModule = true;
Expand Down Expand Up @@ -268,6 +275,7 @@ bool ModulesLoader::isPluginEnabled(const QFileInfo& module)
auto dbusInterface = new QDBusInterface(service, targetPath, interface, dbusConnection);
if (!dbusInterface || !dbusInterface->isValid()) {
qCWarning(DDE_SHELL) << "Check plugin enabled dbus interface is not valid.";
dbusInterface->deleteLater();
return false;
}
const bool pluginEnabled = dbusInterface->property(property.toStdString().c_str()).toBool();
Expand Down Expand Up @@ -346,6 +354,14 @@ void ModulesLoader::unloadPlugin(const QString& path)
}
}

void ModulesLoader::cleanupPluginLoader(QPluginLoader* loader)
{
if (loader) {
loader->unload();
loader->deleteLater();
}
}

// TODO 只重新加载/卸载变更的插件
void ModulesLoader::onDConfigPropertyChanged(const QString& key, const QVariant& value, QObject* objPtr)
{
Expand All @@ -367,4 +383,4 @@ void ModulesLoader::onDbusPropertiesChanged(const QString& interfaceName, const
start(QThread::LowestPriority);
}
}
}
}
1 change: 1 addition & 0 deletions src/global_util/plugin_manager/modules_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class ModulesLoader : public QThread
bool isPluginEnabled(const QFileInfo &module);
bool contains(const QString &pluginFile) const;
QPair<QString, QPluginLoader*> getPluginLoader(const QString &pluginFile) const;
void cleanupPluginLoader(QPluginLoader* loader);

static void onDConfigPropertyChanged(const QString &key, const QVariant &value, QObject *objPtr);

Expand Down