fix: fix system proxy on KDE desktop

This commit is contained in:
parhelia512 2025-10-24 13:42:28 +08:00
parent 8d48582657
commit 43298a4d3b
6 changed files with 18 additions and 94 deletions

View File

@ -225,6 +225,18 @@ namespace Qv2ray::components::proxy {
}
#endif
#ifdef Q_OS_LINUX
QString GetKconfigCmd() {
if(qEnvironmentVariable("KDE_SESSION_VERSION") == "5") {
return "kwriteconfig5";
} else if(qEnvironmentVariable("KDE_SESSION_VERSION") == "6") {
return "kwriteconfig6";
} else {
return "kwriteconfig";
}
}
#endif
void SetSystemProxy(int httpPort, int socksPort, QString scheme) {
const QString &address = "127.0.0.1";
bool hasHTTP = (httpPort > 0 && httpPort < 65536);
@ -292,7 +304,7 @@ namespace Qv2ray::components::proxy {
// for KDE:
if (isKDE) {
actions << ProcessArgument{"kwriteconfig5",
actions << ProcessArgument{GetKconfigCmd(),
{"--file", configPath + "/kioslaverc", //
"--group", "Proxy Settings", //
"--key", protocol + "Proxy", //
@ -311,7 +323,7 @@ namespace Qv2ray::components::proxy {
// for KDE:
if (isKDE) {
actions << ProcessArgument{"kwriteconfig5",
actions << ProcessArgument{GetKconfigCmd(),
{"--file", configPath + "/kioslaverc", //
"--group", "Proxy Settings", //
"--key", "socksProxy", //
@ -328,7 +340,7 @@ namespace Qv2ray::components::proxy {
// for KDE:
if (isKDE) {
actions << ProcessArgument{"kwriteconfig5",
actions << ProcessArgument{GetKconfigCmd(),
{"--file", configPath + "/kioslaverc", //
"--group", "Proxy Settings", //
"--key", "ProxyType", "1"}};
@ -401,7 +413,7 @@ namespace Qv2ray::components::proxy {
// for KDE:
if (isKDE) {
actions << ProcessArgument{"kwriteconfig5",
actions << ProcessArgument{GetKconfigCmd(),
{"--file", configRoot + "/kioslaverc", //
"--group", "Proxy Settings", //
"--key", "ProxyType", "0"}};

View File

@ -1,2 +1,2 @@
set(PLATFORM_SOURCES src/sys/linux/LinuxCap.cpp src/sys/linux/desktopinfo.cpp)
set(PLATFORM_SOURCES src/sys/linux/LinuxCap.cpp)
set(PLATFORM_LIBRARIES dl)

View File

@ -1,31 +0,0 @@
#pragma once
#include <QString>
class DesktopInfo
{
public:
DesktopInfo();
enum WM
{
GNOME,
KDE,
OTHER,
QTILE,
SWAY,
HYPRLAND
};
bool waylandDetected();
WM windowManager();
private:
QString XDG_CURRENT_DESKTOP;
QString XDG_SESSION_TYPE;
QString WAYLAND_DISPLAY;
QString KDE_FULL_SESSION;
QString GNOME_DESKTOP_SESSION_ID;
QString GDMSESSION;
QString DESKTOP_SESSION;
};

View File

@ -22,7 +22,6 @@
#include <qfontdatabase.h>
#endif
#ifdef Q_OS_LINUX
#include "include/sys/linux/desktopinfo.h"
#include <qfontdatabase.h>
#endif

View File

@ -1,54 +0,0 @@
#include "include/sys/linux/desktopinfo.h"
#include <QProcessEnvironment>
DesktopInfo::DesktopInfo()
{
auto e = QProcessEnvironment::systemEnvironment();
XDG_CURRENT_DESKTOP = e.value(QStringLiteral("XDG_CURRENT_DESKTOP"));
XDG_SESSION_TYPE = e.value(QStringLiteral("XDG_SESSION_TYPE"));
WAYLAND_DISPLAY = e.value(QStringLiteral("WAYLAND_DISPLAY"));
KDE_FULL_SESSION = e.value(QStringLiteral("KDE_FULL_SESSION"));
GNOME_DESKTOP_SESSION_ID =
e.value(QStringLiteral("GNOME_DESKTOP_SESSION_ID"));
DESKTOP_SESSION = e.value(QStringLiteral("DESKTOP_SESSION"));
}
bool DesktopInfo::waylandDetected()
{
return XDG_SESSION_TYPE == QLatin1String("wayland") ||
WAYLAND_DISPLAY.contains(QLatin1String("wayland"),
Qt::CaseInsensitive);
}
DesktopInfo::WM DesktopInfo::windowManager()
{
DesktopInfo::WM res = DesktopInfo::OTHER;
QStringList desktops = XDG_CURRENT_DESKTOP.split(QChar(':'));
for (auto& desktop : desktops) {
if (desktop.contains(QLatin1String("GNOME"), Qt::CaseInsensitive)) {
return DesktopInfo::GNOME;
}
if (desktop.contains(QLatin1String("qtile"), Qt::CaseInsensitive)) {
return DesktopInfo::QTILE;
}
if (desktop.contains(QLatin1String("sway"), Qt::CaseInsensitive)) {
return DesktopInfo::SWAY;
}
if (desktop.contains(QLatin1String("Hyprland"), Qt::CaseInsensitive)) {
return DesktopInfo::HYPRLAND;
}
if (desktop.contains(QLatin1String("kde-plasma"))) {
return DesktopInfo::KDE;
}
}
if (!GNOME_DESKTOP_SESSION_ID.isEmpty()) {
return DesktopInfo::GNOME;
}
if (!KDE_FULL_SESSION.isEmpty()) {
return DesktopInfo::KDE;
}
return res;
}

View File

@ -26,7 +26,6 @@
#else
#ifdef Q_OS_LINUX
#include "include/sys/linux/LinuxCap.h"
#include "include/sys/linux/desktopinfo.h"
#include <QDBusInterface>
#include <QDBusReply>
#include <QUuid>
@ -1910,8 +1909,7 @@ QPixmap grabScreen(QScreen* screen, bool& ok)
QPixmap p;
QRect geom = screen->geometry();
#ifdef Q_OS_LINUX
DesktopInfo m_info;
if (m_info.waylandDetected()) {
if (qEnvironmentVariable("XDG_SESSION_TYPE") == "wayland" || qEnvironmentVariable("WAYLAND_DISPLAY").contains("wayland", Qt::CaseInsensitive)) {
QDBusInterface screenshotInterface(
QStringLiteral("org.freedesktop.portal.Desktop"),
QStringLiteral("/org/freedesktop/portal/desktop"),