fix(app-database-service):数据库删除后重建失败,应用打开次数记录错误.
建数据库时缺少START_UP_WMCLAS字段导致所有数据写入失败,记录打开次数换成使用processmanager的信号来触发.
This commit is contained in:
parent
1bcf2922c0
commit
e18bb390a7
|
@ -25,6 +25,8 @@
|
|||
#include "appdatabaseadaptor.h"
|
||||
#include "file-utils.h"
|
||||
#include "application-property-helper.h"
|
||||
#include "app-db-manager.h"
|
||||
|
||||
|
||||
#define GENERAL_APP_DESKTOP_PATH "/usr/share/applications"
|
||||
#define ANDROID_APP_DESKTOP_PATH QDir::homePath() + "/.local/share/applications"
|
||||
|
@ -168,14 +170,24 @@ AppDBManager::AppDBManager(QObject *parent) : QThread(parent), m_database(QSqlDa
|
|||
}, Qt::DirectConnection);
|
||||
*/
|
||||
|
||||
//监控应用进程开启
|
||||
connect(KWindowSystem::self(), &KWindowSystem::windowAdded, [ = ](WId id) {
|
||||
QDBusVariant dbusVariant(id);
|
||||
QString desktopFilePath = this->tranWinIdToDesktopFilePath(dbusVariant);
|
||||
if (!desktopFilePath.isEmpty()) {
|
||||
this->updateLaunchTimes(desktopFilePath);
|
||||
m_processManagerInterface = new QDBusInterface(QStringLiteral("com.kylin.ProcessManager"),
|
||||
QStringLiteral("/com/kylin/ProcessManager/AppLauncher"),
|
||||
QStringLiteral("com.kylin.ProcessManager.AppLauncher"),
|
||||
QDBusConnection::sessionBus(), this);
|
||||
if (!m_processManagerInterface->isValid()) {
|
||||
qWarning() << qPrintable(QDBusConnection::sessionBus().lastError().message());
|
||||
} else {
|
||||
connect(m_processManagerInterface, SIGNAL(AppLaunched(QString)), this, SLOT(handleAppLaunched(QString)));
|
||||
}
|
||||
});
|
||||
|
||||
//监控应用进程开启
|
||||
// connect(KWindowSystem::self(), &KWindowSystem::windowAdded, [ = ](WId id) {
|
||||
// QDBusVariant dbusVariant(id);
|
||||
// QString desktopFilePath = this->tranWinIdToDesktopFilePath(dbusVariant);
|
||||
// if (!desktopFilePath.isEmpty()) {
|
||||
// this->updateLaunchTimes(desktopFilePath);
|
||||
// }
|
||||
// });
|
||||
new AppDBManagerAdaptor(this);
|
||||
} else {
|
||||
qDebug() << "App-db-manager does nothing.";
|
||||
|
@ -187,12 +199,12 @@ AppDBManager::~AppDBManager()
|
|||
if (m_watcher) {
|
||||
delete m_watcher;
|
||||
}
|
||||
m_watcher = NULL;
|
||||
m_watcher = nullptr;
|
||||
|
||||
if (m_snapdWatcher) {
|
||||
delete m_snapdWatcher;
|
||||
}
|
||||
m_snapdWatcher = NULL;
|
||||
m_snapdWatcher = nullptr;
|
||||
|
||||
// if(m_watchAppDir) {
|
||||
// delete m_watchAppDir;
|
||||
|
@ -205,7 +217,7 @@ void AppDBManager::buildAppInfoDB()
|
|||
{
|
||||
qDebug() << "I'm going to build app info database.";
|
||||
QSqlQuery sql(m_database);
|
||||
QString cmd = QString("CREATE TABLE IF NOT EXISTS appInfo(%1, %2, %3, %4, %5, %6, %7, %8,%9, %10, %11, %12, %13, %14, %15, %16, %17, %18, %19, %20, %21, %22)")
|
||||
QString cmd = QString("CREATE TABLE IF NOT EXISTS appInfo(%1, %2, %3, %4, %5, %6, %7, %8,%9, %10, %11, %12, %13, %14, %15, %16, %17, %18, %19, %20, %21, %22, %23)")
|
||||
// .arg("ID INT")//自增id
|
||||
.arg("DESKTOP_FILE_PATH TEXT PRIMARY KEY NOT NULL")//desktop文件路径
|
||||
.arg("MODIFYED_TIME TEXT")//YYYYMMDDHHmmSS 修改日期
|
||||
|
@ -228,7 +240,8 @@ void AppDBManager::buildAppInfoDB()
|
|||
.arg("TOP INT")//置顶顺序 0:未置顶;>0的数字表示置顶顺序
|
||||
.arg("LOCK INT")//应用是否锁定(管控),0未锁定,1锁定
|
||||
.arg("DONT_DISPLAY INT")//应用隐藏(NoDisplay, NotShowIn)
|
||||
.arg("AUTO_START INT");//自启应用
|
||||
.arg("AUTO_START INT")//自启应用
|
||||
.arg("START_UP_WMCLASS TEXT");//classname
|
||||
if (!sql.exec(cmd)) {
|
||||
qWarning() << m_database.lastError() << cmd;
|
||||
return;
|
||||
|
@ -1311,7 +1324,7 @@ void AppDBManager::handleDataBaseRefresh(const QStringList &appPaths, bool dbVer
|
|||
this->loadDesktopFilePaths(path, infos);
|
||||
}
|
||||
|
||||
if(infos.size() < 1) {
|
||||
if(infos.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
XdgDesktopFile desktopfile;
|
||||
|
@ -1329,7 +1342,7 @@ void AppDBManager::handleDataBaseRefresh(const QStringList &appPaths, bool dbVer
|
|||
}
|
||||
|
||||
desktopfile.load(path);
|
||||
//排除loaclized名字为空
|
||||
//排除localized名字为空
|
||||
if (desktopfile.localizedValue("Name").toString().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1379,8 +1392,8 @@ bool AppDBManager::handleValueSet(const ApplicationInfoMap appInfoMap)
|
|||
QSqlQuery query(m_database);
|
||||
|
||||
for (auto iter = appInfoMap.constBegin(); iter != appInfoMap.constEnd(); iter++) {
|
||||
QString desktopFilePath = iter.key();
|
||||
ApplicationPropertyMap propMap = iter.value();
|
||||
const QString& desktopFilePath = iter.key();
|
||||
const ApplicationPropertyMap& propMap = iter.value();
|
||||
for (auto propIter = propMap.constBegin(); propIter != propMap.constEnd(); ++propIter) {
|
||||
QString field = ApplicationPropertyHelper(propIter.key()).dataBaseField();
|
||||
|
||||
|
@ -1643,3 +1656,11 @@ void AppDBManager::setValue(const ApplicationInfoMap &infos2BSet)
|
|||
PendingAppInfoQueue::getAppInfoQueue().enqueue(item);
|
||||
}
|
||||
}
|
||||
|
||||
void AppDBManager::handleAppLaunched(QString desktopFilePath) {
|
||||
if (!desktopFilePath.isEmpty()) {
|
||||
this->updateLaunchTimes(desktopFilePath);
|
||||
} else {
|
||||
qWarning() << "desktopFilePath is empty.";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <QMutex>
|
||||
#include <QSettings>
|
||||
#include <QThread>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusVariant>
|
||||
#include "pending-app-info-queue.h"
|
||||
#include "file-system-watcher.h"
|
||||
|
@ -105,6 +106,9 @@ public Q_SLOTS:
|
|||
|
||||
void setValue(const ApplicationInfoMap &infos2BSet);
|
||||
|
||||
private Q_SLOTS:
|
||||
void handleAppLaunched(QString desktopFilePath);
|
||||
|
||||
protected:
|
||||
void run() override;
|
||||
|
||||
|
@ -143,6 +147,8 @@ private:
|
|||
QSettings *m_lastLocaleNameQsettings = nullptr;
|
||||
QSettings *m_dbVersionQsettings = nullptr;
|
||||
|
||||
QDBusInterface *m_processManagerInterface = nullptr;
|
||||
|
||||
// QTimer *m_timer = nullptr;
|
||||
// QTimer *m_maxProcessTimer = nullptr;
|
||||
// QFileSystemWatcher *m_watchAppDir = nullptr;
|
||||
|
|
Loading…
Reference in New Issue