diff --git a/db/ProfileFilter.cpp b/db/ProfileFilter.cpp index 13c414e..df9bcf4 100644 --- a/db/ProfileFilter.cpp +++ b/db/ProfileFilter.cpp @@ -1,14 +1,20 @@ #include "ProfileFilter.hpp" namespace NekoGui { + + QString ProfileFilter_ent_key(const std::shared_ptr &ent, bool by_address) { + by_address &= ent->type != "custom"; + return by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType()) + : ent->bean->ToJsonBytes(); + } + void ProfileFilter::Uniq(const QList> &in, QList> &out, bool by_address, bool keep_last) { QMap> hashMap; for (const auto &ent: in) { - QString key = by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType()) - : ent->bean->ToJsonBytes(); + QString key = ProfileFilter_ent_key(ent, by_address); if (hashMap.contains(key)) { if (keep_last) { out.removeAll(hashMap[key]); @@ -29,13 +35,11 @@ namespace NekoGui { QMap> hashMap; for (const auto &ent: src) { - QString key = by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType()) - : ent->bean->ToJsonBytes(); + QString key = ProfileFilter_ent_key(ent, by_address); hashMap[key] = ent; } for (const auto &ent: dst) { - QString key = by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType()) - : ent->bean->ToJsonBytes(); + QString key = ProfileFilter_ent_key(ent, by_address); if (hashMap.contains(key)) { if (keep_last) { out += ent; @@ -53,13 +57,11 @@ namespace NekoGui { QMap hashMap; for (const auto &ent: dst) { - QString key = by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType()) - : ent->bean->ToJsonBytes(); + QString key = ProfileFilter_ent_key(ent, by_address); hashMap[key] = true; } for (const auto &ent: src) { - QString key = by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType()) - : ent->bean->ToJsonBytes(); + QString key = ProfileFilter_ent_key(ent, by_address); if (!hashMap.contains(key)) out += ent; } } diff --git a/fmt/Link2Bean.cpp b/fmt/Link2Bean.cpp index b9afb90..2249448 100644 --- a/fmt/Link2Bean.cpp +++ b/fmt/Link2Bean.cpp @@ -13,34 +13,32 @@ namespace NekoGui_fmt { auto url = QUrl("https://" + linkN); bool SocksHttpBean::TryParseLink(const QString &link) { - if (!SubStrAfter(link, "://").contains(":")) { - // v2rayN shit format - DECODE_V2RAY_N_1 + auto url = QUrl(link); + if (!url.isValid()) return false; + auto query = GetQuery(url); - if (hasRemarks) name = url.fragment(QUrl::FullyDecoded); - serverAddress = url.host(); - serverPort = url.port(); - username = url.userName(); - password = url.password(); - } else { - auto url = QUrl(link); - if (!url.isValid()) return false; - auto query = GetQuery(url); + if (link.startsWith("socks4")) socks_http_type = type_Socks4; + if (link.startsWith("http")) socks_http_type = type_HTTP; + name = url.fragment(QUrl::FullyDecoded); + serverAddress = url.host(); + serverPort = url.port(); + username = url.userName(); + password = url.password(); + if (serverPort == -1) serverPort = socks_http_type == type_HTTP ? 443 : 1080; - if (link.startsWith("socks4")) socks_http_type = type_Socks4; - if (link.startsWith("http")) socks_http_type = type_HTTP; - name = url.fragment(QUrl::FullyDecoded); - serverAddress = url.host(); - serverPort = url.port(); - username = url.userName(); - password = url.password(); - if (serverPort == -1) serverPort = socks_http_type == type_HTTP ? 443 : 1080; - - stream->security = GetQueryValue(query, "security", ""); - stream->sni = GetQueryValue(query, "sni"); - - if (link.startsWith("https")) stream->security = "tls"; + // v2rayN fmt + if (password.isEmpty() && !username.isEmpty()) { + QString n = DecodeB64IfValid(username); + if (!n.isEmpty()) { + username = SubStrBefore(n, ":"); + password = SubStrAfter(n, ":"); + } } + + stream->security = GetQueryValue(query, "security", ""); + stream->sni = GetQueryValue(query, "sni"); + + if (link.startsWith("https")) stream->security = "tls"; return true; } diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 54b53eb..8509662 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -247,16 +247,12 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi tray->setContextMenu(ui->menu_program); // 创建托盘菜单 tray->show(); // 让托盘图标显示在系统托盘上 connect(tray, &QSystemTrayIcon::activated, this, [=](QSystemTrayIcon::ActivationReason reason) { - switch (reason) { - case QSystemTrayIcon::Trigger: - if (this->isVisible()) { - hide(); - } else { - ACTIVE_THIS_WINDOW - } - break; - default: - break; + if (reason == QSystemTrayIcon::Trigger) { + if (this->isVisible()) { + hide(); + } else { + ACTIVE_THIS_WINDOW + } } }); @@ -284,7 +280,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi a->setCheckable(true); if (NekoGui::dataStore->started_id == pf->id) a->setChecked(true); ui->menuActive_Server->addAction(a); - if (++active_server_item_count == 50) break; + if (++active_server_item_count == 100) break; } // active routing for (const auto &old: ui->menuActive_Routing->actions()) {