feat: support AutoStart

Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
ComixHe
2023-09-04 18:18:20 +08:00
committed by Comix
parent 30a03974f3
commit acba7b727e
3 changed files with 74 additions and 3 deletions

View File

@ -372,6 +372,32 @@ bool ApplicationService::isAutoStart() const noexcept
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)) {
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;
}
}
m_AutoStart = autostart;
}