diff --git a/src/widgets/krun.cpp b/src/widgets/krun.cpp --- a/src/widgets/krun.cpp +++ b/src/widgets/krun.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -83,8 +84,6 @@ #if HAVE_X11 #include -#elif defined(Q_OS_WIN) -#include #endif #include @@ -122,6 +121,13 @@ return KProtocolInfo::exec(protocol); } +static bool checkNeedPortalSupport() +{ + return !QStandardPaths::locate(QStandardPaths::RuntimeLocation, + QLatin1String("flatpak-info")).isEmpty() || + qEnvironmentVariableIsSet("SNAP"); +} + // --------------------------------------------------------------------------- bool KRun::isExecutableFile(const QUrl &url, const QString &mimetype) @@ -947,6 +953,14 @@ return; } + if (d->m_externalBrowserEnabled && checkNeedPortalSupport()) { + // use the function from QDesktopServices as it handles portals correctly + d->m_bFault = !QDesktopServices::openUrl(d->m_strURL); + d->m_bFinished = true; + d->startTimer(); + return; + } + if (!d->m_externalBrowser.isEmpty() && d->m_strURL.scheme().startsWith(QLatin1String("http"))) { if (d->runExecutable(d->m_externalBrowser)) { return; @@ -1419,7 +1433,8 @@ void KRun::setEnableExternalBrowser(bool b) { - if (b) { + d->m_externalBrowserEnabled = b; + if (d->m_externalBrowserEnabled) { d->m_externalBrowser = KConfigGroup(KSharedConfig::openConfig(), "General").readEntry("BrowserApplication"); // If a default browser isn't set in kdeglobals, fall back to mimeapps.list diff --git a/src/widgets/krun_p.h b/src/widgets/krun_p.h --- a/src/widgets/krun_p.h +++ b/src/widgets/krun_p.h @@ -136,6 +136,8 @@ * This action is invoked from slotTimeout. */ bool m_bCheckPrompt; + + bool m_externalBrowserEnabled; }; #endif // KRUN_P_H