From 7c47a616e40b95b1fc078943598badc465c48a23 Mon Sep 17 00:00:00 2001 From: arm64v8a <48624112+arm64v8a@users.noreply.github.com> Date: Wed, 9 Nov 2022 09:34:03 +0900 Subject: [PATCH] fix: h2 -> http fix: edit profile ui --- fmt/Bean2CoreObj_box.cpp | 4 +--- fmt/Bean2CoreObj_ray.cpp | 10 +++++----- fmt/Bean2Link.cpp | 4 ++-- fmt/Link2Bean.cpp | 6 +++--- fmt/V2RayStreamSettings.hpp | 2 +- sub/GroupUpdater.cpp | 4 ++-- ui/edit/dialog_edit_profile.cpp | 29 +++++++++++++++++++++-------- ui/edit/dialog_edit_profile.ui | 6 +++--- 8 files changed, 38 insertions(+), 27 deletions(-) diff --git a/fmt/Bean2CoreObj_box.cpp b/fmt/Bean2CoreObj_box.cpp index 0f00a50..ccd8038 100644 --- a/fmt/Bean2CoreObj_box.cpp +++ b/fmt/Bean2CoreObj_box.cpp @@ -6,9 +6,7 @@ namespace NekoRay::fmt { // https://sing-box.sagernet.org/configuration/shared/v2ray-transport if (network != "tcp") { - QJsonObject transport{ - {"type", network.replace("h2", "http")}, - }; + QJsonObject transport{{"type", network},}; if (network == "ws") { if (!path.isEmpty()) transport["path"] = path; if (!host.isEmpty()) transport["headers"] = QJsonObject{{"Host", host}}; diff --git a/fmt/Bean2CoreObj_ray.cpp b/fmt/Bean2CoreObj_ray.cpp index 0f6246c..1928868 100644 --- a/fmt/Bean2CoreObj_ray.cpp +++ b/fmt/Bean2CoreObj_ray.cpp @@ -22,11 +22,11 @@ namespace NekoRay::fmt { ws["earlyDataHeaderName"] = ws_early_data_name; } streamSettings["wsSettings"] = ws; - } else if (network == "h2") { - QJsonObject h2; - if (!path.isEmpty()) h2["path"] = path; - if (!host.isEmpty()) h2["host"] = QList2QJsonArray(host.split(",")); - streamSettings["httpSettings"] = h2; + } else if (network == "http") { + QJsonObject http; + if (!path.isEmpty()) http["path"] = path; + if (!host.isEmpty()) http["host"] = QList2QJsonArray(host.split(",")); + streamSettings["httpSettings"] = http; } else if (network == "grpc") { QJsonObject grpc; if (!path.isEmpty()) grpc["serviceName"] = path; diff --git a/fmt/Bean2Link.cpp b/fmt/Bean2Link.cpp index 25f1b9b..1567866 100644 --- a/fmt/Bean2Link.cpp +++ b/fmt/Bean2Link.cpp @@ -33,9 +33,9 @@ namespace NekoRay::fmt { if (!name.isEmpty()) url.setFragment(UrlSafe_encode(name)); if (!stream->sni.isEmpty()) query.addQueryItem("sni", stream->sni); query.addQueryItem("security", "tls"); - query.addQueryItem("type", stream->network.replace("h2", "http")); + query.addQueryItem("type", stream->network); - if (stream->network == "ws" || stream->network == "h2") { + if (stream->network == "ws" || stream->network == "http") { if (!stream->path.isEmpty()) query.addQueryItem("path", stream->path); if (!stream->host.isEmpty()) query.addQueryItem("host", stream->host); } else if (stream->network == "grpc") { diff --git a/fmt/Link2Bean.cpp b/fmt/Link2Bean.cpp index 942ebf7..7d5cf9a 100644 --- a/fmt/Link2Bean.cpp +++ b/fmt/Link2Bean.cpp @@ -52,7 +52,7 @@ namespace NekoRay::fmt { password = url.userName(); if (serverPort == -1) serverPort = 443; - stream->network = GetQueryValue(query, "type", "tcp").replace("http", "h2"); + stream->network = GetQueryValue(query, "type", "tcp"); stream->security = GetQueryValue(query, "security", "tls"); auto sni1 = GetQueryValue(query, "sni"); auto sni2 = GetQueryValue(query, "peer"); @@ -64,7 +64,7 @@ namespace NekoRay::fmt { if (stream->network == "ws") { stream->path = GetQueryValue(query, "path", ""); stream->host = GetQueryValue(query, "host", ""); - } else if (stream->network == "h2") { + } else if (stream->network == "http") { stream->path = GetQueryValue(query, "path", ""); stream->host = GetQueryValue(query, "host", "").replace("|", ","); } else if (stream->network == "grpc") { @@ -119,7 +119,7 @@ namespace NekoRay::fmt { stream->path = objN["path"].toString(); stream->sni = objN["sni"].toString(); stream->header_type = objN["type"].toString(); - auto net = objN["net"].toString().replace("http", "h2"); + auto net = objN["net"].toString(); if (!net.isEmpty()) stream->network = net; auto scy = objN["scy"].toString(); if (!scy.isEmpty()) security = scy; diff --git a/fmt/V2RayStreamSettings.hpp b/fmt/V2RayStreamSettings.hpp index cde72bc..7f11560 100644 --- a/fmt/V2RayStreamSettings.hpp +++ b/fmt/V2RayStreamSettings.hpp @@ -8,7 +8,7 @@ namespace NekoRay::fmt { QString network = "tcp"; QString security = ""; QString packet_encoding = ""; - // ws/h2/grpc/tcp-http + // ws/http/grpc/tcp-http QString path = ""; QString host = ""; // kcp/quic/tcp-http diff --git a/sub/GroupUpdater.cpp b/sub/GroupUpdater.cpp index 02a7b17..b506285 100644 --- a/sub/GroupUpdater.cpp +++ b/sub/GroupUpdater.cpp @@ -250,7 +250,7 @@ namespace NekoRay::sub { bean->uuid = Node2QString(proxy["uuid"]); bean->aid = Node2Int(proxy["alterId"]); bean->security = Node2QString(proxy["cipher"]); - bean->stream->network = Node2QString(proxy["network"], "tcp"); + bean->stream->network = Node2QString(proxy["network"], "tcp").replace("h2", "http"); bean->stream->sni = FIRST_OR_SECOND(Node2QString(proxy["sni"]), Node2QString(proxy["servername"])); if (Node2Bool(proxy["tls"])) bean->stream->security = "tls"; if (Node2Bool(proxy["skip-cert-verify"])) bean->stream->allow_insecure = true; @@ -273,7 +273,7 @@ namespace NekoRay::sub { auto h2 = NodeChild(proxy, {"h2-opts", "h2-opt"}); if (h2.IsMap()) { - auto hosts = ws["host"]; + auto hosts = h2["host"]; for (auto host: hosts) { bean->stream->host = Node2QString(host); break; diff --git a/ui/edit/dialog_edit_profile.cpp b/ui/edit/dialog_edit_profile.cpp index 88087d0..2b316ed 100644 --- a/ui/edit/dialog_edit_profile.cpp +++ b/ui/edit/dialog_edit_profile.cpp @@ -30,7 +30,8 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId, network_title_base = ui->network_box->title(); connect(ui->network, &QComboBox::currentTextChanged, this, [=](const QString &txt) { ui->network_box->setTitle(network_title_base.arg(txt)); - if (txt == "tcp" || txt == "quic") { + // 传输设置 + if (txt == "tcp" || (!IS_NEKO_BOX && txt == "quic")) { ui->header_type->setVisible(true); ui->header_type_l->setVisible(true); ui->path->setVisible(true); @@ -44,7 +45,7 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId, ui->path_l->setVisible(true); ui->host->setVisible(false); ui->host_l->setVisible(false); - } else if (txt == "ws" || txt == "h2") { + } else if (txt == "ws" || txt == "http") { ui->header_type->setVisible(false); ui->header_type_l->setVisible(false); ui->path->setVisible(true); @@ -59,6 +60,7 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId, ui->host->setVisible(false); ui->host_l->setVisible(false); } + // 传输设置 ED if (txt == "ws") { ui->ws_early_data_length->setVisible(true); ui->ws_early_data_length_l->setVisible(true); @@ -70,6 +72,17 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId, ui->ws_early_data_name->setVisible(false); ui->ws_early_data_name_l->setVisible(false); } + // 传输设置 for NekoBox + if (IS_NEKO_BOX) { + ui->header_type->setVisible(false); + ui->header_type_l->setVisible(false); + } + // 传输设置 是否可见 + int networkBoxVisible = 0; + for (auto label: ui->network_box->findChildren()) { + if (!label->isHidden()) networkBoxVisible++; + } + ui->network_box->setVisible(networkBoxVisible); ADJUST_SIZE }); ui->network->removeItem(0); @@ -83,6 +96,7 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId, } ADJUST_SIZE }); + emit ui->security->currentTextChanged(ui->security->currentText()); // 确定模式和 ent newEnt = _type != ""; @@ -240,10 +254,8 @@ void DialogEditProfile::typeSelected(const QString &newType) { } } + // 设置 for NekoBox if (IS_NEKO_BOX) { - ui->header_type->hide(); - ui->header_type_l->hide(); - // if (type == "vmess" || type == "vless") { ui->packet_encoding->setVisible(true); ui->packet_encoding_l->setVisible(true); @@ -267,7 +279,7 @@ void DialogEditProfile::typeSelected(const QString &newType) { ui->security->setVisible(false); ui->security_l->setVisible(false); } - // + // 设置 是否可见 int streamBoxVisible = 0; for (auto label: ui->stream_box->findChildren()) { if (!label->isHidden()) streamBoxVisible++; @@ -275,7 +287,8 @@ void DialogEditProfile::typeSelected(const QString &newType) { ui->stream_box->setVisible(streamBoxVisible); } - auto rightNoBox = (ui->stream_box->isHidden() && ui->security_box->isHidden() && ui->network_box->isHidden()); + // 载入 type 之后,有些类型没有右边的设置 + auto rightNoBox = (ui->stream_box->isHidden() && ui->network_box->isHidden() && ui->security_box->isHidden()); if (rightNoBox && !ui->right_all_w->isHidden()) { ui->right_all_w->setVisible(false); } @@ -285,7 +298,7 @@ void DialogEditProfile::typeSelected(const QString &newType) { // 第一次显示 if (isHidden()) { - show(); + runOnUiThread([=] { show(); }, this); } } diff --git a/ui/edit/dialog_edit_profile.ui b/ui/edit/dialog_edit_profile.ui index d0ed167..a370625 100644 --- a/ui/edit/dialog_edit_profile.ui +++ b/ui/edit/dialog_edit_profile.ui @@ -240,7 +240,7 @@ - h2 + http @@ -314,7 +314,7 @@ - http path (ws/h2/伪装http) + http path (ws/http/伪装http) serviceName (gRPC) key (QUIC) @@ -329,7 +329,7 @@ key (QUIC) - http host (ws/h2/伪装http) + http host (ws/http/伪装http) security (QUIC)