Fix activating browser windows on Wayland

QDesktopServices::openUrl does not have XDG activation support yet so it can't raise an existing browser window when opening URLs

Instead use KIO::OpenUrlJob, which does support that
This commit is contained in:
Nicolas Fella
2022-06-09 17:01:55 +02:00
parent 70de0dc624
commit 722aa422e7
12 changed files with 67 additions and 12 deletions

24
src/urlhelper.cpp Normal file
View File

@@ -0,0 +1,24 @@
// SPDX-FileCopyrightText: 2022 Nicolas Fella <nicolas.fella@gmx.de>
// SPDX-License-Identifier: GPL-2.0-or-later
#include "urlhelper.h"
#include <QtGlobal>
#ifdef Q_OS_ANDROID
#include <QDesktopServices>
#else
#include <KIO/OpenUrlJob>
#endif
// QDesktopServices::openUrl doesn't support XDG activation yet, OpenUrlJob does
// On Android XDG activation is not relevant, so use QDesktopServices::openUrl to avoid the heavy KIO dependency
void UrlHelper::openUrl(const QUrl &url)
{
#ifdef Q_OS_ANDROID
QDesktopServices::openUrl(url);
#else
auto *job = new KIO::OpenUrlJob(url);
job->start();
#endif
}