Use system call

This commit is contained in:
reionwong 2021-11-21 02:25:31 +08:00
parent 8918480892
commit 368f7ee0c1
3 changed files with 37 additions and 8 deletions

View file

@ -19,6 +19,8 @@
#include "filelauncher.h"
#include <QDBusInterface>
#include <QDBusPendingCall>
#include <QSettings>
#include <QProcess>
#include <QFile>
@ -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;
}

View file

@ -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

View file

@ -18,6 +18,7 @@
*/
#include "mimeappmanager.h"
#include "helper/filelauncher.h"
#include <QStandardPaths>
#include <QDirIterator>
@ -26,7 +27,6 @@
#include <QMimeDatabase>
#include <QMimeType>
#include <QProcess>
#include <QSettings>
#include <QDateTime>
#include <QThread>
@ -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)