Compare commits

..

No commits in common. "0695c9784cdb282614001aeb62bcf8e39ac3f04f" and "006f80d681b9f15d087997148e3beb2585688615" have entirely different histories.

19 changed files with 216 additions and 468 deletions

11
.gitignore vendored
View File

@ -1,13 +1,10 @@
.cache
build*
.vscode
/debian/.debhelper
/debian/dde-application-manager
/debian/dde-application-manager-api
/debian/*.substvars
/debian/*.debhelper
/debian/dde-application-manager.substvars
/debian/dde-application-manager.debhelper.log
/debian/debhelper-build-stamp
/debian/files
/debian/tmp
/obj-*-linux-gnu
*.user
/obj-x86_64-linux-gnu
*.user

View File

@ -23,11 +23,6 @@ Files: .gitignore
Copyright: None
License: CC0-1.0
# cmake
Files: api/*.cmake.in
Copyright: None
License: CC0-1.0
# DBus API
Files: api/dbus/*.xml apps/app-update-notifier/api/dbus/*.xml
Copyright: None

View File

@ -2,13 +2,5 @@ include(GNUInstallDirs)
file(GLOB DBusAPI ${CMAKE_CURRENT_LIST_DIR}/dbus/*.xml)
configure_file(
${CMAKE_SOURCE_DIR}/api/DDEApplicationManagerConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/DDEApplicationManagerConfig.cmake
@ONLY)
install(FILES ${DBusAPI}
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/dde-application-manager/)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/DDEApplicationManagerConfig.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/DDEApplicationManager/)

View File

@ -1 +0,0 @@
set(DDE_APPLICATION_MANAGER_DBUS_API_DIR @CMAKE_INSTALL_FULL_DATAROOTDIR@/dde-application-manager/)

View File

@ -117,14 +117,6 @@
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QStringMap"/>
</property>
<property name="StartupWMClass" type="s" access="read">
<annotation
name="org.freedesktop.DBus.Description"
value="The meaning of this property's type is same as which in StartupWMClass."
/>
<annotation name="org.qtproject.QtDBus.QtTypeName" value="QStringMap"/>
</property>
<method name="Launch">
<arg type="s" name="action" direction="in" />
<arg type="as" name="fields" direction="in" />
@ -146,13 +138,10 @@
1. `uid` (type u):
The user id as who is that application will be run.
This option might request a polikit authentication.
2. `env` (type as):
2. `env` (type s):
passing some specific environment variables to Launch
this application without them, eg. '[LANG=en_US, PATH=xxx:yyy]'
3. `unsetEnv` (type as):
passed environment variables will be ignored when
launching this application, eg. '[LANG, PATH]'
4. `path` (type s):
this application, eg. 'LANG=en_US;PATH=xxx:yyy;'
3. `path` (type s):
set this application's working directory, please pass
absolute directory path.
NOTE:

View File

@ -11,7 +11,6 @@
#include <algorithm>
#include <cstdlib>
#include <map>
#include <list>
#include <thread>
#include "constant.h"
#include "types.h"
@ -141,7 +140,6 @@ 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}};
@ -152,7 +150,7 @@ DBusValueType getPropType(std::string_view key)
return DBusValueType::String; // fallback to string
}
int appendPropValue(msg_ptr &msg, DBusValueType type, const std::list<std::string_view> &value)
int appendPropValue(msg_ptr &msg, DBusValueType type, std::string_view value)
{
int ret;
@ -167,11 +165,9 @@ int appendPropValue(msg_ptr &msg, DBusValueType type, const std::list<std::strin
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->appendValue(std::string{value}); ret < 0) {
sd_journal_perror("append property's variant value failed.");
return ret;
}
if (ret = handler->closeVariant(); ret < 0) {
@ -182,12 +178,13 @@ int appendPropValue(msg_ptr &msg, DBusValueType type, const std::list<std::strin
return 0;
}
int processKVPair(msg_ptr &msg, const std::map<std::string_view, std::list<std::string_view>> &props)
int processKVPair(msg_ptr &msg, const std::map<std::string_view, 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;
@ -198,7 +195,7 @@ int processKVPair(msg_ptr &msg, const std::map<std::string_view, std::list<std::
return ret;
}
if (ret = appendPropValue(msg, getPropType(key), value); ret < 0) {
if (ret = appendPropValue(msg, getPropType(key), valueStr); ret < 0) {
sd_journal_perror("append value of property failed.");
return ret;
}
@ -215,7 +212,7 @@ int processKVPair(msg_ptr &msg, const std::map<std::string_view, std::list<std::
std::string cmdParse(msg_ptr &msg, std::deque<std::string_view> cmdLines)
{
std::string serviceName{"internalError"};
std::map<std::string_view, std::list<std::string_view>> props;
std::map<std::string_view, std::string_view> props;
while (!cmdLines.empty()) { // NOTE: avoid stl exception
auto str = cmdLines.front();
if (str.size() < 2) {
@ -252,7 +249,7 @@ std::string cmdParse(msg_ptr &msg, std::deque<std::string_view> cmdLines)
cmdLines.pop_front();
continue;
}
props[key].push_back(kvStr.substr(splitIndex + 1));
props[key] = kvStr.substr(splitIndex + 1);
cmdLines.pop_front();
continue;
}
@ -268,19 +265,18 @@ 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;
}
int ret;
if (ret = sd_bus_message_append(msg, "s", props["unitName"].front().data()); ret < 0) { // unitName
if (ret = sd_bus_message_append(msg, "s", props["unitName"].data()); ret < 0) { // unitName
sd_journal_perror("append unitName failed.");
return serviceName;
}
serviceName = props["unitName"].front();
serviceName = props["unitName"];
props.erase("unitName");
if (ret = sd_bus_message_append(msg, "s", "replace"); ret < 0) { // start mode

View File

@ -3,7 +3,6 @@
// 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)
@ -35,21 +34,29 @@ int StringValue::appendValue(std::string &&value) noexcept
int ASValue::openVariant() noexcept
{
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");
return sd_bus_message_open_container(msgRef(), SD_BUS_TYPE_VARIANT, "as");
}
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
{
return sd_bus_message_append(msgRef(), "s", value.data());
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());
}

12
debian/changelog vendored
View File

@ -1,15 +1,3 @@
dde-application-manager (1.2.16) unstable; urgency=medium
* release 1.2.16
-- tsic404 <liuheng@deepin.org> Thu, 10 Oct 2024 15:34:38 +0800
dde-application-manager (1.2.15) unstable; urgency=medium
* release 1.2.15
-- Mike Chen <chenke@deepin.org> Wed, 10 Jul 2024 13:09:51 +0800
dde-application-manager (1.2.14) unstable; urgency=medium
* release 1.2.14

View File

@ -1,2 +1 @@
usr/share/dde-application-manager/*.xml
usr/lib/*/cmake/DDEApplicationManager/*

View File

@ -1,6 +1,6 @@
etc/dpkg/*
usr/bin/*
usr/lib/systemd/*
usr/lib/*
usr/libexec/*
usr/share/dbus-1/*
usr/share/dsg/*

View File

@ -70,7 +70,5 @@ install(FILES ${CMAKE_CURRENT_LIST_DIR}/hooks.d/debFix.sh
)
dtk_add_config_meta_files(APPID ${APPLICATION_SERVICEID}
FILES
${CMAKE_CURRENT_LIST_DIR}/dsg/configs/dde-application-manager/org.deepin.dde.am.json
${CMAKE_CURRENT_LIST_DIR}/dsg/configs/dde-application-manager/org.deepin.dde.application-manager.json
FILES ${CMAKE_CURRENT_LIST_DIR}/dsg/configs/dde-application-manager/org.deepin.dde.am.json
)

View File

@ -1,26 +0,0 @@
{
"magic": "dsg.config.meta",
"version": "1.0",
"contents": {
"appExtraEnvironments": {
"value": [],
"serial": 0,
"flags": [],
"name": "Launching app with extra environments",
"name[zh_CN]": "启动应用时附加额外环境变量",
"description": "Launching app with extra environments",
"permissions": "readwrite",
"visibility": "public"
},
"appEnvironmentsBlacklist": {
"value": [],
"serial": 0,
"flags": [],
"name": "Ignore blacklisted environment variables before launching app",
"name[zh_CN]": "启动应用时取消某些环境变量",
"description": "Ignore blacklisted environment variables before launching app",
"permissions": "readwrite",
"visibility": "public"
}
}
}

View File

@ -65,8 +65,4 @@ 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

View File

@ -24,7 +24,6 @@ target_link_libraries(
Qt${QT_VERSION_MAJOR}::Core
Qt${QT_VERSION_MAJOR}::DBus
Qt${QT_VERSION_MAJOR}::Concurrent
Dtk6::Core
)
target_include_directories(

View File

@ -14,7 +14,6 @@
#include "launchoptions.h"
#include "desktopentry.h"
#include "desktopfileparser.h"
#include "config.h"
#include <QUuid>
#include <QStringList>
#include <QList>
@ -32,51 +31,22 @@
#include <qtmetamacros.h>
#include <utility>
#include <wordexp.h>
#include <DConfig>
static inline void appendEnvs(const QVariant &var, QStringList &envs)
{
if (var.canConvert<QStringList>()) {
envs.append(var.value<QStringList>());
} else if (var.canConvert<QString>()) {
envs.append(var.value<QString>().split(";", Qt::SkipEmptyParts));
}
}
void ApplicationService::appendExtraEnvironments(QVariantMap &runtimeOptions) const noexcept
{
DCORE_USE_NAMESPACE
QStringList envs, unsetEnvs;
QStringList envs;
const QString &env = environ();
if (!env.isEmpty())
envs.append(env);
if (auto it = runtimeOptions.find("env"); it != runtimeOptions.cend()) {
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);
envs.append(it->value<QString>());
}
// it's useful for App to get itself AppId.
envs.append(QString{"DSG_APP_ID=%1"}.arg(id()));
runtimeOptions.insert("env", envs);
runtimeOptions.insert("unsetEnv", unsetEnvs);
runtimeOptions.insert("env", envs.join(';'));
}
ApplicationService::ApplicationService(DesktopFile source,
@ -250,8 +220,8 @@ ApplicationService::Launch(const QString &action, const QStringList &fields, con
execStr = toString(actionExec.value());
if (execStr.isEmpty()) {
qWarning() << "exec value to string failed, try default action."; // we need this log.
break;
}
break;
}
@ -295,7 +265,7 @@ ApplicationService::Launch(const QString &action, const QStringList &fields, con
if (terminal()) {
// don't change this sequence
execCmds.push_front("-e"); // run all original execution commands in deepin-terminal
execCmds.push_front("-C"); // means run a shellscript
execCmds.push_front("--keep-open"); // keep terminal open, prevent exit immediately
execCmds.push_front("deepin-terminal");
}
@ -304,78 +274,46 @@ ApplicationService::Launch(const QString &action, const QStringList &fields, con
auto &jobManager = parent()->jobManager();
return jobManager.addJob(
m_applicationPath.path(),
[this, binary = std::move(bin), commands = std::move(cmds)](const QVariant &value) -> QVariant {
auto rawResources = value.toString();
[this, binary = std::move(bin), commands = std::move(cmds)](const QVariant &variantValue) -> QVariant {
auto resourceFile = variantValue.toString();
auto instanceRandomUUID = QUuid::createUuid().toString(QUuid::Id128);
auto objectPath = m_applicationPath.path() + "/" + instanceRandomUUID;
auto newCommands = commands;
newCommands.push_front(QString{"--SourcePath=%1"}.arg(m_desktopSource.sourcePath()));
if (rawResources.isEmpty()) {
auto location = newCommands.indexOf(R"(%f)");
if (location != -1) { // due to std::move, there only remove once
newCommands.remove(location);
}
if (resourceFile.isEmpty()) {
newCommands.push_front(QString{R"(--unitName=app-DDE-%1@%2.service)"}.arg(
escapeApplicationId(this->id()), instanceRandomUUID)); // launcher should use this instanceId
QProcess process;
qDebug() << "launcher :" << m_launcher << "run with commands:" << newCommands;
qDebug() << "run with commands:" << newCommands;
process.start(m_launcher, newCommands);
process.waitForFinished();
if (auto code = process.exitCode(); code != 0) {
qWarning() << "Launch Application Failed";
return QDBusError::Failed;
}
return objectPath;
}
auto location = newCommands.end();
qsizetype fieldIndex{-1};
for (auto it = newCommands.begin(); it != newCommands.end(); ++it) {
auto fieldLocation = it->indexOf(R"(%f)");
if (fieldLocation != -1) {
fieldIndex = fieldLocation;
location = it;
break;
}
fieldLocation = it->indexOf(R"(%F)");
if (fieldLocation != -1) {
fieldIndex = fieldLocation;
location = it;
break;
auto url = QUrl::fromUserInput(resourceFile);
if (!url.isValid()) { // if url is invalid, passing to launcher directly
auto scheme = url.scheme();
if (!scheme.isEmpty()) {
// TODO: resourceFile = processRemoteFile(resourceFile);
}
}
if (location == newCommands.end()) {
qCritical() << R"(internal logic error, can't find %f or %F in exec command, abort.)";
return QDBusError::Failed;
}
// NOTE: resourceFile must be available in the following contexts
newCommands.insert(location, resourceFile);
const auto &rawResource = rawResources.split(' ', Qt::SkipEmptyParts);
QStringList resources;
std::transform(rawResource.cbegin(), rawResource.cend(), std::back_inserter(resources), [](const QString &res) {
auto url = QUrl::fromUserInput(res);
if (url.isValid()) {
if (url.isLocalFile()) {
return url.toLocalFile();
}
// for now, we only support local file, maybe we will support remote file in the future.
// TODO: return processRemoteFile(url);
} // if url is invalid, passing to launcher directly
return res;
});
auto tmpRes = resources.join(' ');
location->replace(fieldIndex, tmpRes.size(), tmpRes);
auto newCmd = location->split(' ', Qt::SkipEmptyParts);
location = newCommands.erase(location);
for (auto &c : newCmd) {
location = newCommands.insert(location, std::move(c));
}
newCommands.push_front(QString{R"(--unitName=DDE-%1@%2.service)"}.arg(this->id(), instanceRandomUUID));
QProcess process;
qDebug().noquote() << "launcher :" << m_launcher << "run with commands:" << newCommands;
qDebug() << "run with commands:" << newCommands;
process.start(getApplicationLauncherBinary(), newCommands);
process.waitForFinished();
auto exitCode = process.exitCode();
@ -383,7 +321,6 @@ ApplicationService::Launch(const QString &action, const QStringList &fields, con
qWarning() << "Launch Application Failed";
return QDBusError::Failed;
}
return objectPath;
},
std::move(res));
@ -592,12 +529,6 @@ bool ApplicationService::terminal() const noexcept
return false;
}
QString ApplicationService::startupWMClass() const noexcept
{
auto value = findEntryValue(DesktopFileEntryKey, "StartupWMClass", EntryValueType::String);
return value.isNull() ? QString{} : value.toString();
}
qint64 ApplicationService::installedTime() const noexcept
{
return m_installedTime;
@ -668,12 +599,6 @@ bool ApplicationService::autostartCheck(const QString &filePath) const noexcept
}
}
QString source = s.value(DesktopFileEntryKey, X_Deepin_GenerateSource).value_or(DesktopEntry::Value{}).toString();
// file has been removed
if (source != m_autostartSource.m_filePath && filePath != m_autostartSource.m_filePath) {
return false;
}
auto hiddenVal = s.value(DesktopFileEntryKey, DesktopEntryHidden);
if (!hiddenVal) {
qDebug() << "no hidden in autostart desktop";
@ -711,6 +636,11 @@ bool ApplicationService::isAutoStart() const noexcept
{"*.desktop"},
QDir::Name | QDir::DirsLast);
// file has been removed
if (destDesktopFile != m_autostartSource.m_filePath) {
return false;
}
return autostartCheck(destDesktopFile);
}
@ -720,7 +650,7 @@ void ApplicationService::setAutoStart(bool autostart) noexcept
return;
}
QDir startDir(getAutoStartDirs().first());
QDir startDir (getAutoStartDirs().first());
if (!startDir.exists() && !startDir.mkpath(startDir.path())) {
qWarning() << "mkpath " << startDir.path() << "failed";
safe_sendErrorReply(QDBusError::InternalError);
@ -933,7 +863,6 @@ void ApplicationService::resetEntry(DesktopEntry *newEntry) noexcept
emit terminalChanged();
emit environChanged();
emit launchedTimesChanged();
emit startupWMClassChanged();
}
std::optional<QStringList> ApplicationService::unescapeExecArgs(const QString &str) noexcept
@ -990,236 +919,162 @@ std::optional<QStringList> ApplicationService::unescapeExecArgs(const QString &s
return execList;
}
LaunchTask ApplicationService::unescapeExec(const QString &str, QStringList fields) noexcept
LaunchTask ApplicationService::unescapeExec(const QString &str, const QStringList &fields) noexcept
{
LaunchTask task;
auto args = unescapeExecArgs(str);
auto opt = unescapeExecArgs(str);
if (!args) {
if (!opt.has_value()) {
qWarning() << "unescapeExecArgs failed.";
return {};
}
if (args->isEmpty()) {
auto execList = std::move(opt).value();
if (execList.isEmpty()) {
qWarning() << "exec format is invalid.";
return {};
}
auto processUrl = [](const QString &str) {
auto url = QUrl::fromUserInput(str);
if (!url.isValid()) {
qDebug() << "url is invalid, pass to exec directly.";
return str;
task.LaunchBin = execList.first();
QRegularExpression re{"%[fFuUickdDnNvm]"};
auto matcher = re.match(str);
if (!matcher.hasMatch()) {
task.command.append(std::move(execList));
task.Resources.emplace_back(QString{""}); // mapReduce should run once at least
return task;
}
auto list = matcher.capturedTexts();
if (list.count() != 1) {
qWarning() << "invalid exec format, all filed code will be ignored.";
for (const auto &code : list) {
execList.removeOne(code);
}
task.command.append(std::move(execList));
return task;
}
auto filesCode = list.first().back().toLatin1();
auto codeStr = QString(R"(%%1)").arg(filesCode);
auto location = execList.indexOf(codeStr);
if (location == -1) {
qWarning() << "invalid exec format, all filed code will be ignored.";
return {};
}
switch (filesCode) {
case 'f': { // Defer to async job
task.command.append(std::move(execList));
for (const auto &field : fields) {
task.Resources.emplace_back(field);
}
} break;
case 'u': {
execList.removeAt(location);
if (fields.empty()) {
task.command.append(execList);
break;
}
if (fields.count() > 1) {
qDebug() << R"(fields count is greater than one, %u will only take first element.)";
}
execList.insert(location, fields.first());
task.command.append(execList);
} break;
case 'F': {
execList.remove(location);
auto it = execList.begin() + location;
for (const auto &field : fields) {
auto tmp = QUrl::fromUserInput(field);
if (auto scheme = tmp.scheme(); scheme.startsWith("file") or scheme.isEmpty()) {
it = execList.insert(it, tmp.toLocalFile());
} else {
qWarning() << "shouldn't replace %F with an URL:" << field;
it = execList.insert(it, field);
}
++it;
}
task.command.append(std::move(execList));
} break;
case 'U': {
execList.removeAt(location);
auto it = execList.begin() + location;
for (const auto &field : fields) {
it = execList.insert(it, field);
++it;
}
task.command.append(std::move(execList));
} break;
case 'i': {
execList.removeAt(location);
auto val = m_entry->value(DesktopFileEntryKey, "Icon");
if (!val) {
qDebug() << R"(Application Icons can't be found. %i will be ignored.)";
task.command.append(std::move(execList));
return task;
}
if (url.isLocalFile()) {
return url.toLocalFile();
auto iconStr = toIconString(val.value());
if (iconStr.isEmpty()) {
qDebug() << R"(Icons Convert to string failed. %i will be ignored.)";
task.command.append(std::move(execList));
return task;
}
auto it = execList.insert(location, iconStr);
execList.insert(it, "--icon");
task.command.append(std::move(execList));
} break;
case 'c': {
execList.removeAt(location);
auto val = m_entry->value(DesktopFileEntryKey, "Name");
if (!val) {
qDebug() << R"(Application Name can't be found. %c will be ignored.)";
task.command.append(std::move(execList));
return task;
}
return url.toString();
};
task.LaunchBin = args->first();
const QChar percentage{'%'};
bool exclusiveField{false};
for (const auto &arg : *args) {
QString newArg;
for (const auto *it = arg.cbegin(); it != arg.cend();) {
if (*it != percentage) {
newArg.append(*(it++));
continue;
}
const auto *code = it + 1;
if (code == arg.cend()) {
qWarning() << R"(content of exec is invalid, a unterminated % is detected.)";
return {};
}
if (*code == percentage) {
newArg.append(percentage);
it += 2;
continue;
}
switch (code->toLatin1()) {
case 'f': { // Defer to async job
if (exclusiveField) {
qDebug() << R"(exclusive field is detected again, %f will be ignored.)";
break;
}
exclusiveField = true;
if (fields.empty()) {
qDebug() << R"(fields is empty, %f will be ignored.)";
break;
}
if (fields.size() > 1) {
qDebug() << R"(fields count is greater than one, %f will only take first element.)";
}
task.Resources.emplace_back(fields.takeFirst());
newArg.append(R"(%f)");
} break;
case 'u': {
if (exclusiveField) {
qDebug() << R"(exclusive field is detected again, %f will be ignored.)";
break;
}
exclusiveField = true;
if (fields.empty()) {
qDebug() << "fields is empty, %u will be ignored.";
break;
}
if (fields.size() > 1) {
qDebug() << R"(fields count is greater than one, %u will only take first element.)";
}
newArg.append(processUrl(fields.takeFirst()));
} break;
case 'F': { // Defer to async job
if (exclusiveField) {
qDebug() << R"(exclusive field is detected again, %f will be ignored.)";
break;
}
exclusiveField = true;
task.Resources.emplace_back(fields.join(' '));
fields.clear();
newArg.append(R"(%F)");
} break;
case 'U': {
if (exclusiveField) {
qDebug() << R"(exclusive field is detected again, %f will be ignored.)";
break;
}
exclusiveField = true;
QStringList urls;
std::transform(fields.cbegin(), fields.cend(), std::back_inserter(urls), processUrl);
fields.clear();
newArg.append(urls.join(' ')); // split at the end of loop
} break;
case 'i': {
auto val = m_entry->value(DesktopFileEntryKey, "Icon");
if (!val) {
qDebug() << R"(Application Icons can't be found. %i will be ignored.)";
break;
}
auto iconStr = toIconString(val.value());
if (iconStr.isEmpty()) {
qDebug() << R"(Icons Convert to string failed. %i will be ignored.)";
break;
}
// split at the end of loop
newArg.append(QString{"--icon %1"}.arg(iconStr));
} break;
case 'c': {
auto val = m_entry->value(DesktopFileEntryKey, "Name");
if (!val) {
qDebug() << R"(Application Name can't be found. %c will be ignored.)";
break;
}
const auto &rawValue = val.value();
if (!rawValue.canConvert<QStringMap>()) {
qDebug() << "Name's underlying type mismatch:" << "QStringMap" << rawValue.metaType().name();
break;
}
auto NameStr = toLocaleString(rawValue.value<QStringMap>(), getUserLocale());
if (NameStr.isEmpty()) {
qDebug() << R"(Name Convert to locale string failed. %c will be ignored.)";
break;
}
newArg.append(NameStr);
} break;
case 'k': { // ignore all desktop file location for now.
newArg.append(m_desktopSource.sourcePath());
} break;
case 'd':
case 'D':
case 'n':
case 'N':
case 'v':
[[fallthrough]]; // Deprecated field codes should be removed from the command line and ignored.
case 'm': {
qDebug() << "field code" << *code << "has been deprecated.";
} break;
default: {
qDebug() << "unknown field code:" << *code << ", ignore it.";
}
}
it += 2; // skip filed code
const auto &rawValue = val.value();
if (!rawValue.canConvert<QStringMap>()) {
qDebug() << "Name's underlying type mismatch:" << "QStringMap" << rawValue.metaType().name();
task.command.append(std::move(execList));
return task;
}
auto newArgList = newArg.split(' ', Qt::SkipEmptyParts);
if (!newArgList.isEmpty()) {
task.command.append(std::move(newArgList));
auto NameStr = toLocaleString(rawValue.value<QStringMap>(), getUserLocale());
if (NameStr.isEmpty()) {
qDebug() << R"(Name Convert to locale string failed. %c will be ignored.)";
task.command.append(std::move(execList));
return task;
}
execList.insert(location, NameStr);
task.command.append(std::move(execList));
} break;
case 'k': { // ignore all desktop file location for now.
execList.removeAt(location);
task.command.append(std::move(execList));
} break;
case 'd':
case 'D':
case 'n':
case 'N':
case 'v':
[[fallthrough]]; // Deprecated field codes should be removed from the command line and ignored.
case 'm': {
execList.removeAt(location);
task.command.append(std::move(execList));
} break;
default: {
qDebug() << "unrecognized file code.";
}
}
if (task.Resources.isEmpty()) {
task.Resources.emplace_back(QString{""}); // mapReduce should run once at least
}
qInfo() << "after unescape exec:" << task.LaunchBin << task.command << task.Resources;
return task;
}
void ApplicationService::unescapeEens(QVariantMap &options) noexcept
{
if (options.find("env") == options.end()) {
return;
}
QStringList result;
auto envs = options["env"];
for (const QString &var : envs.toStringList()) {
wordexp_t p;
if (wordexp(var.toStdString().c_str(), &p, 0) == 0) {
for (size_t i = 0; i < p.we_wordc; i++) {
result << QString::fromLocal8Bit(p.we_wordv[i]); // 将结果转换为QString
}
wordfree(&p);
} else {
return;
}
}
options.insert("env", result);
}
void ApplicationService::autoRemoveFromDesktop() const noexcept
{
auto dir = QStandardPaths::writableLocation(QStandardPaths::DesktopLocation);
if (dir.isEmpty()) {
return;
}
QFileInfo desktopFile{QDir{dir}.filePath(m_desktopSource.desktopId() + ".desktop")};
if (!desktopFile.isSymbolicLink()) {
qDebug() << desktopFile.filePath() << " is not symbolicLink";
return;
}
QFile file{desktopFile.filePath()};
auto success = file.remove();
if (!success) {
qWarning() << "remove desktop file failed:" << file.errorString();
return;
}
}
QVariant ApplicationService::findEntryValue(const QString &group,
const QString &valueKey,
EntryValueType type,

View File

@ -74,9 +74,6 @@ public:
Q_PROPERTY(bool Terminal READ terminal NOTIFY terminalChanged)
[[nodiscard]] bool terminal() const noexcept;
Q_PROPERTY(QString StartupWMClass READ startupWMClass NOTIFY startupWMClassChanged)
[[nodiscard]] QString startupWMClass() const noexcept;
// FIXME:
// This property should implement with fuse guarded
// $XDG_CONFIG_HOME/autostart/. Current implementation has some problems,
@ -134,9 +131,7 @@ public:
EntryValueType type,
const QLocale &locale = getUserLocale()) const noexcept;
[[nodiscard]] LaunchTask unescapeExec(const QString &str, QStringList fields) noexcept;
void autoRemoveFromDesktop() const noexcept;
void unescapeEens(QVariantMap&) noexcept;
[[nodiscard]] LaunchTask unescapeExec(const QString &str, const QStringList &fields) noexcept;
[[nodiscard]] static std::optional<QStringList> unescapeExecArgs(const QString &str) noexcept;
public Q_SLOTS:
@ -168,7 +163,6 @@ Q_SIGNALS:
void terminalChanged();
void environChanged();
void launchedTimesChanged();
void startupWMClassChanged();
private:
friend class ApplicationManager1Service;

View File

@ -544,8 +544,6 @@ template <typename Key, typename Value>
ObjectMap dumpDBusObject(const QHash<Key, QSharedPointer<Value>> &map)
{
static_assert(std::is_base_of_v<QObject, Value>, "dumpDBusObject only support which derived by QObject class");
static_assert(std::is_same_v<Key, QString> || std::is_same_v<Key, QDBusObjectPath>,
"dumpDBusObject only support QString/QDBusObject as key type");
ObjectMap objs;
for (const auto &[key, value] : map.asKeyValueRange()) {
@ -554,6 +552,8 @@ ObjectMap dumpDBusObject(const QHash<Key, QSharedPointer<Value>> &map)
objs.insert(QDBusObjectPath{getObjectPathFromAppId(key)}, interAndProps);
} else if constexpr (std::is_same_v<Key, QDBusObjectPath>) {
objs.insert(key, interAndProps);
} else {
static_assert(false, "dumpDBusObject only support QString/QDBusObject as key type");
}
}

View File

@ -17,8 +17,6 @@ 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()) {
@ -102,6 +100,16 @@ 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();
@ -112,18 +120,13 @@ QStringList setWorkingPathLaunchOption::generateCommandLine() const noexcept
return QStringList{QString{"--WorkingDirectory=%1"}.arg(str)};
}
QStringList StringListLaunchOption::generateCommandLine() const noexcept
QStringList builtInSearchExecOption::generateCommandLine() const noexcept
{
auto list = m_val.toStringList();
if (list.isEmpty()) {
return {};
}
QStringList ret;
const QString ok = optionKey();
for (const auto &ov : list) {
ret << QString{"%1=%2"}.arg(ok).arg(ov);
}
return ret;
auto content = list.join(';');
return QStringList{QString{"--ExecSearchPath=%1"}.arg(content)};
}

View File

@ -27,14 +27,6 @@ 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;
@ -51,9 +43,9 @@ struct setUserLaunchOption : public LaunchOption
[[nodiscard]] QStringList generateCommandLine() const noexcept override;
};
struct setEnvLaunchOption : public StringListLaunchOption
struct setEnvLaunchOption : public LaunchOption
{
using StringListLaunchOption::StringListLaunchOption;
using LaunchOption::LaunchOption;
[[nodiscard]] const QString &type() const noexcept override
{
static QString tp{systemdOption};
@ -64,10 +56,7 @@ struct setEnvLaunchOption : public StringListLaunchOption
static QString env{"env"};
return env;
}
protected:
[[nodiscard]] virtual const QString optionKey() const noexcept {
return QString("--Environment");
}
[[nodiscard]] QStringList generateCommandLine() const noexcept override;
};
struct splitLaunchOption : public LaunchOption
@ -121,9 +110,9 @@ struct setWorkingPathLaunchOption : public LaunchOption
[[nodiscard]] QStringList generateCommandLine() const noexcept override;
};
struct builtInSearchExecOption : public StringListLaunchOption
struct builtInSearchExecOption : public LaunchOption
{
using StringListLaunchOption::StringListLaunchOption;
using LaunchOption::LaunchOption;
[[nodiscard]] const QString &type() const noexcept override
{
static QString tp{systemdOption};
@ -134,29 +123,7 @@ struct builtInSearchExecOption : public StringListLaunchOption
static QString key{"_builtIn_searchExec"};
return key;
}
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");
}
[[nodiscard]] QStringList generateCommandLine() const noexcept override;
};
QStringList generateCommand(const QVariantMap &props) noexcept;