feat: 修改自启动应用启动方式
*修改自启动应用启动方式, 采用loader进程先校验应用信息,再拉起应用的方式 *修复launcher模块部分接口导出失败的问题 *增加launcher、dock、loader模块代码注释 Log: 修改自启动应用启动方式 Task: https://pms.uniontech.com/task-view-131611.html Influence: 应用启动方式不同 Change-Id: Ie88027602d1395c6bbad69e610f3639ecc7dfbc1
This commit is contained in:
@ -35,30 +35,19 @@ AlRecorder::AlRecorder(DFWatcher *_watcher, QObject *parent)
|
||||
, watcher(_watcher)
|
||||
, mutex(QMutex(QMutex::NonRecursive))
|
||||
{
|
||||
QDBusConnection con = QDBusConnection::sessionBus();
|
||||
if (!con.registerService("org.deepin.daemon.AlRecorder1"))
|
||||
{
|
||||
qWarning() << "register service AlRecorder1 error:" << con.lastError().message();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!con.registerObject("/org/deepin/daemon/AlRecorder1", this, QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals))
|
||||
{
|
||||
qWarning() << "register object AlRecorder1 error:" << con.lastError().message();
|
||||
return;
|
||||
}
|
||||
|
||||
connect(watcher, &DFWatcher::Event, this, &AlRecorder::onDFChanged, Qt::QueuedConnection);
|
||||
Q_EMIT ServiceRestarted();
|
||||
Q_EMIT serviceRestarted();
|
||||
}
|
||||
|
||||
AlRecorder::~AlRecorder()
|
||||
{
|
||||
QDBusConnection::sessionBus().unregisterObject("/org/deepin/daemon/AlRecorder1");
|
||||
}
|
||||
|
||||
// 获取未启动应用列表
|
||||
QMap<QString, QStringList> AlRecorder::GetNew()
|
||||
/**
|
||||
* @brief AlRecorder::getNew 获取未启动应用列表
|
||||
* @return
|
||||
*/
|
||||
QMap<QString, QStringList> AlRecorder::getNew()
|
||||
{
|
||||
QMap<QString, QStringList> ret;
|
||||
QMutexLocker locker(&mutex);
|
||||
@ -76,8 +65,11 @@ QMap<QString, QStringList> AlRecorder::GetNew()
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 标记应用已启动状态
|
||||
void AlRecorder::MarkLaunched(const QString &filePath)
|
||||
/**
|
||||
* @brief AlRecorder::markLaunched 标记应用已启动状态
|
||||
* @param filePath
|
||||
*/
|
||||
void AlRecorder::markLaunched(const QString &filePath)
|
||||
{
|
||||
if (!filePath.endsWith(".desktop"))
|
||||
return;
|
||||
@ -102,12 +94,15 @@ void AlRecorder::MarkLaunched(const QString &filePath)
|
||||
end:
|
||||
if (info.isDir()) {
|
||||
saveStatusFile(info.absolutePath() + "/");
|
||||
Q_EMIT Launched(filePath);
|
||||
Q_EMIT launched(filePath);
|
||||
}
|
||||
}
|
||||
|
||||
// 记录Launcher服务卸载应用信息, 终端卸载不会调用该函数, desktopFiles为绝对路径
|
||||
void AlRecorder::UninstallHints(const QStringList &desktopFiles)
|
||||
/**
|
||||
* @brief AlRecorder::uninstallHints 记录Launcher服务卸载应用信息, 终端卸载不会调用该函数, desktopFiles为绝对路径
|
||||
* @param desktopFiles
|
||||
*/
|
||||
void AlRecorder::uninstallHints(const QStringList &desktopFiles)
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
for (auto desktop : desktopFiles) {
|
||||
@ -121,8 +116,11 @@ void AlRecorder::UninstallHints(const QStringList &desktopFiles)
|
||||
}
|
||||
}
|
||||
|
||||
// 监控目录
|
||||
void AlRecorder::WatchDirs(const QStringList &dataDirs)
|
||||
/**
|
||||
* @brief AlRecorder::watchDirs 监控目录
|
||||
* @param dataDirs
|
||||
*/
|
||||
void AlRecorder::watchDirs(const QStringList &dataDirs)
|
||||
{
|
||||
for (auto dirPath : dataDirs) {
|
||||
if (subRecoders.contains(dirPath))
|
||||
@ -143,7 +141,10 @@ void AlRecorder::WatchDirs(const QStringList &dataDirs)
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化应用目录记录
|
||||
/**
|
||||
* @brief AlRecorder::initSubRecoder 初始化应用目录记录
|
||||
* @param dirPath
|
||||
*/
|
||||
void AlRecorder::initSubRecoder(const QString &dirPath)
|
||||
{
|
||||
subRecorder sub;
|
||||
@ -191,6 +192,11 @@ void AlRecorder::initSubRecoder(const QString &dirPath)
|
||||
subRecoders[dirPath] = sub;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AlRecorder::onDFChanged 处理desktopFile文件改变事件
|
||||
* @param filePath
|
||||
* @param op
|
||||
*/
|
||||
void AlRecorder::onDFChanged(const QString &filePath, uint32_t op)
|
||||
{
|
||||
QFileInfo info(filePath);
|
||||
@ -232,6 +238,10 @@ void AlRecorder::onDFChanged(const QString &filePath, uint32_t op)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief AlRecorder::saveStatusFile 保存状态文件
|
||||
* @param dirPath
|
||||
*/
|
||||
void AlRecorder::saveStatusFile(const QString &dirPath)
|
||||
{
|
||||
subRecorder sub = subRecoders[dirPath];
|
||||
@ -252,6 +262,6 @@ void AlRecorder::saveStatusFile(const QString &dirPath)
|
||||
// 覆盖原文件
|
||||
QFile::remove(sub.statusFile);
|
||||
QFile::rename(tmpFile, sub.statusFile);
|
||||
Q_EMIT StatusSaved(dirPath, sub.statusFile, ok);
|
||||
Q_EMIT statusSaved(dirPath, sub.statusFile, ok);
|
||||
}
|
||||
|
||||
|
@ -46,18 +46,18 @@ public:
|
||||
~AlRecorder();
|
||||
|
||||
Q_SIGNALS:
|
||||
void Launched(const QString &file);
|
||||
void StatusSaved(const QString &root, const QString &file, bool ok);
|
||||
void ServiceRestarted();
|
||||
void launched(const QString &file);
|
||||
void statusSaved(const QString &root, const QString &file, bool ok);
|
||||
void serviceRestarted();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onDFChanged(const QString &filePath, uint32_t op);
|
||||
|
||||
public Q_SLOTS:
|
||||
QMap<QString, QStringList> GetNew();
|
||||
void MarkLaunched(const QString &filePath);
|
||||
void UninstallHints(const QStringList &desktopFiles);
|
||||
void WatchDirs(const QStringList &dataDirs);
|
||||
QMap<QString, QStringList> getNew();
|
||||
void markLaunched(const QString &filePath);
|
||||
void uninstallHints(const QStringList &desktopFiles);
|
||||
void watchDirs(const QStringList &dataDirs);
|
||||
|
||||
private:
|
||||
void initSubRecoder(const QString &dirPath);
|
||||
|
@ -23,6 +23,7 @@
|
||||
#include "dfwatcher.h"
|
||||
#include "alrecorder.h"
|
||||
#include "basedir.h"
|
||||
#include "dbusalrecorderadaptor.h"
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
@ -32,12 +33,27 @@ AppManager::AppManager(QObject *parent)
|
||||
, watcher(new DFWatcher(this))
|
||||
, recorder(new AlRecorder(watcher, this))
|
||||
{
|
||||
new DBusAdaptorRecorder(recorder);
|
||||
QDBusConnection con = QDBusConnection::sessionBus();
|
||||
if (!con.registerService("org.deepin.daemon.AlRecorder1"))
|
||||
{
|
||||
qWarning() << "register service AlRecorder1 error:" << con.lastError().message();
|
||||
return;
|
||||
}
|
||||
|
||||
if (!con.registerObject("/org/deepin/daemon/AlRecorder1", recorder))
|
||||
{
|
||||
qWarning() << "register object AlRecorder1 error:" << con.lastError().message();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
QStringList dataDirs;
|
||||
dataDirs << BaseDir::userAppDir().c_str();
|
||||
for (auto &dir : BaseDir::sysAppDirs())
|
||||
dataDirs << dir.c_str();
|
||||
|
||||
recorder->WatchDirs(dataDirs); // 监控应用desktop
|
||||
recorder->watchDirs(dataDirs); // 监控应用desktop
|
||||
}
|
||||
|
||||
AppManager::~AppManager()
|
||||
|
48
src/modules/apps/dbusalrecorderadaptor.cpp
Normal file
48
src/modules/apps/dbusalrecorderadaptor.cpp
Normal file
@ -0,0 +1,48 @@
|
||||
#include "dbusalrecorderadaptor.h"
|
||||
|
||||
DBusAdaptorRecorder::DBusAdaptorRecorder(QObject *parent)
|
||||
: QDBusAbstractAdaptor(parent)
|
||||
{
|
||||
// constructor
|
||||
setAutoRelaySignals(true);
|
||||
if (QMetaType::type("UnlaunchedAppMap") == QMetaType::UnknownType)
|
||||
registerUnLaunchedAppMapMetaType();
|
||||
|
||||
AlRecorder *recorder = static_cast<AlRecorder *>(QObject::parent());
|
||||
if (recorder) {
|
||||
connect(recorder, &AlRecorder::launched, this, &DBusAdaptorRecorder::Launched);
|
||||
connect(recorder, &AlRecorder::serviceRestarted, this, &DBusAdaptorRecorder::ServiceRestarted);
|
||||
connect(recorder, &AlRecorder::statusSaved, this, &DBusAdaptorRecorder::StatusSaved);
|
||||
}
|
||||
}
|
||||
|
||||
DBusAdaptorRecorder::~DBusAdaptorRecorder()
|
||||
{
|
||||
// destructor
|
||||
}
|
||||
|
||||
AlRecorder *DBusAdaptorRecorder::parent() const
|
||||
{
|
||||
return static_cast<AlRecorder *>(QObject::parent());
|
||||
}
|
||||
|
||||
UnLaunchedAppMap DBusAdaptorRecorder::GetNew()
|
||||
{
|
||||
return parent()->getNew();
|
||||
}
|
||||
|
||||
void DBusAdaptorRecorder::MarkLaunched(const QString &desktopFile)
|
||||
{
|
||||
parent()->markLaunched(desktopFile);
|
||||
}
|
||||
|
||||
void DBusAdaptorRecorder::UninstallHints(const QStringList &desktopFiles)
|
||||
{
|
||||
parent()->uninstallHints(desktopFiles);
|
||||
}
|
||||
|
||||
void DBusAdaptorRecorder::WatchDirs(const QStringList &dirs)
|
||||
{
|
||||
parent()->watchDirs(dirs);
|
||||
}
|
||||
|
67
src/modules/apps/dbusalrecorderadaptor.h
Normal file
67
src/modules/apps/dbusalrecorderadaptor.h
Normal file
@ -0,0 +1,67 @@
|
||||
#ifndef DBUSALRECORDERADAPTOR_H
|
||||
#define DBUSALRECORDERADAPTOR_H
|
||||
|
||||
#include "alrecorder.h"
|
||||
#include "unlaunchedappmap.h"
|
||||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QMetaObject>
|
||||
#include <QtCore/QVariant>
|
||||
#include <QtDBus/QtDBus>
|
||||
#include <QtCore/QByteArray>
|
||||
#include <QtCore/QList>
|
||||
#include <QtCore/QMap>
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QVariant>
|
||||
|
||||
class DBusAdaptorRecorder: public QDBusAbstractAdaptor
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_CLASSINFO("D-Bus Interface", "org.deepin.daemon.AlRecorder1")
|
||||
Q_CLASSINFO("D-Bus Introspection", ""
|
||||
" <interface name=\"org.deepin.daemon.AlRecorder1\">\n"
|
||||
" <method name=\"GetNew\">\n"
|
||||
" <arg direction=\"out\" type=\"a{sas}\" name=\"newApps\"/>\n"
|
||||
" <annotation value=\"UnLaunchedAppMap\" name=\"org.qtproject.QtDBus.QtTypeName.Out0\"/>\n"
|
||||
" </method>\n"
|
||||
" <method name=\"MarkLaunched\">\n"
|
||||
" <arg direction=\"in\" type=\"s\" name=\"desktopFile\"/>\n"
|
||||
" </method>\n"
|
||||
" <method name=\"UninstallHints\">\n"
|
||||
" <arg direction=\"in\" type=\"as\" name=\"desktopFiles\"/>\n"
|
||||
" </method>\n"
|
||||
" <method name=\"WatchDirs\">\n"
|
||||
" <arg direction=\"in\" type=\"as\" name=\"dirs\"/>\n"
|
||||
" </method>\n"
|
||||
" <signal name=\"Launched\">\n"
|
||||
" <arg type=\"s\" name=\"file\"/>\n"
|
||||
" </signal>\n"
|
||||
" <signal name=\"StatusSaved\">\n"
|
||||
" <arg type=\"s\" name=\"root\"/>\n"
|
||||
" <arg type=\"s\" name=\"file\"/>\n"
|
||||
" <arg type=\"b\" name=\"ok\"/>\n"
|
||||
" </signal>\n"
|
||||
" <signal name=\"ServiceRestarted\"/>\n"
|
||||
" </interface>\n"
|
||||
"")
|
||||
|
||||
AlRecorder *parent() const;
|
||||
|
||||
public:
|
||||
explicit DBusAdaptorRecorder(QObject *parent);
|
||||
virtual ~DBusAdaptorRecorder();
|
||||
|
||||
public: // PROPERTIES
|
||||
public Q_SLOTS: // METHODS
|
||||
UnLaunchedAppMap GetNew();
|
||||
void MarkLaunched(const QString &desktopFile);
|
||||
void UninstallHints(const QStringList &desktopFiles);
|
||||
void WatchDirs(const QStringList &dirs);
|
||||
Q_SIGNALS: // SIGNALS
|
||||
void Launched(const QString &file);
|
||||
void ServiceRestarted();
|
||||
void StatusSaved(const QString &root, const QString &file, bool ok);
|
||||
};
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user