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:
@ -65,4 +65,8 @@ constexpr auto ApplicationManagerHookDir = u8"/deepin/dde-application-manager/ho
|
||||
|
||||
constexpr auto ApplicationManagerToolsConfig = u8"org.deepin.dde.am";
|
||||
|
||||
constexpr auto ApplicationManagerConfig = u8"org.deepin.dde.application-manager";
|
||||
constexpr auto AppExtraEnvironments = u8"appExtraEnvironments";
|
||||
constexpr auto AppEnvironmentsBlacklist = u8"appEnvironmentsBlacklist";
|
||||
|
||||
#endif
|
||||
|
@ -24,6 +24,7 @@ target_link_libraries(
|
||||
Qt${QT_VERSION_MAJOR}::Core
|
||||
Qt${QT_VERSION_MAJOR}::DBus
|
||||
Qt${QT_VERSION_MAJOR}::Concurrent
|
||||
Dtk6::Core
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "launchoptions.h"
|
||||
#include "desktopentry.h"
|
||||
#include "desktopfileparser.h"
|
||||
#include "config.h"
|
||||
#include <QUuid>
|
||||
#include <QStringList>
|
||||
#include <QList>
|
||||
@ -31,22 +32,50 @@
|
||||
#include <qtmetamacros.h>
|
||||
#include <utility>
|
||||
#include <wordexp.h>
|
||||
#include <DConfig>
|
||||
|
||||
static inline void appendEnvs(const QVariant &var, QStringList &envs)
|
||||
{
|
||||
if (var.canConvert(QMetaType::QStringList)) {
|
||||
envs.append(var.value<QStringList>());
|
||||
} else if (var.canConvert(QMetaType::QString)) {
|
||||
envs.append(var.value<QString>().split(";", Qt::SkipEmptyParts));
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationService::appendExtraEnvironments(QVariantMap &runtimeOptions) const noexcept
|
||||
{
|
||||
QStringList envs;
|
||||
DCORE_USE_NAMESPACE
|
||||
QStringList envs, unsetEnvs;
|
||||
const QString &env = environ();
|
||||
if (!env.isEmpty())
|
||||
envs.append(env);
|
||||
|
||||
if (auto it = runtimeOptions.find("env"); it != runtimeOptions.cend()) {
|
||||
envs.append(it->value<QString>());
|
||||
appendEnvs(*it, envs);
|
||||
}
|
||||
|
||||
if (auto it = runtimeOptions.find("unsetEnv"); it != runtimeOptions.cend()) {
|
||||
appendEnvs(*it, unsetEnvs);
|
||||
}
|
||||
|
||||
std::unique_ptr<DConfig> config(DConfig::create(ApplicationServiceID, ApplicationManagerConfig,
|
||||
QString("/%1").arg((id())))); // $appid as subpath
|
||||
if (config->isValid()){
|
||||
const QStringList &extraEnvs = config->value(AppExtraEnvironments).toStringList();
|
||||
if (!extraEnvs.isEmpty())
|
||||
envs.append(extraEnvs);
|
||||
|
||||
const QStringList &envsBlacklist = config->value(AppEnvironmentsBlacklist).toStringList();
|
||||
if (!envsBlacklist.isEmpty())
|
||||
unsetEnvs.append(envsBlacklist);
|
||||
}
|
||||
|
||||
// it's useful for App to get itself AppId.
|
||||
envs.append(QString{"DSG_APP_ID=%1"}.arg(id()));
|
||||
|
||||
runtimeOptions.insert("env", envs.join(';'));
|
||||
runtimeOptions.insert("env", envs);
|
||||
runtimeOptions.insert("unsetEnv", unsetEnvs);
|
||||
}
|
||||
|
||||
ApplicationService::ApplicationService(DesktopFile source,
|
||||
|
@ -17,6 +17,8 @@ QStringList generateCommand(const QVariantMap &props) noexcept
|
||||
options.emplace_back(std::make_unique<setUserLaunchOption>(value));
|
||||
} else if (key == setEnvLaunchOption::key()) {
|
||||
options.emplace_back(std::make_unique<setEnvLaunchOption>(value));
|
||||
} else if (key == unsetEnvLaunchOption::key()) {
|
||||
options.emplace_back(std::make_unique<unsetEnvLaunchOption>(value));
|
||||
} else if (key == hookLaunchOption::key()) {
|
||||
options.emplace_back(std::make_unique<hookLaunchOption>(value));
|
||||
} else if (key == setWorkingPathLaunchOption::key()) {
|
||||
@ -100,16 +102,6 @@ QStringList splitLaunchOption::generateCommandLine() const noexcept
|
||||
return QStringList{m_val.toString()};
|
||||
}
|
||||
|
||||
QStringList setEnvLaunchOption::generateCommandLine() const noexcept
|
||||
{
|
||||
auto str = m_val.toString();
|
||||
if (str.isEmpty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
return QStringList{QString{"--Environment=%1"}.arg(str)};
|
||||
}
|
||||
|
||||
QStringList setWorkingPathLaunchOption::generateCommandLine() const noexcept
|
||||
{
|
||||
auto str = m_val.toString();
|
||||
@ -120,13 +112,18 @@ QStringList setWorkingPathLaunchOption::generateCommandLine() const noexcept
|
||||
return QStringList{QString{"--WorkingDirectory=%1"}.arg(str)};
|
||||
}
|
||||
|
||||
QStringList builtInSearchExecOption::generateCommandLine() const noexcept
|
||||
QStringList StringListLaunchOption::generateCommandLine() const noexcept
|
||||
{
|
||||
auto list = m_val.toStringList();
|
||||
if (list.isEmpty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto content = list.join(';');
|
||||
return QStringList{QString{"--ExecSearchPath=%1"}.arg(content)};
|
||||
QStringList ret;
|
||||
const QString ok = optionKey();
|
||||
for (const auto &ov : list) {
|
||||
ret << QString{"%1=%2"}.arg(ok).arg(ov);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -27,6 +27,14 @@ protected:
|
||||
LaunchOption() = default;
|
||||
};
|
||||
|
||||
struct StringListLaunchOption : public LaunchOption
|
||||
{
|
||||
using LaunchOption::LaunchOption;
|
||||
[[nodiscard]] QStringList generateCommandLine() const noexcept override;
|
||||
protected:
|
||||
[[nodiscard]] virtual const QString optionKey() const noexcept = 0;
|
||||
};
|
||||
|
||||
struct setUserLaunchOption : public LaunchOption
|
||||
{
|
||||
using LaunchOption::LaunchOption;
|
||||
@ -43,9 +51,9 @@ struct setUserLaunchOption : public LaunchOption
|
||||
[[nodiscard]] QStringList generateCommandLine() const noexcept override;
|
||||
};
|
||||
|
||||
struct setEnvLaunchOption : public LaunchOption
|
||||
struct setEnvLaunchOption : public StringListLaunchOption
|
||||
{
|
||||
using LaunchOption::LaunchOption;
|
||||
using StringListLaunchOption::StringListLaunchOption;
|
||||
[[nodiscard]] const QString &type() const noexcept override
|
||||
{
|
||||
static QString tp{systemdOption};
|
||||
@ -56,7 +64,10 @@ struct setEnvLaunchOption : public LaunchOption
|
||||
static QString env{"env"};
|
||||
return env;
|
||||
}
|
||||
[[nodiscard]] QStringList generateCommandLine() const noexcept override;
|
||||
protected:
|
||||
[[nodiscard]] virtual const QString optionKey() const noexcept {
|
||||
return QString("--Environment");
|
||||
}
|
||||
};
|
||||
|
||||
struct splitLaunchOption : public LaunchOption
|
||||
@ -110,9 +121,9 @@ struct setWorkingPathLaunchOption : public LaunchOption
|
||||
[[nodiscard]] QStringList generateCommandLine() const noexcept override;
|
||||
};
|
||||
|
||||
struct builtInSearchExecOption : public LaunchOption
|
||||
struct builtInSearchExecOption : public StringListLaunchOption
|
||||
{
|
||||
using LaunchOption::LaunchOption;
|
||||
using StringListLaunchOption::StringListLaunchOption;
|
||||
[[nodiscard]] const QString &type() const noexcept override
|
||||
{
|
||||
static QString tp{systemdOption};
|
||||
@ -123,7 +134,29 @@ struct builtInSearchExecOption : public LaunchOption
|
||||
static QString key{"_builtIn_searchExec"};
|
||||
return key;
|
||||
}
|
||||
[[nodiscard]] QStringList generateCommandLine() const noexcept override;
|
||||
protected:
|
||||
[[nodiscard]] virtual const QString optionKey() const noexcept {
|
||||
return QString("--ExecSearchPath");
|
||||
}
|
||||
};
|
||||
|
||||
struct unsetEnvLaunchOption : public StringListLaunchOption
|
||||
{
|
||||
using StringListLaunchOption::StringListLaunchOption;
|
||||
[[nodiscard]] const QString &type() const noexcept override
|
||||
{
|
||||
static QString tp{systemdOption};
|
||||
return tp;
|
||||
}
|
||||
[[nodiscard]] static const QString &key() noexcept
|
||||
{
|
||||
static QString env{"unsetEnv"};
|
||||
return env;
|
||||
}
|
||||
protected:
|
||||
[[nodiscard]] virtual const QString optionKey() const noexcept {
|
||||
return QString("--UnsetEnvironment");
|
||||
}
|
||||
};
|
||||
|
||||
QStringList generateCommand(const QVariantMap &props) noexcept;
|
||||
|
Reference in New Issue
Block a user