diff --git a/CMakeLists.txt b/CMakeLists.txt
index 52c6b05..b74f3e7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -29,7 +29,7 @@ find_package(PkgConfig REQUIRED)
set(UKUI_MENU_EXTERNAL_LIBS "")
# glib-2.0 gio-unix-2.0 gsettings-qt x11 kysdk-waylandhelper
-set(UKUI_MENU_PC_PKGS glib-2.0 gsettings-qt x11 kysdk-waylandhelper ukui-search kysdk-datacollect)
+set(UKUI_MENU_PC_PKGS gsettings-qt x11 kysdk-waylandhelper ukui-search kysdk-datacollect)
foreach(external_lib IN ITEMS ${UKUI_MENU_PC_PKGS})
pkg_check_modules(${external_lib} REQUIRED ${external_lib})
diff --git a/src/utils/app-manager.cpp b/src/utils/app-manager.cpp
index 3a7042d..8d52a0e 100644
--- a/src/utils/app-manager.cpp
+++ b/src/utils/app-manager.cpp
@@ -15,9 +15,6 @@
* along with this program. If not, see .
*
*/
-#include
-#include
-
#include "app-manager.h"
#include "basic-app-model.h"
@@ -26,6 +23,7 @@
#include
#include
#include
+#include
#define KYLIN_APP_MANAGER_NAME "com.kylin.ProcessManager"
#define KYLIN_APP_MANAGER_PATH "/com/kylin/ProcessManager/AppLauncher"
@@ -43,36 +41,31 @@ AppManager::AppManager(QObject *parent) : QObject(parent)
}
-void AppManager::launchApp(const QString &desktopFilePath)
+void AppManager::launchApp(const QString &appid)
{
- if (desktopFilePath.isEmpty()) {
+ if (appid.isEmpty()) {
return;
}
Q_EMIT request(UkuiMenuApplication::Hide);
QDBusMessage message = QDBusMessage::createMethodCall(KYLIN_APP_MANAGER_NAME, KYLIN_APP_MANAGER_PATH, KYLIN_APP_MANAGER_INTERFACE, "LaunchApp");
- message << desktopFilePath;
+ message << appid;
auto watcher = new QDBusPendingCallWatcher(QDBusPendingCall(QDBusConnection::sessionBus().asyncCall(message)), this);
- QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [desktopFilePath] (QDBusPendingCallWatcher *self) {
+ QObject::connect(watcher, &QDBusPendingCallWatcher::finished, this, [appid] (QDBusPendingCallWatcher *self) {
if (self->isError()) {
-// QString cmd = parseDesktopFile(desktopFilePath);
-// if (!cmd.isEmpty()) {
-// QProcess::startDetached(cmd, QStringList());
-// }
- GDesktopAppInfo *desktopAppInfo = g_desktop_app_info_new_from_filename(desktopFilePath.toLocal8Bit().data());
- if (desktopAppInfo == nullptr) {
- return;
+ QStringList list = parseDesktopFile(appid);
+ if (!list.isEmpty()) {
+ QString cmd = list.takeFirst();
+ QProcess::startDetached(cmd, list);
+ qDebug() << "launch with QProcess:" << cmd << list;
}
- bool launched = g_app_info_launch(G_APP_INFO(desktopAppInfo), nullptr, nullptr, nullptr);
- g_object_unref(desktopAppInfo);
- qDebug() << "launch with GDesktopAppInfo:" << launched;
}
self->deleteLater();
});
- BasicAppModel::instance()->databaseInterface()->updateApLaunchedState(desktopFilePath, true);
+ BasicAppModel::instance()->databaseInterface()->updateApLaunchedState(appid, true);
}
void AppManager::launchBinaryApp(const QString &app, const QString &args)
@@ -93,13 +86,13 @@ void AppManager::launchBinaryApp(const QString &app, const QString &args)
});
}
-void AppManager::launchAppWithArguments(const QString &desktopFile, const QStringList &args, const QString &applicationName)
+void AppManager::launchAppWithArguments(const QString &appid, const QStringList &args, const QString &applicationName)
{
QDBusMessage message = QDBusMessage::createMethodCall(KYLIN_APP_MANAGER_NAME,
KYLIN_APP_MANAGER_PATH,
KYLIN_APP_MANAGER_INTERFACE,
"LaunchAppWithArguments");
- message << desktopFile << args;
+ message << appid << args;
auto watcher = new QDBusPendingCallWatcher(QDBusConnection::sessionBus().asyncCall(message), this);
connect(watcher, &QDBusPendingCallWatcher::finished, this, [applicationName, args] (QDBusPendingCallWatcher *self) {
@@ -119,41 +112,30 @@ void AppManager::changeFavoriteState(const QString &appid, bool isFavorite)
BasicAppModel::instance()->databaseInterface()->fixAppToFavorite(appid, isFavorite ? 1 : 0);
}
-QString AppManager::parseDesktopFile(const QString &desktopFilePath)
+QStringList AppManager::parseDesktopFile(const QString &appid)
{
// 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 "";
- }
+ QSettings file(appid, QSettings::IniFormat);
- 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);
+ file.beginGroup(QStringLiteral("Desktop Entry"));
+ QStringList stringList = file.value(QStringLiteral("Exec")).toString().split(" ");
+ file.endGroup();
if (stringList.isEmpty()) {
- return "";
+ return {};
}
- QString program = stringList.first();
- stringList.removeFirst();
+ QStringList res;
+ res << stringList.takeFirst();
// TODO: freedesktop group
for (const auto &str : stringList) {
if (!str.startsWith("%")) {
- program.append(" " + str);
+ res.append(str);
}
}
- return program;
+ return res;
}
} // UkuiMenu
diff --git a/src/utils/app-manager.h b/src/utils/app-manager.h
index 10dbf35..9dd4b9a 100644
--- a/src/utils/app-manager.h
+++ b/src/utils/app-manager.h
@@ -33,14 +33,14 @@ public:
AppManager(const AppManager &obj) = delete;
AppManager &operator = (const AppManager &obj) = delete;
- Q_INVOKABLE void launchApp(const QString &desktopFilePath);
+ Q_INVOKABLE void launchApp(const QString &appid);
Q_INVOKABLE void launchBinaryApp(const QString &app, const QString &args = QString());
- Q_INVOKABLE void launchAppWithArguments(const QString &desktopFile, const QStringList &args, const QString &applicationName);
+ Q_INVOKABLE void launchAppWithArguments(const QString &appid, const QStringList &args, const QString &applicationName);
Q_INVOKABLE void changeFavoriteState(const QString &appid, bool isFavorite);
private:
explicit AppManager(QObject *parent = nullptr);
- static QString parseDesktopFile(const QString &desktopFilePath);
+ static QStringList parseDesktopFile(const QString &desktopFilePath);
Q_SIGNALS:
void request(UkuiMenuApplication::Command command);