mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-06 23:24:01 +02:00
Use QProcess instead of system()
Use g_get_home_dir since it already uses both $HOME and passwd
This commit is contained in:
parent
170ec16f39
commit
95c0c400c7
1 changed files with 27 additions and 13 deletions
|
@ -181,13 +181,24 @@ QString RealExecutablePath(int argc, char *argv[]) {
|
||||||
: QString();
|
: QString();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RunShellCommand(const QByteArray &command) {
|
bool RunShellCommand(const QString &program, const QStringList &arguments) {
|
||||||
auto result = system(command.constData());
|
const auto result = QProcess::execute(program, arguments);
|
||||||
|
|
||||||
|
const auto command = qsl("%1 %2")
|
||||||
|
.arg(program)
|
||||||
|
.arg(arguments.join(' '));
|
||||||
|
|
||||||
if (result) {
|
if (result) {
|
||||||
DEBUG_LOG(("App Error: command failed, code: %1, command (in utf8): %2").arg(result).arg(command.constData()));
|
DEBUG_LOG(("App Error: command failed, code: %1, command: %2")
|
||||||
|
.arg(result)
|
||||||
|
.arg(command));
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
DEBUG_LOG(("App Info: command succeeded, command (in utf8): %1").arg(command.constData()));
|
|
||||||
|
DEBUG_LOG(("App Info: command succeeded, command: %1")
|
||||||
|
.arg(command));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1103,13 +1114,13 @@ void psActivateProcess(uint64 pid) {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
QString getHomeDir() {
|
QString getHomeDir() {
|
||||||
auto home = QDir::homePath();
|
const auto home = QString(g_get_home_dir());
|
||||||
|
|
||||||
if (home != QDir::rootPath())
|
if (!home.isEmpty() && !home.endsWith('/')) {
|
||||||
return home + '/';
|
return home + '/';
|
||||||
|
}
|
||||||
|
|
||||||
struct passwd *pw = getpwuid(getuid());
|
return home;
|
||||||
return (pw && pw->pw_dir && strlen(pw->pw_dir)) ? (QFile::decodeName(pw->pw_dir) + '/') : QString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
@ -1292,12 +1303,15 @@ void RegisterCustomScheme(bool force) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RunShellCommand("update-desktop-database "
|
RunShellCommand("update-desktop-database", {
|
||||||
+ EscapeShell(QFile::encodeName(applicationsPath)));
|
applicationsPath
|
||||||
|
});
|
||||||
|
|
||||||
RunShellCommand("xdg-mime default "
|
RunShellCommand("xdg-mime", {
|
||||||
+ GetLauncherFilename().toLatin1()
|
"default",
|
||||||
+ " x-scheme-handler/tg");
|
GetLauncherFilename(),
|
||||||
|
"x-scheme-handler/tg"
|
||||||
|
});
|
||||||
#endif // !TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
|
#endif // !TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue