2022-03-30 17:56:27 +08:00
|
|
|
|
#include "application_manager.h"
|
|
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
2022-05-15 12:10:42 +08:00
|
|
|
|
#include <QDBusMessage>
|
|
|
|
|
#include <QDBusConnectionInterface>
|
|
|
|
|
#include <QDBusConnection>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
2022-03-30 17:56:27 +08:00
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <mutex>
|
|
|
|
|
#include <thread>
|
2022-06-15 14:14:43 +08:00
|
|
|
|
#include <QProcess>
|
2022-03-30 17:56:27 +08:00
|
|
|
|
|
|
|
|
|
#include "../../modules/methods/basic.h"
|
|
|
|
|
#include "../../modules/methods/instance.hpp"
|
|
|
|
|
#include "../../modules/methods/quit.hpp"
|
|
|
|
|
#include "../../modules/methods/registe.hpp"
|
|
|
|
|
#include "../../modules/methods/task.hpp"
|
2022-05-18 21:14:48 +08:00
|
|
|
|
#include "../../modules/startmanager/startmanager.h"
|
2022-03-30 17:56:27 +08:00
|
|
|
|
#include "application.h"
|
|
|
|
|
#include "application_instance.h"
|
2022-11-17 17:25:20 +08:00
|
|
|
|
#include "instanceadaptor.h"
|
2022-06-15 14:14:43 +08:00
|
|
|
|
#include "../lib/keyfile.h"
|
2022-03-30 17:56:27 +08:00
|
|
|
|
|
2022-06-15 14:14:43 +08:00
|
|
|
|
ApplicationManagerPrivate::ApplicationManagerPrivate(ApplicationManager* parent)
|
2022-05-18 21:14:48 +08:00
|
|
|
|
: QObject(parent)
|
|
|
|
|
, q_ptr(parent)
|
|
|
|
|
, startManager(new StartManager(this))
|
2022-06-15 14:14:43 +08:00
|
|
|
|
, virtualMachePath("/usr/share/dde-daemon/supportVirsConf.ini")
|
|
|
|
|
, section("AppName")
|
|
|
|
|
, key("support")
|
2022-05-19 13:13:55 +08:00
|
|
|
|
{
|
2022-06-15 14:14:43 +08:00
|
|
|
|
const QString socketPath{QString("/run/user/%1/deepin-application-manager.socket").arg(getuid())};
|
|
|
|
|
connect(&server, &Socket::Server::onReadyRead, this, &ApplicationManagerPrivate::recvClientData, Qt::QueuedConnection);
|
|
|
|
|
server.listen(socketPath.toStdString());
|
2022-05-19 13:13:55 +08:00
|
|
|
|
}
|
2022-03-30 17:56:27 +08:00
|
|
|
|
|
2022-05-19 13:13:55 +08:00
|
|
|
|
ApplicationManagerPrivate::~ApplicationManagerPrivate()
|
|
|
|
|
{
|
|
|
|
|
}
|
2022-04-24 14:52:13 +08:00
|
|
|
|
|
2022-05-19 13:13:55 +08:00
|
|
|
|
bool ApplicationManagerPrivate::checkDMsgUid()
|
|
|
|
|
{
|
|
|
|
|
QDBusReply<uint> reply = q_ptr->connection().interface()->serviceUid(q_ptr->message().service());
|
|
|
|
|
return reply.isValid() && (reply.value() == getuid());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief ApplicationManagerPrivate::recvClientData 接受客户端数据,进行校验
|
|
|
|
|
* @param socket 客户端套接字
|
|
|
|
|
* @param data 接受到客户端数据
|
|
|
|
|
*/
|
2022-06-15 14:14:43 +08:00
|
|
|
|
void ApplicationManagerPrivate::recvClientData(int socket, const std::vector<char>& data)
|
2022-05-19 13:13:55 +08:00
|
|
|
|
{
|
|
|
|
|
QByteArray jsonArray = data.data();
|
|
|
|
|
Methods::Basic basic;
|
|
|
|
|
Methods::fromJson(jsonArray, basic);
|
|
|
|
|
QByteArray tmpArray;
|
|
|
|
|
do {
|
|
|
|
|
// 运行实例
|
|
|
|
|
if (basic.type == "instance") {
|
|
|
|
|
Methods::Instance instance;
|
|
|
|
|
Methods::fromJson(jsonArray, instance);
|
|
|
|
|
|
|
|
|
|
// 校验实例信息
|
|
|
|
|
auto find = tasks.find(instance.hash.toStdString());
|
|
|
|
|
if (find != tasks.end()) {
|
|
|
|
|
Methods::Task task = find->second->taskInfo();
|
|
|
|
|
Methods::toJson(tmpArray, task);
|
|
|
|
|
|
|
|
|
|
// 通过校验,传入应用启动信息
|
2022-04-24 14:52:13 +08:00
|
|
|
|
write(socket, tmpArray.toStdString());
|
2022-05-19 13:13:55 +08:00
|
|
|
|
tasks.erase(find);
|
2022-03-30 17:56:27 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
2022-05-19 13:13:55 +08:00
|
|
|
|
}
|
2022-03-30 17:56:27 +08:00
|
|
|
|
|
2022-05-19 13:13:55 +08:00
|
|
|
|
// 退出
|
|
|
|
|
if (basic.type == "quit") {
|
2022-06-15 14:14:43 +08:00
|
|
|
|
Methods::ProcessStatus quit;
|
2022-05-19 13:13:55 +08:00
|
|
|
|
Methods::fromJson(jsonArray, quit);
|
2022-06-15 14:14:43 +08:00
|
|
|
|
processInstanceStatus(quit);
|
2022-05-19 13:13:55 +08:00
|
|
|
|
server.close(socket);
|
|
|
|
|
std::cout << "client quit" << std::endl;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 注册应用
|
|
|
|
|
if (basic.type == "registe") {
|
|
|
|
|
Methods::Registe registe;
|
|
|
|
|
Methods::fromJson(jsonArray, registe);
|
|
|
|
|
Methods::Registe result;
|
|
|
|
|
result.state = false;
|
|
|
|
|
// std::lock_guard<std::mutex> lock(task_mutex);
|
|
|
|
|
for (auto it = tasks.begin(); it != tasks.end(); ++it) {
|
2022-05-25 11:46:28 +08:00
|
|
|
|
if (registe.hash == QString::fromStdString(it->first)) {
|
|
|
|
|
result.state = true;
|
|
|
|
|
result.hash = registe.hash;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-05-19 13:13:55 +08:00
|
|
|
|
}
|
|
|
|
|
Methods::toJson(tmpArray, result);
|
|
|
|
|
write(socket, tmpArray.toStdString());
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-06-15 14:14:43 +08:00
|
|
|
|
|
|
|
|
|
if (basic.type == "success") {
|
|
|
|
|
Methods::ProcessStatus processSuccess;
|
|
|
|
|
Methods::fromJson(jsonArray, processSuccess);
|
|
|
|
|
processInstanceStatus(processSuccess);
|
|
|
|
|
std::cout << "client success" << std::endl;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-05-19 13:13:55 +08:00
|
|
|
|
write(socket, jsonArray.toStdString());
|
|
|
|
|
} while (false);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 14:14:43 +08:00
|
|
|
|
void ApplicationManagerPrivate::write(int socket, const std::vector<char>& data)
|
2022-05-19 13:13:55 +08:00
|
|
|
|
{
|
|
|
|
|
std::vector<char> tmp = data;
|
|
|
|
|
tmp.push_back('\0');
|
|
|
|
|
server.write(socket, tmp);
|
|
|
|
|
}
|
2022-03-30 17:56:27 +08:00
|
|
|
|
|
2022-06-15 14:14:43 +08:00
|
|
|
|
void ApplicationManagerPrivate::write(int socket, const std::string& data)
|
2022-05-19 13:13:55 +08:00
|
|
|
|
{
|
|
|
|
|
std::vector<char> result;
|
|
|
|
|
std::copy(data.cbegin(), data.cend(), std::back_inserter(result));
|
|
|
|
|
return write(socket, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ApplicationManagerPrivate::write(int socket, const char c)
|
|
|
|
|
{
|
|
|
|
|
return write(socket, std::vector<char>(c));
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 14:14:43 +08:00
|
|
|
|
void ApplicationManagerPrivate::init()
|
|
|
|
|
{
|
|
|
|
|
KeyFile keyFile;
|
|
|
|
|
keyFile.loadFile(virtualMachePath);
|
|
|
|
|
virtualMachines = keyFile.getStrList(section, key);
|
|
|
|
|
if (virtualMachines.empty()) {
|
|
|
|
|
virtualMachines = {"hvm", "bochs", "virt", "vmware", "kvm", "cloud", "invented"};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ApplicationManagerPrivate::processInstanceStatus(Methods::ProcessStatus instanceStatus)
|
|
|
|
|
{
|
|
|
|
|
bool bFound = false;
|
|
|
|
|
|
|
|
|
|
auto application = applications.begin();
|
|
|
|
|
while (application != applications.end()) {
|
2022-05-19 13:13:55 +08:00
|
|
|
|
|
2022-06-15 14:14:43 +08:00
|
|
|
|
auto instance = (*application)->getAllInstances().begin();
|
|
|
|
|
while (instance != (*application)->getAllInstances().end()) {
|
|
|
|
|
if ((*instance)->hash() == instanceStatus.id) {
|
|
|
|
|
bFound = true;
|
|
|
|
|
}
|
|
|
|
|
if (bFound) {
|
|
|
|
|
if (instanceStatus.type == "success") {
|
|
|
|
|
(*instance)->Success(instanceStatus.data);
|
|
|
|
|
} else if (instanceStatus.type == "quit") {
|
|
|
|
|
(*instance)->Exit();
|
|
|
|
|
(*application)->getAllInstances().erase(instance);
|
|
|
|
|
} else {
|
|
|
|
|
qWarning() << "instance tyep : " << instanceStatus.type << "not found";
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
instance++;
|
|
|
|
|
}
|
|
|
|
|
application++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ApplicationManager* ApplicationManager::instance()
|
|
|
|
|
{
|
2022-05-18 21:14:48 +08:00
|
|
|
|
static ApplicationManager manager;
|
|
|
|
|
return &manager;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 14:14:43 +08:00
|
|
|
|
ApplicationManager::ApplicationManager(QObject* parent)
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
, dd_ptr(new ApplicationManagerPrivate(this))
|
2022-05-15 12:10:42 +08:00
|
|
|
|
{
|
2022-05-18 21:14:48 +08:00
|
|
|
|
Q_D(ApplicationManager);
|
|
|
|
|
|
|
|
|
|
connect(d->startManager, &StartManager::autostartChanged, this, &ApplicationManager::AutostartChanged);
|
2022-05-15 12:10:42 +08:00
|
|
|
|
}
|
2022-03-30 17:56:27 +08:00
|
|
|
|
|
|
|
|
|
ApplicationManager::~ApplicationManager() {}
|
|
|
|
|
|
2022-06-15 14:14:43 +08:00
|
|
|
|
void ApplicationManager::addApplication(const QList<QSharedPointer<Application>>& list)
|
2022-03-30 17:56:27 +08:00
|
|
|
|
{
|
|
|
|
|
Q_D(ApplicationManager);
|
|
|
|
|
|
|
|
|
|
d->applications = list;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-19 13:13:55 +08:00
|
|
|
|
/**
|
|
|
|
|
* @brief ApplicationManager::launchAutostartApps 加载自启动应用
|
|
|
|
|
* TODO 待优化点: 多个loader使用同一个套接字通信,串行执行,效率低
|
|
|
|
|
*/
|
|
|
|
|
void ApplicationManager::launchAutostartApps()
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
Launch("/freedesktop/system/seahorse", QStringList());
|
|
|
|
|
QTimer::singleShot(1000, [&] {
|
|
|
|
|
for (auto app : startManager->autostartList()) {
|
|
|
|
|
QString id = app.split("/").last().split(".").first();
|
|
|
|
|
Launch(id, QStringList());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 14:14:43 +08:00
|
|
|
|
QDBusObjectPath ApplicationManager::GetInformation(const QString& id)
|
2022-03-30 17:56:27 +08:00
|
|
|
|
{
|
|
|
|
|
Q_D(ApplicationManager);
|
|
|
|
|
|
2022-05-18 21:14:48 +08:00
|
|
|
|
if (!d->checkDMsgUid())
|
2022-05-15 12:10:42 +08:00
|
|
|
|
return {};
|
|
|
|
|
|
2022-06-15 14:14:43 +08:00
|
|
|
|
for (const QSharedPointer<Application>& app : d->applications) {
|
2022-03-30 17:56:27 +08:00
|
|
|
|
if (app->id() == id) {
|
|
|
|
|
return app->path();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 14:14:43 +08:00
|
|
|
|
QList<QDBusObjectPath> ApplicationManager::GetInstances(const QString& id)
|
2022-03-30 17:56:27 +08:00
|
|
|
|
{
|
2022-05-18 21:14:48 +08:00
|
|
|
|
Q_D(ApplicationManager);
|
|
|
|
|
if (!d->checkDMsgUid())
|
2022-05-15 12:10:42 +08:00
|
|
|
|
return {};
|
2022-03-30 17:56:27 +08:00
|
|
|
|
|
2022-06-15 14:14:43 +08:00
|
|
|
|
for (const auto& app : d->applications) {
|
2022-03-30 17:56:27 +08:00
|
|
|
|
if (app->id() == id) {
|
|
|
|
|
return app->instances();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 14:36:04 +08:00
|
|
|
|
bool ApplicationManager::AddAutostart(const QString &desktop)
|
2022-05-15 12:10:42 +08:00
|
|
|
|
{
|
2022-05-18 21:14:48 +08:00
|
|
|
|
Q_D(ApplicationManager);
|
2022-12-06 11:18:45 +08:00
|
|
|
|
if (!d->checkDMsgUid()) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::Failed, "The call failed");
|
|
|
|
|
|
|
|
|
|
qWarning() << "check msg failed...";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!d->startManager->addAutostart(desktop)) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::InvalidArgs, "invalid arguments");
|
|
|
|
|
|
|
|
|
|
qWarning() << "invalid arguments";
|
2022-05-15 12:10:42 +08:00
|
|
|
|
return false;
|
2022-12-06 11:18:45 +08:00
|
|
|
|
}
|
2022-05-15 12:10:42 +08:00
|
|
|
|
|
2022-12-06 11:18:45 +08:00
|
|
|
|
return true;
|
2022-05-15 12:10:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 14:36:04 +08:00
|
|
|
|
bool ApplicationManager::RemoveAutostart(const QString &fileName)
|
2022-05-15 12:10:42 +08:00
|
|
|
|
{
|
2022-05-18 21:14:48 +08:00
|
|
|
|
Q_D(ApplicationManager);
|
2022-12-06 11:18:45 +08:00
|
|
|
|
if (!d->checkDMsgUid()) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::Failed, "The call failed");
|
|
|
|
|
|
|
|
|
|
qWarning() << "check msg failed...";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!d->startManager->removeAutostart(fileName)) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::InvalidArgs, "invalid arguments");
|
|
|
|
|
|
|
|
|
|
qWarning() << "invalid arguments";
|
2022-05-15 12:10:42 +08:00
|
|
|
|
return false;
|
2022-12-06 11:18:45 +08:00
|
|
|
|
}
|
2022-05-15 12:10:42 +08:00
|
|
|
|
|
2022-12-06 11:18:45 +08:00
|
|
|
|
return true;
|
2022-05-15 12:10:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QStringList ApplicationManager::AutostartList()
|
|
|
|
|
{
|
2022-05-18 21:14:48 +08:00
|
|
|
|
Q_D(ApplicationManager);
|
2022-12-06 11:18:45 +08:00
|
|
|
|
if (!d->checkDMsgUid()) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::Failed, "The call failed");
|
|
|
|
|
|
|
|
|
|
qWarning() << "check msg failed...";
|
|
|
|
|
return QStringList();
|
|
|
|
|
}
|
2022-05-15 12:10:42 +08:00
|
|
|
|
|
2022-05-18 21:14:48 +08:00
|
|
|
|
return d->startManager->autostartList();
|
2022-05-15 12:10:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 14:36:04 +08:00
|
|
|
|
bool ApplicationManager::IsAutostart(const QString &fileName)
|
2022-05-15 12:10:42 +08:00
|
|
|
|
{
|
2022-05-18 21:14:48 +08:00
|
|
|
|
Q_D(ApplicationManager);
|
2022-12-06 11:18:45 +08:00
|
|
|
|
if (!d->checkDMsgUid()) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::Failed, "The call failed");
|
|
|
|
|
|
|
|
|
|
qWarning() << "check msg failed...";
|
2022-05-15 12:10:42 +08:00
|
|
|
|
return false;
|
2022-12-06 11:18:45 +08:00
|
|
|
|
}
|
2022-05-15 12:10:42 +08:00
|
|
|
|
|
2022-12-06 11:18:45 +08:00
|
|
|
|
if (!d->startManager->isAutostart(fileName)) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::InvalidArgs, "invalid arguments");
|
|
|
|
|
|
|
|
|
|
qWarning() << "invalid arguments";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
2022-05-15 12:10:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 15:33:53 +08:00
|
|
|
|
void ApplicationManager::Launch(const QString &desktopFile, bool withMsgCheck)
|
2022-05-15 12:10:42 +08:00
|
|
|
|
{
|
2022-05-18 21:14:48 +08:00
|
|
|
|
Q_D(ApplicationManager);
|
2022-12-06 11:18:45 +08:00
|
|
|
|
if (withMsgCheck && !d->checkDMsgUid()) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::Failed, "The call failed");
|
|
|
|
|
|
|
|
|
|
qWarning() << "check msg failed...";
|
2022-11-04 14:22:45 +08:00
|
|
|
|
return;
|
2022-12-06 11:18:45 +08:00
|
|
|
|
}
|
2022-05-15 12:10:42 +08:00
|
|
|
|
|
2022-12-06 11:18:45 +08:00
|
|
|
|
if (!d->startManager->launchApp(desktopFile)) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::InvalidArgs, "invalid arguments");
|
|
|
|
|
|
|
|
|
|
qWarning() << "invalid arguments";
|
|
|
|
|
}
|
2022-05-15 12:10:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-04 14:22:45 +08:00
|
|
|
|
|
2022-11-29 15:33:53 +08:00
|
|
|
|
void ApplicationManager::LaunchApp(const QString &desktopFile, uint32_t timestamp, const QStringList &files, bool withMsgCheck)
|
2022-05-15 12:10:42 +08:00
|
|
|
|
{
|
2022-05-18 21:14:48 +08:00
|
|
|
|
Q_D(ApplicationManager);
|
2022-12-06 11:18:45 +08:00
|
|
|
|
if (withMsgCheck && !d->checkDMsgUid()) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::Failed, "The call failed");
|
|
|
|
|
|
|
|
|
|
qWarning() << "check msg failed...";
|
2022-05-15 12:10:42 +08:00
|
|
|
|
return;
|
2022-12-06 11:18:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!d->startManager->launchApp(desktopFile, timestamp, files)) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::InvalidArgs, "invalid arguments");
|
2022-05-15 12:10:42 +08:00
|
|
|
|
|
2022-12-06 11:18:45 +08:00
|
|
|
|
qWarning() << "invalid arguments";
|
|
|
|
|
}
|
2022-05-15 12:10:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-29 15:33:53 +08:00
|
|
|
|
void ApplicationManager::LaunchAppAction(const QString &desktopFile, const QString &action, uint32_t timestamp, bool withMsgCheck)
|
2022-05-15 12:10:42 +08:00
|
|
|
|
{
|
2022-05-18 21:14:48 +08:00
|
|
|
|
Q_D(ApplicationManager);
|
2022-12-06 11:18:45 +08:00
|
|
|
|
if (withMsgCheck && !d->checkDMsgUid()) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::Failed, "The call failed");
|
|
|
|
|
|
|
|
|
|
qWarning() << "check msg failed...";
|
2022-05-15 12:10:42 +08:00
|
|
|
|
return;
|
2022-12-06 11:18:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!d->startManager->launchAppAction(desktopFile, action, timestamp)) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::InvalidArgs, "invalid arguments");
|
2022-05-15 12:10:42 +08:00
|
|
|
|
|
2022-12-06 11:18:45 +08:00
|
|
|
|
qWarning() << "invalid arguments";
|
|
|
|
|
}
|
2022-05-15 12:10:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ApplicationManager::LaunchAppWithOptions(QString desktopFile, uint32_t timestamp, QStringList files, QMap<QString, QString> options)
|
|
|
|
|
{
|
2022-05-18 21:14:48 +08:00
|
|
|
|
Q_D(ApplicationManager);
|
2022-12-06 11:18:45 +08:00
|
|
|
|
if (!d->checkDMsgUid()) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::Failed, "The call failed");
|
|
|
|
|
|
|
|
|
|
qWarning() << "check msg failed...";
|
2022-05-15 12:10:42 +08:00
|
|
|
|
return;
|
2022-12-06 11:18:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!d->startManager->launchAppWithOptions(desktopFile, timestamp, files, options)) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::InvalidArgs, "invalid arguments");
|
2022-05-15 12:10:42 +08:00
|
|
|
|
|
2022-12-06 11:18:45 +08:00
|
|
|
|
qWarning() << "invalid arguments";
|
|
|
|
|
}
|
2022-05-15 12:10:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ApplicationManager::RunCommandWithOptions(QString exe, QStringList args, QMap<QString, QString> options)
|
|
|
|
|
{
|
2022-05-18 21:14:48 +08:00
|
|
|
|
Q_D(ApplicationManager);
|
2022-12-06 11:18:45 +08:00
|
|
|
|
if (!d->checkDMsgUid()) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::Failed, "The call failed");
|
|
|
|
|
|
|
|
|
|
qWarning() << "check msg failed...";
|
2022-05-15 12:10:42 +08:00
|
|
|
|
return;
|
2022-12-06 11:18:45 +08:00
|
|
|
|
}
|
2022-05-15 12:10:42 +08:00
|
|
|
|
|
2022-12-06 11:18:45 +08:00
|
|
|
|
if (!d->startManager->runCommandWithOptions(exe, args, options)) {
|
|
|
|
|
if (calledFromDBus())
|
|
|
|
|
sendErrorReply(QDBusError::InvalidArgs, "invalid arguments");
|
|
|
|
|
|
|
|
|
|
qWarning() << "invalid arguments";
|
|
|
|
|
}
|
2022-05-15 12:10:42 +08:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-30 17:56:27 +08:00
|
|
|
|
QList<QDBusObjectPath> ApplicationManager::instances() const
|
|
|
|
|
{
|
|
|
|
|
Q_D(const ApplicationManager);
|
|
|
|
|
|
|
|
|
|
QList<QDBusObjectPath> result;
|
|
|
|
|
|
2022-06-15 14:14:43 +08:00
|
|
|
|
for (const auto& app : d->applications) {
|
2022-03-30 17:56:27 +08:00
|
|
|
|
result += app->instances();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QList<QDBusObjectPath> ApplicationManager::list() const
|
|
|
|
|
{
|
|
|
|
|
Q_D(const ApplicationManager);
|
|
|
|
|
|
|
|
|
|
QList<QDBusObjectPath> result;
|
2022-06-15 14:14:43 +08:00
|
|
|
|
for (const QSharedPointer<Application>& app : d->applications) {
|
2022-03-30 17:56:27 +08:00
|
|
|
|
result << app->path();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-15 14:14:43 +08:00
|
|
|
|
bool ApplicationManager::IsProcessExist(uint32_t pid)
|
|
|
|
|
{
|
|
|
|
|
Q_D(const ApplicationManager);
|
|
|
|
|
|
|
|
|
|
for (auto app : d->applications) {
|
|
|
|
|
for (auto instance : app->getAllInstances()) {
|
|
|
|
|
if (instance->getPid() == pid) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-30 17:56:27 +08:00
|
|
|
|
#include "application_manager.moc"
|