diff --git a/api/dbus/org.desktopspec.ApplicationManager1.Application.xml b/api/dbus/org.desktopspec.ApplicationManager1.Application.xml index e2e7ee2..d6a91da 100644 --- a/api/dbus/org.desktopspec.ApplicationManager1.Application.xml +++ b/api/dbus/org.desktopspec.ApplicationManager1.Application.xml @@ -96,6 +96,9 @@ 2. `env` (type s): passing some specific environment variables to Launch this application, eg. 'LANG=en_US;PATH=xxx:yyy;' + 3. `path` (type s): + set this application's working directory, please pass + absoult directory path. NOTE: When application launched with `uid` option, `env` option will not take effect at all." diff --git a/apps/app-launch-helper/src/main.cpp b/apps/app-launch-helper/src/main.cpp index f441a23..995e846 100644 --- a/apps/app-launch-helper/src/main.cpp +++ b/apps/app-launch-helper/src/main.cpp @@ -141,13 +141,14 @@ int processExecStart(msg_ptr &msg, const std::deque &execArgs) DBusValueType getPropType(std::string_view key) { - static std::unordered_map map{{"Environment", DBusValueType::ArrayOfString}}; + static std::unordered_map map{{"Environment", DBusValueType::ArrayOfString}, + {"WorkingDirectory", DBusValueType::String}}; if (auto it = map.find(key); it != map.cend()) { return it->second; } - return DBusValueType::Default; + return DBusValueType::String; // fallback to string } int appendPropValue(msg_ptr &msg, DBusValueType type, std::string_view value) diff --git a/apps/app-launch-helper/src/types.h b/apps/app-launch-helper/src/types.h index 3311a23..4475243 100644 --- a/apps/app-launch-helper/src/types.h +++ b/apps/app-launch-helper/src/types.h @@ -12,7 +12,7 @@ enum class ExitCode { SystemdError = -3, InvalidInput = -2, InternalError = -1, Done = 0, Waiting = 1 }; -enum class DBusValueType { Default, ArrayOfString }; +enum class DBusValueType { String, ArrayOfString }; using msg_ptr = sd_bus_message *; using bus_ptr = sd_bus *; diff --git a/apps/app-launch-helper/src/variantvalue.cpp b/apps/app-launch-helper/src/variantvalue.cpp index 4409387..c11cd88 100644 --- a/apps/app-launch-helper/src/variantvalue.cpp +++ b/apps/app-launch-helper/src/variantvalue.cpp @@ -8,7 +8,7 @@ std::unique_ptr creatValueHandler(msg_ptr &msg, DBusValueType type) { switch (type) { - case DBusValueType::Default: + case DBusValueType::String: return std::make_unique(msg); case DBusValueType::ArrayOfString: return std::make_unique(msg); diff --git a/src/launchoptions.cpp b/src/launchoptions.cpp index bd88e0a..8921dcf 100644 --- a/src/launchoptions.cpp +++ b/src/launchoptions.cpp @@ -19,6 +19,8 @@ QStringList generateCommand(const QVariantMap &props) noexcept options.emplace_back(std::make_unique(value)); } else if (key == hookLaunchOption::key()) { options.emplace_back(std::make_unique(value)); + } else if (key == setPathLaunchOption::key()) { + options.emplace_back(std::make_unique(value)); } else { qWarning() << "unsupported options" << key; } @@ -106,3 +108,13 @@ QStringList setEnvLaunchOption::generateCommandLine() const noexcept return QStringList{QString{"--Environment=%1"}.arg(str)}; } + +QStringList setPathLaunchOption::generateCommandLine() const noexcept +{ + auto str = m_val.toString(); + if (str.isEmpty()) { + return {}; + } + + return QStringList{QString{"--WorkingDirectory=%1"}.arg(str)}; +} diff --git a/src/launchoptions.h b/src/launchoptions.h index e4ba7bb..8775bca 100644 --- a/src/launchoptions.h +++ b/src/launchoptions.h @@ -94,4 +94,20 @@ struct hookLaunchOption : public LaunchOption [[nodiscard]] QStringList generateCommandLine() const noexcept override { return m_val.toStringList(); }; }; +struct setPathLaunchOption : public LaunchOption +{ + using LaunchOption::LaunchOption; + [[nodiscard]] const QString &type() const noexcept override + { + static QString tp{systemdOption}; + return tp; + } + [[nodiscard]] static const QString &key() noexcept + { + static QString path{"path"}; + return path; + } + [[nodiscard]] QStringList generateCommandLine() const noexcept override; +}; + QStringList generateCommand(const QVariantMap &props) noexcept;