fix: correct autostart source during scanning autostart desktop file
Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
parent
0555895452
commit
23002cda6a
@ -357,8 +357,12 @@ QHash<QSharedPointer<ApplicationService>, QString> ApplicationManager1Service::s
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString originalSource;
|
||||||
QSharedPointer<ApplicationService> app{nullptr};
|
QSharedPointer<ApplicationService> app{nullptr};
|
||||||
auto asApplication = tmp.value(DesktopFileEntryKey, X_Deepin_GenerateSource).value_or(DesktopEntry::Value{});
|
auto asApplication = tmp.value(DesktopFileEntryKey, X_Deepin_GenerateSource).value_or(DesktopEntry::Value{});
|
||||||
|
auto shouldLaunch = tmp.value(DesktopFileEntryKey, DesktopEntryHidden).value_or(DesktopEntry::Value{});
|
||||||
|
auto autostartFlag = shouldLaunch.isNull() || (shouldLaunch.toString().compare("true", Qt::CaseInsensitive) != 0);
|
||||||
|
|
||||||
if (!asApplication.isNull()) { // modified by application manager
|
if (!asApplication.isNull()) { // modified by application manager
|
||||||
auto appSource = asApplication.toString();
|
auto appSource = asApplication.toString();
|
||||||
|
|
||||||
@ -388,22 +392,19 @@ QHash<QSharedPointer<ApplicationService>, QString> ApplicationManager1Service::s
|
|||||||
qWarning() << "add autostart application failed, skip.";
|
qWarning() << "add autostart application failed, skip.";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
originalSource = appSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto shouldLaunch = tmp.value(DesktopFileEntryKey, DesktopEntryHidden).value_or(DesktopEntry::Value{});
|
originalSource = originalSource.isNull() ? desktopFile.sourcePath() : originalSource;
|
||||||
if (!shouldLaunch.isNull() and (shouldLaunch.toString().compare("true", Qt::CaseInsensitive) == 0)) {
|
|
||||||
if (app)
|
|
||||||
app->setAutostartSource({desktopFile.sourcePath(), std::move(tmp)});
|
|
||||||
|
|
||||||
qInfo() << "shouldn't launch this autoStart item.";
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (app) {
|
if (app) {
|
||||||
auto realExec = tmp.value(DesktopFileEntryKey, "Exec").value_or(QString{""}).toString();
|
if (autostartFlag) {
|
||||||
qInfo() << "launch normal autostart application " << app->id() << " by " << realExec;
|
auto realExec = tmp.value(DesktopFileEntryKey, "Exec").value_or(QString{""}).toString();
|
||||||
ret.insert(app, realExec);
|
qInfo() << "launch autostart application " << app->id() << " by " << realExec;
|
||||||
app->setAutostartSource({desktopFile.sourcePath(), std::move(tmp)});
|
ret.insert(app, realExec);
|
||||||
|
}
|
||||||
|
|
||||||
|
app->setAutostartSource({std::move(originalSource), std::move(tmp)});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -417,24 +418,28 @@ QHash<QSharedPointer<ApplicationService>, QString> ApplicationManager1Service::s
|
|||||||
m_applicationList.cend(),
|
m_applicationList.cend(),
|
||||||
[&desktopFile](const auto &app) { return desktopFile.desktopId() == app->id(); });
|
[&desktopFile](const auto &app) { return desktopFile.desktopId() == app->id(); });
|
||||||
appIt != m_applicationList.cend()) {
|
appIt != m_applicationList.cend()) {
|
||||||
auto realExec = tmp.value(DesktopFileEntryKey, "Exec").value_or(QString{""}).toString();
|
if (autostartFlag) {
|
||||||
qInfo() << "launch exist autostart application " << (*appIt)->id() << " by " << realExec;
|
auto realExec = tmp.value(DesktopFileEntryKey, "Exec").value_or(QString{""}).toString();
|
||||||
ret.insert(*appIt, realExec);
|
qInfo() << "launch exist autostart application " << (*appIt)->id() << " by " << realExec;
|
||||||
(*appIt)->setAutostartSource({desktopFile.sourcePath(), std::move(tmp)});
|
ret.insert(*appIt, realExec);
|
||||||
|
}
|
||||||
|
(*appIt)->setAutostartSource({std::move(originalSource), std::move(tmp)});
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
guard.close();
|
guard.close();
|
||||||
// new application
|
// new application
|
||||||
auto newApp = addApplication(std::move(desktopFile));
|
app = addApplication(std::move(desktopFile));
|
||||||
if (!newApp) {
|
if (!app) {
|
||||||
qWarning() << "add autostart application failed, skip.";
|
qWarning() << "add autostart application failed, skip.";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
app->setAutostartSource({std::move(originalSource), {}});
|
||||||
|
|
||||||
qInfo() << "launch new autostart application " << newApp->id();
|
if (autostartFlag) {
|
||||||
newApp->setAutostartSource({desktopFile.sourcePath(), {}});
|
qInfo() << "launch new autostart application " << app->id();
|
||||||
ret.insert(newApp, {});
|
ret.insert(app, {});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -475,8 +480,7 @@ QSharedPointer<ApplicationService> ApplicationManager1Service::addApplication(De
|
|||||||
{
|
{
|
||||||
auto objectPath = QDBusObjectPath{getObjectPathFromAppId(desktopFileSource.desktopId())};
|
auto objectPath = QDBusObjectPath{getObjectPathFromAppId(desktopFileSource.desktopId())};
|
||||||
if (auto app = m_applicationList.constFind(objectPath); app != m_applicationList.cend()) {
|
if (auto app = m_applicationList.constFind(objectPath); app != m_applicationList.cend()) {
|
||||||
qInfo() << "this application already exists."
|
qInfo() << "this application already exists." << "current desktop source:" << desktopFileSource.sourcePath()
|
||||||
<< "current desktop source:" << desktopFileSource.sourcePath()
|
|
||||||
<< "exists app source:" << app->data()->desktopFileSource().sourcePath();
|
<< "exists app source:" << app->data()->desktopFileSource().sourcePath();
|
||||||
return *app;
|
return *app;
|
||||||
}
|
}
|
||||||
|
@ -623,6 +623,10 @@ bool ApplicationService::isAutoStart() const noexcept
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (m_autostartSource.m_filePath == m_desktopSource.sourcePath()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
auto appId = id();
|
auto appId = id();
|
||||||
auto dirs = getAutoStartDirs();
|
auto dirs = getAutoStartDirs();
|
||||||
QString destDesktopFile;
|
QString destDesktopFile;
|
||||||
@ -663,13 +667,18 @@ void ApplicationService::setAutoStart(bool autostart) noexcept
|
|||||||
}
|
}
|
||||||
|
|
||||||
DesktopEntry newEntry;
|
DesktopEntry newEntry;
|
||||||
|
QString originalSource;
|
||||||
if (!m_autostartSource.m_entry.data().isEmpty()) {
|
if (!m_autostartSource.m_entry.data().isEmpty()) {
|
||||||
newEntry = m_autostartSource.m_entry;
|
newEntry = m_autostartSource.m_entry;
|
||||||
|
originalSource = newEntry.value(DesktopFileEntryKey, X_Deepin_GenerateSource)
|
||||||
|
.value_or(DesktopEntry::Value{m_autostartSource.m_filePath})
|
||||||
|
.toString();
|
||||||
} else {
|
} else {
|
||||||
newEntry = *m_entry;
|
newEntry = *m_entry;
|
||||||
|
originalSource = m_desktopSource.sourcePath();
|
||||||
}
|
}
|
||||||
|
|
||||||
newEntry.insert(DesktopFileEntryKey, X_Deepin_GenerateSource, m_desktopSource.sourcePath());
|
newEntry.insert(DesktopFileEntryKey, X_Deepin_GenerateSource, originalSource);
|
||||||
newEntry.insert(DesktopFileEntryKey, DesktopEntryHidden, !autostart);
|
newEntry.insert(DesktopFileEntryKey, DesktopEntryHidden, !autostart);
|
||||||
|
|
||||||
setAutostartSource({fileName, newEntry});
|
setAutostartSource({fileName, newEntry});
|
||||||
@ -1027,8 +1036,7 @@ LaunchTask ApplicationService::unescapeExec(const QString &str, const QStringLis
|
|||||||
|
|
||||||
const auto &rawValue = val.value();
|
const auto &rawValue = val.value();
|
||||||
if (!rawValue.canConvert<QStringMap>()) {
|
if (!rawValue.canConvert<QStringMap>()) {
|
||||||
qDebug() << "Name's underlying type mismatch:"
|
qDebug() << "Name's underlying type mismatch:" << "QStringMap" << rawValue.metaType().name();
|
||||||
<< "QStringMap" << rawValue.metaType().name();
|
|
||||||
task.command.append(std::move(execList));
|
task.command.append(std::move(execList));
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user