Fallback to plain xdg-open as a last resort

Even though QDesktopServices::openUrl calls xdg-open, it doesn't fallback to xdg-open in confined environments.
This is useful in snap where portals aren't guaranteed to be present.
This commit is contained in:
Ilya Fedin 2021-03-10 14:26:44 +04:00 committed by John Preston
parent b24cba99e2
commit 59e6fd9989
1 changed files with 12 additions and 2 deletions

View File

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "platform/linux/linux_xdp_open_with_dialog.h"
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
#include <QtCore/QProcess>
#include <QtGui/QDesktopServices>
#include <glibmm.h>
@ -34,7 +35,11 @@ void UnsafeOpenUrl(const QString &url) {
LOG(("App Error: %1").arg(QString::fromStdString(e.what())));
}
QDesktopServices::openUrl(url);
if (QDesktopServices::openUrl(url)) {
return;
}
QProcess::execute(qsl("xdg-open"), { url });
}
void UnsafeOpenEmailLink(const QString &email) {
@ -73,7 +78,12 @@ void UnsafeLaunch(const QString &filepath) {
return;
}
QDesktopServices::openUrl(QUrl::fromLocalFile(filepath));
const auto qUrlPath = QUrl::fromLocalFile(filepath);
if (QDesktopServices::openUrl(qUrlPath)) {
return;
}
QProcess::execute(qsl("xdg-open"), { qUrlPath.toEncoded() });
}
} // namespace File