From 875cadc5123a2c76d83f906a0b000422e34ec31e Mon Sep 17 00:00:00 2001 From: kamiyadm Date: Sun, 25 Jun 2023 17:27:27 +0800 Subject: [PATCH] feat: launch the application by AM in actionInvoke We can't call an application up by QProcess if it is running in a sandbox. So we add a new way to call it. Log: --- dde-osd/src/notification/bubbletool.cpp | 24 ++++++++++++++++++++++++ dde-osd/src/notification/bubbletool.h | 1 + 2 files changed, 25 insertions(+) diff --git a/dde-osd/src/notification/bubbletool.cpp b/dde-osd/src/notification/bubbletool.cpp index f14ea9f9e..26c17f5f7 100644 --- a/dde-osd/src/notification/bubbletool.cpp +++ b/dde-osd/src/notification/bubbletool.cpp @@ -203,6 +203,21 @@ const QString BubbleTool::getDeepinAppName(const QString &name) return desktop.localizedValue("Name", localKey, "Desktop Entry", name); } +const QString BubbleTool::getDesktopPath(const QString &desktopName) +{ + QString desktopPath; + + for (const auto dataPath : DStandardPaths::standardLocations(QStandardPaths::ApplicationsLocation)) { + auto path = QStringList{ dataPath, desktopName }.join(QDir::separator()); + if (QFile::exists(path)) { + desktopPath = path; + break; + } + } + + return desktopPath; +} + void BubbleTool::actionInvoke(const QString &actionId, EntityPtr entity) { qDebug() << "actionId:" << actionId; @@ -215,6 +230,15 @@ void BubbleTool::actionInvoke(const QString &actionId, EntityPtr entity) args.removeFirst(); if (i.key() == "x-deepin-action-" + actionId) { QProcess::startDetached(cmd, args); //执行相关命令 + } else if(i.key() == "x-deepin-action-" + "_openbydesktop") { + auto desktopPath = getDesktopPath(cmd); + QDBusConnection conn = QDBusConnection::sessionBus(); + QDBusMessage msg = QDBusMessage::createMethodCall("org.deepin.dde.StartManager1", + "/org/deepin/dde/StartManager1", + "org.deepin.dde.StartManager1", + "LaunchApp"); + msg << desktopPath << 0 << args; + conn.sessionBus().call(msg, QDBus::NoBlock); } } ++i; diff --git a/dde-osd/src/notification/bubbletool.h b/dde-osd/src/notification/bubbletool.h index 72b3494d5..8377594b3 100644 --- a/dde-osd/src/notification/bubbletool.h +++ b/dde-osd/src/notification/bubbletool.h @@ -26,6 +26,7 @@ class BubbleTool static void actionInvoke(const QString &actionId, EntityPtr entity);//从entity提取出命令信息,执行命令产生相应动作 static void register_wm_state(WId winid);//保持气泡窗口置顶 static const QString getDeepinAppName(const QString &name);//获取应用名称 + static const QString getDeepinDesktopPath(const QString &name);//获取desktop文件路径 private: /*!