refact: improve scanAutoStart
improve scanAutoStart
This commit is contained in:
parent
7d0c5bb615
commit
4ff60db556
@ -53,23 +53,24 @@ ApplicationManager1Service::ApplicationManager1Service(std::unique_ptr<Identifie
|
|||||||
|
|
||||||
scanInstances();
|
scanInstances();
|
||||||
|
|
||||||
|
// TODO: This is a workaround, we will use database at the end.
|
||||||
auto runtimePath = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
|
auto runtimePath = QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation);
|
||||||
if (runtimePath.isEmpty()) {
|
if (runtimePath.isEmpty()) {
|
||||||
runtimePath = QString{"/run/user/%1"}.arg(getCurrentUID());
|
runtimePath = QString{"/run/user/%1/"}.arg(getCurrentUID());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool firstStart{false};
|
|
||||||
QDir runtimeDir{runtimePath};
|
QDir runtimeDir{runtimePath};
|
||||||
if (!runtimeDir.exists("ApplicationManager")) {
|
auto filename = "deepin-application-manager";
|
||||||
QFile flag{runtimeDir.filePath("ApplicationManager")};
|
if (runtimeDir.exists(filename)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QFile flag{runtimeDir.filePath(filename)};
|
||||||
if (!flag.open(QFile::WriteOnly | QFile::NewOnly)) {
|
if (!flag.open(QFile::WriteOnly | QFile::NewOnly)) {
|
||||||
qWarning() << "create record file failed.";
|
qWarning() << "create record file failed.";
|
||||||
} else {
|
|
||||||
firstStart = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
scanAutoStart(firstStart);
|
scanAutoStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationManager1Service::addInstanceToApplication(const QString &unitName, const QDBusObjectPath &systemdUnitPath)
|
void ApplicationManager1Service::addInstanceToApplication(const QString &unitName, const QDBusObjectPath &systemdUnitPath)
|
||||||
@ -177,12 +178,8 @@ void ApplicationManager1Service::scanInstances() noexcept
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplicationManager1Service::scanAutoStart(bool firstStart) noexcept
|
void ApplicationManager1Service::scanAutoStart() noexcept
|
||||||
{
|
{
|
||||||
if (!firstStart) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto autostartDirs = getAutoStartDirs();
|
auto autostartDirs = getAutoStartDirs();
|
||||||
QStringList needToLaunch;
|
QStringList needToLaunch;
|
||||||
applyIteratively(QList<QDir>{autostartDirs.cbegin(), autostartDirs.cend()}, [&needToLaunch](const QFileInfo &info) {
|
applyIteratively(QList<QDir>{autostartDirs.cbegin(), autostartDirs.cend()}, [&needToLaunch](const QFileInfo &info) {
|
||||||
|
@ -56,7 +56,7 @@ private:
|
|||||||
|
|
||||||
void scanApplications() noexcept;
|
void scanApplications() noexcept;
|
||||||
void scanInstances() noexcept;
|
void scanInstances() noexcept;
|
||||||
void scanAutoStart(bool firstStart) noexcept;
|
void scanAutoStart() noexcept;
|
||||||
void addInstanceToApplication(const QString &unitName, const QDBusObjectPath &systemdUnitPath);
|
void addInstanceToApplication(const QString &unitName, const QDBusObjectPath &systemdUnitPath);
|
||||||
void removeInstanceFromApplication(const QString &unitName, const QDBusObjectPath &systemdUnitPath);
|
void removeInstanceFromApplication(const QString &unitName, const QDBusObjectPath &systemdUnitPath);
|
||||||
};
|
};
|
||||||
|
@ -395,6 +395,8 @@ inline QStringList getAutoStartDirs()
|
|||||||
XDGConfigDirs.append("/etc/xdg");
|
XDGConfigDirs.append("/etc/xdg");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: What if XDG_CONFIG_HOME already in XDG_CONFIG_DIRS?
|
||||||
|
|
||||||
auto XDGConfigHome = QString::fromLocal8Bit(qgetenv("XDG_CONFIG_HOME"));
|
auto XDGConfigHome = QString::fromLocal8Bit(qgetenv("XDG_CONFIG_HOME"));
|
||||||
if (XDGConfigHome.isEmpty()) {
|
if (XDGConfigHome.isEmpty()) {
|
||||||
XDGConfigHome = QString::fromLocal8Bit(qgetenv("HOME")) + QDir::separator() + ".config";
|
XDGConfigHome = QString::fromLocal8Bit(qgetenv("HOME")) + QDir::separator() + ".config";
|
||||||
|
Loading…
Reference in New Issue
Block a user