77
88#include < signal.h>
99
10+ #include < DConfig>
11+
1012#include < QDir>
1113#include < QTimer>
1214#include < QGuiApplication>
@@ -32,58 +34,17 @@ LoadTrayPlugins::~LoadTrayPlugins()
3234
3335void LoadTrayPlugins::loadDockPlugins ()
3436{
35- QStringList filters;
36- filters << " *.so" ;
37-
38- QStringList execPaths;
39- execPaths << qEnvironmentVariable (" TRAY_LOADER_EXECUTE_PATH" )
40- << QString (" %1/trayplugin-loader" ).arg (CMAKE_INSTALL_FULL_LIBEXECDIR);
41-
42- QString validExePath;
43- for (const QString &execPath : execPaths) {
44- if (QFile::exists (execPath)) {
45- validExePath = execPath;
46- break ;
47- }
48- }
49-
37+ QString validExePath = loaderPath ();
5038 if (validExePath.isEmpty ()) {
5139 qWarning () << " No valid loader executable path found." ;
5240 return ;
5341 }
5442
55- QStringList dirs;
56- const auto pluginsPath = qEnvironmentVariable (" TRAY_DEBUG_PLUGIN_PATH" );
57- if (!pluginsPath.isEmpty ())
58- dirs << pluginsPath.split (QDir::listSeparator ());
59-
60- if (dirs.isEmpty ())
61- dirs << pluginDirs;
62-
63- for (auto &pluginDir : dirs) {
64- QDir dir (pluginDir);
65- if (!dir.exists ()) {
66- qWarning () << " The plugin directory does not exist:" << pluginDir;
67- continue ;
68- }
69-
70- auto pluginFileInfos = dir.entryInfoList (filters, QDir::Files);
71- foreach (auto pluginInfo, pluginFileInfos) {
72- qInfo () << " pluginLoader load plugin" << pluginInfo.absoluteFilePath ();
73-
74- QProcess *process = new QProcess (this );
75- setProcessEnv (process);
76-
77- connect (process, QOverload<int , QProcess::ExitStatus>::of (&QProcess::finished),
78- this , &LoadTrayPlugins::handleProcessFinished);
79-
80- ProcessInfo pInfo = { process, pluginInfo.absoluteFilePath (), 0 };
81- m_processes.append (pInfo);
82-
83- process->setProgram (validExePath);
84- process->setArguments ({" -p" , pluginInfo.absoluteFilePath (), " -platform" , " wayland" });
85- process->start ();
86- }
43+ auto pluginGroupMap = getPluginGroup ();
44+ for (auto it = pluginGroupMap.begin (); it != pluginGroupMap.end (); ++it) {
45+ if (it.value ().isEmpty ()) continue ;
46+ qDebug () << " Load plugin:" << it.value () << " group:" << it.key ();
47+ startProcess (validExePath, it.value (), it.key ());
8748 }
8849}
8950
@@ -113,6 +74,22 @@ void LoadTrayPlugins::handleProcessFinished(int exitCode, QProcess::ExitStatus e
11374 }
11475}
11576
77+ void LoadTrayPlugins::startProcess (const QString &loaderPath, const QString &pluginPath, const QString &groupName)
78+ {
79+ auto *process = new QProcess (this );
80+ setProcessEnv (process);
81+
82+ connect (process, QOverload<int , QProcess::ExitStatus>::of (&QProcess::finished),
83+ this , &LoadTrayPlugins::handleProcessFinished);
84+
85+ ProcessInfo pInfo = { process, pluginPath, 0 };
86+ m_processes.append (pInfo);
87+
88+ process->setProgram (loaderPath);
89+ process->setArguments ({" -l" , pluginPath, " -g" , groupName, " -platform" , " wayland" });
90+ process->start ();
91+ }
92+
11693void LoadTrayPlugins::setProcessEnv (QProcess *process)
11794{
11895 if (!process) return ;
@@ -127,4 +104,84 @@ void LoadTrayPlugins::setProcessEnv(QProcess *process)
127104 process->setProcessEnvironment (env);
128105}
129106
107+ QString LoadTrayPlugins::loaderPath () const
108+ {
109+ QStringList execPaths;
110+ execPaths << qEnvironmentVariable (" TRAY_LOADER_EXECUTE_PATH" )
111+ << QString (" %1/trayplugin-loader" ).arg (CMAKE_INSTALL_FULL_LIBEXECDIR);
112+
113+ QString validExePath;
114+ for (const QString &execPath : execPaths) {
115+ if (QFile::exists (execPath)) {
116+ validExePath = execPath;
117+ break ;
118+ }
119+ }
120+
121+ return validExePath;
122+ }
123+
124+ QMap<QString, QString> LoadTrayPlugins::getPluginGroup () const
125+ {
126+ const QString selfMaintenancePlugins = " selfMaintenancePlugins" ;
127+ const QString applicationPlugins = " applicationPlugins" ;
128+ const QString otherPlugins = " otherPlugins" ;
129+
130+ auto dConfig = Dtk::Core::DConfig::create (" org.deepin.dde.shell" , " org.deepin.ds.dock.tray" , QString ());
131+ QStringList selfMaintenanceTrayPlugins = dConfig->value (" selfMaintenanceTrayPlugins" ).toStringList ();
132+ QStringList applicationTrayPlugins = dConfig->value (" applicationTrayPlugins" ).toStringList ();
133+ dConfig->deleteLater ();
134+
135+ QStringList dirs;
136+ const auto pluginsPath = qEnvironmentVariable (" TRAY_DEBUG_PLUGIN_PATH" );
137+ if (!pluginsPath.isEmpty ())
138+ dirs << pluginsPath.split (QDir::listSeparator ());
139+
140+ if (dirs.isEmpty ())
141+ dirs << pluginDirs;
142+
143+ QString selfMaintenancePluginPaths;
144+ QString applicationPluginPaths;
145+ QString otherPluginPaths;
146+
147+ for (auto &pluginDir : dirs) {
148+ QDir dir (pluginDir);
149+ if (!dir.exists ()) {
150+ qWarning () << " The plugin directory does not exist:" << pluginDir;
151+ continue ;
152+ }
153+
154+ auto pluginFileInfos = dir.entryInfoList ({" *.so" }, QDir::Files);
155+ for (auto &pluginInfo : pluginFileInfos) {
156+ QString pluginName = pluginInfo.absoluteFilePath ().section (" /" , -1 );
157+ if (selfMaintenanceTrayPlugins.contains (pluginName)) {
158+ selfMaintenancePluginPaths += pluginInfo.absoluteFilePath () + " ;" ;
159+ } else if (applicationTrayPlugins.contains (pluginName)) {
160+ applicationPluginPaths += pluginInfo.absoluteFilePath () + " ;" ;
161+ } else {
162+ otherPluginPaths += pluginInfo.absoluteFilePath () + " ;" ;
163+ }
164+ }
165+ }
166+
167+ QMap<QString, QString> pluginGroup;
168+
169+ if (!selfMaintenancePluginPaths.isEmpty ()) {
170+ // remove the last ';'
171+ selfMaintenancePluginPaths.chop (1 );
172+ pluginGroup.insert (selfMaintenancePlugins, selfMaintenancePluginPaths);
173+ }
174+
175+ if (!applicationPluginPaths.isEmpty ()) {
176+ applicationPluginPaths.chop (1 );
177+ pluginGroup.insert (applicationPlugins, applicationPluginPaths);
178+ }
179+
180+ if (!otherPluginPaths.isEmpty ()) {
181+ otherPluginPaths.chop (1 );
182+ pluginGroup.insert (otherPlugins, otherPluginPaths);
183+ }
184+
185+ return pluginGroup;
186+ }
130187}
0 commit comments