refact: assuming all applications have been launched during AM create
storage at first time issue: https://github.com/linuxdeepin/developer-center/issues/5768 Signed-off-by: ComixHe <heyuming@deepin.org>
This commit is contained in:
parent
6bfbd63c01
commit
b75bb395fd
@ -36,6 +36,7 @@ ApplicationManager1Storage::createApplicationManager1Storage(const QString &stor
|
|||||||
auto content = obj->m_file->readAll();
|
auto content = obj->m_file->readAll();
|
||||||
if (content.isEmpty()) { // new file
|
if (content.isEmpty()) { // new file
|
||||||
obj->setVersion(STORAGE_VERSION);
|
obj->setVersion(STORAGE_VERSION);
|
||||||
|
obj->setFirstLaunch(true);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,8 +47,11 @@ ApplicationManager1Storage::createApplicationManager1Storage(const QString &stor
|
|||||||
if (err.error != QJsonParseError::NoError) {
|
if (err.error != QJsonParseError::NoError) {
|
||||||
qDebug() << "parse json failed:" << err.errorString() << "clear this file content.";
|
qDebug() << "parse json failed:" << err.errorString() << "clear this file content.";
|
||||||
obj->m_file->resize(0);
|
obj->m_file->resize(0);
|
||||||
|
obj->setVersion(STORAGE_VERSION);
|
||||||
|
obj->setFirstLaunch(true);
|
||||||
} else {
|
} else {
|
||||||
obj->m_data = json.object();
|
obj->m_data = json.object();
|
||||||
|
obj->setFirstLaunch(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
@ -95,6 +99,17 @@ uint8_t ApplicationManager1Storage::version() const noexcept
|
|||||||
return m_data["version"].toInt(-1);
|
return m_data["version"].toInt(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ApplicationManager1Storage::setFirstLaunch(bool first) noexcept
|
||||||
|
{
|
||||||
|
m_data["FirstLaunch"] = first;
|
||||||
|
return writeToFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool ApplicationManager1Storage::firstLaunch() const noexcept
|
||||||
|
{
|
||||||
|
return m_data["FirstLaunch"].toBool(true);
|
||||||
|
}
|
||||||
|
|
||||||
bool ApplicationManager1Storage::createApplicationValue(const QString &appId,
|
bool ApplicationManager1Storage::createApplicationValue(const QString &appId,
|
||||||
const QString &groupName,
|
const QString &groupName,
|
||||||
const QString &valueKey,
|
const QString &valueKey,
|
||||||
|
@ -38,6 +38,9 @@ public:
|
|||||||
bool setVersion(uint8_t version) noexcept;
|
bool setVersion(uint8_t version) noexcept;
|
||||||
[[nodiscard]] uint8_t version() const noexcept;
|
[[nodiscard]] uint8_t version() const noexcept;
|
||||||
|
|
||||||
|
bool setFirstLaunch(bool first) noexcept;
|
||||||
|
[[nodiscard]] bool firstLaunch() const noexcept;
|
||||||
|
|
||||||
static std::shared_ptr<ApplicationManager1Storage> createApplicationManager1Storage(const QString &storageDir) noexcept;
|
static std::shared_ptr<ApplicationManager1Storage> createApplicationManager1Storage(const QString &storageDir) noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -84,6 +84,9 @@ void ApplicationManager1Service::initService(QDBusConnection &connection) noexce
|
|||||||
|
|
||||||
scanInstances();
|
scanInstances();
|
||||||
|
|
||||||
|
auto storagePtr = m_storage.lock();
|
||||||
|
storagePtr->setFirstLaunch(false);
|
||||||
|
|
||||||
loadHooks();
|
loadHooks();
|
||||||
|
|
||||||
if (auto *ptr = new (std::nothrow) PropertiesForwarder{DDEApplicationManager1ObjectPath, this}; ptr == nullptr) {
|
if (auto *ptr = new (std::nothrow) PropertiesForwarder{DDEApplicationManager1ObjectPath, this}; ptr == nullptr) {
|
||||||
|
@ -47,14 +47,21 @@ ApplicationService::ApplicationService(DesktopFile source,
|
|||||||
|
|
||||||
auto appId = id();
|
auto appId = id();
|
||||||
auto value = storagePtr->readApplicationValue(appId, ApplicationPropertiesGroup, LastLaunchedTime);
|
auto value = storagePtr->readApplicationValue(appId, ApplicationPropertiesGroup, LastLaunchedTime);
|
||||||
if (value.isNull()) {
|
|
||||||
if (!storagePtr->createApplicationValue(
|
qint64 val{0};
|
||||||
appId, ApplicationPropertiesGroup, LastLaunchedTime, QVariant::fromValue<qint64>(0))) {
|
if (storagePtr->firstLaunch()) {
|
||||||
m_lastLaunch = -1;
|
val = QDateTime::currentMSecsSinceEpoch();
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
|
if (value.isNull()) {
|
||||||
|
if (!storagePtr->createApplicationValue(appId, ApplicationPropertiesGroup, LastLaunchedTime, QVariant::fromValue(val))) {
|
||||||
|
m_lastLaunch = -1;
|
||||||
|
} else {
|
||||||
|
m_lastLaunch = val;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
m_lastLaunch = value.toLongLong();
|
||||||
}
|
}
|
||||||
m_lastLaunch = value.toInt();
|
|
||||||
|
|
||||||
value = storagePtr->readApplicationValue(appId, ApplicationPropertiesGroup, ScaleFactor);
|
value = storagePtr->readApplicationValue(appId, ApplicationPropertiesGroup, ScaleFactor);
|
||||||
if (!value.isNull()) {
|
if (!value.isNull()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user