Running apps using system calls

This commit is contained in:
reionwong 2021-11-21 02:02:53 +08:00
parent 27ffb0f7a0
commit cda28fe176
3 changed files with 20 additions and 16 deletions

View file

@ -18,6 +18,7 @@
*/ */
#include "applicationmodel.h" #include "applicationmodel.h"
#include "processprovider.h"
#include "utils.h" #include "utils.h"
#include <QProcess> #include <QProcess>
@ -192,25 +193,21 @@ bool ApplicationModel::openNewInstance(const QString &appId)
if (!item) if (!item)
return false; return false;
QProcess process;
if (appId == "cutefish-launcher")
process.setArguments(QStringList() << "--show");
if (!item->exec.isEmpty()) { if (!item->exec.isEmpty()) {
QStringList args = item->exec.split(" "); QStringList args = item->exec.split(" ");
process.setProgram(args.first()); QString exec = args.first();
args.removeFirst(); args.removeFirst();
if (!args.isEmpty()) { if (!args.isEmpty()) {
process.setArguments(args); ProcessProvider::startDetached(exec, args);
}
} else { } else {
process.setProgram(appId); ProcessProvider::startDetached(exec);
}
} else {
ProcessProvider::startDetached(appId);
} }
return process.startDetached(); return true;
} }
void ApplicationModel::closeAllByAppId(const QString &appId) void ApplicationModel::closeAllByAppId(const QString &appId)

View file

@ -18,7 +18,8 @@
*/ */
#include "processprovider.h" #include "processprovider.h"
#include <QProcess> #include <QDBusInterface>
#include <QDBusPendingCall>
ProcessProvider::ProcessProvider(QObject *parent) ProcessProvider::ProcessProvider(QObject *parent)
: QObject(parent) : QObject(parent)
@ -28,8 +29,14 @@ ProcessProvider::ProcessProvider(QObject *parent)
bool ProcessProvider::startDetached(const QString &exec, QStringList args) bool ProcessProvider::startDetached(const QString &exec, QStringList args)
{ {
QProcess process; QDBusInterface iface("com.cutefish.Session",
process.setProgram(exec); "/Session",
process.setArguments(args); "com.cutefish.Session", QDBusConnection::sessionBus());
return process.startDetached();
if (iface.isValid()) {
iface.asyncCall("launch", exec, args).waitForFinished();
return true;
}
return false;
} }

View file

@ -29,7 +29,7 @@ class ProcessProvider : public QObject
public: public:
explicit ProcessProvider(QObject *parent = nullptr); explicit ProcessProvider(QObject *parent = nullptr);
Q_INVOKABLE bool startDetached(const QString &exec, QStringList args = QStringList()); Q_INVOKABLE static bool startDetached(const QString &exec, QStringList args = QStringList());
}; };
#endif // PROCESSPROVIDER_H #endif // PROCESSPROVIDER_H