feat: dplugin#262
Conversation
black-desk
commented
Feb 9, 2023
- build: clean cmakelist
- feat: start impl dplugin
|
Doc Check bot
|
f18bad2 to
1a02895
Compare
|
@kegechen @zccrs @Groveer @justforlxz 这边希望给 DTK 添加一个通用的插件寻找机制, 方便需要使用插件来加载可选功能的应用编写. 这个机制目前设计如下: 应用会从 QT 给的 AppDataLocation 目录下的 plugins 文件夹中寻找配置文件. 配置文件中记录该插件的名称 版本和库名(也可以是绝对路径). 这些信息被用来初始化一个 QLibrary 对象. 需要加载插件的应用使用这个对象来工作. 这种设计参考了 chrome 以及 fcitx 的设计, 这两个项目都没有采取固定位置直接放置 so 库的做法, 而是采取了如此通过配置文件来寻找真正要使用的插件的做法. 由于 AppDataLocation 尊重 XDG_DATA_DIR 环境变量1, 如此设计对于需要更改插件实际存放位置的情况来说比较友好. Footnotes |
|
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
53937c9 to
1c26bc7
Compare
为什么不直接使用 QPluginLoader 呢 |
重点并不在于加载库的具体过程,而在于插件加载的过程需要:
这对nix/flatpak以及玲珑类的打包方式都很有意义。 |
| ${CMAKE_CURRENT_LIST_DIR}/dvtablehook.cpp | ||
| ${CMAKE_CURRENT_LIST_DIR}/dthreadutils.cpp | ||
| ${CMAKE_CURRENT_LIST_DIR}/dtimedloop.cpp | ||
| set(UTILS_SOURCE ${UTILS_SOURCE} |
There was a problem hiding this comment.
I recommend using list(APPEND).
|
|
||
| class DPluginPrivate; | ||
|
|
||
| class DPlugin : public QObject |
There was a problem hiding this comment.
Should DPlugin derive from DObject? If yes, it's better to use D_DECLARE_PRIVATE. And remember to make DPluginPrivate derive from DObjectPrivate.
No logical change.
This commit implement DPlugin class. Documentation will be added later.
1c26bc7 to
d2cc763
Compare
|
想了想好像解决不了插件里面又加载了其他的so的问题, 我再考虑考虑怎么解决 这个先挂着 |
| QList<std::shared_ptr<DPlugin>> DPluginPrivate::searchPluginsInPath(const QString &pluginDirPath) | ||
| { | ||
| auto const pluginDir = QDir(pluginDirPath); | ||
| auto const entryList = pluginDir.entryList(); |
There was a problem hiding this comment.
可以通过 QDir::Filter::Files 过滤一下,下面就不用判断是不是文件了
| } | ||
|
|
||
| auto config = jsonDoc.object(); | ||
| if (!DPluginPrivate::configCompatible(config["pluginConfigVersion"])) { |
There was a problem hiding this comment.
- json 的示例文件可以在注释或者什么地方提供一下。
- 既然已知是 plugin 的配置文件,是不是 json 中的 key 可以去掉 plugin 的前缀
| return plugins; | ||
| } | ||
|
|
||
| QList<std::shared_ptr<DPlugin>> DPluginPrivate::searchPluginsInPath(const QString &pluginDirPath) |
There was a problem hiding this comment.
| QList<std::shared_ptr<DPlugin>> DPluginPrivate::searchPluginsInPath(const QString &pluginDirPath) | |
| QList<std::shared_ptr<DPlugin>> DPluginPrivate::load(const QString &pluginDirPath) |
|
TAG Bot New tag: 5.6.21 |
|
TAG Bot New tag: 5.6.22 |
|
TAG Bot New tag: 5.6.25 |
|
TAG Bot New tag: 5.6.26 |
|
TAG Bot New tag: 5.6.27 |
|
TAG Bot New tag: 5.6.28 |
|
TAG Bot New tag: 5.6.29 |
|
TAG Bot New tag: 5.6.30 |