添加对预装应用的识别功能,重装不显示蓝点
This commit is contained in:
parent
d28fbb0487
commit
b2fc1ad387
|
@ -20,7 +20,17 @@
|
|||
|
||||
#include <application-info.h>
|
||||
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QDebug>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonObject>
|
||||
|
||||
#define APP_ICON_PREFIX "image://appicon/"
|
||||
#define MENU_CONFIG_FILE_PATH ".config/ukui-menu/"
|
||||
#define MENU_CONFIG_FILE_NAME "config.json"
|
||||
|
||||
|
||||
namespace UkuiMenu {
|
||||
|
||||
|
@ -51,6 +61,8 @@ public Q_SLOTS:
|
|||
void setAppLaunched(const QString &path);
|
||||
|
||||
private:
|
||||
void loadPreInstallAppData();
|
||||
void removePreInstallAppData(const QStringList &infos);
|
||||
void updateFavoriteApps();
|
||||
void removeApps(QStringList& appIdList, QStringList &removedIdList);
|
||||
void updateApps(const UkuiSearch::ApplicationInfoMap &infos, QList<DataEntity> &apps);
|
||||
|
@ -59,6 +71,7 @@ private:
|
|||
void addInfoToApp(const UkuiSearch::ApplicationPropertyMap &info, DataEntity &app);
|
||||
|
||||
private:
|
||||
QMutex m_mutex;
|
||||
AppDataManager *m_appManager{nullptr};
|
||||
UkuiSearch::ApplicationInfo *m_applicationInfo{nullptr};
|
||||
UkuiSearch::ApplicationProperties m_appProperties;
|
||||
|
@ -75,6 +88,7 @@ AppDataWorker::AppDataWorker(AppDataManager *appManager) : QObject(nullptr), m_a
|
|||
}
|
||||
|
||||
initAppData();
|
||||
loadPreInstallAppData();
|
||||
|
||||
connect(m_applicationInfo, &UkuiSearch::ApplicationInfo::appDBItems2BAdd, this, &AppDataWorker::onAppAdded);
|
||||
connect(m_applicationInfo, &UkuiSearch::ApplicationInfo::appDBItems2BUpdate, this, &AppDataWorker::onAppUpdated);
|
||||
|
@ -296,6 +310,8 @@ void AppDataWorker::onAppDeleted(QStringList infos)
|
|||
Q_EMIT appDeleted(removedIdList);
|
||||
|
||||
updateFavoriteApps();
|
||||
|
||||
removePreInstallAppData(infos);
|
||||
}
|
||||
|
||||
void AppDataWorker::fixToFavoriteSlot(const QString &path, const int &num)
|
||||
|
@ -326,6 +342,115 @@ void AppDataWorker::setAppLaunched(const QString &path)
|
|||
m_applicationInfo->setAppLaunchedState(path);
|
||||
}
|
||||
|
||||
void AppDataWorker::loadPreInstallAppData()
|
||||
{
|
||||
QString configpath = QDir::homePath() + "/" + MENU_CONFIG_FILE_PATH + MENU_CONFIG_FILE_NAME;
|
||||
if (!QFile::exists(configpath)) {
|
||||
QDir dir;
|
||||
QString menuConfigDir(QDir::homePath() + "/" + MENU_CONFIG_FILE_PATH);
|
||||
|
||||
if (!dir.exists(menuConfigDir)) {
|
||||
if (!dir.mkdir(menuConfigDir)) {
|
||||
qWarning() << "Unable to create profile menu config.";
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QFile file(configpath);
|
||||
|
||||
if (!file.open(QFile::WriteOnly)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonDocument jsonDocument;
|
||||
QJsonArray jsonArray;
|
||||
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
QJsonObject object;
|
||||
QJsonArray apps;
|
||||
for (auto &app : m_appManager->m_normalApps) {
|
||||
apps.append(app.id());
|
||||
m_appManager->m_preInstallAppData.insert(app.id());
|
||||
}
|
||||
object.insert("preInstall", apps);
|
||||
jsonArray.append(object);
|
||||
}
|
||||
|
||||
jsonDocument.setArray(jsonArray);
|
||||
if (file.write(jsonDocument.toJson()) == -1) {
|
||||
qWarning() << "Error saving configuration file.";
|
||||
}
|
||||
file.flush();
|
||||
file.close();
|
||||
return;
|
||||
}
|
||||
|
||||
QFile file(configpath);
|
||||
if (!file.open(QFile::ReadOnly)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QByteArray byteArray = file.readAll();
|
||||
file.close();
|
||||
|
||||
QJsonDocument jsonDocument(QJsonDocument::fromJson(byteArray));
|
||||
if (jsonDocument.isNull() || jsonDocument.isEmpty() || !jsonDocument.isArray()) {
|
||||
qWarning() << "AppDataManager: Incorrect configuration files are ignored.";
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
m_appManager->m_preInstallAppData.clear();
|
||||
}
|
||||
|
||||
QJsonArray jsonArray = jsonDocument.array();
|
||||
for (const auto &value : jsonArray) {
|
||||
QJsonObject object = value.toObject();
|
||||
if (object.contains("preInstall")) {
|
||||
QJsonArray apps = object.value(QLatin1String("preInstall")).toArray();
|
||||
for (const auto &app : apps) {
|
||||
m_appManager->m_preInstallAppData.insert(app.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AppDataWorker::removePreInstallAppData(const QStringList &infos)
|
||||
{
|
||||
for (const auto &info : infos) {
|
||||
if (m_appManager->isPreInstalled(info))
|
||||
m_appManager->m_preInstallAppData.remove(info);
|
||||
}
|
||||
QFile file(QDir::homePath() + "/" + MENU_CONFIG_FILE_PATH + MENU_CONFIG_FILE_NAME);
|
||||
|
||||
if (!file.open(QFile::WriteOnly|QFile::Truncate)) {
|
||||
return;
|
||||
}
|
||||
|
||||
QJsonDocument jsonDocument;
|
||||
QJsonArray jsonArray;
|
||||
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
QJsonObject object;
|
||||
QJsonArray apps;
|
||||
for (auto &app : m_appManager->m_preInstallAppData) {
|
||||
apps.append(app);
|
||||
}
|
||||
object.insert("preInstall", apps);
|
||||
jsonArray.append(object);
|
||||
}
|
||||
|
||||
jsonDocument.setArray(jsonArray);
|
||||
if (file.write(jsonDocument.toJson()) == -1) {
|
||||
qWarning() << "Error saving configuration file.";
|
||||
}
|
||||
file.flush();
|
||||
file.close();
|
||||
}
|
||||
|
||||
void AppDataWorker::removeApps(QStringList &appIdList, QStringList &removedIdList)
|
||||
{
|
||||
QMutexLocker locker(&m_appManager->m_mutex);
|
||||
|
@ -374,6 +499,11 @@ QList<DataEntity> AppDataManager::normalApps()
|
|||
return m_normalApps.values();
|
||||
}
|
||||
|
||||
bool AppDataManager::isPreInstalled(const QString &id)
|
||||
{
|
||||
return m_preInstallAppData.contains(id);
|
||||
}
|
||||
|
||||
QVector<DataEntity> AppDataManager::favoriteApps()
|
||||
{
|
||||
QMutexLocker locker(&m_mutex);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <QMutexLocker>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QSet>
|
||||
|
||||
#include "commons.h"
|
||||
|
||||
|
@ -47,6 +48,7 @@ public:
|
|||
|
||||
bool getApp(const QString &appId, DataEntity &app);
|
||||
QList<DataEntity> normalApps();
|
||||
bool isPreInstalled(const QString &id);
|
||||
QVector<DataEntity> favoriteApps();
|
||||
|
||||
Q_SIGNALS:
|
||||
|
@ -67,6 +69,7 @@ private:
|
|||
QMutex m_mutex;
|
||||
QThread m_workerThread;
|
||||
QMap <QString, DataEntity> m_normalApps;
|
||||
QSet<QString> m_preInstallAppData;
|
||||
QVector<DataEntity> m_favoriteApps;
|
||||
};
|
||||
|
||||
|
|
|
@ -184,13 +184,15 @@ bool AllAppDataProvider::appDataSort(const DataEntity &a, const DataEntity &b)
|
|||
|
||||
void AllAppDataProvider::setRecentState(DataEntity &app)
|
||||
{
|
||||
if (app.launched() == 0) {
|
||||
QDateTime installTime = QDateTime::fromString(app.insertTime(), "yyyy-MM-dd hh:mm:ss");
|
||||
if (installTime.isValid()) {
|
||||
int appTime = installTime.secsTo(QDateTime::currentDateTime());
|
||||
if ((appTime >= 0 ) && (appTime <= 3600*48)) {
|
||||
app.setRecentInstall(true);
|
||||
return;
|
||||
if (!AppDataManager::instance()->isPreInstalled(app.id())) {
|
||||
if (app.launched() == 0) {
|
||||
QDateTime installTime = QDateTime::fromString(app.insertTime(), "yyyy-MM-dd hh:mm:ss");
|
||||
if (installTime.isValid()) {
|
||||
int appTime = installTime.secsTo(QDateTime::currentDateTime());
|
||||
if ((appTime >= 0 ) && (appTime <= 3600*48)) {
|
||||
app.setRecentInstall(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue