-
Notifications
You must be signed in to change notification settings - Fork 55
chore: TrayLoader single process support to start multiple plugins #926
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,6 +76,38 @@ | |
| "description[zh_CN]": "托盘折叠区域当前的状态", | ||
| "permissions": "readwrite", | ||
| "visibility": "private" | ||
| }, | ||
| "selfMaintenanceTrayPlugins": { | ||
| "value": ["libapplication-tray.so", "libbrightness.so", "libdatetime.so", "libdnd-mode.so", "libeye-comfort-mode.so", "libmedia.so", "libnotification.so", "libonboard.so", "libshutdown.so", "libairplane-mode.so", "libbluetooth.so", "libdock-tray-network-plugin.so", "libdock-wirelesscasting-plugin.so", "libkeyboard-layout.so", "libpower.so", "libsound.so"], | ||
| "serial": 0, | ||
| "flags": [], | ||
| "name": "self maintenance plugins", | ||
| "name[zh_CN]": "自维护托盘插件", | ||
| "description": "self maintenance plugins", | ||
| "description[zh_CN]": "自维护托盘插件", | ||
| "permissions": "readonly", | ||
| "visibility": "private" | ||
| }, | ||
| "subprojectTrayPlugins": { | ||
| "value": ["libdock-clipboard-plugin.so", "libddegrandsearch_dockplugin.so", "libdeepin-screen-recorder-plugin.so", "libdeepin-system-monitor-plugin.so", "libshot-start-plugin.so", "libshot-start-record-plugin.so", "libdde-disk-mount-plugin.so"], | ||
| "serial": 0, | ||
| "flags": [], | ||
| "name": "subproject tray plugins", | ||
| "name[zh_CN]": "子项目托盘插件", | ||
| "description": "subproject tray plugins", | ||
| "description[zh_CN]": "子项目托盘插件", | ||
| "permissions": "readwrite", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 同
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| "visibility": "private" | ||
| }, | ||
| "crashProneTrayPlugins": { | ||
| "value": [], | ||
| "serial": 0, | ||
| "flags": [], | ||
| "name": "crash-prone tray plugins", | ||
| "name[zh_CN]": "易于崩溃的托盘插件", | ||
| "description": "crash-prone tray plugins", | ||
| "description[zh_CN]": "易于崩溃的托盘插件", | ||
| "permissions": "readwrite" | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ | |
|
|
||
| #include <signal.h> | ||
|
|
||
| #include <DConfig> | ||
|
|
||
| #include <QDir> | ||
| #include <QTimer> | ||
| #include <QGuiApplication> | ||
|
|
@@ -30,60 +32,19 @@ | |
| } | ||
| } | ||
|
|
||
| void LoadTrayPlugins::loadDockPlugins() | ||
| { | ||
| QStringList filters; | ||
| filters << "*.so"; | ||
|
|
||
| QStringList execPaths; | ||
| execPaths << qEnvironmentVariable("TRAY_LOADER_EXECUTE_PATH") | ||
| << QString("%1/trayplugin-loader").arg(CMAKE_INSTALL_FULL_LIBEXECDIR); | ||
|
|
||
| QString validExePath; | ||
| for (const QString &execPath : execPaths) { | ||
| if (QFile::exists(execPath)) { | ||
| validExePath = execPath; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| QString validExePath = loaderPath(); | ||
| if (validExePath.isEmpty()) { | ||
| qWarning() << "No valid loader executable path found."; | ||
| return; | ||
| } | ||
|
|
||
| QStringList dirs; | ||
| const auto pluginsPath = qEnvironmentVariable("TRAY_DEBUG_PLUGIN_PATH"); | ||
| if (!pluginsPath.isEmpty()) | ||
| dirs << pluginsPath.split(QDir::listSeparator()); | ||
|
|
||
| if (dirs.isEmpty()) | ||
| dirs << pluginDirs; | ||
|
|
||
| for (auto &pluginDir : dirs) { | ||
| QDir dir(pluginDir); | ||
| if (!dir.exists()) { | ||
| qWarning() << "The plugin directory does not exist:" << pluginDir; | ||
| continue; | ||
| } | ||
|
|
||
| auto pluginFileInfos = dir.entryInfoList(filters, QDir::Files); | ||
| foreach (auto pluginInfo, pluginFileInfos) { | ||
| qInfo() << "pluginLoader load plugin" << pluginInfo.absoluteFilePath(); | ||
|
|
||
| QProcess *process = new QProcess(this); | ||
| setProcessEnv(process); | ||
|
|
||
| connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), | ||
| this, &LoadTrayPlugins::handleProcessFinished); | ||
|
|
||
| ProcessInfo pInfo = { process, pluginInfo.absoluteFilePath(), 0 }; | ||
| m_processes.append(pInfo); | ||
|
|
||
| process->setProgram(validExePath); | ||
| process->setArguments({"-p", pluginInfo.absoluteFilePath(), "-platform", "wayland"}); | ||
| process->start(); | ||
| } | ||
| auto pluginGroupMap = groupPlugins(allPluginPaths()); | ||
| for (auto it = pluginGroupMap.begin(); it != pluginGroupMap.end(); ++it) { | ||
| if (it.value().isEmpty()) continue; | ||
| qDebug() << "Load plugin:" << it.value() << " group:" << it.key(); | ||
| startProcess(validExePath, it.value(), it.key()); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -113,6 +74,22 @@ | |
| } | ||
| } | ||
|
|
||
| void LoadTrayPlugins::startProcess(const QString &loaderPath, const QString &pluginPath, const QString &groupName) | ||
| { | ||
| auto *process = new QProcess(this); | ||
| setProcessEnv(process); | ||
|
|
||
| connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished), | ||
| this, &LoadTrayPlugins::handleProcessFinished); | ||
|
|
||
| ProcessInfo pInfo = { process, pluginPath, 0 }; | ||
| m_processes.append(pInfo); | ||
|
|
||
| process->setProgram(loaderPath); | ||
| process->setArguments({"-p", pluginPath, "-g", groupName, "-platform", "wayland"}); | ||
| process->start(); | ||
| } | ||
|
|
||
| void LoadTrayPlugins::setProcessEnv(QProcess *process) | ||
| { | ||
| if (!process) return; | ||
|
|
@@ -124,4 +101,99 @@ | |
| process->setProcessEnvironment(env); | ||
| } | ||
|
|
||
| QString LoadTrayPlugins::loaderPath() const | ||
| { | ||
| QStringList execPaths; | ||
| execPaths << qEnvironmentVariable("TRAY_LOADER_EXECUTE_PATH") | ||
| << QString("%1/trayplugin-loader").arg(CMAKE_INSTALL_FULL_LIBEXECDIR); | ||
|
|
||
| QString validExePath; | ||
| for (const QString &execPath : execPaths) { | ||
| if (QFile::exists(execPath)) { | ||
| validExePath = execPath; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| return validExePath; | ||
| } | ||
|
|
||
| QStringList LoadTrayPlugins::allPluginPaths() const | ||
| { | ||
| QStringList dirs; | ||
| const auto pluginsPath = qEnvironmentVariable("TRAY_DEBUG_PLUGIN_PATH"); | ||
| if (!pluginsPath.isEmpty()) | ||
| dirs << pluginsPath.split(QDir::listSeparator()); | ||
|
|
||
| if (dirs.isEmpty()) | ||
| dirs << pluginDirs; | ||
|
|
||
| QStringList pluginPaths; | ||
| for (auto &pluginDir : dirs) { | ||
| QDir dir(pluginDir); | ||
| if (!dir.exists()) { | ||
| qWarning() << "The plugin directory does not exist:" << pluginDir; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. category?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这个地方是遍历插件目录 |
||
| continue; | ||
| } | ||
|
|
||
| auto pluginFileInfos = dir.entryInfoList({"*.so"}, QDir::Files); | ||
| for (auto &pluginInfo : pluginFileInfos) { | ||
| pluginPaths.append(pluginInfo.absoluteFilePath()); | ||
| } | ||
| } | ||
|
|
||
| return pluginPaths; | ||
| } | ||
|
|
||
| QMap<QString, QString> LoadTrayPlugins::groupPlugins(const QStringList &pluginPaths) const | ||
| { | ||
| const QString selfMaintenancePluginsKey = "selfMaintenanceTrayPlugins"; | ||
| const QString subprojectPluginsKey = "subprojectTrayPlugins"; | ||
| const QString crashPronePluginsKey = "crashProneTrayPlugins"; | ||
| const QString otherPluginsKey = "otherTrayPlugins"; | ||
|
|
||
| auto dConfig = Dtk::Core::DConfig::create("org.deepin.dde.shell", "org.deepin.ds.dock.tray", QString()); | ||
| QStringList selfMaintenanceTrayPlugins = dConfig->value(selfMaintenancePluginsKey).toStringList(); | ||
| QStringList subprojectTrayPlugins = dConfig->value(subprojectPluginsKey).toStringList(); | ||
| QStringList crashProneTrayPlugins = dConfig->value(crashPronePluginsKey).toStringList(); | ||
| dConfig->deleteLater(); | ||
|
|
||
| QStringList selfMaintenancePluginPaths; | ||
| QStringList subprojectPluginPaths; | ||
| QStringList crashPronePluginPaths; | ||
| QStringList otherPluginPaths; | ||
|
|
||
| for (auto &filePath : pluginPaths) { | ||
| QString pluginName = filePath.section("/", -1); | ||
| if (crashProneTrayPlugins.contains(pluginName)) { | ||
| crashPronePluginPaths.append(filePath); | ||
| } else if (selfMaintenanceTrayPlugins.contains(pluginName)) { | ||
| selfMaintenancePluginPaths.append(filePath); | ||
| } else if (subprojectTrayPlugins.contains(pluginName)) { | ||
| subprojectPluginPaths.append(filePath); | ||
| } else { | ||
| otherPluginPaths.append(filePath); | ||
| } | ||
| } | ||
|
|
||
| QMap<QString, QString> pluginGroup; | ||
|
|
||
| if (!selfMaintenancePluginPaths.isEmpty()) { | ||
| pluginGroup.insert(selfMaintenancePluginsKey, selfMaintenancePluginPaths.join(";")); | ||
| } | ||
|
|
||
| if (!subprojectPluginPaths.isEmpty()) { | ||
| pluginGroup.insert(subprojectPluginsKey, subprojectPluginPaths.join(";")); | ||
| } | ||
|
|
||
| if (!crashPronePluginPaths.isEmpty()) { | ||
| pluginGroup.insert(crashPronePluginsKey, crashPronePluginPaths.join(";")); | ||
| } | ||
|
|
||
| if (!otherPluginPaths.isEmpty()) { | ||
| pluginGroup.insert(otherPluginsKey, otherPluginPaths.join(";")); | ||
| } | ||
|
|
||
| return pluginGroup; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我们自己维护的插件,能不能改插件类型,在meta中加个字段,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
想,但目前不是很允许。