Add checking background service before connect (#716)

checking if the service is running for all platforms
This commit is contained in:
Vladyslav Miachkov 2024-05-10 13:06:04 +03:00 committed by GitHub
parent d67c378bff
commit ff348a348c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 20 additions and 4 deletions

View file

@ -76,7 +76,7 @@ QString Utils::usrExecutable(const QString &baseName)
return ("/usr/bin/" + baseName);
}
bool Utils::processIsRunning(const QString &fileName)
bool Utils::processIsRunning(const QString &fileName, const bool fullFlag)
{
#ifdef Q_OS_WIN
QProcess process;
@ -107,10 +107,14 @@ bool Utils::processIsRunning(const QString &fileName)
#else
QProcess process;
process.setProcessChannelMode(QProcess::MergedChannels);
process.start("pgrep", QStringList({ fileName }));
process.start("pgrep", QStringList({ fullFlag ? "-f" : "", fileName }));
process.waitForFinished();
if (process.exitStatus() == QProcess::NormalExit) {
return (process.readAll().toUInt() > 0);
if (fullFlag) {
return (process.readLine().toUInt() > 0);
} else {
return (process.readAll().toUInt() > 0);
}
}
return false;
#endif