fix: Manual removal of symbolic links leads to state error
Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
parent
4d6e399653
commit
8d033daf6b
@ -376,40 +376,45 @@ qulonglong ApplicationService::lastLaunchedTime() const noexcept
|
||||
return m_lastLaunch;
|
||||
}
|
||||
|
||||
bool ApplicationService::autostartCheck(const QString &linkPath) noexcept
|
||||
{
|
||||
QFileInfo info{linkPath};
|
||||
|
||||
if (!info.exists() or !info.isSymbolicLink()) {
|
||||
qWarning() << "same name desktop file exists:" << linkPath << "but this may not created by AM.";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ApplicationService::isAutoStart() const noexcept
|
||||
{
|
||||
return m_AutoStart;
|
||||
auto path = getAutoStartDirs().first();
|
||||
auto linkName = QDir{path}.filePath(m_desktopSource.desktopId() + ".desktop");
|
||||
return autostartCheck(linkName);
|
||||
}
|
||||
|
||||
void ApplicationService::setAutoStart(bool autostart) noexcept
|
||||
{
|
||||
if (autostart == m_AutoStart) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto path = getAutoStartDirs().first();
|
||||
auto linkName = QDir{path}.filePath(m_desktopSource.desktopId() + ".desktop");
|
||||
auto &file = m_desktopSource.sourceFileRef();
|
||||
|
||||
if (autostart) {
|
||||
if (!file.link(linkName)) {
|
||||
if (!autostartCheck(linkName) and !file.link(linkName)) {
|
||||
qWarning() << "link to autostart failed:" << file.errorString();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
QFileInfo info{linkName};
|
||||
if (!info.exists() or !info.isSymbolicLink()) {
|
||||
qWarning() << "same name desktop file exists:" << linkName << "but this may not created by AM.";
|
||||
return;
|
||||
}
|
||||
QFile linkFile{linkName};
|
||||
if (!linkFile.remove()) {
|
||||
qWarning() << "remove link failed:" << linkFile.errorString();
|
||||
return;
|
||||
if (autostartCheck(linkName)) {
|
||||
QFile linkFile{linkName};
|
||||
if (!linkFile.remove()) {
|
||||
qWarning() << "remove link failed:" << linkFile.errorString();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_AutoStart = autostart;
|
||||
}
|
||||
|
||||
QList<QDBusObjectPath> ApplicationService::instances() const noexcept
|
||||
|
@ -53,6 +53,10 @@ public:
|
||||
Q_PROPERTY(qulonglong LastLaunchedTime READ lastLaunchedTime)
|
||||
[[nodiscard]] qulonglong lastLaunchedTime() const noexcept;
|
||||
|
||||
// FIXME:
|
||||
// This property should implement with fuse guarded $XDG_CONFIG_HOME/autostart/.
|
||||
// Current implementation has some problems,
|
||||
// such as it will not emit changed signal.
|
||||
Q_PROPERTY(bool AutoStart READ isAutoStart WRITE setAutoStart)
|
||||
[[nodiscard]] bool isAutoStart() const noexcept;
|
||||
void setAutoStart(bool autostart) noexcept;
|
||||
@ -104,7 +108,6 @@ private:
|
||||
explicit ApplicationService(DesktopFile source, ApplicationManager1Service *parent);
|
||||
static QSharedPointer<ApplicationService> createApplicationService(DesktopFile source,
|
||||
ApplicationManager1Service *parent) noexcept;
|
||||
bool m_AutoStart{false};
|
||||
qlonglong m_lastLaunch{0};
|
||||
QDBusObjectPath m_applicationPath;
|
||||
QString m_launcher{getApplicationLauncherBinary()};
|
||||
@ -117,6 +120,7 @@ private:
|
||||
EntryValueType type,
|
||||
const QLocale &locale = getUserLocale()) const noexcept;
|
||||
static bool shouldBeShown(const std::unique_ptr<DesktopEntry> &entry) noexcept;
|
||||
static bool autostartCheck(const QString &linkPath) noexcept;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user