feat: add app extra/unset env config

to fix #8667 you can
- subpath:"/FoxitReader" appExtraEnvironments : "QT_QPA_PLATFORM=xcb"
- subpath:"/FoxitReader" appEnvironmentsBlacklist : "QT_QPA_PLATFORM"

```
dde-dconfig set -a org.deepin.dde.application-manager -r org.deepin.dde.application-manager -k appExtraEnvironments -s "/FoxitReader" -v "[\"QT_QPA_PLATFORM=xcb\"]"
dde-dconfig set -a org.deepin.dde.application-manager -r org.deepin.dde.application-manager -k appEnvironmentsBlacklist -s "/FoxitReader" -v "[\"QT_QPA_PLATFORM\"]"
```

Issue: https://github.com/linuxdeepin/developer-center/issues/8667
This commit is contained in:
ck
2024-05-22 11:32:11 +08:00
committed by mike
parent 006f80d681
commit 50a0ad53ec
10 changed files with 146 additions and 54 deletions

View File

@ -11,6 +11,7 @@
#include <algorithm>
#include <cstdlib>
#include <map>
#include <list>
#include <thread>
#include "constant.h"
#include "types.h"
@ -140,6 +141,7 @@ int processExecStart(msg_ptr &msg, const std::deque<std::string_view> &execArgs)
DBusValueType getPropType(std::string_view key)
{
static std::unordered_map<std::string_view, DBusValueType> map{{"Environment", DBusValueType::ArrayOfString},
{"UnsetEnvironment", DBusValueType::ArrayOfString},
{"WorkingDirectory", DBusValueType::String},
{"ExecSearchPath", DBusValueType::ArrayOfString}};
@ -150,7 +152,7 @@ DBusValueType getPropType(std::string_view key)
return DBusValueType::String; // fallback to string
}
int appendPropValue(msg_ptr &msg, DBusValueType type, std::string_view value)
int appendPropValue(msg_ptr &msg, DBusValueType type, const std::list<std::string_view> &value)
{
int ret;
@ -165,9 +167,11 @@ int appendPropValue(msg_ptr &msg, DBusValueType type, std::string_view value)
return ret;
}
if (ret = handler->appendValue(std::string{value}); ret < 0) {
sd_journal_perror("append property's variant value failed.");
return ret;
for (const auto &v : value) {
if (ret = handler->appendValue(std::string{v}); ret < 0) {
sd_journal_perror("append property's variant value failed.");
return ret;
}
}
if (ret = handler->closeVariant(); ret < 0) {
@ -178,13 +182,12 @@ int appendPropValue(msg_ptr &msg, DBusValueType type, std::string_view value)
return 0;
}
int processKVPair(msg_ptr &msg, const std::map<std::string_view, std::string_view> &props)
int processKVPair(msg_ptr &msg, const std::map<std::string_view, std::list<std::string_view>> &props)
{
int ret;
if (!props.empty()) {
for (auto [key, value] : props) {
std::string keyStr{key};
std::string valueStr{value};
if (ret = sd_bus_message_open_container(msg, SD_BUS_TYPE_STRUCT, "sv"); ret < 0) {
sd_journal_perror("open struct of properties failed.");
return ret;
@ -195,7 +198,7 @@ int processKVPair(msg_ptr &msg, const std::map<std::string_view, std::string_vie
return ret;
}
if (ret = appendPropValue(msg, getPropType(key), valueStr); ret < 0) {
if (ret = appendPropValue(msg, getPropType(key), value); ret < 0) {
sd_journal_perror("append value of property failed.");
return ret;
}
@ -212,7 +215,7 @@ int processKVPair(msg_ptr &msg, const std::map<std::string_view, std::string_vie
std::string cmdParse(msg_ptr &msg, std::deque<std::string_view> cmdLines)
{
std::string serviceName{"internalError"};
std::map<std::string_view, std::string_view> props;
std::map<std::string_view, std::list<std::string_view>> props;
while (!cmdLines.empty()) { // NOTE: avoid stl exception
auto str = cmdLines.front();
if (str.size() < 2) {
@ -249,7 +252,7 @@ std::string cmdParse(msg_ptr &msg, std::deque<std::string_view> cmdLines)
cmdLines.pop_front();
continue;
}
props[key] = kvStr.substr(splitIndex + 1);
props[key].push_back(kvStr.substr(splitIndex + 1));
cmdLines.pop_front();
continue;
}
@ -265,18 +268,19 @@ std::string cmdParse(msg_ptr &msg, std::deque<std::string_view> cmdLines)
serviceName = "invalidInput";
return serviceName;
}
int ret;
if (props.find("unitName") == props.cend()) {
sd_journal_perror("unitName doesn't exists.");
serviceName = "invalidInput";
return serviceName;
}
if (ret = sd_bus_message_append(msg, "s", props["unitName"].data()); ret < 0) { // unitName
int ret;
if (ret = sd_bus_message_append(msg, "s", props["unitName"].front().data()); ret < 0) { // unitName
sd_journal_perror("append unitName failed.");
return serviceName;
}
serviceName = props["unitName"];
serviceName = props["unitName"].front();
props.erase("unitName");
if (ret = sd_bus_message_append(msg, "s", "replace"); ret < 0) { // start mode

View File

@ -3,6 +3,7 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
#include "variantValue.h"
#include "constant.h"
#include <sstream>
std::unique_ptr<VariantValue> creatValueHandler(msg_ptr &msg, DBusValueType type)
@ -34,29 +35,21 @@ int StringValue::appendValue(std::string &&value) noexcept
int ASValue::openVariant() noexcept
{
return sd_bus_message_open_container(msgRef(), SD_BUS_TYPE_VARIANT, "as");
if (int ret = sd_bus_message_open_container(msgRef(), SD_BUS_TYPE_VARIANT, "as"); ret < 0)
return ret;
return sd_bus_message_open_container(msgRef(), SD_BUS_TYPE_ARRAY, "s");
}
int ASValue::closeVariant() noexcept
{
if (int ret = sd_bus_message_close_container(msgRef()); ret < 0)
return ret;
return sd_bus_message_close_container(msgRef());
}
int ASValue::appendValue(std::string &&value) noexcept
{
std::string envs{std::move(value)};
std::istringstream stream{envs};
int ret{0};
if (ret = sd_bus_message_open_container(msgRef(), SD_BUS_TYPE_ARRAY, "s"); ret < 0) {
return ret;
}
for (std::string line; std::getline(stream, line, ';');) {
if (ret = sd_bus_message_append(msgRef(), "s", line.data()); ret < 0) {
return ret;
}
}
return sd_bus_message_close_container(msgRef());
return sd_bus_message_append(msgRef(), "s", value.data());
}