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 "filelauncher.h"
#include <QDBusInterface>
#include <QDBusPendingCall>
#include <QSettings> #include <QSettings>
#include <QProcess> #include <QProcess>
#include <QFile> #include <QFile>
@ -69,10 +71,38 @@ bool FileLauncher::launchApp(const QString &desktopFile, const QString &fileName
qDebug() << "launchApp()" << exec << args; qDebug() << "launchApp()" << exec << args;
return QProcess::startDetached(exec, args); return startDetached(exec, args);
} }
bool FileLauncher::launchExecutable(const QString &fileName) 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 launchApp(const QString &desktopFile, const QString &fileName);
Q_INVOKABLE bool launchExecutable(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 #endif // FILELAUNCHER_H

View file

@ -18,6 +18,7 @@
*/ */
#include "mimeappmanager.h" #include "mimeappmanager.h"
#include "helper/filelauncher.h"
#include <QStandardPaths> #include <QStandardPaths>
#include <QDirIterator> #include <QDirIterator>
@ -26,7 +27,6 @@
#include <QMimeDatabase> #include <QMimeDatabase>
#include <QMimeType> #include <QMimeType>
#include <QProcess>
#include <QSettings> #include <QSettings>
#include <QDateTime> #include <QDateTime>
#include <QThread> #include <QThread>
@ -434,11 +434,7 @@ void MimeAppManager::launchTerminal(const QString &path)
return; return;
QString command = m_terminalApps.first().value("Exec").toString(); QString command = m_terminalApps.first().value("Exec").toString();
QProcess process; FileLauncher::startDetached(command, path, QStringList());
process.setProgram(command);
// Launch terminal with working directory set.
process.setWorkingDirectory(path);
process.startDetached();
} }
void MimeAppManager::onFileChanged(const QString &path) void MimeAppManager::onFileChanged(const QString &path)