mirror of
https://github.com/linuxdeepin/dde-dock.git
synced 2025-06-04 09:23:03 +00:00
fix: 任务栏加载缓慢
原因:使用ldd判断插件使用dtk版本的函数耗时较长。 解决方案:多线程处理 Log: 优化任务栏加载缓慢的问题 Bug: https://pms.uniontech.com/bug-view-119393.html Influence: 任务栏插件加载时间。 Change-Id: I774610e5743d27dd9cd4045ea50d7cb3754ba20a
This commit is contained in:
parent
0cab90e76d
commit
444613357f
@ -25,6 +25,9 @@
|
||||
#include <QDebug>
|
||||
#include <QLibrary>
|
||||
#include <QGSettings>
|
||||
#include <QProcess>
|
||||
#include <QtConcurrent>
|
||||
#include <QFuture>
|
||||
|
||||
#include <DSysInfo>
|
||||
|
||||
@ -56,6 +59,7 @@ void PluginLoader::run()
|
||||
QStringList plugins;
|
||||
|
||||
// 查找可用插件
|
||||
QList<QString> filePaths;
|
||||
for (QString file : files) {
|
||||
if (!QLibrary::isLibrary(file))
|
||||
continue;
|
||||
@ -72,14 +76,26 @@ void PluginLoader::run()
|
||||
qDebug() << "disable loading plugin:" << file;
|
||||
continue;
|
||||
}
|
||||
// 判断当前进程加载的dtkcore库是否和当前库加载的dtkcore的库为同一个,如果不同,则无需加载,
|
||||
// 否则在加载dtkcore的时候会报错(dtkcore内部判断如果加载两次会抛出错误)
|
||||
QString libUsedDtkCore = libUsedDtkCoreFileName(pluginsDir.absoluteFilePath(file));
|
||||
if (!libUsedDtkCore.isEmpty() && libUsedDtkCore != dtkCoreName)
|
||||
continue;
|
||||
|
||||
plugins << file;
|
||||
filePaths.push_back(pluginsDir.absoluteFilePath(file));
|
||||
}
|
||||
|
||||
// 由于使用ldd获取.so信息比较耗时,采用并行处理
|
||||
QFuture<QString> f = QtConcurrent::mapped(filePaths, &PluginLoader::libUsedDtkCoreFileName);
|
||||
f.waitForFinished();
|
||||
const QStringList &results = f.results();
|
||||
if (results.size() == filePaths.size()) {
|
||||
for (int i = 0; i < results.size(); ++i) {
|
||||
const QString &libUsedDtkCore = results.at(i);
|
||||
// 判断当前进程加载的dtkcore库是否和当前库加载的dtkcore的库为同一个,如果不同,则无需加载,
|
||||
// 否则在加载dtkcore的时候会报错(dtkcore内部判断如果加载两次会抛出错误
|
||||
if (libUsedDtkCore.isEmpty() || libUsedDtkCore == dtkCoreName)
|
||||
plugins << filePaths.at(i);
|
||||
}
|
||||
} else {
|
||||
plugins.append(filePaths);
|
||||
}
|
||||
|
||||
for (auto plugin : plugins) {
|
||||
emit pluginFounded(pluginsDir.absoluteFilePath(plugin));
|
||||
}
|
||||
|
@ -30,6 +30,13 @@ class PluginLoader : public QThread
|
||||
|
||||
public:
|
||||
explicit PluginLoader(const QString &pluginDirPath, QObject *parent);
|
||||
static QString libUsedDtkCoreFileName(const QString &fileName);
|
||||
/**
|
||||
* @brief realFileName 获取软连接的真实文件的路径
|
||||
* @param fileName 文件地址
|
||||
* @return
|
||||
*/
|
||||
static QString realFileName(QString fileName);
|
||||
|
||||
signals:
|
||||
void finished() const;
|
||||
@ -39,8 +46,6 @@ protected:
|
||||
void run();
|
||||
|
||||
QString dtkCoreFileName();
|
||||
QString libUsedDtkCoreFileName(const QString &fileName);
|
||||
QString realFileName(QString fileName); // 获取软连接的真实文件的路径
|
||||
|
||||
private:
|
||||
QString m_pluginDirPath;
|
||||
|
Loading…
x
Reference in New Issue
Block a user