diff --git a/src/utils/app-manager.cpp b/src/utils/app-manager.cpp
index 8f46ce8..677a262 100644
--- a/src/utils/app-manager.cpp
+++ b/src/utils/app-manager.cpp
@@ -15,12 +15,14 @@
* along with this program. If not, see .
*
*/
+#include
#include "app-manager.h"
#include
#include
#include
+#include
#define KYLIN_APP_MANAGER_NAME "com.kylin.AppManager"
#define KYLIN_APP_MANAGER_PATH "/com/kylin/AppManager"
@@ -44,15 +46,66 @@ AppManager::AppManager(QObject *parent) : QObject(parent)
}
}
-bool AppManager::launchApp(const QString &desktopFile)
+bool AppManager::launchApp(const QString &desktopFilePath)
{
- if (m_appManagerDbusInterface != nullptr) {
- QDBusReply status = m_appManagerDbusInterface->call("LaunchApp", desktopFile);
- return status;
- } else {
- qWarning() <<"LaunchApp is failed,return false";
+ if (launchAppWithDBus(desktopFilePath)) {
+ return true;
+ }
+
+ QString cmd = parseDesktopFile(desktopFilePath);
+// qDebug() << "launchApp:" << desktopFilePath << cmd;
+ if (cmd.isEmpty()) {
return false;
}
+
+ return QProcess::startDetached(cmd);
}
-} // UkuiMenu
\ No newline at end of file
+bool AppManager::launchAppWithDBus(const QString &desktopFilePath)
+{
+ if (!m_appManagerDbusInterface) {
+ return false;
+ }
+
+ QDBusReply status = m_appManagerDbusInterface->call("LaunchApp", desktopFilePath);
+ return status.value();
+}
+
+QString AppManager::parseDesktopFile(const QString &desktopFilePath)
+{
+ // TODO: try QSettings?
+ GKeyFile *keyFile = g_key_file_new();
+ gboolean res = g_key_file_load_from_file(keyFile, desktopFilePath.toUtf8(), G_KEY_FILE_NONE, nullptr);
+ if (!res) {
+ return "";
+ }
+
+ gchar *exec = g_key_file_get_value(keyFile, "Desktop Entry", "Exec", nullptr);
+ if (!exec) {
+ g_key_file_free(keyFile);
+ return "";
+ }
+
+ QStringList stringList = QString(exec).split(" ");
+
+ g_free(exec);
+ g_key_file_free(keyFile);
+
+ if (stringList.isEmpty()) {
+ return "";
+ }
+
+ QString program = stringList.first();
+ stringList.removeFirst();
+
+ // TODO: freedesktop group
+ for (const auto &str : stringList) {
+ if (!str.startsWith("%")) {
+ program.append(" " + str);
+ }
+ }
+
+ return program;
+}
+
+} // UkuiMenu
diff --git a/src/utils/app-manager.h b/src/utils/app-manager.h
index 437bff8..78fada2 100644
--- a/src/utils/app-manager.h
+++ b/src/utils/app-manager.h
@@ -32,10 +32,12 @@ public:
AppManager(const AppManager &obj) = delete;
AppManager &operator = (const AppManager &obj) = delete;
- bool launchApp(const QString &desktopFile);
+ bool launchApp(const QString &desktopFilePath);
private:
explicit AppManager(QObject *parent = nullptr);
+ bool launchAppWithDBus(const QString &desktopFilePath);
+ static QString parseDesktopFile(const QString &desktopFilePath);
private:
QDBusInterface *m_appManagerDbusInterface = nullptr;