From 368f7ee0c1acd945aa135b3d4f1c97f26df13ef4 Mon Sep 17 00:00:00 2001 From: reionwong Date: Sun, 21 Nov 2021 02:25:31 +0800 Subject: [PATCH] Use system call --- helper/filelauncher.cpp | 34 ++++++++++++++++++++++++++++++++-- helper/filelauncher.h | 3 +++ mimetype/mimeappmanager.cpp | 8 ++------ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/helper/filelauncher.cpp b/helper/filelauncher.cpp index eb5c969..2124788 100644 --- a/helper/filelauncher.cpp +++ b/helper/filelauncher.cpp @@ -19,6 +19,8 @@ #include "filelauncher.h" +#include +#include #include #include #include @@ -69,10 +71,38 @@ bool FileLauncher::launchApp(const QString &desktopFile, const QString &fileName qDebug() << "launchApp()" << exec << args; - return QProcess::startDetached(exec, args); + return startDetached(exec, args); } bool FileLauncher::launchExecutable(const QString &fileName) { - return QProcess::startDetached(fileName, QStringList()); + return startDetached(fileName); +} + +bool FileLauncher::startDetached(const QString &exec, QStringList args) +{ + QDBusInterface iface("com.cutefish.Session", + "/Session", + "com.cutefish.Session", QDBusConnection::sessionBus()); + + if (iface.isValid()) { + iface.asyncCall("launch", exec, args).waitForFinished(); + } else { + QProcess::startDetached(exec, args); + } + + return true; +} + +bool FileLauncher::startDetached(const QString &exec, const QString &workingDir, QStringList args) +{ + QDBusInterface iface("com.cutefish.Session", + "/Session", + "com.cutefish.Session", QDBusConnection::sessionBus()); + + if (iface.isValid()) { + iface.asyncCall("launch", exec, workingDir, args).waitForFinished(); + } + + return true; } diff --git a/helper/filelauncher.h b/helper/filelauncher.h index 6d4e46c..1728005 100644 --- a/helper/filelauncher.h +++ b/helper/filelauncher.h @@ -32,6 +32,9 @@ public: Q_INVOKABLE bool launchApp(const QString &desktopFile, const QString &fileName); Q_INVOKABLE bool launchExecutable(const QString &fileName); + + static bool startDetached(const QString &exec, QStringList args = QStringList()); + static bool startDetached(const QString &exec, const QString &workingDir, QStringList args = QStringList()); }; #endif // FILELAUNCHER_H diff --git a/mimetype/mimeappmanager.cpp b/mimetype/mimeappmanager.cpp index bf4a818..890d3b4 100644 --- a/mimetype/mimeappmanager.cpp +++ b/mimetype/mimeappmanager.cpp @@ -18,6 +18,7 @@ */ #include "mimeappmanager.h" +#include "helper/filelauncher.h" #include #include @@ -26,7 +27,6 @@ #include #include -#include #include #include #include @@ -434,11 +434,7 @@ void MimeAppManager::launchTerminal(const QString &path) return; QString command = m_terminalApps.first().value("Exec").toString(); - QProcess process; - process.setProgram(command); - // Launch terminal with working directory set. - process.setWorkingDirectory(path); - process.startDetached(); + FileLauncher::startDetached(command, path, QStringList()); } void MimeAppManager::onFileChanged(const QString &path)