feat: 修复启动器获取新安装应用数据异常的问题

修复启动器获取新安装应用数据异常的问题

Log:
Task: https://pms.uniontech.com/task-view-143305.html
Influence: 启动器正常获取新安装应用
Change-Id: I556b6725348813cc1674f00273cb9e34f96283a2
This commit is contained in:
weizhixiang 2022-06-06 11:55:16 +08:00
parent 765365d364
commit a74c02d4c5
4 changed files with 16 additions and 15 deletions

View File

@ -77,25 +77,22 @@ void AlRecorder::markLaunched(const QString &filePath)
QFileInfo info;
QMutexLocker locker(&mutex);
for (auto sri = subRecoders.begin(); sri != subRecoders.end(); sri++) {
if (!filePath.contains(sri.key()))
if (!filePath.startsWith(sri.key()))
continue;
info.setFile(filePath);
QString name = info.baseName();
for (auto li = sri.value().launchedMap.begin(); li != sri.value().launchedMap.end(); li++) {
// 查找同名且未启动过的应用
if (li.key() == name && !li.value()) {
li.value() = true;
goto end;
Q_EMIT launched(filePath);
// 记录启动状态
saveStatusFile(info.absolutePath() + "/");
}
}
}
// 根据filePath匹配到唯一应用
end:
if (info.isDir()) {
saveStatusFile(info.absolutePath() + "/");
Q_EMIT launched(filePath);
}
}
/**
@ -154,7 +151,7 @@ void AlRecorder::initSubRecoder(const QString &dirPath)
// 读取App状态记录
QMap<QString, bool> launchedApp;
QFile file(statusFile);
if (file.open(QIODevice::ReadWrite | QIODevice::Text)) {
if (file.exists() && file.open(QIODevice::ReadWrite | QIODevice::Text)) {
while (!file.atEnd()){
QString line(file.readLine());
QStringList strs = line.split(",");
@ -166,6 +163,7 @@ void AlRecorder::initSubRecoder(const QString &dirPath)
else
launchedApp[strs[0]] = false;
}
file.close();
} else {
// 读取app desktop

View File

@ -28,13 +28,14 @@
class DFWatcher;
// 记录应用状态信息
// 记录当前用户应用状态信息
class AlRecorder: public QObject
{
Q_OBJECT
Q_CLASSINFO("D-Bus Interface", "org.deepin.daemon.AlRecorder1")
public:
// 各个应用目录中应用的启动记录
struct subRecorder {
QString statusFile; // 应用目录状态文件
QMap<QString, bool> launchedMap; // 应用启动记录

View File

@ -3,7 +3,6 @@
DBusAdaptorRecorder::DBusAdaptorRecorder(QObject *parent)
: QDBusAbstractAdaptor(parent)
{
// constructor
setAutoRelaySignals(true);
if (QMetaType::type("UnlaunchedAppMap") == QMetaType::UnknownType)
registerUnLaunchedAppMapMetaType();
@ -18,7 +17,6 @@ DBusAdaptorRecorder::DBusAdaptorRecorder(QObject *parent)
DBusAdaptorRecorder::~DBusAdaptorRecorder()
{
// destructor
}
AlRecorder *DBusAdaptorRecorder::parent() const

View File

@ -178,8 +178,12 @@ QStringList Launcher::getAllNewInstalledApps()
newApps = reply;
for (auto iter = newApps.begin(); iter != newApps.end(); iter++) {
if (iter.value().size() > 0) {
ret << iter.value();
for (QString name : iter.value()) {
QString path = iter.key() + name + ".desktop";
Item item = getItemByPath(path);
if (item.isValid()) {
ret << item.info.id;
}
}
}
return ret;