diff --git a/db/Database.cpp b/db/Database.cpp index 739bbd0..3dc40d3 100644 --- a/db/Database.cpp +++ b/db/Database.cpp @@ -430,6 +430,7 @@ namespace NekoGui { _add(new configItem("port_range", &port_range, itemType::stringList)); _add(new configItem("process_name", &process_name, itemType::stringList)); _add(new configItem("process_path", &process_path, itemType::stringList)); + _add(new configItem("process_path_regex", &process_path, itemType::stringList)); _add(new configItem("rule_set", &rule_set, itemType::stringList)); _add(new configItem("invert", &invert, itemType::boolean)); _add(new configItem("outboundID", &outboundID, itemType::integer)); diff --git a/db/RouteEntity.cpp b/db/RouteEntity.cpp index 705a520..0f0ab53 100644 --- a/db/RouteEntity.cpp +++ b/db/RouteEntity.cpp @@ -42,6 +42,7 @@ namespace NekoGui { port_range << other.port_range; process_name << other.process_name; process_path << other.process_path; + process_path_regex << other.process_path_regex; rule_set << other.rule_set; invert = other.invert; outboundID = other.outboundID; @@ -65,6 +66,7 @@ namespace NekoGui { _add(new configItem("port_range", &port_range, itemType::stringList)); _add(new configItem("process_name", &process_name, itemType::stringList)); _add(new configItem("process_path", &process_path, itemType::stringList)); + _add(new configItem("process_path_regex", &process_path_regex, itemType::stringList)); _add(new configItem("rule_set", &rule_set, itemType::stringList)); _add(new configItem("invert", &invert, itemType::boolean)); _add(new configItem("outboundID", &outboundID, itemType::integer)); @@ -91,6 +93,7 @@ namespace NekoGui { if (isValidStrArray(port_range)) obj["port_range"] = get_as_array(port_range); if (isValidStrArray(process_name)) obj["process_name"] = get_as_array(process_name); if (isValidStrArray(process_path)) obj["process_path"] = get_as_array(process_path); + if (isValidStrArray(process_path_regex)) obj["process_path_regex"] = get_as_array(process_path_regex); if (isValidStrArray(rule_set)) obj["rule_set"] = get_as_array(rule_set); if (invert) obj["invert"] = invert; @@ -145,6 +148,7 @@ namespace NekoGui { "port_range", "process_name", "process_path", + "process_path_regex", "rule_set", "invert", }; @@ -200,6 +204,7 @@ namespace NekoGui { if (fieldName == "port_range") return port_range; if (fieldName == "process_name") return process_name; if (fieldName == "process_path") return process_path; + if (fieldName == "process_path_regex") return process_path_regex; if (fieldName == "rule_set") return rule_set; return {}; } @@ -281,6 +286,9 @@ namespace NekoGui { if (fieldName == "process_path") { process_path = filterEmpty(value); } + if (fieldName == "process_path_regex") { + process_path_regex = filterEmpty(value); + } if (fieldName == "rule_set") { rule_set = filterEmpty(value); } diff --git a/db/RouteEntity.h b/db/RouteEntity.h index f20e0c7..00a0cb2 100644 --- a/db/RouteEntity.h +++ b/db/RouteEntity.h @@ -32,6 +32,7 @@ namespace NekoGui { QList port_range; QList process_name; QList process_path; + QList process_path_regex; QList rule_set; bool invert = false; int outboundID = -2; // -1 is proxy -2 is direct -3 is block -4 is dns_out diff --git a/fmt/Preset.hpp b/fmt/Preset.hpp index 9650215..e0c0730 100644 --- a/fmt/Preset.hpp +++ b/fmt/Preset.hpp @@ -1,14 +1,11 @@ #pragma once -namespace Preset { - namespace SingBox { - inline QStringList VpnImplementation = {"mixed", "system", "gvisor"}; - inline QStringList DomainStrategy = {"", "ipv4_only", "ipv6_only", "prefer_ipv4", "prefer_ipv6"}; - inline QStringList UtlsFingerPrint = {"", "chrome", "firefox", "edge", "safari", "360", "qq", "ios", "android", "random", "randomized", "chrome_psk", "chrome_psk_shuffle", "chrome_padding_psk_shuffle", "chrome_pq", "chrome_pq_psk"}; - inline QStringList ShadowsocksMethods = {"2022-blake3-aes-128-gcm", "2022-blake3-aes-256-gcm", "2022-blake3-chacha20-poly1305", "none", "aes-128-gcm", "aes-192-gcm", "aes-256-gcm", "chacha20-ietf-poly1305", "xchacha20-ietf-poly1305", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb", "rc4-md5", "chacha20-ietf", "xchacha20"}; - inline QStringList V2RAYTransports = {"http", "grpc", "quic", "httpupgrade", "ws", "tcp"}; - inline QStringList Flows = {"xtls-rprx-vision"}; - inline QStringList SniffProtocols = {"http", "tls", "quic", "stun", "dns", "bittorrent", "dtls", "ssh"}; - } // namespace SingBox - -} // namespace Preset +namespace Preset::SingBox { + inline QStringList VpnImplementation = {"mixed", "system", "gvisor"}; + inline QStringList DomainStrategy = {"", "ipv4_only", "ipv6_only", "prefer_ipv4", "prefer_ipv6"}; + inline QStringList UtlsFingerPrint = {"", "chrome", "firefox", "edge", "safari", "360", "qq", "ios", "android", "random", "randomized"}; + inline QStringList ShadowsocksMethods = {"2022-blake3-aes-128-gcm", "2022-blake3-aes-256-gcm", "2022-blake3-chacha20-poly1305", "none", "aes-128-gcm", "aes-192-gcm", "aes-256-gcm", "chacha20-ietf-poly1305", "xchacha20-ietf-poly1305", "aes-128-ctr", "aes-192-ctr", "aes-256-ctr", "aes-128-cfb", "aes-192-cfb", "aes-256-cfb", "rc4-md5", "chacha20-ietf", "xchacha20"}; + inline QStringList V2RAYTransports = {"http", "grpc", "quic", "httpupgrade", "ws", "tcp"}; + inline QStringList Flows = {"xtls-rprx-vision"}; + inline QStringList SniffProtocols = {"http", "tls", "quic", "stun", "dns", "bittorrent", "dtls", "ssh", "rdp"}; +} // namespace Preset::SingBox \ No newline at end of file diff --git a/ui/widget/RouteItem.cpp b/ui/widget/RouteItem.cpp index cefc425..2b74d40 100644 --- a/ui/widget/RouteItem.cpp +++ b/ui/widget/RouteItem.cpp @@ -4,6 +4,23 @@ #include "db/Database.hpp" #include "rpc/gRPC.h" +void adjustComboBoxWidth(const QComboBox *comboBox) { + int maxWidth = 0; + + // Iterate over all items and calculate the width required + for (int i = 0; i < comboBox->count(); ++i) { + QFontMetrics fontMetrics(comboBox->font()); + int itemWidth = fontMetrics.horizontalAdvance(comboBox->itemText(i)); + maxWidth = qMax(maxWidth, itemWidth); + } + + // Add some padding to the width to avoid text being too close to the edge + maxWidth += 30; + + // Set the minimum width for the drop-down menu + comboBox->view()->setMinimumWidth(maxWidth); +} + int RouteItem::getIndexOf(const QString& name) const { for (int i=0;iRules.size();i++) { if (chain->Rules[i]->name == name) return i; @@ -102,6 +119,7 @@ RouteItem::RouteItem(QWidget *parent, const std::shared_ptrroute_name->setText(chain->name); ui->rule_attr->addItems(NekoGui::RouteRule::get_attributes()); + adjustComboBoxWidth(ui->rule_attr); ui->rule_out->addItems(outboundOptions); ui->rule_attr_text->hide(); ui->rule_attr_data->setTitle(""); @@ -313,6 +331,7 @@ void RouteItem::showSelectItem(const QStringList& items, const QString& currentI ui->rule_attr_selector->clear(); ui->rule_attr_selector->show(); ui->rule_attr_selector->addItems(items); + adjustComboBoxWidth(ui->rule_attr_selector); ui->rule_attr_selector->setCurrentText(currentItem); adjustSize(); } diff --git a/ui/widget/RouteItem.ui b/ui/widget/RouteItem.ui index 9a17dd5..36d9276 100644 --- a/ui/widget/RouteItem.ui +++ b/ui/widget/RouteItem.ui @@ -166,7 +166,7 @@ - + QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok