mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-18 20:50:09 +08:00
fix: fix system proxy on KDE desktop
This commit is contained in:
parent
8d48582657
commit
43298a4d3b
20
3rdparty/qv2ray/v2/proxy/QvProxyConfigurator.cpp
vendored
20
3rdparty/qv2ray/v2/proxy/QvProxyConfigurator.cpp
vendored
@ -225,6 +225,18 @@ namespace Qv2ray::components::proxy {
|
|||||||
}
|
}
|
||||||
#endif
|
#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) {
|
void SetSystemProxy(int httpPort, int socksPort, QString scheme) {
|
||||||
const QString &address = "127.0.0.1";
|
const QString &address = "127.0.0.1";
|
||||||
bool hasHTTP = (httpPort > 0 && httpPort < 65536);
|
bool hasHTTP = (httpPort > 0 && httpPort < 65536);
|
||||||
@ -292,7 +304,7 @@ namespace Qv2ray::components::proxy {
|
|||||||
|
|
||||||
// for KDE:
|
// for KDE:
|
||||||
if (isKDE) {
|
if (isKDE) {
|
||||||
actions << ProcessArgument{"kwriteconfig5",
|
actions << ProcessArgument{GetKconfigCmd(),
|
||||||
{"--file", configPath + "/kioslaverc", //
|
{"--file", configPath + "/kioslaverc", //
|
||||||
"--group", "Proxy Settings", //
|
"--group", "Proxy Settings", //
|
||||||
"--key", protocol + "Proxy", //
|
"--key", protocol + "Proxy", //
|
||||||
@ -311,7 +323,7 @@ namespace Qv2ray::components::proxy {
|
|||||||
|
|
||||||
// for KDE:
|
// for KDE:
|
||||||
if (isKDE) {
|
if (isKDE) {
|
||||||
actions << ProcessArgument{"kwriteconfig5",
|
actions << ProcessArgument{GetKconfigCmd(),
|
||||||
{"--file", configPath + "/kioslaverc", //
|
{"--file", configPath + "/kioslaverc", //
|
||||||
"--group", "Proxy Settings", //
|
"--group", "Proxy Settings", //
|
||||||
"--key", "socksProxy", //
|
"--key", "socksProxy", //
|
||||||
@ -328,7 +340,7 @@ namespace Qv2ray::components::proxy {
|
|||||||
|
|
||||||
// for KDE:
|
// for KDE:
|
||||||
if (isKDE) {
|
if (isKDE) {
|
||||||
actions << ProcessArgument{"kwriteconfig5",
|
actions << ProcessArgument{GetKconfigCmd(),
|
||||||
{"--file", configPath + "/kioslaverc", //
|
{"--file", configPath + "/kioslaverc", //
|
||||||
"--group", "Proxy Settings", //
|
"--group", "Proxy Settings", //
|
||||||
"--key", "ProxyType", "1"}};
|
"--key", "ProxyType", "1"}};
|
||||||
@ -401,7 +413,7 @@ namespace Qv2ray::components::proxy {
|
|||||||
|
|
||||||
// for KDE:
|
// for KDE:
|
||||||
if (isKDE) {
|
if (isKDE) {
|
||||||
actions << ProcessArgument{"kwriteconfig5",
|
actions << ProcessArgument{GetKconfigCmd(),
|
||||||
{"--file", configRoot + "/kioslaverc", //
|
{"--file", configRoot + "/kioslaverc", //
|
||||||
"--group", "Proxy Settings", //
|
"--group", "Proxy Settings", //
|
||||||
"--key", "ProxyType", "0"}};
|
"--key", "ProxyType", "0"}};
|
||||||
|
|||||||
@ -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)
|
set(PLATFORM_LIBRARIES dl)
|
||||||
|
|||||||
@ -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;
|
|
||||||
};
|
|
||||||
@ -22,7 +22,6 @@
|
|||||||
#include <qfontdatabase.h>
|
#include <qfontdatabase.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
#include "include/sys/linux/desktopinfo.h"
|
|
||||||
#include <qfontdatabase.h>
|
#include <qfontdatabase.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|||||||
@ -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;
|
|
||||||
}
|
|
||||||
@ -26,7 +26,6 @@
|
|||||||
#else
|
#else
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
#include "include/sys/linux/LinuxCap.h"
|
#include "include/sys/linux/LinuxCap.h"
|
||||||
#include "include/sys/linux/desktopinfo.h"
|
|
||||||
#include <QDBusInterface>
|
#include <QDBusInterface>
|
||||||
#include <QDBusReply>
|
#include <QDBusReply>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
@ -1910,8 +1909,7 @@ QPixmap grabScreen(QScreen* screen, bool& ok)
|
|||||||
QPixmap p;
|
QPixmap p;
|
||||||
QRect geom = screen->geometry();
|
QRect geom = screen->geometry();
|
||||||
#ifdef Q_OS_LINUX
|
#ifdef Q_OS_LINUX
|
||||||
DesktopInfo m_info;
|
if (qEnvironmentVariable("XDG_SESSION_TYPE") == "wayland" || qEnvironmentVariable("WAYLAND_DISPLAY").contains("wayland", Qt::CaseInsensitive)) {
|
||||||
if (m_info.waylandDetected()) {
|
|
||||||
QDBusInterface screenshotInterface(
|
QDBusInterface screenshotInterface(
|
||||||
QStringLiteral("org.freedesktop.portal.Desktop"),
|
QStringLiteral("org.freedesktop.portal.Desktop"),
|
||||||
QStringLiteral("/org/freedesktop/portal/desktop"),
|
QStringLiteral("/org/freedesktop/portal/desktop"),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user