diff --git a/3rdparty/WinCommander.cpp b/3rdparty/WinCommander.cpp index 062fc24..1d65450 100644 --- a/3rdparty/WinCommander.cpp +++ b/3rdparty/WinCommander.cpp @@ -60,7 +60,7 @@ uint WinCommander::runProcessElevated(const QString &path, LPCTSTR pszParameters = (LPCTSTR)params.utf16(); QString dir; - if (workingDir.isEmpty()) + if (workingDir.count() == 0) dir = QDir::toNativeSeparators(QDir::currentPath()); else dir = QDir::toNativeSeparators(workingDir); diff --git a/3rdparty/base64.cpp b/3rdparty/base64.cpp index 7bb5ead..88aae27 100644 --- a/3rdparty/base64.cpp +++ b/3rdparty/base64.cpp @@ -1,5 +1,9 @@ #include "base64.h" +#ifndef qsizetype +#define qsizetype size_t +#endif + namespace Qt515Base64 { namespace { struct fromBase64_helper_result { diff --git a/3rdparty/fix_old_qt.h b/3rdparty/fix_old_qt.h new file mode 100644 index 0000000..2620809 --- /dev/null +++ b/3rdparty/fix_old_qt.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0) + +inline QString qEnvironmentVariable(const char *varName) { + return qgetenv(varName); +} + +#endif diff --git a/3rdparty/qv2ray/v2/components/proxy/QvProxyConfigurator.cpp b/3rdparty/qv2ray/v2/components/proxy/QvProxyConfigurator.cpp index 22991ee..693c5ca 100644 --- a/3rdparty/qv2ray/v2/components/proxy/QvProxyConfigurator.cpp +++ b/3rdparty/qv2ray/v2/components/proxy/QvProxyConfigurator.cpp @@ -16,9 +16,10 @@ #include #include +#include "3rdparty/fix_old_qt.h" #include "3rdparty/qv2ray/wrapper.hpp" #include "fmt/Preset.hpp" -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" #define QV_MODULE_NAME "SystemProxy" @@ -253,7 +254,7 @@ namespace Qv2ray::components::proxy { #endif #ifdef Q_OS_WIN - QString str = NekoRay::dataStore->system_proxy_format; + QString str = NekoGui::dataStore->system_proxy_format; if (str.isEmpty()) str = Preset::Windows::system_proxy_format[0]; str = str.replace("{ip}", address) .replace("{http_port}", Int2String(httpPort)) diff --git a/3rdparty/qv2ray/v2/ui/LogHighlighter.cpp b/3rdparty/qv2ray/v2/ui/LogHighlighter.cpp index 7f855ec..e24d02b 100644 --- a/3rdparty/qv2ray/v2/ui/LogHighlighter.cpp +++ b/3rdparty/qv2ray/v2/ui/LogHighlighter.cpp @@ -118,7 +118,7 @@ namespace Qv2ray::ui { } void SyntaxHighlighter::highlightBlock(const QString &text) { - for (const HighlightingRule &rule: qAsConst(highlightingRules)) { + for (const HighlightingRule &rule: highlightingRules) { QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text); while (matchIterator.hasNext()) { diff --git a/3rdparty/qv2ray/v2/ui/LogHighlighter.hpp b/3rdparty/qv2ray/v2/ui/LogHighlighter.hpp index a6358f1..4c24a44 100644 --- a/3rdparty/qv2ray/v2/ui/LogHighlighter.hpp +++ b/3rdparty/qv2ray/v2/ui/LogHighlighter.hpp @@ -55,36 +55,38 @@ #include #include -namespace Qv2ray::ui { - class SyntaxHighlighter : public QSyntaxHighlighter { - Q_OBJECT +namespace Qv2ray { + namespace ui { + class SyntaxHighlighter : public QSyntaxHighlighter { + Q_OBJECT - public: - explicit SyntaxHighlighter(bool darkMode, QTextDocument *parent = nullptr); + public: + explicit SyntaxHighlighter(bool darkMode, QTextDocument *parent = nullptr); - protected: - void highlightBlock(const QString &text) override; + protected: + void highlightBlock(const QString &text) override; - private: - struct HighlightingRule { - QRegularExpression pattern; - QTextCharFormat format; + private: + struct HighlightingRule { + QRegularExpression pattern; + QTextCharFormat format; + }; + QVector highlightingRules; + + QTextCharFormat tcpudpFormat; + QTextCharFormat dateFormat; + QTextCharFormat acceptedFormat; + QTextCharFormat rejectedFormat; + QTextCharFormat failedFormat; + QTextCharFormat warningFormat; + QTextCharFormat warningFormat2; + QTextCharFormat infoFormat; + QTextCharFormat debugFormat; + QTextCharFormat timeFormat; + QTextCharFormat ipHostFormat; + QTextCharFormat v2rayComponentFormat; }; - QVector highlightingRules; - - QTextCharFormat tcpudpFormat; - QTextCharFormat dateFormat; - QTextCharFormat acceptedFormat; - QTextCharFormat rejectedFormat; - QTextCharFormat failedFormat; - QTextCharFormat warningFormat; - QTextCharFormat warningFormat2; - QTextCharFormat infoFormat; - QTextCharFormat debugFormat; - QTextCharFormat timeFormat; - QTextCharFormat ipHostFormat; - QTextCharFormat v2rayComponentFormat; - }; -} // namespace Qv2ray::ui + } // namespace ui +} // namespace Qv2ray using namespace Qv2ray::ui; diff --git a/3rdparty/qv2ray/v2/ui/QvAutoCompleteTextEdit.cpp b/3rdparty/qv2ray/v2/ui/QvAutoCompleteTextEdit.cpp index cf82aa8..17c9a23 100644 --- a/3rdparty/qv2ray/v2/ui/QvAutoCompleteTextEdit.cpp +++ b/3rdparty/qv2ray/v2/ui/QvAutoCompleteTextEdit.cpp @@ -70,7 +70,7 @@ namespace Qv2ray::ui::widgets { c->setWidget(this); c->setCompletionMode(QCompleter::PopupCompletion); c->setCaseSensitivity(Qt::CaseInsensitive); - QObject::connect(c, QOverload::of(&QCompleter::activated), this, &AutoCompleteTextEdit::insertCompletion); + QObject::connect(c, static_cast(&QCompleter::activated), this, &AutoCompleteTextEdit::insertCompletion); } AutoCompleteTextEdit::~AutoCompleteTextEdit() { diff --git a/3rdparty/qv2ray/v2/ui/QvAutoCompleteTextEdit.hpp b/3rdparty/qv2ray/v2/ui/QvAutoCompleteTextEdit.hpp index 723232a..b7bf570 100644 --- a/3rdparty/qv2ray/v2/ui/QvAutoCompleteTextEdit.hpp +++ b/3rdparty/qv2ray/v2/ui/QvAutoCompleteTextEdit.hpp @@ -55,27 +55,31 @@ QT_BEGIN_NAMESPACE class QCompleter; QT_END_NAMESPACE -namespace Qv2ray::ui::widgets { - class AutoCompleteTextEdit : public QPlainTextEdit { - Q_OBJECT +namespace Qv2ray { + namespace ui { + namespace widgets { + class AutoCompleteTextEdit : public QPlainTextEdit { + Q_OBJECT - public: - AutoCompleteTextEdit(const QString &prefix, const QStringList &sourceStrings, QWidget *parent = nullptr); - ~AutoCompleteTextEdit(); + public: + AutoCompleteTextEdit(const QString &prefix, const QStringList &sourceStrings, QWidget *parent = nullptr); + ~AutoCompleteTextEdit(); - protected: - void keyPressEvent(QKeyEvent *e) override; - void focusInEvent(QFocusEvent *e) override; + protected: + void keyPressEvent(QKeyEvent *e) override; + void focusInEvent(QFocusEvent *e) override; - private slots: - void insertCompletion(const QString &completion); + private slots: + void insertCompletion(const QString &completion); - private: - QString lineUnderCursor() const; - QString wordUnderCursor() const; + private: + QString lineUnderCursor() const; + QString wordUnderCursor() const; - QString prefix; - QCompleter *c = nullptr; - }; -} // namespace Qv2ray::ui::widgets + QString prefix; + QCompleter *c = nullptr; + }; + } // namespace widgets + } // namespace ui +} // namespace Qv2ray using namespace Qv2ray::ui::widgets; diff --git a/3rdparty/qv2ray/v2/ui/widgets/editors/w_JsonEditor.cpp b/3rdparty/qv2ray/v2/ui/widgets/editors/w_JsonEditor.cpp index 55dfa63..2eb6bdb 100644 --- a/3rdparty/qv2ray/v2/ui/widgets/editors/w_JsonEditor.cpp +++ b/3rdparty/qv2ray/v2/ui/widgets/editors/w_JsonEditor.cpp @@ -1,6 +1,6 @@ #include "w_JsonEditor.hpp" -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" JsonEditor::JsonEditor(const QJsonObject& rootObject, QWidget* parent) : QDialog(parent) { setupUi(this); diff --git a/3rdparty/qv2ray/wrapper.hpp b/3rdparty/qv2ray/wrapper.hpp index e68d771..3a2cc38 100644 --- a/3rdparty/qv2ray/wrapper.hpp +++ b/3rdparty/qv2ray/wrapper.hpp @@ -7,10 +7,12 @@ #define LOG(...) Qv2ray::base::log_internal(__VA_ARGS__) #define DEBUG(...) Qv2ray::base::log_internal(__VA_ARGS__) -namespace Qv2ray::base { - template - inline void log_internal(T... v) {} -} // namespace Qv2ray::base +namespace Qv2ray { + namespace base { + template + inline void log_internal(T... v) {} + } // namespace base +} // namespace Qv2ray #define JsonToString(a) QJsonObject2QString(a, false) #define JsonFromString(a) QString2QJsonObject(a) diff --git a/CMakeLists.txt b/CMakeLists.txt index ac807c1..c194449 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -138,8 +138,8 @@ set(PROJECT_SOURCES ${PLATFORM_SOURCES} main/main.cpp - main/NekoRay.cpp - main/NekoRay_Utils.cpp + main/NekoGui.cpp + main/NekoGui_Utils.cpp main/QJS.cpp main/HTTPRequestHelper.cpp @@ -161,7 +161,7 @@ set(PROJECT_SOURCES rpc/gRPC.cpp db/Database.cpp - db/TrafficLooper.cpp + db/traffic/TrafficLooper.cpp db/ProfileFilter.cpp db/ConfigBuilder.cpp diff --git a/db/ConfigBuilder.cpp b/db/ConfigBuilder.cpp index 62f0855..be9d7bb 100644 --- a/db/ConfigBuilder.cpp +++ b/db/ConfigBuilder.cpp @@ -8,12 +8,12 @@ #include #include -#define BOX_UNDERLYING_DNS NekoRay::dataStore->core_box_underlying_dns.isEmpty() ? "underlying://0.0.0.0" : NekoRay::dataStore->core_box_underlying_dns -#define BOX_UNDERLYING_DNS_EXPORT NekoRay::dataStore->core_box_underlying_dns.isEmpty() ? (status->forExport ? "local" : "underlying://0.0.0.0") : NekoRay::dataStore->core_box_underlying_dns +#define BOX_UNDERLYING_DNS dataStore->core_box_underlying_dns.isEmpty() ? "underlying://0.0.0.0" : dataStore->core_box_underlying_dns +#define BOX_UNDERLYING_DNS_EXPORT dataStore->core_box_underlying_dns.isEmpty() ? (status->forExport ? "local" : "underlying://0.0.0.0") : dataStore->core_box_underlying_dns -namespace NekoRay { +namespace NekoGui { - QStringList getAutoBypassExternalProcessPaths(const QSharedPointer &result) { + QStringList getAutoBypassExternalProcessPaths(const std::shared_ptr &result) { QStringList paths; for (const auto &extR: result->extRs) { auto path = extR->program; @@ -54,15 +54,15 @@ namespace NekoRay { // Common - QSharedPointer BuildConfig(const QSharedPointer &ent, bool forTest, bool forExport) { - auto result = QSharedPointer(new BuildConfigResult); - auto status = QSharedPointer(new BuildConfigStatus); + std::shared_ptr BuildConfig(const std::shared_ptr &ent, bool forTest, bool forExport) { + auto result = std::make_shared(); + auto status = std::make_shared(); status->ent = ent; status->result = result; status->forTest = forTest; status->forExport = forExport; - auto customBean = dynamic_cast(ent->bean.get()); + auto customBean = dynamic_cast(ent->bean.get()); if (customBean != nullptr && customBean->core == "internal-full") { result->coreConfig = QString2QJsonObject(customBean->config_simple); } else { @@ -92,9 +92,9 @@ namespace NekoRay { return result; } - QString BuildChain(int chainId, const QSharedPointer &status) { + QString BuildChain(int chainId, const std::shared_ptr &status) { // Make list - QList> ents; + QList> ents; auto ent = status->ent; auto result = status->result; @@ -155,7 +155,7 @@ namespace NekoRay { // V2Ray - void BuildConfigV2Ray(const QSharedPointer &status) { + void BuildConfigV2Ray(const std::shared_ptr &status) { // Log auto logObj = QJsonObject{{"loglevel", dataStore->log_level}}; status->result->coreConfig.insert("log", logObj); @@ -397,8 +397,8 @@ namespace NekoRay { status->result->coreConfig.insert("stats", QJsonObject()); } - QString BuildChainInternal(int chainId, const QList> &ents, - const QSharedPointer &status) { + QString BuildChainInternal(int chainId, const QList> &ents, + const std::shared_ptr &status) { QString chainTag = "c-" + Int2String(chainId); QString chainTagOut; bool muxApplied = false; @@ -550,7 +550,7 @@ namespace NekoRay { // Outbound QJsonObject outbound; - auto stream = GetStreamSettings(ent->bean.data()); + auto stream = GetStreamSettings(ent->bean.get()); if (thisExternalStat > 0) { auto extR = ent->bean->BuildExternal(ext_mapping_port, ext_socks_port, thisExternalStat); @@ -563,7 +563,7 @@ namespace NekoRay { return {}; } extR.tag = ent->bean->DisplayType(); - status->result->extRs.emplace_back(std::make_shared(extR)); + status->result->extRs.emplace_back(std::make_shared(extR)); // SOCKS OUTBOUND if (IS_NEKO_BOX) { @@ -664,7 +664,7 @@ namespace NekoRay { // Bypass Lookup for the first profile auto serverAddress = ent->bean->serverAddress; - auto customBean = dynamic_cast(ent->bean.get()); + auto customBean = dynamic_cast(ent->bean.get()); if (customBean != nullptr && customBean->core == "internal") { auto server = QString2QJsonObject(customBean->config_simple)["server"].toString(); if (!server.isEmpty()) serverAddress = server; @@ -685,7 +685,7 @@ namespace NekoRay { // SingBox - void BuildConfigSingBox(const QSharedPointer &status) { + void BuildConfigSingBox(const std::shared_ptr &status) { // Log status->result->coreConfig["log"] = QJsonObject{{"level", dataStore->log_level}}; @@ -921,7 +921,7 @@ namespace NekoRay { // tun user rule if (IS_NEKO_BOX_INTERNAL_TUN && dataStore->spmode_vpn) { - auto match_out = NekoRay::dataStore->vpn_rule_white ? "proxy" : "bypass"; + auto match_out = dataStore->vpn_rule_white ? "proxy" : "bypass"; QString process_name_rule = dataStore->vpn_rule_process.trimmed(); if (!process_name_rule.isEmpty()) { @@ -984,10 +984,10 @@ namespace NekoRay { // experimental QJsonObject experimentalObj; - if (!status->forTest && NekoRay::dataStore->core_box_clash_api > 0) { + if (!status->forTest && dataStore->core_box_clash_api > 0) { QJsonObject clash_api = { - {"external_controller", "127.0.0.1:" + Int2String(NekoRay::dataStore->core_box_clash_api)}, - {"secret", NekoRay::dataStore->core_box_clash_api_secret}, + {"external_controller", "127.0.0.1:" + Int2String(dataStore->core_box_clash_api)}, + {"secret", dataStore->core_box_clash_api_secret}, {"external_ui", "dashboard"}, }; experimentalObj["clash_api"] = clash_api; @@ -998,8 +998,8 @@ namespace NekoRay { QString WriteVPNSingBoxConfig() { // tun user rule - auto match_out = NekoRay::dataStore->vpn_rule_white ? "nekoray-socks" : "direct"; - auto no_match_out = NekoRay::dataStore->vpn_rule_white ? "direct" : "nekoray-socks"; + auto match_out = dataStore->vpn_rule_white ? "nekoray-socks" : "direct"; + auto no_match_out = dataStore->vpn_rule_white ? "direct" : "nekoray-socks"; QString process_name_rule = dataStore->vpn_rule_process.trimmed(); if (!process_name_rule.isEmpty()) { @@ -1090,4 +1090,4 @@ namespace NekoRay { return QFileInfo(file2).absoluteFilePath(); } -} // namespace NekoRay \ No newline at end of file +} // namespace NekoGui \ No newline at end of file diff --git a/db/ConfigBuilder.hpp b/db/ConfigBuilder.hpp index ed411b8..661c881 100644 --- a/db/ConfigBuilder.hpp +++ b/db/ConfigBuilder.hpp @@ -3,23 +3,23 @@ #include "ProxyEntity.hpp" #include "sys/ExternalProcess.hpp" -namespace NekoRay { +namespace NekoGui { class BuildConfigResult { public: QString error; QJsonObject coreConfig; - QList> outboundStats; // all, but not including "bypass" "block" - QSharedPointer outboundStat; // main + QList> outboundStats; // all, but not including "bypass" "block" + std::shared_ptr outboundStat; // main QStringList ignoreConnTag; - std::list> extRs; + std::list> extRs; }; class BuildConfigStatus { public: - QSharedPointer result; - QSharedPointer ent; + std::shared_ptr result; + std::shared_ptr ent; bool forTest; bool forExport; @@ -44,18 +44,18 @@ namespace NekoRay { QJsonArray outbounds; }; - QSharedPointer BuildConfig(const QSharedPointer &ent, bool forTest, bool forExport); + std::shared_ptr BuildConfig(const std::shared_ptr &ent, bool forTest, bool forExport); - void BuildConfigV2Ray(const QSharedPointer &status); + void BuildConfigV2Ray(const std::shared_ptr &status); - void BuildConfigSingBox(const QSharedPointer &status); + void BuildConfigSingBox(const std::shared_ptr &status); - QString BuildChain(int chainId, const QSharedPointer &status); + QString BuildChain(int chainId, const std::shared_ptr &status); - QString BuildChainInternal(int chainId, const QList> &ents, - const QSharedPointer &status); + QString BuildChainInternal(int chainId, const QList> &ents, + const std::shared_ptr &status); QString WriteVPNSingBoxConfig(); QString WriteVPNLinuxScript(const QString &protectPath, const QString &configPath); -} // namespace NekoRay +} // namespace NekoGui diff --git a/db/Database.cpp b/db/Database.cpp index fa9cac2..5efba31 100644 --- a/db/Database.cpp +++ b/db/Database.cpp @@ -5,7 +5,7 @@ #include #include -namespace NekoRay { +namespace NekoGui { ProfileManager *profileManager = new ProfileManager(); @@ -40,7 +40,7 @@ namespace NekoRay { void ProfileManager::SaveManager() { } - QSharedPointer ProfileManager::LoadProxyEntity(const QString &jsonPath) { + std::shared_ptr ProfileManager::LoadProxyEntity(const QString &jsonPath) { // Load type ProxyEntity ent0(nullptr, nullptr); ent0.fn = jsonPath; @@ -48,7 +48,7 @@ namespace NekoRay { auto type = ent0.type; // Load content - QSharedPointer ent; + std::shared_ptr ent; bool validType = validJson; if (validType) { @@ -66,45 +66,45 @@ namespace NekoRay { // 新建的不给 fn 和 id - QSharedPointer ProfileManager::NewProxyEntity(const QString &type) { - fmt::AbstractBean *bean; + std::shared_ptr ProfileManager::NewProxyEntity(const QString &type) { + NekoGui_fmt::AbstractBean *bean; if (type == "socks") { - bean = new fmt::SocksHttpBean(NekoRay::fmt::SocksHttpBean::type_Socks5); + bean = new NekoGui_fmt::SocksHttpBean(NekoGui_fmt::SocksHttpBean::type_Socks5); } else if (type == "http") { - bean = new fmt::SocksHttpBean(NekoRay::fmt::SocksHttpBean::type_HTTP); + bean = new NekoGui_fmt::SocksHttpBean(NekoGui_fmt::SocksHttpBean::type_HTTP); } else if (type == "shadowsocks") { - bean = new fmt::ShadowSocksBean(); + bean = new NekoGui_fmt::ShadowSocksBean(); } else if (type == "chain") { - bean = new fmt::ChainBean(); + bean = new NekoGui_fmt::ChainBean(); } else if (type == "vmess") { - bean = new fmt::VMessBean(); + bean = new NekoGui_fmt::VMessBean(); } else if (type == "trojan") { - bean = new fmt::TrojanVLESSBean(fmt::TrojanVLESSBean::proxy_Trojan); + bean = new NekoGui_fmt::TrojanVLESSBean(NekoGui_fmt::TrojanVLESSBean::proxy_Trojan); } else if (type == "vless") { - bean = new fmt::TrojanVLESSBean(fmt::TrojanVLESSBean::proxy_VLESS); + bean = new NekoGui_fmt::TrojanVLESSBean(NekoGui_fmt::TrojanVLESSBean::proxy_VLESS); } else if (type == "naive") { - bean = new fmt::NaiveBean(); + bean = new NekoGui_fmt::NaiveBean(); } else if (type == "hysteria") { - bean = new fmt::HysteriaBean(); + bean = new NekoGui_fmt::HysteriaBean(); } else if (type == "custom") { - bean = new fmt::CustomBean(); + bean = new NekoGui_fmt::CustomBean(); } else { - bean = new fmt::AbstractBean(-114514); + bean = new NekoGui_fmt::AbstractBean(-114514); } - auto ent = QSharedPointer(new ProxyEntity(bean, type)); + auto ent = std::make_shared(bean, type); return ent; } - QSharedPointer ProfileManager::NewGroup() { - auto ent = QSharedPointer(new Group()); + std::shared_ptr ProfileManager::NewGroup() { + auto ent = std::make_shared(); return ent; } // ProxyEntity - ProxyEntity::ProxyEntity(fmt::AbstractBean *bean, const QString &type_) { + ProxyEntity::ProxyEntity(NekoGui_fmt::AbstractBean *bean, const QString &type_) { if (type_ != nullptr) this->type = type_; _add(new configItem("type", &type, itemType::string)); @@ -115,7 +115,7 @@ namespace NekoRay { // 可以不关联 bean,只加载 ProxyEntity 的信息 if (bean != nullptr) { - this->bean = QSharedPointer(bean); + this->bean = std::shared_ptr(bean); // 有虚函数就要在这里 dynamic_cast _add(new configItem("bean", dynamic_cast(bean), itemType::jsonStore)); _add(new configItem("traffic", dynamic_cast(traffic_data.get()), itemType::jsonStore)); @@ -158,7 +158,7 @@ namespace NekoRay { } } - bool ProfileManager::AddProfile(const QSharedPointer &ent, int gid) { + bool ProfileManager::AddProfile(const std::shared_ptr &ent, int gid) { if (ent->id >= 0) { return false; } @@ -183,7 +183,7 @@ namespace NekoRay { QFile(QString("profiles/%1.json").arg(id)).remove(); } - void ProfileManager::MoveProfile(const QSharedPointer &ent, int gid) { + void ProfileManager::MoveProfile(const std::shared_ptr &ent, int gid) { if (gid == ent->gid || gid < 0) return; auto oldGroup = GetGroup(ent->gid); if (oldGroup != nullptr && !oldGroup->order.isEmpty()) { @@ -199,7 +199,7 @@ namespace NekoRay { ent->Save(); } - QSharedPointer ProfileManager::GetProfile(int id) { + std::shared_ptr ProfileManager::GetProfile(int id) { return profiles.value(id, nullptr); } @@ -212,13 +212,13 @@ namespace NekoRay { _add(new configItem("order", &order, itemType::integerList)); _add(new configItem("url", &url, itemType::string)); _add(new configItem("info", &info, itemType::string)); - _add(new configItem("lastup", &last_update, itemType::integer64)); + _add(new configItem("lastup", &sub_last_update, itemType::integer64)); _add(new configItem("manually_column_width", &manually_column_width, itemType::boolean)); _add(new configItem("column_width", &column_width, itemType::integerList)); } - QSharedPointer ProfileManager::LoadGroup(const QString &jsonPath) { - QSharedPointer ent = QSharedPointer(new Group()); + std::shared_ptr ProfileManager::LoadGroup(const QString &jsonPath) { + auto ent = std::make_shared(); ent->fn = jsonPath; ent->Load(); return ent; @@ -232,7 +232,7 @@ namespace NekoRay { } } - bool ProfileManager::AddGroup(const QSharedPointer &ent) { + bool ProfileManager::AddGroup(const std::shared_ptr &ent) { if (ent->id >= 0) { return false; } @@ -262,27 +262,27 @@ namespace NekoRay { QFile(QString("groups/%1.json").arg(gid)).remove(); } - QSharedPointer ProfileManager::GetGroup(int id) { + std::shared_ptr ProfileManager::GetGroup(int id) { return groups.value(id, nullptr); } - QSharedPointer ProfileManager::CurrentGroup() { - return GetGroup(NekoRay::dataStore->current_group); + std::shared_ptr ProfileManager::CurrentGroup() { + return GetGroup(dataStore->current_group); } - QList> Group::Profiles() const { - QList> ret; + QList> Group::Profiles() const { + QList> ret; for (const auto &ent: profileManager->profiles) { if (id == ent->gid) ret += ent; } return ret; } - QList> Group::ProfilesWithOrder() const { + QList> Group::ProfilesWithOrder() const { if (order.isEmpty()) { return Profiles(); } else { - QList> ret; + QList> ret; for (auto _id: order) { auto ent = profileManager->GetProfile(_id); if (ent != nullptr) ret += ent; @@ -291,4 +291,4 @@ namespace NekoRay { } } -} // namespace NekoRay \ No newline at end of file +} // namespace NekoGui \ No newline at end of file diff --git a/db/Database.hpp b/db/Database.hpp index 9e2ea36..e888fe9 100644 --- a/db/Database.hpp +++ b/db/Database.hpp @@ -1,15 +1,15 @@ #pragma once -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" #include "ProxyEntity.hpp" #include "Group.hpp" -namespace NekoRay { +namespace NekoGui { class ProfileManager : public JsonStore { public: // Manager - QMap> profiles; - QMap> groups; + QMap> profiles; + QMap> groups; // JSON QList _profiles; @@ -17,25 +17,25 @@ namespace NekoRay { ProfileManager(); - [[nodiscard]] static QSharedPointer NewProxyEntity(const QString &type); + [[nodiscard]] static std::shared_ptr NewProxyEntity(const QString &type); - [[nodiscard]] static QSharedPointer NewGroup(); + [[nodiscard]] static std::shared_ptr NewGroup(); - bool AddProfile(const QSharedPointer &ent, int gid = -1); + bool AddProfile(const std::shared_ptr &ent, int gid = -1); void DeleteProfile(int id); - void MoveProfile(const QSharedPointer &ent, int gid); + void MoveProfile(const std::shared_ptr &ent, int gid); - QSharedPointer GetProfile(int id); + std::shared_ptr GetProfile(int id); - bool AddGroup(const QSharedPointer &ent); + bool AddGroup(const std::shared_ptr &ent); void DeleteGroup(int gid); - QSharedPointer GetGroup(int id); + std::shared_ptr GetGroup(int id); - QSharedPointer CurrentGroup(); + std::shared_ptr CurrentGroup(); private: void LoadManager(); @@ -46,10 +46,10 @@ namespace NekoRay { [[nodiscard]] int NewGroupID() const; - static QSharedPointer LoadProxyEntity(const QString &jsonPath); + static std::shared_ptr LoadProxyEntity(const QString &jsonPath); - static QSharedPointer LoadGroup(const QString &jsonPath); + static std::shared_ptr LoadGroup(const QString &jsonPath); }; extern ProfileManager *profileManager; -} // namespace NekoRay +} // namespace NekoGui diff --git a/db/Group.hpp b/db/Group.hpp index 64ae678..f6e0a36 100644 --- a/db/Group.hpp +++ b/db/Group.hpp @@ -1,9 +1,9 @@ #pragma once -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" #include "ProxyEntity.hpp" -namespace NekoRay { +namespace NekoGui { class Group : public JsonStore { public: int id = -1; @@ -11,7 +11,7 @@ namespace NekoRay { QString name = ""; QString url = ""; QString info = ""; - qint64 last_update = 0; + qint64 sub_last_update = 0; // list ui bool manually_column_width = false; @@ -21,9 +21,9 @@ namespace NekoRay { Group(); // 按 id 顺序 - [[nodiscard]] QList> Profiles() const; + [[nodiscard]] QList> Profiles() const; // 按 显示 顺序 - [[nodiscard]] QList> ProfilesWithOrder() const; + [[nodiscard]] QList> ProfilesWithOrder() const; }; -} // namespace NekoRay +} // namespace NekoGui diff --git a/db/ProfileFilter.cpp b/db/ProfileFilter.cpp index 2f1aa43..13c414e 100644 --- a/db/ProfileFilter.cpp +++ b/db/ProfileFilter.cpp @@ -1,10 +1,10 @@ #include "ProfileFilter.hpp" -namespace NekoRay { - void ProfileFilter::Uniq(const QList> &in, - QList> &out, +namespace NekoGui { + void ProfileFilter::Uniq(const QList> &in, + QList> &out, bool by_address, bool keep_last) { - QMap> hashMap; + QMap> hashMap; for (const auto &ent: in) { QString key = by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType()) @@ -22,11 +22,11 @@ namespace NekoRay { } } - void ProfileFilter::Common(const QList> &src, - const QList> &dst, - QList> &out, + void ProfileFilter::Common(const QList> &src, + const QList> &dst, + QList> &out, bool by_address, bool keep_last) { - QMap> hashMap; + QMap> hashMap; for (const auto &ent: src) { QString key = by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType()) @@ -46,9 +46,9 @@ namespace NekoRay { } } - void ProfileFilter::OnlyInSrc(const QList> &src, - const QList> &dst, - QList> &out, + void ProfileFilter::OnlyInSrc(const QList> &src, + const QList> &dst, + QList> &out, bool by_address) { QMap hashMap; @@ -64,12 +64,12 @@ namespace NekoRay { } } - void ProfileFilter::OnlyInSrc_ByPointer(const QList> &src, - const QList> &dst, - QList> &out) { + void ProfileFilter::OnlyInSrc_ByPointer(const QList> &src, + const QList> &dst, + QList> &out) { for (const auto &ent: src) { if (!dst.contains(ent)) out += ent; } } -} // namespace NekoRay \ No newline at end of file +} // namespace NekoGui \ No newline at end of file diff --git a/db/ProfileFilter.hpp b/db/ProfileFilter.hpp index 822989b..97a5b94 100644 --- a/db/ProfileFilter.hpp +++ b/db/ProfileFilter.hpp @@ -2,34 +2,34 @@ #include "ProxyEntity.hpp" -namespace NekoRay { +namespace NekoGui { class ProfileFilter { public: static void Uniq( - const QList> &in, - QList> &out, + const QList> &in, + QList> &out, bool by_address = false, // def by bean bool keep_last = false // def keep first ); static void Common( - const QList> &src, - const QList> &dst, - QList> &out, + const QList> &src, + const QList> &dst, + QList> &out, bool by_address = false, // def by bean bool keep_last = false // def keep first ); static void OnlyInSrc( - const QList> &src, - const QList> &dst, - QList> &out, + const QList> &src, + const QList> &dst, + QList> &out, bool by_address = false // def by bean ); static void OnlyInSrc_ByPointer( - const QList> &src, - const QList> &dst, - QList> &out); + const QList> &src, + const QList> &dst, + QList> &out); }; -} // namespace NekoRay +} // namespace NekoGui diff --git a/db/ProxyEntity.hpp b/db/ProxyEntity.hpp index 6d05a58..81dec91 100644 --- a/db/ProxyEntity.hpp +++ b/db/ProxyEntity.hpp @@ -1,28 +1,28 @@ #pragma once -#include "main/NekoRay.hpp" -#include "TrafficData.hpp" +#include "main/NekoGui.hpp" +#include "db/traffic/TrafficData.hpp" #include "fmt/AbstractBean.hpp" -namespace NekoRay { - namespace fmt { - class SocksHttpBean; +namespace NekoGui_fmt { + class SocksHttpBean; - class ShadowSocksBean; + class ShadowSocksBean; - class VMessBean; + class VMessBean; - class TrojanVLESSBean; + class TrojanVLESSBean; - class NaiveBean; + class NaiveBean; - class HysteriaBean; + class HysteriaBean; - class CustomBean; + class CustomBean; - class ChainBean; - }; // namespace fmt + class ChainBean; +}; // namespace NekoGui_fmt +namespace NekoGui { class ProxyEntity : public JsonStore { public: QString type; @@ -30,47 +30,47 @@ namespace NekoRay { int id = -1; int gid = 0; int latency = 0; - QSharedPointer bean; - QSharedPointer traffic_data = QSharedPointer(new traffic::TrafficData("")); + std::shared_ptr bean; + std::shared_ptr traffic_data = std::make_shared(""); QString full_test_report; - ProxyEntity(fmt::AbstractBean *bean, const QString &type_); + ProxyEntity(NekoGui_fmt::AbstractBean *bean, const QString &type_); [[nodiscard]] QString DisplayLatency() const; [[nodiscard]] QColor DisplayLatencyColor() const; - [[nodiscard]] fmt::ChainBean *ChainBean() const { - return (fmt::ChainBean *) bean.get(); + [[nodiscard]] NekoGui_fmt::ChainBean *ChainBean() const { + return (NekoGui_fmt::ChainBean *) bean.get(); }; - [[nodiscard]] fmt::SocksHttpBean *SocksHTTPBean() const { - return (fmt::SocksHttpBean *) bean.get(); + [[nodiscard]] NekoGui_fmt::SocksHttpBean *SocksHTTPBean() const { + return (NekoGui_fmt::SocksHttpBean *) bean.get(); }; - [[nodiscard]] fmt::ShadowSocksBean *ShadowSocksBean() const { - return (fmt::ShadowSocksBean *) bean.get(); + [[nodiscard]] NekoGui_fmt::ShadowSocksBean *ShadowSocksBean() const { + return (NekoGui_fmt::ShadowSocksBean *) bean.get(); }; - [[nodiscard]] fmt::VMessBean *VMessBean() const { - return (fmt::VMessBean *) bean.get(); + [[nodiscard]] NekoGui_fmt::VMessBean *VMessBean() const { + return (NekoGui_fmt::VMessBean *) bean.get(); }; - [[nodiscard]] fmt::TrojanVLESSBean *TrojanVLESSBean() const { - return (fmt::TrojanVLESSBean *) bean.get(); + [[nodiscard]] NekoGui_fmt::TrojanVLESSBean *TrojanVLESSBean() const { + return (NekoGui_fmt::TrojanVLESSBean *) bean.get(); }; - [[nodiscard]] fmt::NaiveBean *NaiveBean() const { - return (fmt::NaiveBean *) bean.get(); + [[nodiscard]] NekoGui_fmt::NaiveBean *NaiveBean() const { + return (NekoGui_fmt::NaiveBean *) bean.get(); }; - [[nodiscard]] fmt::HysteriaBean *HysteriaBean() const { - return (fmt::HysteriaBean *) bean.get(); + [[nodiscard]] NekoGui_fmt::HysteriaBean *HysteriaBean() const { + return (NekoGui_fmt::HysteriaBean *) bean.get(); }; - [[nodiscard]] fmt::CustomBean *CustomBean() const { - return (fmt::CustomBean *) bean.get(); + [[nodiscard]] NekoGui_fmt::CustomBean *CustomBean() const { + return (NekoGui_fmt::CustomBean *) bean.get(); }; }; -} // namespace NekoRay +} // namespace NekoGui diff --git a/db/TrafficData.hpp b/db/traffic/TrafficData.hpp similarity index 92% rename from db/TrafficData.hpp rename to db/traffic/TrafficData.hpp index 53cc29a..8e8eb87 100644 --- a/db/TrafficData.hpp +++ b/db/traffic/TrafficData.hpp @@ -1,8 +1,8 @@ #pragma once -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" -namespace NekoRay::traffic { +namespace NekoGui_traffic { class TrafficData : public JsonStore { public: int id = -1; // ent id @@ -37,4 +37,4 @@ namespace NekoRay::traffic { return UNICODE_LRO + QString("%1↑ %2↓").arg(ReadableSize(uplink), ReadableSize(downlink)); } }; -} // namespace NekoRay::traffic +} // namespace NekoGui_traffic diff --git a/db/TrafficLooper.cpp b/db/traffic/TrafficLooper.cpp similarity index 86% rename from db/TrafficLooper.cpp rename to db/traffic/TrafficLooper.cpp index b10e5ee..04f10cf 100644 --- a/db/TrafficLooper.cpp +++ b/db/traffic/TrafficLooper.cpp @@ -9,7 +9,7 @@ #include #include -namespace NekoRay::traffic { +namespace NekoGui_traffic { TrafficLooper *trafficLooper = new TrafficLooper; QElapsedTimer elapsedTimer; @@ -23,8 +23,8 @@ namespace NekoRay::traffic { if (interval <= 0) return nullptr; // query - auto uplink = NekoRay::rpc::defaultClient->QueryStats(item->tag, "uplink"); - auto downlink = NekoRay::rpc::defaultClient->QueryStats(item->tag, "downlink"); + auto uplink = NekoGui_rpc::defaultClient->QueryStats(item->tag, "uplink"); + auto downlink = NekoGui_rpc::defaultClient->QueryStats(item->tag, "downlink"); // add diff item->downlink += downlink; @@ -45,7 +45,7 @@ namespace NekoRay::traffic { QJsonArray TrafficLooper::get_connection_list() { #ifndef NKR_NO_GRPC - auto str = NekoRay::rpc::defaultClient->ListConnections(); + auto str = NekoGui_rpc::defaultClient->ListConnections(); QJsonDocument jsonDocument = QJsonDocument::fromJson(str.c_str()); return jsonDocument.array(); #else @@ -79,10 +79,10 @@ namespace NekoRay::traffic { void TrafficLooper::Loop() { elapsedTimer.start(); while (true) { - auto sleep_ms = dataStore->traffic_loop_interval; + auto sleep_ms = NekoGui::dataStore->traffic_loop_interval; if (sleep_ms < 500 || sleep_ms > 5000) sleep_ms = 1000; QThread::msleep(sleep_ms); - if (dataStore->traffic_loop_interval == 0) continue; // user disabled + if (NekoGui::dataStore->traffic_loop_interval == 0) continue; // user disabled // profile start and stop if (!loop_enabled) { @@ -109,7 +109,7 @@ namespace NekoRay::traffic { // do conn list update QJsonArray conn_list; - if (dataStore->connection_statistics) { + if (NekoGui::dataStore->connection_statistics) { conn_list = get_connection_list(); } @@ -125,11 +125,11 @@ namespace NekoRay::traffic { if (item->id < 0) continue; m->refresh_proxy_list(item->id); } - if (dataStore->connection_statistics) { + if (NekoGui::dataStore->connection_statistics) { m->refresh_connection_list(conn_list); } }); } } -} // namespace NekoRay::traffic +} // namespace NekoGui_traffic diff --git a/db/TrafficLooper.hpp b/db/traffic/TrafficLooper.hpp similarity index 80% rename from db/TrafficLooper.hpp rename to db/traffic/TrafficLooper.hpp index 2e55c52..f5b64fa 100644 --- a/db/TrafficLooper.hpp +++ b/db/traffic/TrafficLooper.hpp @@ -1,20 +1,19 @@ #pragma once -#include #include #include #include #include "TrafficData.hpp" -namespace NekoRay::traffic { +namespace NekoGui_traffic { class TrafficLooper { public: bool loop_enabled = false; bool looping = false; QMutex loop_mutex; - QList> items; + QList> items; TrafficData *proxy = nullptr; void UpdateAll(); @@ -30,4 +29,4 @@ namespace NekoRay::traffic { }; extern TrafficLooper *trafficLooper; -} // namespace NekoRay::traffic +} // namespace NekoGui_traffic diff --git a/fmt/AbstractBean.cpp b/fmt/AbstractBean.cpp index 89bf033..688bc79 100644 --- a/fmt/AbstractBean.cpp +++ b/fmt/AbstractBean.cpp @@ -4,7 +4,7 @@ #include #include -namespace NekoRay::fmt { +namespace NekoGui_fmt { AbstractBean::AbstractBean(int version) { this->version = version; _add(new configItem("_v", &this->version, itemType::integer)); @@ -52,6 +52,7 @@ namespace NekoRay::fmt { return; } +#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) // TODO older QT QHostInfo::lookupHost(serverAddress, QApplication::instance(), [=](const QHostInfo &host) { auto addr = host.addresses(); if (!addr.isEmpty()) { @@ -73,5 +74,6 @@ namespace NekoRay::fmt { } onFinished(); }); +#endif } -} // namespace NekoRay::fmt +} // namespace NekoGui_fmt diff --git a/fmt/AbstractBean.hpp b/fmt/AbstractBean.hpp index db6784b..56782fb 100644 --- a/fmt/AbstractBean.hpp +++ b/fmt/AbstractBean.hpp @@ -3,9 +3,9 @@ #include #include -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" -namespace NekoRay::fmt { +namespace NekoGui_fmt { struct CoreObjOutboundBuildResult { public: QJsonObject outbound; @@ -68,4 +68,4 @@ namespace NekoRay::fmt { virtual QString ToShareLink() { return {}; }; }; -} // namespace NekoRay::fmt +} // namespace NekoGui_fmt diff --git a/fmt/Bean2CoreObj_box.cpp b/fmt/Bean2CoreObj_box.cpp index cab8105..73a29d0 100644 --- a/fmt/Bean2CoreObj_box.cpp +++ b/fmt/Bean2CoreObj_box.cpp @@ -1,7 +1,7 @@ #include "db/ProxyEntity.hpp" #include "fmt/includes.h" -namespace NekoRay::fmt { +namespace NekoGui_fmt { void V2rayStreamSettings::BuildStreamSettingsSingBox(QJsonObject *outbound) { // https://sing-box.sagernet.org/configuration/shared/v2ray-transport @@ -44,7 +44,7 @@ namespace NekoRay::fmt { // 对应字段 tls if (security == "tls") { QJsonObject tls{{"enabled", true}}; - if (allow_insecure || dataStore->skip_cert) tls["insecure"] = true; + if (allow_insecure || NekoGui::dataStore->skip_cert) tls["insecure"] = true; if (!sni.trimmed().isEmpty()) tls["server_name"] = sni; if (!certificate.trimmed().isEmpty()) { tls["certificate"] = certificate.trimmed(); @@ -52,7 +52,7 @@ namespace NekoRay::fmt { if (!alpn.trimmed().isEmpty()) { tls["alpn"] = QList2QJsonArray(alpn.split(",")); } - auto fp = utlsFingerprint.isEmpty() ? NekoRay::dataStore->utlsFingerprint : utlsFingerprint; + auto fp = utlsFingerprint.isEmpty() ? NekoGui::dataStore->utlsFingerprint : utlsFingerprint; if (!fp.isEmpty()) { tls["utls"] = QJsonObject{ {"enabled", true}, @@ -194,4 +194,4 @@ namespace NekoRay::fmt { return result; } -} // namespace NekoRay::fmt +} // namespace NekoGui_fmt diff --git a/fmt/Bean2CoreObj_ray.cpp b/fmt/Bean2CoreObj_ray.cpp index 19ddb40..48c8095 100644 --- a/fmt/Bean2CoreObj_ray.cpp +++ b/fmt/Bean2CoreObj_ray.cpp @@ -7,7 +7,7 @@ auto streamSettings = stream->BuildStreamSettingsV2Ray(); \ outbound["streamSettings"] = streamSettings; -namespace NekoRay::fmt { +namespace NekoGui_fmt { QJsonObject V2rayStreamSettings::BuildStreamSettingsV2Ray() { QJsonObject streamSettings{{"network", network}}; @@ -56,10 +56,10 @@ namespace NekoRay::fmt { } if (security == "tls") { - auto fp = utlsFingerprint.isEmpty() ? NekoRay::dataStore->utlsFingerprint : utlsFingerprint; + auto fp = utlsFingerprint.isEmpty() ? NekoGui::dataStore->utlsFingerprint : utlsFingerprint; bool v5_utls = !fp.isEmpty(); QJsonObject tls; - if (allow_insecure || dataStore->skip_cert) tls["allowInsecure"] = true; + if (allow_insecure || NekoGui::dataStore->skip_cert) tls["allowInsecure"] = true; if (!sni.trimmed().isEmpty()) tls["serverName"] = sni; if (!certificate.trimmed().isEmpty()) { tls["disableSystemRoot"] = true; @@ -212,4 +212,4 @@ namespace NekoRay::fmt { return result; } -} // namespace NekoRay::fmt \ No newline at end of file +} // namespace NekoGui_fmt \ No newline at end of file diff --git a/fmt/Bean2External.cpp b/fmt/Bean2External.cpp index dc9c7b6..6b321f5 100644 --- a/fmt/Bean2External.cpp +++ b/fmt/Bean2External.cpp @@ -19,7 +19,7 @@ f.close(); \ auto TempFile = QFileInfo(f).absoluteFilePath(); -namespace NekoRay::fmt { +namespace NekoGui_fmt { // -1: Cannot use this config // 0: Internal // 1: Mapping External @@ -27,7 +27,7 @@ namespace NekoRay::fmt { int NaiveBean::NeedExternal(bool isFirstProfile) { if (isFirstProfile) { - if (dataStore->spmode_vpn) { + if (NekoGui::dataStore->spmode_vpn) { return 1; } return 2; @@ -38,7 +38,7 @@ namespace NekoRay::fmt { int HysteriaBean::NeedExternal(bool isFirstProfile) { auto hysteriaCore = [=] { if (isFirstProfile) { - if (dataStore->spmode_vpn && protocol != hysteria_protocol_facktcp && hopPort.trimmed().isEmpty()) { + if (NekoGui::dataStore->spmode_vpn && protocol != hysteria_protocol_facktcp && hopPort.trimmed().isEmpty()) { return 1; } return 2; @@ -69,7 +69,7 @@ namespace NekoRay::fmt { } ExternalBuildResult NaiveBean::BuildExternal(int mapping_port, int socks_port, int external_stat) { - ExternalBuildResult result{dataStore->extraCore->Get("naive")}; + ExternalBuildResult result{NekoGui::dataStore->extraCore->Get("naive")}; auto is_direct = external_stat == 2; auto domain_address = sni.isEmpty() ? serverAddress : sni; @@ -105,7 +105,7 @@ namespace NekoRay::fmt { } ExternalBuildResult HysteriaBean::BuildExternal(int mapping_port, int socks_port, int external_stat) { - ExternalBuildResult result{dataStore->extraCore->Get("hysteria")}; + ExternalBuildResult result{NekoGui::dataStore->extraCore->Get("hysteria")}; QJsonObject config; @@ -166,7 +166,7 @@ namespace NekoRay::fmt { } ExternalBuildResult CustomBean::BuildExternal(int mapping_port, int socks_port, int external_stat) { - ExternalBuildResult result{dataStore->extraCore->Get(core)}; + ExternalBuildResult result{NekoGui::dataStore->extraCore->Get(core)}; result.arguments = command; // TODO split? @@ -206,4 +206,4 @@ namespace NekoRay::fmt { return result; } -} // namespace NekoRay::fmt \ No newline at end of file +} // namespace NekoGui_fmt \ No newline at end of file diff --git a/fmt/Bean2Link.cpp b/fmt/Bean2Link.cpp index 9fb0bc1..d4bdd51 100644 --- a/fmt/Bean2Link.cpp +++ b/fmt/Bean2Link.cpp @@ -3,7 +3,7 @@ #include -namespace NekoRay::fmt { +namespace NekoGui_fmt { QString SocksHttpBean::ToShareLink() { QUrl url; if (socks_http_type == type_HTTP) { // http @@ -151,4 +151,4 @@ namespace NekoRay::fmt { return url.toString(QUrl::FullyEncoded); } -} // namespace NekoRay::fmt \ No newline at end of file +} // namespace NekoGui_fmt \ No newline at end of file diff --git a/fmt/ChainBean.hpp b/fmt/ChainBean.hpp index 718a87c..27f14ab 100644 --- a/fmt/ChainBean.hpp +++ b/fmt/ChainBean.hpp @@ -1,8 +1,8 @@ #pragma once -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" -namespace NekoRay::fmt { +namespace NekoGui_fmt { class ChainBean : public AbstractBean { public: QList list; // in to out @@ -15,4 +15,4 @@ namespace NekoRay::fmt { QString DisplayAddress() override { return ""; }; }; -} // namespace NekoRay::fmt +} // namespace NekoGui_fmt diff --git a/fmt/CustomBean.hpp b/fmt/CustomBean.hpp index 80e2fb0..c30f763 100644 --- a/fmt/CustomBean.hpp +++ b/fmt/CustomBean.hpp @@ -2,7 +2,7 @@ #include "fmt/AbstractBean.hpp" -namespace NekoRay::fmt { +namespace NekoGui_fmt { class CustomBean : public AbstractBean { public: QString core; @@ -55,4 +55,4 @@ namespace NekoRay::fmt { CoreObjOutboundBuildResult BuildCoreObjV2Ray() override; }; -} // namespace NekoRay::fmt \ No newline at end of file +} // namespace NekoGui_fmt \ No newline at end of file diff --git a/fmt/HysteriaBean.hpp b/fmt/HysteriaBean.hpp index 04ec7fa..1a8b49f 100644 --- a/fmt/HysteriaBean.hpp +++ b/fmt/HysteriaBean.hpp @@ -2,7 +2,7 @@ #include "fmt/AbstractBean.hpp" -namespace NekoRay::fmt { +namespace NekoGui_fmt { class HysteriaBean : public AbstractBean { public: static constexpr int hysteria_protocol_udp = 0; @@ -77,4 +77,4 @@ namespace NekoRay::fmt { QString ToShareLink() override; }; -} // namespace NekoRay::fmt \ No newline at end of file +} // namespace NekoGui_fmt \ No newline at end of file diff --git a/fmt/Link2Bean.cpp b/fmt/Link2Bean.cpp index 0ff14bc..b9afb90 100644 --- a/fmt/Link2Bean.cpp +++ b/fmt/Link2Bean.cpp @@ -3,7 +3,7 @@ #include -namespace NekoRay::fmt { +namespace NekoGui_fmt { #define DECODE_V2RAY_N_1 \ QString linkN = DecodeB64IfValid(SubStrBefore(SubStrAfter(link, "://"), "#"), QByteArray::Base64Option::Base64UrlEncoding); \ @@ -193,14 +193,14 @@ namespace NekoRay::fmt { auto protocolStr = (query.hasQueryItem("protocol") ? query.queryItemValue("protocol") : "udp").toLower(); if (protocolStr == "faketcp") { - protocol = fmt::HysteriaBean::hysteria_protocol_facktcp; + protocol = NekoGui_fmt::HysteriaBean::hysteria_protocol_facktcp; } else if (protocolStr.startsWith("wechat")) { - protocol = fmt::HysteriaBean::hysteria_protocol_wechat_video; + protocol = NekoGui_fmt::HysteriaBean::hysteria_protocol_wechat_video; } if (query.hasQueryItem("auth")) { authPayload = query.queryItemValue("auth"); - authPayloadType = fmt::HysteriaBean::hysteria_auth_string; + authPayloadType = NekoGui_fmt::HysteriaBean::hysteria_auth_string; } alpn = query.queryItemValue("alpn"); @@ -212,4 +212,4 @@ namespace NekoRay::fmt { return true; } -} // namespace NekoRay::fmt +} // namespace NekoGui_fmt diff --git a/fmt/NaiveBean.hpp b/fmt/NaiveBean.hpp index fa8bf31..155264a 100644 --- a/fmt/NaiveBean.hpp +++ b/fmt/NaiveBean.hpp @@ -2,7 +2,7 @@ #include "fmt/AbstractBean.hpp" -namespace NekoRay::fmt { +namespace NekoGui_fmt { class NaiveBean : public AbstractBean { public: QString username = ""; @@ -35,4 +35,4 @@ namespace NekoRay::fmt { QString ToShareLink() override; }; -} // namespace NekoRay::fmt \ No newline at end of file +} // namespace NekoGui_fmt \ No newline at end of file diff --git a/fmt/ShadowSocksBean.hpp b/fmt/ShadowSocksBean.hpp index 83cc1d5..2db40d3 100644 --- a/fmt/ShadowSocksBean.hpp +++ b/fmt/ShadowSocksBean.hpp @@ -3,7 +3,7 @@ #include "fmt/AbstractBean.hpp" #include "fmt/V2RayStreamSettings.hpp" -namespace NekoRay::fmt { +namespace NekoGui_fmt { class ShadowSocksBean : public AbstractBean { public: QString method = "aes-128-gcm"; @@ -11,7 +11,7 @@ namespace NekoRay::fmt { QString plugin = ""; bool uot = false; - QSharedPointer stream = QSharedPointer(new V2rayStreamSettings()); + std::shared_ptr stream = std::make_shared(); ShadowSocksBean() : AbstractBean(0) { _add(new configItem("method", &method, itemType::string)); @@ -31,4 +31,4 @@ namespace NekoRay::fmt { QString ToShareLink() override; }; -} // namespace NekoRay::fmt +} // namespace NekoGui_fmt diff --git a/fmt/SocksHttpBean.hpp b/fmt/SocksHttpBean.hpp index 0ff497b..ef18326 100644 --- a/fmt/SocksHttpBean.hpp +++ b/fmt/SocksHttpBean.hpp @@ -3,7 +3,7 @@ #include "fmt/AbstractBean.hpp" #include "fmt/V2RayStreamSettings.hpp" -namespace NekoRay::fmt { +namespace NekoGui_fmt { class SocksHttpBean : public AbstractBean { public: static constexpr int type_HTTP = -80; @@ -14,7 +14,7 @@ namespace NekoRay::fmt { QString username = ""; QString password = ""; - QSharedPointer stream = QSharedPointer(new V2rayStreamSettings()); + std::shared_ptr stream = std::make_shared(); explicit SocksHttpBean(int _socks_http_type) : AbstractBean(0) { this->socks_http_type = _socks_http_type; @@ -34,4 +34,4 @@ namespace NekoRay::fmt { QString ToShareLink() override; }; -} // namespace NekoRay::fmt +} // namespace NekoGui_fmt diff --git a/fmt/TrojanVLESSBean.hpp b/fmt/TrojanVLESSBean.hpp index bdfd356..e47f41d 100644 --- a/fmt/TrojanVLESSBean.hpp +++ b/fmt/TrojanVLESSBean.hpp @@ -3,7 +3,7 @@ #include "fmt/AbstractBean.hpp" #include "fmt/V2RayStreamSettings.hpp" -namespace NekoRay::fmt { +namespace NekoGui_fmt { class TrojanVLESSBean : public AbstractBean { public: static constexpr int proxy_Trojan = 0; @@ -13,7 +13,7 @@ namespace NekoRay::fmt { QString password = ""; QString flow = ""; - QSharedPointer stream = QSharedPointer(new V2rayStreamSettings()); + std::shared_ptr stream = std::make_shared(); explicit TrojanVLESSBean(int _proxy_type) : AbstractBean(0) { proxy_type = _proxy_type; @@ -32,4 +32,4 @@ namespace NekoRay::fmt { QString ToShareLink() override; }; -} // namespace NekoRay::fmt \ No newline at end of file +} // namespace NekoGui_fmt \ No newline at end of file diff --git a/fmt/V2RayStreamSettings.hpp b/fmt/V2RayStreamSettings.hpp index 9d9c0b9..3f217b1 100644 --- a/fmt/V2RayStreamSettings.hpp +++ b/fmt/V2RayStreamSettings.hpp @@ -2,7 +2,7 @@ #include "AbstractBean.hpp" -namespace NekoRay::fmt { +namespace NekoGui_fmt { class V2rayStreamSettings : public JsonStore { public: QString network = "tcp"; @@ -56,10 +56,10 @@ namespace NekoRay::fmt { if (bean == nullptr) return nullptr; auto stream_item = bean->_get("stream"); if (stream_item != nullptr) { - auto stream_store = (NekoRay::JsonStore *) stream_item->ptr; - auto stream = (NekoRay::fmt::V2rayStreamSettings *) stream_store; + auto stream_store = (JsonStore *) stream_item->ptr; + auto stream = (NekoGui_fmt::V2rayStreamSettings *) stream_store; return stream; } return nullptr; } -} // namespace NekoRay::fmt +} // namespace NekoGui_fmt diff --git a/fmt/VMessBean.hpp b/fmt/VMessBean.hpp index 6681ca1..9bbd590 100644 --- a/fmt/VMessBean.hpp +++ b/fmt/VMessBean.hpp @@ -3,14 +3,14 @@ #include "fmt/AbstractBean.hpp" #include "fmt/V2RayStreamSettings.hpp" -namespace NekoRay::fmt { +namespace NekoGui_fmt { class VMessBean : public AbstractBean { public: QString uuid = ""; int aid = 0; QString security = "auto"; - QSharedPointer stream = QSharedPointer(new V2rayStreamSettings()); + std::shared_ptr stream = std::make_shared(); VMessBean() : AbstractBean(0) { _add(new configItem("id", &uuid, itemType::string)); @@ -29,4 +29,4 @@ namespace NekoRay::fmt { QString ToShareLink() override; }; -} // namespace NekoRay::fmt +} // namespace NekoGui_fmt diff --git a/main/Const.hpp b/main/Const.hpp index 2d52d92..440c847 100644 --- a/main/Const.hpp +++ b/main/Const.hpp @@ -1,6 +1,6 @@ #pragma once -namespace NekoRay { +namespace NekoGui { namespace DomainMatcher { enum DomainMatcher { DEFAULT, @@ -22,4 +22,4 @@ namespace NekoRay { SING_BOX, }; } -} // namespace NekoRay +} // namespace NekoGui diff --git a/main/GuiUtils.hpp b/main/GuiUtils.hpp index acafbfc..6526eb2 100644 --- a/main/GuiUtils.hpp +++ b/main/GuiUtils.hpp @@ -19,48 +19,48 @@ #define P_C_LOAD_STRING(a) CACHE.a = bean->a; #define P_C_SAVE_STRING(a) bean->a = CACHE.a; -#define D_C_LOAD_STRING(a) CACHE.a = NekoRay::dataStore->a; -#define D_C_SAVE_STRING(a) NekoRay::dataStore->a = CACHE.a; +#define D_C_LOAD_STRING(a) CACHE.a = NekoGui::dataStore->a; +#define D_C_SAVE_STRING(a) NekoGui::dataStore->a = CACHE.a; #define P_LOAD_STRING(a) ui->a->setText(bean->a); #define P_SAVE_STRING(a) bean->a = ui->a->text(); #define P_SAVE_STRING_QTEXTEDIT(a) bean->a = ui->a->toPlainText(); -#define D_LOAD_STRING(a) ui->a->setText(NekoRay::dataStore->a); -#define D_SAVE_STRING(a) NekoRay::dataStore->a = ui->a->text(); -#define D_SAVE_STRING_QTEXTEDIT(a) NekoRay::dataStore->a = ui->a->toPlainText(); +#define D_LOAD_STRING(a) ui->a->setText(NekoGui::dataStore->a); +#define D_SAVE_STRING(a) NekoGui::dataStore->a = ui->a->text(); +#define D_SAVE_STRING_QTEXTEDIT(a) NekoGui::dataStore->a = ui->a->toPlainText(); #define P_LOAD_INT(a) \ ui->a->setText(Int2String(bean->a)); \ ui->a->setValidator(QRegExpValidator_Number); #define P_SAVE_INT(a) bean->a = ui->a->text().toInt(); #define D_LOAD_INT(a) \ - ui->a->setText(Int2String(NekoRay::dataStore->a)); \ + ui->a->setText(Int2String(NekoGui::dataStore->a)); \ ui->a->setValidator(QRegExpValidator_Number); -#define D_SAVE_INT(a) NekoRay::dataStore->a = ui->a->text().toInt(); +#define D_SAVE_INT(a) NekoGui::dataStore->a = ui->a->text().toInt(); #define P_LOAD_COMBO_STRING(a) ui->a->setCurrentText(bean->a); #define P_SAVE_COMBO_STRING(a) bean->a = ui->a->currentText(); -#define D_LOAD_COMBO_STRING(a) ui->a->setCurrentText(NekoRay::dataStore->a); -#define D_SAVE_COMBO_STRING(a) NekoRay::dataStore->a = ui->a->currentText(); +#define D_LOAD_COMBO_STRING(a) ui->a->setCurrentText(NekoGui::dataStore->a); +#define D_SAVE_COMBO_STRING(a) NekoGui::dataStore->a = ui->a->currentText(); #define P_LOAD_COMBO_INT(a) ui->a->setCurrentIndex(bean->a); #define P_SAVE_COMBO_INT(a) bean->a = ui->a->currentIndex(); -#define D_LOAD_BOOL(a) ui->a->setChecked(NekoRay::dataStore->a); -#define D_SAVE_BOOL(a) NekoRay::dataStore->a = ui->a->isChecked(); +#define D_LOAD_BOOL(a) ui->a->setChecked(NekoGui::dataStore->a); +#define D_SAVE_BOOL(a) NekoGui::dataStore->a = ui->a->isChecked(); #define P_LOAD_BOOL(a) ui->a->setChecked(bean->a); #define P_SAVE_BOOL(a) bean->a = ui->a->isChecked(); #define D_LOAD_INT_ENABLE(i, e) \ - if (NekoRay::dataStore->i > 0) { \ + if (NekoGui::dataStore->i > 0) { \ ui->e->setChecked(true); \ - ui->i->setText(Int2String(NekoRay::dataStore->i)); \ + ui->i->setText(Int2String(NekoGui::dataStore->i)); \ } else { \ ui->e->setChecked(false); \ - ui->i->setText(Int2String(-NekoRay::dataStore->i)); \ + ui->i->setText(Int2String(-NekoGui::dataStore->i)); \ } \ ui->i->setValidator(QRegExpValidator_Number); #define D_SAVE_INT_ENABLE(i, e) \ if (ui->e->isChecked()) { \ - NekoRay::dataStore->i = ui->i->text().toInt(); \ + NekoGui::dataStore->i = ui->i->text().toInt(); \ } else { \ - NekoRay::dataStore->i = -ui->i->text().toInt(); \ + NekoGui::dataStore->i = -ui->i->text().toInt(); \ } #define C_EDIT_JSON_ALLOW_EMPTY(a) \ diff --git a/main/HTTPRequestHelper.cpp b/main/HTTPRequestHelper.cpp index a85fc3f..7f081bc 100644 --- a/main/HTTPRequestHelper.cpp +++ b/main/HTTPRequestHelper.cpp @@ -5,27 +5,27 @@ #include #include -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" -namespace NekoRay::network { +namespace NekoGui_network { NekoHTTPResponse NetworkRequestHelper::HttpGet(const QUrl &url) { QNetworkRequest request; QNetworkAccessManager accessManager; request.setUrl(url); // Set proxy - if (NekoRay::dataStore->sub_use_proxy) { + if (NekoGui::dataStore->sub_use_proxy) { QNetworkProxy p; // Note: sing-box mixed socks5 protocol error p.setType(IS_NEKO_BOX ? QNetworkProxy::HttpProxy : QNetworkProxy::Socks5Proxy); p.setHostName("127.0.0.1"); - p.setPort(NekoRay::dataStore->inbound_socks_port); - if (dataStore->inbound_auth->NeedAuth()) { - p.setUser(dataStore->inbound_auth->username); - p.setPassword(dataStore->inbound_auth->password); + p.setPort(NekoGui::dataStore->inbound_socks_port); + if (NekoGui::dataStore->inbound_auth->NeedAuth()) { + p.setUser(NekoGui::dataStore->inbound_auth->username); + p.setPassword(NekoGui::dataStore->inbound_auth->password); } accessManager.setProxy(p); - if (NekoRay::dataStore->started_id < 0) { + if (NekoGui::dataStore->started_id < 0) { return NekoHTTPResponse{QObject::tr("Request with proxy but no profile started.")}; } } @@ -34,9 +34,11 @@ namespace NekoRay::network { accessManager.proxy().setCapabilities(cap | QNetworkProxy::HostNameLookupCapability); } // Set attribute +#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)) request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); - request.setHeader(QNetworkRequest::KnownHeaders::UserAgentHeader, NekoRay::dataStore->user_agent); - if (NekoRay::dataStore->sub_insecure) { +#endif + request.setHeader(QNetworkRequest::KnownHeaders::UserAgentHeader, NekoGui::dataStore->user_agent); + if (NekoGui::dataStore->sub_insecure) { QSslConfiguration c; c.setPeerVerifyMode(QSslSocket::PeerVerifyMode::VerifyNone); request.setSslConfiguration(c); @@ -48,7 +50,7 @@ namespace NekoRay::network { for (const auto &err: errors) { error_str << err.errorString(); } - MW_show_log(QString("SSL Errors: %1 %2").arg(error_str.join(","), NekoRay::dataStore->sub_insecure ? "(Ignored)" : "")); + MW_show_log(QString("SSL Errors: %1 %2").arg(error_str.join(","), NekoGui::dataStore->sub_insecure ? "(Ignored)" : "")); }); // { @@ -70,4 +72,4 @@ namespace NekoRay::network { return ""; } -} // namespace NekoRay::network +} // namespace NekoGui_network diff --git a/main/HTTPRequestHelper.hpp b/main/HTTPRequestHelper.hpp index 439978e..76760f0 100644 --- a/main/HTTPRequestHelper.hpp +++ b/main/HTTPRequestHelper.hpp @@ -6,7 +6,7 @@ #include #include -namespace NekoRay::network { +namespace NekoGui_network { struct NekoHTTPResponse { QString error; QByteArray data; @@ -26,6 +26,6 @@ namespace NekoRay::network { static QString GetHeader(const QList> &header, const QString &name); }; -} // namespace NekoRay::network +} // namespace NekoGui_network -using namespace NekoRay::network; +using namespace NekoGui_network; diff --git a/main/NekoRay.cpp b/main/NekoGui.cpp similarity index 95% rename from main/NekoRay.cpp rename to main/NekoGui.cpp index 9ddf01b..2a54add 100644 --- a/main/NekoRay.cpp +++ b/main/NekoGui.cpp @@ -1,10 +1,9 @@ -#include "NekoRay.hpp" +#include "NekoGui.hpp" #include #include #include #include -#include #include #include #include @@ -15,191 +14,11 @@ #include #endif -namespace NekoRay { - - DataStore *dataStore = new DataStore(); - - // datastore - - DataStore::DataStore() : JsonStore() { - _add(new configItem("extraCore", dynamic_cast(extraCore), itemType::jsonStore)); - _add(new configItem("inbound_auth", dynamic_cast(inbound_auth), itemType::jsonStore)); - - _add(new configItem("user_agent", &user_agent, itemType::string)); - _add(new configItem("test_url", &test_url, itemType::string)); - _add(new configItem("current_group", ¤t_group, itemType::integer)); - _add(new configItem("inbound_address", &inbound_address, itemType::string)); - _add(new configItem("inbound_socks_port", &inbound_socks_port, itemType::integer)); - _add(new configItem("inbound_http_port", &inbound_http_port, itemType::integer)); - _add(new configItem("log_level", &log_level, itemType::string)); - _add(new configItem("mux_protocol", &mux_protocol, itemType::string)); - _add(new configItem("mux_concurrency", &mux_concurrency, itemType::integer)); - _add(new configItem("mux_default_on", &mux_default_on, itemType::boolean)); - _add(new configItem("traffic_loop_interval", &traffic_loop_interval, itemType::integer)); - _add(new configItem("test_concurrent", &test_concurrent, itemType::integer)); - _add(new configItem("theme", &theme, itemType::string)); - _add(new configItem("custom_inbound", &custom_inbound, itemType::string)); - _add(new configItem("custom_route", &custom_route_global, itemType::string)); - _add(new configItem("v2ray_asset_dir", &v2ray_asset_dir, itemType::string)); - _add(new configItem("sub_use_proxy", &sub_use_proxy, itemType::boolean)); - _add(new configItem("remember_id", &remember_id, itemType::integer)); - _add(new configItem("remember_enable", &remember_enable, itemType::boolean)); - _add(new configItem("language", &language, itemType::integer)); - _add(new configItem("spmode2", &remember_spmode, itemType::stringList)); - _add(new configItem("skip_cert", &skip_cert, itemType::boolean)); - _add(new configItem("hk_mw", &hotkey_mainwindow, itemType::string)); - _add(new configItem("hk_group", &hotkey_group, itemType::string)); - _add(new configItem("hk_route", &hotkey_route, itemType::string)); - _add(new configItem("hk_spmenu", &hotkey_system_proxy_menu, itemType::string)); - _add(new configItem("fakedns", &fake_dns, itemType::boolean)); - _add(new configItem("active_routing", &active_routing, itemType::string)); - _add(new configItem("mw_size", &mw_size, itemType::string)); - _add(new configItem("conn_stat", &connection_statistics, itemType::boolean)); - _add(new configItem("vpn_impl", &vpn_implementation, itemType::integer)); - _add(new configItem("vpn_mtu", &vpn_mtu, itemType::integer)); - _add(new configItem("vpn_ipv6", &vpn_ipv6, itemType::boolean)); - _add(new configItem("vpn_hide_console", &vpn_hide_console, itemType::boolean)); - _add(new configItem("vpn_strict_route", &vpn_strict_route, itemType::boolean)); - _add(new configItem("vpn_bypass_process", &vpn_rule_process, itemType::string)); - _add(new configItem("vpn_bypass_cidr", &vpn_rule_cidr, itemType::string)); - _add(new configItem("vpn_rule_white", &vpn_rule_white, itemType::boolean)); - _add(new configItem("check_include_pre", &check_include_pre, itemType::boolean)); - _add(new configItem("sp_format", &system_proxy_format, itemType::string)); - _add(new configItem("sub_clear", &sub_clear, itemType::boolean)); - _add(new configItem("sub_insecure", &sub_insecure, itemType::boolean)); - _add(new configItem("enable_js_hook", &enable_js_hook, itemType::integer)); - _add(new configItem("log_ignore", &log_ignore, itemType::stringList)); - _add(new configItem("start_minimal", &start_minimal, itemType::boolean)); - _add(new configItem("max_log_line", &max_log_line, itemType::integer)); - _add(new configItem("splitter_state", &splitter_state, itemType::string)); - _add(new configItem("utlsFingerprint", &utlsFingerprint, itemType::string)); - _add(new configItem("core_box_clash_api", &core_box_clash_api, itemType::integer)); - _add(new configItem("core_box_clash_api_secret", &core_box_clash_api_secret, itemType::string)); - _add(new configItem("core_box_underlying_dns", &core_box_underlying_dns, itemType::string)); - _add(new configItem("core_ray_direct_dns", &core_ray_direct_dns, itemType::boolean)); - _add(new configItem("vpn_internal_tun", &vpn_internal_tun, itemType::boolean)); -#ifdef Q_OS_WIN - _add(new configItem("core_ray_windows_disable_auto_interface", &core_ray_windows_disable_auto_interface, itemType::boolean)); -#endif - } - - void DataStore::UpdateStartedId(int id) { - started_id = id; - if (remember_enable) { - remember_id = id; - Save(); - } else if (remember_id >= 0) { - remember_id = -1919; - Save(); - } - } - - // preset routing - Routing::Routing(int preset) : JsonStore() { - if (preset == 1) { - direct_ip = - "geoip:cn\n" - "geoip:private"; - direct_domain = "geosite:cn"; - proxy_ip = ""; - proxy_domain = ""; - block_ip = ""; - block_domain = - "geosite:category-ads-all\n" - "domain:appcenter.ms\n" - "domain:app-measurement.com\n" - "domain:firebase.io\n" - "domain:crashlytics.com\n" - "domain:google-analytics.com"; - } - _add(new configItem("direct_ip", &this->direct_ip, itemType::string)); - _add(new configItem("direct_domain", &this->direct_domain, itemType::string)); - _add(new configItem("proxy_ip", &this->proxy_ip, itemType::string)); - _add(new configItem("proxy_domain", &this->proxy_domain, itemType::string)); - _add(new configItem("block_ip", &this->block_ip, itemType::string)); - _add(new configItem("block_domain", &this->block_domain, itemType::string)); - _add(new configItem("def_outbound", &this->def_outbound, itemType::string)); - _add(new configItem("custom", &this->custom, itemType::string)); - // - _add(new configItem("remote_dns", &this->remote_dns, itemType::string)); - _add(new configItem("remote_dns_strategy", &this->remote_dns_strategy, itemType::string)); - _add(new configItem("direct_dns", &this->direct_dns, itemType::string)); - _add(new configItem("direct_dns_strategy", &this->direct_dns_strategy, itemType::string)); - _add(new configItem("domain_strategy", &this->domain_strategy, itemType::string)); - _add(new configItem("outbound_domain_strategy", &this->outbound_domain_strategy, itemType::string)); - _add(new configItem("dns_routing", &this->dns_routing, itemType::boolean)); - _add(new configItem("sniffing_mode", &this->sniffing_mode, itemType::integer)); - _add(new configItem("use_dns_object", &this->use_dns_object, itemType::boolean)); - _add(new configItem("dns_object", &this->dns_object, itemType::string)); - } - - QString Routing::DisplayRouting() const { - return QString("[Proxy] %1\n[Proxy] %2\n[Direct] %3\n[Direct] %4\n[Block] %5\n[Block] %6\n[Default Outbound] %7\n[DNS] %8") - .arg(SplitLinesSkipSharp(proxy_domain).join(",")) - .arg(SplitLinesSkipSharp(proxy_ip).join(",")) - .arg(SplitLinesSkipSharp(direct_domain).join(",")) - .arg(SplitLinesSkipSharp(direct_ip).join(",")) - .arg(SplitLinesSkipSharp(block_domain).join(",")) - .arg(SplitLinesSkipSharp(block_ip).join(",")) - .arg(def_outbound) - .arg(use_dns_object ? "DNS Object" : "Simple DNS"); - } - - QStringList Routing::List() { - QStringList l; - QDir d; - if (d.exists(ROUTES_PREFIX)) { - QDir dr(ROUTES_PREFIX); - return dr.entryList(QDir::Files); - } - return l; - } - - void Routing::SetToActive(const QString &name) { - dataStore->routing->fn = ROUTES_PREFIX + name; - dataStore->routing->Load(); - dataStore->active_routing = name; - dataStore->Save(); - } - - // NO default extra core - - ExtraCore::ExtraCore() : JsonStore() { - _add(new configItem("core_map", &this->core_map, itemType::string)); - } - - QString ExtraCore::Get(const QString &id) const { - auto obj = QString2QJsonObject(core_map); - for (const auto &c: obj.keys()) { - if (c == id) return obj[id].toString(); - } - return ""; - } - - void ExtraCore::Set(const QString &id, const QString &path) { - auto obj = QString2QJsonObject(core_map); - obj[id] = path; - core_map = QJsonObject2QString(obj, true); - } - - void ExtraCore::Delete(const QString &id) { - auto obj = QString2QJsonObject(core_map); - obj.remove(id); - core_map = QJsonObject2QString(obj, true); - } - - InboundAuthorization::InboundAuthorization() : JsonStore() { - _add(new configItem("user", &this->username, itemType::string)); - _add(new configItem("pass", &this->password, itemType::string)); - } - - bool InboundAuthorization::NeedAuth() const { - return !username.trimmed().isEmpty() && !password.trimmed().isEmpty(); - } +namespace NekoGui_ConfigItem { // 添加关联 void JsonStore::_add(configItem *item) { - _map.insert(item->name, QSharedPointer(item)); + _map.insert(item->name, std::shared_ptr(item)); } QString JsonStore::_name(void *p) { @@ -209,7 +28,7 @@ namespace NekoRay { return {}; } - QSharedPointer JsonStore::_get(const QString &name) { + std::shared_ptr JsonStore::_get(const QString &name) { // 直接 [] 会设置一个 nullptr ,所以先判断是否存在 if (_map.contains(name)) { return _map[name]; @@ -222,16 +41,16 @@ namespace NekoRay { if (item == nullptr) return; switch (item->type) { - case NekoRay::itemType::string: + case itemType::string: *(QString *) item->ptr = *(QString *) p; break; - case NekoRay::itemType::boolean: + case itemType::boolean: *(bool *) item->ptr = *(bool *) p; break; - case NekoRay::itemType::integer: + case itemType::integer: *(int *) item->ptr = *(int *) p; break; - case NekoRay::itemType::integer64: + case itemType::integer64: *(long long *) item->ptr = *(long long *) p; break; // others... @@ -394,10 +213,192 @@ namespace NekoRay { return ok; } - // +} // namespace NekoGui_ConfigItem + +namespace NekoGui { + + DataStore *dataStore = new DataStore(); + + // datastore + + DataStore::DataStore() : JsonStore() { + _add(new configItem("extraCore", dynamic_cast(extraCore), itemType::jsonStore)); + _add(new configItem("inbound_auth", dynamic_cast(inbound_auth), itemType::jsonStore)); + + _add(new configItem("user_agent", &user_agent, itemType::string)); + _add(new configItem("test_url", &test_url, itemType::string)); + _add(new configItem("current_group", ¤t_group, itemType::integer)); + _add(new configItem("inbound_address", &inbound_address, itemType::string)); + _add(new configItem("inbound_socks_port", &inbound_socks_port, itemType::integer)); + _add(new configItem("inbound_http_port", &inbound_http_port, itemType::integer)); + _add(new configItem("log_level", &log_level, itemType::string)); + _add(new configItem("mux_protocol", &mux_protocol, itemType::string)); + _add(new configItem("mux_concurrency", &mux_concurrency, itemType::integer)); + _add(new configItem("mux_default_on", &mux_default_on, itemType::boolean)); + _add(new configItem("traffic_loop_interval", &traffic_loop_interval, itemType::integer)); + _add(new configItem("test_concurrent", &test_concurrent, itemType::integer)); + _add(new configItem("theme", &theme, itemType::string)); + _add(new configItem("custom_inbound", &custom_inbound, itemType::string)); + _add(new configItem("custom_route", &custom_route_global, itemType::string)); + _add(new configItem("v2ray_asset_dir", &v2ray_asset_dir, itemType::string)); + _add(new configItem("sub_use_proxy", &sub_use_proxy, itemType::boolean)); + _add(new configItem("remember_id", &remember_id, itemType::integer)); + _add(new configItem("remember_enable", &remember_enable, itemType::boolean)); + _add(new configItem("language", &language, itemType::integer)); + _add(new configItem("spmode2", &remember_spmode, itemType::stringList)); + _add(new configItem("skip_cert", &skip_cert, itemType::boolean)); + _add(new configItem("hk_mw", &hotkey_mainwindow, itemType::string)); + _add(new configItem("hk_group", &hotkey_group, itemType::string)); + _add(new configItem("hk_route", &hotkey_route, itemType::string)); + _add(new configItem("hk_spmenu", &hotkey_system_proxy_menu, itemType::string)); + _add(new configItem("fakedns", &fake_dns, itemType::boolean)); + _add(new configItem("active_routing", &active_routing, itemType::string)); + _add(new configItem("mw_size", &mw_size, itemType::string)); + _add(new configItem("conn_stat", &connection_statistics, itemType::boolean)); + _add(new configItem("vpn_impl", &vpn_implementation, itemType::integer)); + _add(new configItem("vpn_mtu", &vpn_mtu, itemType::integer)); + _add(new configItem("vpn_ipv6", &vpn_ipv6, itemType::boolean)); + _add(new configItem("vpn_hide_console", &vpn_hide_console, itemType::boolean)); + _add(new configItem("vpn_strict_route", &vpn_strict_route, itemType::boolean)); + _add(new configItem("vpn_bypass_process", &vpn_rule_process, itemType::string)); + _add(new configItem("vpn_bypass_cidr", &vpn_rule_cidr, itemType::string)); + _add(new configItem("vpn_rule_white", &vpn_rule_white, itemType::boolean)); + _add(new configItem("check_include_pre", &check_include_pre, itemType::boolean)); + _add(new configItem("sp_format", &system_proxy_format, itemType::string)); + _add(new configItem("sub_clear", &sub_clear, itemType::boolean)); + _add(new configItem("sub_insecure", &sub_insecure, itemType::boolean)); + _add(new configItem("enable_js_hook", &enable_js_hook, itemType::integer)); + _add(new configItem("log_ignore", &log_ignore, itemType::stringList)); + _add(new configItem("start_minimal", &start_minimal, itemType::boolean)); + _add(new configItem("max_log_line", &max_log_line, itemType::integer)); + _add(new configItem("splitter_state", &splitter_state, itemType::string)); + _add(new configItem("utlsFingerprint", &utlsFingerprint, itemType::string)); + _add(new configItem("core_box_clash_api", &core_box_clash_api, itemType::integer)); + _add(new configItem("core_box_clash_api_secret", &core_box_clash_api_secret, itemType::string)); + _add(new configItem("core_box_underlying_dns", &core_box_underlying_dns, itemType::string)); + _add(new configItem("core_ray_direct_dns", &core_ray_direct_dns, itemType::boolean)); + _add(new configItem("vpn_internal_tun", &vpn_internal_tun, itemType::boolean)); +#ifdef Q_OS_WIN + _add(new configItem("core_ray_windows_disable_auto_interface", &core_ray_windows_disable_auto_interface, itemType::boolean)); +#endif + } + + void DataStore::UpdateStartedId(int id) { + started_id = id; + if (remember_enable) { + remember_id = id; + Save(); + } else if (remember_id >= 0) { + remember_id = -1919; + Save(); + } + } + + // preset routing + Routing::Routing(int preset) : JsonStore() { + if (preset == 1) { + direct_ip = + "geoip:cn\n" + "geoip:private"; + direct_domain = "geosite:cn"; + proxy_ip = ""; + proxy_domain = ""; + block_ip = ""; + block_domain = + "geosite:category-ads-all\n" + "domain:appcenter.ms\n" + "domain:app-measurement.com\n" + "domain:firebase.io\n" + "domain:crashlytics.com\n" + "domain:google-analytics.com"; + } + _add(new configItem("direct_ip", &this->direct_ip, itemType::string)); + _add(new configItem("direct_domain", &this->direct_domain, itemType::string)); + _add(new configItem("proxy_ip", &this->proxy_ip, itemType::string)); + _add(new configItem("proxy_domain", &this->proxy_domain, itemType::string)); + _add(new configItem("block_ip", &this->block_ip, itemType::string)); + _add(new configItem("block_domain", &this->block_domain, itemType::string)); + _add(new configItem("def_outbound", &this->def_outbound, itemType::string)); + _add(new configItem("custom", &this->custom, itemType::string)); + // + _add(new configItem("remote_dns", &this->remote_dns, itemType::string)); + _add(new configItem("remote_dns_strategy", &this->remote_dns_strategy, itemType::string)); + _add(new configItem("direct_dns", &this->direct_dns, itemType::string)); + _add(new configItem("direct_dns_strategy", &this->direct_dns_strategy, itemType::string)); + _add(new configItem("domain_strategy", &this->domain_strategy, itemType::string)); + _add(new configItem("outbound_domain_strategy", &this->outbound_domain_strategy, itemType::string)); + _add(new configItem("dns_routing", &this->dns_routing, itemType::boolean)); + _add(new configItem("sniffing_mode", &this->sniffing_mode, itemType::integer)); + _add(new configItem("use_dns_object", &this->use_dns_object, itemType::boolean)); + _add(new configItem("dns_object", &this->dns_object, itemType::string)); + } + + QString Routing::DisplayRouting() const { + return QString("[Proxy] %1\n[Proxy] %2\n[Direct] %3\n[Direct] %4\n[Block] %5\n[Block] %6\n[Default Outbound] %7\n[DNS] %8") + .arg(SplitLinesSkipSharp(proxy_domain).join(",")) + .arg(SplitLinesSkipSharp(proxy_ip).join(",")) + .arg(SplitLinesSkipSharp(direct_domain).join(",")) + .arg(SplitLinesSkipSharp(direct_ip).join(",")) + .arg(SplitLinesSkipSharp(block_domain).join(",")) + .arg(SplitLinesSkipSharp(block_ip).join(",")) + .arg(def_outbound) + .arg(use_dns_object ? "DNS Object" : "Simple DNS"); + } + + QStringList Routing::List() { + QStringList l; + QDir d; + if (d.exists(ROUTES_PREFIX)) { + QDir dr(ROUTES_PREFIX); + return dr.entryList(QDir::Files); + } + return l; + } + + void Routing::SetToActive(const QString &name) { + NekoGui::dataStore->routing->fn = ROUTES_PREFIX + name; + NekoGui::dataStore->routing->Load(); + NekoGui::dataStore->active_routing = name; + NekoGui::dataStore->Save(); + } + + // NO default extra core + + ExtraCore::ExtraCore() : JsonStore() { + _add(new configItem("core_map", &this->core_map, itemType::string)); + } + + QString ExtraCore::Get(const QString &id) const { + auto obj = QString2QJsonObject(core_map); + for (const auto &c: obj.keys()) { + if (c == id) return obj[id].toString(); + } + return ""; + } + + void ExtraCore::Set(const QString &id, const QString &path) { + auto obj = QString2QJsonObject(core_map); + obj[id] = path; + core_map = QJsonObject2QString(obj, true); + } + + void ExtraCore::Delete(const QString &id) { + auto obj = QString2QJsonObject(core_map); + obj.remove(id); + core_map = QJsonObject2QString(obj, true); + } + + InboundAuthorization::InboundAuthorization() : JsonStore() { + _add(new configItem("user", &this->username, itemType::string)); + _add(new configItem("pass", &this->password, itemType::string)); + } + + bool InboundAuthorization::NeedAuth() const { + return !username.trimmed().isEmpty() && !password.trimmed().isEmpty(); + } QString FindCoreAsset(const QString &name) { - QStringList search{dataStore->v2ray_asset_dir}; + QStringList search{NekoGui::dataStore->v2ray_asset_dir}; search << QApplication::applicationDirPath(); search << "/usr/share/v2ray"; search << "/usr/local/share/v2ray"; @@ -422,7 +423,7 @@ namespace NekoRay { bool isAdmin() { if (isAdminCache >= 0) return isAdminCache; - auto admin = NekoRay::dataStore->flag_linux_run_core_as_admin; + auto admin = NekoGui::dataStore->flag_linux_run_core_as_admin; #ifdef Q_OS_WIN admin = Windows_IsInAdmin(); #else @@ -433,4 +434,4 @@ namespace NekoRay { return admin; }; -} // namespace NekoRay +} // namespace NekoGui diff --git a/main/NekoGui.hpp b/main/NekoGui.hpp new file mode 100644 index 0000000..d6e6db5 --- /dev/null +++ b/main/NekoGui.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "Const.hpp" +#include "NekoGui_Utils.hpp" +#include "NekoGui_ConfigItem.hpp" +#include "NekoGui_DataStore.hpp" + +// Switch core support + +namespace NekoGui { + inline int coreType = CoreType::V2RAY; + + QString FindCoreAsset(const QString &name); + + bool isAdmin(); +} // namespace NekoGui + +#define IS_NEKO_BOX (NekoGui::coreType == NekoGui::CoreType::SING_BOX) +#define IS_NEKO_BOX_INTERNAL_TUN (IS_NEKO_BOX && NekoGui::dataStore->vpn_internal_tun) +#define ROUTES_PREFIX_NAME QString(IS_NEKO_BOX ? "routes_box" : "routes") +#define ROUTES_PREFIX QString(ROUTES_PREFIX_NAME + "/") diff --git a/main/NekoRay_ConfigItem.hpp b/main/NekoGui_ConfigItem.hpp similarity index 85% rename from main/NekoRay_ConfigItem.hpp rename to main/NekoGui_ConfigItem.hpp index 1691783..8b0f602 100644 --- a/main/NekoRay_ConfigItem.hpp +++ b/main/NekoGui_ConfigItem.hpp @@ -1,6 +1,6 @@ // DO NOT INCLUDE THIS -namespace NekoRay { +namespace NekoGui_ConfigItem { // config 工具 enum itemType { string, @@ -28,7 +28,7 @@ namespace NekoRay { // 可格式化对象 class JsonStore { public: - QMap> _map; + QMap> _map; std::function callback_after_load = nullptr; std::function callback_before_save = nullptr; @@ -49,7 +49,7 @@ namespace NekoRay { QString _name(void *p); - QSharedPointer _get(const QString &name); + std::shared_ptr _get(const QString &name); void _setValue(const QString &name, void *p); @@ -65,4 +65,6 @@ namespace NekoRay { bool Load(); }; -} // namespace NekoRay +} // namespace NekoGui_ConfigItem + +using namespace NekoGui_ConfigItem; diff --git a/main/NekoRay_DataStore.hpp b/main/NekoGui_DataStore.hpp similarity index 99% rename from main/NekoRay_DataStore.hpp rename to main/NekoGui_DataStore.hpp index e52db53..b9acf2b 100644 --- a/main/NekoRay_DataStore.hpp +++ b/main/NekoGui_DataStore.hpp @@ -1,6 +1,6 @@ // DO NOT INCLUDE THIS -namespace NekoRay { +namespace NekoGui { class Routing : public JsonStore { public: @@ -175,4 +175,4 @@ namespace NekoRay { extern DataStore *dataStore; -} // namespace NekoRay +} // namespace NekoGui diff --git a/main/NekoRay_Utils.cpp b/main/NekoGui_Utils.cpp similarity index 99% rename from main/NekoRay_Utils.cpp rename to main/NekoGui_Utils.cpp index b8d2ab8..1226bf6 100644 --- a/main/NekoRay_Utils.cpp +++ b/main/NekoGui_Utils.cpp @@ -1,4 +1,4 @@ -#include "NekoRay_Utils.hpp" +#include "NekoGui_Utils.hpp" #include "3rdparty/base64.h" #include "3rdparty/QThreadCreateThread.hpp" @@ -189,7 +189,7 @@ bool IsIpAddressV6(const QString &str) { QString DisplayTime(long long time, int formatType) { QDateTime t; - t.setSecsSinceEpoch(time); + t.setMSecsSinceEpoch(time * 1000); return QLocale().toString(t, QLocale::FormatType(formatType)); } diff --git a/main/NekoRay_Utils.hpp b/main/NekoGui_Utils.hpp similarity index 100% rename from main/NekoRay_Utils.hpp rename to main/NekoGui_Utils.hpp diff --git a/main/NekoRay.hpp b/main/NekoRay.hpp deleted file mode 100644 index 96d7ccb..0000000 --- a/main/NekoRay.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "Const.hpp" -#include "NekoRay_Utils.hpp" -#include "NekoRay_ConfigItem.hpp" -#include "NekoRay_DataStore.hpp" - -// Switch core support - -namespace NekoRay { - inline int coreType = NekoRay::CoreType::V2RAY; - - QString FindCoreAsset(const QString &name); - - bool isAdmin(); - -} // namespace NekoRay - -#define IS_NEKO_BOX (NekoRay::coreType == NekoRay::CoreType::SING_BOX) -#define IS_NEKO_BOX_INTERNAL_TUN (IS_NEKO_BOX && NekoRay::dataStore->vpn_internal_tun) -#define ROUTES_PREFIX_NAME QString(IS_NEKO_BOX ? "routes_box" : "routes") -#define ROUTES_PREFIX QString(ROUTES_PREFIX_NAME + "/") diff --git a/main/QJS.cpp b/main/QJS.cpp index 0a276bb..b5ee85e 100644 --- a/main/QJS.cpp +++ b/main/QJS.cpp @@ -5,9 +5,9 @@ #endif #include "3rdparty/qjs/nekoray_qjs.h" -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" -namespace NekoRay::qjs { +namespace qjs { #ifndef NKR_NO_QUICKJS namespace exception { static void js_dump_obj(JSContext *ctx, QString &out, JSValueConst val) { @@ -80,7 +80,7 @@ namespace NekoRay::qjs { this->neko_ctx = malloc(sizeof(nekoray_qjs_context)); nekoray_qjs_new_arg arg; arg.neko_ctx = NEKO_CTX; - arg.enable_std = NekoRay::dataStore->enable_js_hook == 2 ? 1 : 0; + arg.enable_std = NekoGui::dataStore->enable_js_hook == 2 ? 1 : 0; arg.func_log = func_log; nekoray_qjs_new(arg); #endif @@ -139,10 +139,10 @@ namespace NekoRay::qjs { QByteArray ReadHookJS() { #ifndef NKR_NO_QUICKJS - if (NekoRay::dataStore->enable_js_hook > 0) { + if (NekoGui::dataStore->enable_js_hook > 0) { return ReadFile(QString("./hook.%1.js").arg(software_name.toLower())); } #endif return {}; } -} // namespace NekoRay::qjs +} // namespace qjs diff --git a/main/QJS.hpp b/main/QJS.hpp index 466d761..34e39b3 100644 --- a/main/QJS.hpp +++ b/main/QJS.hpp @@ -3,7 +3,7 @@ class QByteArray; class QString; -namespace NekoRay::qjs { +namespace qjs { class QJS { public: QJS(); @@ -20,4 +20,4 @@ namespace NekoRay::qjs { }; QByteArray ReadHookJS(); -} // namespace NekoRay::qjs +} // namespace qjs diff --git a/main/main.cpp b/main/main.cpp index 359704d..6ceb0d1 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -10,7 +10,7 @@ #include #include "3rdparty/RunGuard.hpp" -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" #include "ui/mainwindow_interface.h" #include "ui/dialog_first_setup.h" @@ -58,10 +58,12 @@ int main(int argc, char* argv[]) { #endif // pre-init QApplication -#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton); #endif +#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0) QApplication::setAttribute(Qt::AA_DontUseNativeDialogs); +#endif QApplication::setQuitOnLastWindowClosed(false); auto preQApp = new QApplication(argc, argv); @@ -77,31 +79,31 @@ int main(int argc, char* argv[]) { #endif // Flags - NekoRay::dataStore->argv = QApplication::arguments(); - if (NekoRay::dataStore->argv.contains("-many")) NekoRay::dataStore->flag_many = true; - if (NekoRay::dataStore->argv.contains("-appdata")) { - NekoRay::dataStore->flag_use_appdata = true; - int appdataIndex = NekoRay::dataStore->argv.indexOf("-appdata"); - if (NekoRay::dataStore->argv.size() > appdataIndex + 1 && !NekoRay::dataStore->argv.at(appdataIndex + 1).startsWith("-")) { - NekoRay::dataStore->appdataDir = NekoRay::dataStore->argv.at(appdataIndex + 1); + NekoGui::dataStore->argv = QApplication::arguments(); + if (NekoGui::dataStore->argv.contains("-many")) NekoGui::dataStore->flag_many = true; + if (NekoGui::dataStore->argv.contains("-appdata")) { + NekoGui::dataStore->flag_use_appdata = true; + int appdataIndex = NekoGui::dataStore->argv.indexOf("-appdata"); + if (NekoGui::dataStore->argv.size() > appdataIndex + 1 && !NekoGui::dataStore->argv.at(appdataIndex + 1).startsWith("-")) { + NekoGui::dataStore->appdataDir = NekoGui::dataStore->argv.at(appdataIndex + 1); } } - if (NekoRay::dataStore->argv.contains("-tray")) NekoRay::dataStore->flag_tray = true; - if (NekoRay::dataStore->argv.contains("-debug")) NekoRay::dataStore->flag_debug = true; - if (NekoRay::dataStore->argv.contains("-flag_linux_run_core_as_admin")) NekoRay::dataStore->flag_linux_run_core_as_admin = true; + if (NekoGui::dataStore->argv.contains("-tray")) NekoGui::dataStore->flag_tray = true; + if (NekoGui::dataStore->argv.contains("-debug")) NekoGui::dataStore->flag_debug = true; + if (NekoGui::dataStore->argv.contains("-flag_linux_run_core_as_admin")) NekoGui::dataStore->flag_linux_run_core_as_admin = true; #ifdef NKR_CPP_USE_APPDATA - NekoRay::dataStore->flag_use_appdata = true; // Example: Package & MacOS + NekoGui::dataStore->flag_use_appdata = true; // Example: Package & MacOS #endif #ifdef NKR_CPP_DEBUG - NekoRay::dataStore->flag_debug = true; + NekoGui::dataStore->flag_debug = true; #endif // dirs & clean auto wd = QDir(QApplication::applicationDirPath()); - if (NekoRay::dataStore->flag_use_appdata) { + if (NekoGui::dataStore->flag_use_appdata) { QApplication::setApplicationName("nekoray"); - if (!NekoRay::dataStore->appdataDir.isEmpty()) { - wd.setPath(NekoRay::dataStore->appdataDir); + if (!NekoGui::dataStore->appdataDir.isEmpty()) { + wd.setPath(NekoGui::dataStore->appdataDir); } else { wd.setPath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); } @@ -111,13 +113,6 @@ int main(int argc, char* argv[]) { QDir::setCurrent(wd.absoluteFilePath("config")); QDir("temp").removeRecursively(); - // HiDPI workaround - // Mainly for Windows, not required in Qt6 - if (ReadFileText("./groups/HiDPI").toInt() == 1) { - QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); - QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); - } - // init QApplication delete preQApp; QApplication a(argc, argv); @@ -130,7 +125,7 @@ int main(int argc, char* argv[]) { RunGuard guard("nekoray" + wd.absolutePath()); quint64 guard_data_in = GetRandomUint64(); quint64 guard_data_out = 0; - if (!NekoRay::dataStore->flag_many && !guard.tryToRun(&guard_data_in)) { + if (!NekoGui::dataStore->flag_many && !guard.tryToRun(&guard_data_in)) { // Some Good System if (guard.isAnotherRunning(&guard_data_out)) { // Wake up a running instance @@ -150,11 +145,18 @@ int main(int argc, char* argv[]) { } MF_release_runguard = [&] { guard.release(); }; - // icons +// icons +#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0)) QIcon::setFallbackSearchPaths(QStringList{ ":/nekoray", ":/icon", }); +#else + QIcon::setThemeSearchPaths(QStringList{ + ":/nekoray", + ":/icon", + }); +#endif // icon for no theme if (QIcon::themeName().isEmpty()) { @@ -164,23 +166,23 @@ int main(int argc, char* argv[]) { // Load coreType auto coreLoaded = ReadFileText("groups/coreType"); if (coreLoaded.isEmpty()) { - NekoRay::coreType = -1; + NekoGui::coreType = -1; loadTranslate(QLocale().name()); auto dialogFirstSetup = new DialogFirstSetup; dialogFirstSetup->exec(); dialogFirstSetup->deleteLater(); - if (NekoRay::coreType < 0) { + if (NekoGui::coreType < 0) { return 0; } else { QDir().mkdir("groups"); QFile file; file.setFileName("groups/coreType"); file.open(QIODevice::ReadWrite | QIODevice::Truncate); - file.write(Int2String(NekoRay::coreType).toUtf8()); + file.write(Int2String(NekoGui::coreType).toUtf8()); file.close(); } } else { - NekoRay::coreType = coreLoaded.toInt(); + NekoGui::coreType = coreLoaded.toInt(); } // Dir @@ -201,35 +203,35 @@ int main(int argc, char* argv[]) { } // Load dataStore - switch (NekoRay::coreType) { - case NekoRay::CoreType::V2RAY: - NekoRay::dataStore->fn = "groups/nekoray.json"; + switch (NekoGui::coreType) { + case NekoGui::CoreType::V2RAY: + NekoGui::dataStore->fn = "groups/nekoray.json"; break; - case NekoRay::CoreType::SING_BOX: - NekoRay::dataStore->fn = "groups/nekobox.json"; + case NekoGui::CoreType::SING_BOX: + NekoGui::dataStore->fn = "groups/nekobox.json"; break; default: MessageBoxWarning("Error", "Unknown coreType."); return 0; } - auto isLoaded = NekoRay::dataStore->Load(); + auto isLoaded = NekoGui::dataStore->Load(); if (!isLoaded) { - NekoRay::dataStore->Save(); + NekoGui::dataStore->Save(); } // Datastore & Flags - if (NekoRay::dataStore->start_minimal) NekoRay::dataStore->flag_tray = true; + if (NekoGui::dataStore->start_minimal) NekoGui::dataStore->flag_tray = true; // load routing - NekoRay::dataStore->routing->fn = ROUTES_PREFIX + NekoRay::dataStore->active_routing; - isLoaded = NekoRay::dataStore->routing->Load(); + NekoGui::dataStore->routing->fn = ROUTES_PREFIX + NekoGui::dataStore->active_routing; + isLoaded = NekoGui::dataStore->routing->Load(); if (!isLoaded) { - NekoRay::dataStore->routing->Save(); + NekoGui::dataStore->routing->Save(); } // Translate QString locale; - switch (NekoRay::dataStore->language) { + switch (NekoGui::dataStore->language) { case 1: // English break; case 2: @@ -262,13 +264,13 @@ int main(int argc, char* argv[]) { }); // Do preset update - if (NekoRay::dataStore->user_agent.isEmpty() || NekoRay::dataStore->user_agent.startsWith("Nekoray/1.0") || NekoRay::dataStore->user_agent.startsWith("ClashForAndroid")) { + if (NekoGui::dataStore->user_agent.isEmpty() || NekoGui::dataStore->user_agent.startsWith("Nekoray/1.0") || NekoGui::dataStore->user_agent.startsWith("ClashForAndroid")) { if (IS_NEKO_BOX) { - NekoRay::dataStore->user_agent = "NekoBox/PC/2.0 (Prefer ClashMeta Format)"; + NekoGui::dataStore->user_agent = "NekoBox/PC/2.0 (Prefer ClashMeta Format)"; } else { - NekoRay::dataStore->user_agent = "NekoRay/PC/2.0 (Prefer ClashMeta Format)"; + NekoGui::dataStore->user_agent = "NekoRay/PC/2.0 (Prefer ClashMeta Format)"; } - NekoRay::dataStore->Save(); + NekoGui::dataStore->Save(); } UI_InitMainWindow(); diff --git a/rpc/gRPC.cpp b/rpc/gRPC.cpp index 4131d37..7d043a7 100644 --- a/rpc/gRPC.cpp +++ b/rpc/gRPC.cpp @@ -5,7 +5,7 @@ #ifndef NKR_NO_GRPC -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" #include #include @@ -166,7 +166,7 @@ namespace QtGrpc { QNetworkReply::NetworkError Call(const QString &methodName, const google::protobuf::Message &req, google::protobuf::Message *rsp, int timeout_ms = 0) { - if (!NekoRay::dataStore->core_running) return QNetworkReply::NetworkError(-1919); + if (!NekoGui::dataStore->core_running) return QNetworkReply::NetworkError(-1919); std::string reqStr; req.SerializeToString(&reqStr); @@ -200,7 +200,7 @@ namespace QtGrpc { }; } // namespace QtGrpc -namespace NekoRay::rpc { +namespace NekoGui_rpc { Client::Client(std::function onError, const QString &target, const QString &token) { this->make_grpc_channel = [=]() { return std::make_unique(target, token, "libcore.LibcoreService"); }; @@ -299,6 +299,6 @@ namespace NekoRay::rpc { return reply; } } -} // namespace NekoRay::rpc +} // namespace NekoGui_rpc #endif diff --git a/rpc/gRPC.h b/rpc/gRPC.h index 02ced3f..25c03a0 100644 --- a/rpc/gRPC.h +++ b/rpc/gRPC.h @@ -9,7 +9,7 @@ namespace QtGrpc { class Http2GrpcChannelPrivate; } -namespace NekoRay::rpc { +namespace NekoGui_rpc { class Client { public: explicit Client(std::function onError, const QString &target, const QString &token); @@ -39,5 +39,5 @@ namespace NekoRay::rpc { }; inline Client *defaultClient; -} // namespace NekoRay::rpc +} // namespace NekoGui_rpc #endif diff --git a/sub/GroupUpdater.cpp b/sub/GroupUpdater.cpp index 9f77ccd..1fe0070 100644 --- a/sub/GroupUpdater.cpp +++ b/sub/GroupUpdater.cpp @@ -16,13 +16,13 @@ #endif -namespace NekoRay::sub { +namespace NekoGui_sub { GroupUpdater *groupUpdater = new GroupUpdater; - void RawUpdater_FixEnt(const QSharedPointer &ent) { + void RawUpdater_FixEnt(const std::shared_ptr &ent) { if (ent == nullptr) return; - auto stream = fmt::GetStreamSettings(ent->bean.get()); + auto stream = NekoGui_fmt::GetStreamSettings(ent->bean.get()); if (stream == nullptr) return; // 1. "security" if (stream->security == "none" || stream->security == "0" || stream->security == "false") { @@ -58,7 +58,7 @@ namespace NekoRay::sub { return; } - QSharedPointer ent; + std::shared_ptr ent; bool needFix = true; // Nekoray format @@ -66,7 +66,7 @@ namespace NekoRay::sub { needFix = false; auto link = QUrl(str); if (!link.isValid()) return; - ent = ProfileManager::NewProxyEntity(link.host()); + ent = NekoGui::ProfileManager::NewProxyEntity(link.host()); if (ent->bean->version == -114514) return; auto j = DecodeB64IfValid(link.fragment().toUtf8(), QByteArray::Base64UrlEncoding); if (j.isEmpty()) return; @@ -77,42 +77,42 @@ namespace NekoRay::sub { // SOCKS if (str.startsWith("socks5://") || str.startsWith("socks4://") || str.startsWith("socks4a://") || str.startsWith("socks://")) { - ent = ProfileManager::NewProxyEntity("socks"); + ent = NekoGui::ProfileManager::NewProxyEntity("socks"); auto ok = ent->SocksHTTPBean()->TryParseLink(str); if (!ok) return; } // HTTP if (str.startsWith("http://") || str.startsWith("https://")) { - ent = ProfileManager::NewProxyEntity("http"); + ent = NekoGui::ProfileManager::NewProxyEntity("http"); auto ok = ent->SocksHTTPBean()->TryParseLink(str); if (!ok) return; } // ShadowSocks if (str.startsWith("ss://")) { - ent = ProfileManager::NewProxyEntity("shadowsocks"); + ent = NekoGui::ProfileManager::NewProxyEntity("shadowsocks"); auto ok = ent->ShadowSocksBean()->TryParseLink(str); if (!ok) return; } // VMess if (str.startsWith("vmess://")) { - ent = ProfileManager::NewProxyEntity("vmess"); + ent = NekoGui::ProfileManager::NewProxyEntity("vmess"); auto ok = ent->VMessBean()->TryParseLink(str); if (!ok) return; } // VLESS if (str.startsWith("vless://")) { - ent = ProfileManager::NewProxyEntity("vless"); + ent = NekoGui::ProfileManager::NewProxyEntity("vless"); auto ok = ent->TrojanVLESSBean()->TryParseLink(str); if (!ok) return; } // Trojan if (str.startsWith("trojan://")) { - ent = ProfileManager::NewProxyEntity("trojan"); + ent = NekoGui::ProfileManager::NewProxyEntity("trojan"); auto ok = ent->TrojanVLESSBean()->TryParseLink(str); if (!ok) return; } @@ -120,7 +120,7 @@ namespace NekoRay::sub { // Naive if (str.startsWith("naive+")) { needFix = false; - ent = ProfileManager::NewProxyEntity("naive"); + ent = NekoGui::ProfileManager::NewProxyEntity("naive"); auto ok = ent->NaiveBean()->TryParseLink(str); if (!ok) return; } @@ -128,7 +128,7 @@ namespace NekoRay::sub { // Hysteria if (str.startsWith("hysteria://")) { needFix = false; - ent = ProfileManager::NewProxyEntity("hysteria"); + ent = NekoGui::ProfileManager::NewProxyEntity("hysteria"); auto ok = ent->HysteriaBean()->TryParseLink(str); if (!ok) return; } @@ -139,7 +139,7 @@ namespace NekoRay::sub { if (needFix) RawUpdater_FixEnt(ent); // End - profileManager->AddProfile(ent, gid_add_to); + NekoGui::profileManager->AddProfile(ent, gid_add_to); update_counter++; } @@ -217,7 +217,7 @@ namespace NekoRay::sub { if (type == "ss" || type == "ssr") type = "shadowsocks"; if (type == "socks5") type = "socks"; - auto ent = ProfileManager::NewProxyEntity(type); + auto ent = NekoGui::ProfileManager::NewProxyEntity(type); if (ent->bean->version == -114514) continue; bool needFix = false; @@ -372,11 +372,11 @@ namespace NekoRay::sub { auto auth_str = FIRST_OR_SECOND(Node2QString(proxy["auth_str"]), Node2QString(proxy["auth-str"])); auto auth = Node2QString(proxy["auth"]); if (!auth_str.isEmpty()) { - bean->authPayloadType = fmt::HysteriaBean::hysteria_auth_string; + bean->authPayloadType = NekoGui_fmt::HysteriaBean::hysteria_auth_string; bean->authPayload = auth_str; } if (!auth.isEmpty()) { - bean->authPayloadType = fmt::HysteriaBean::hysteria_auth_base64; + bean->authPayloadType = NekoGui_fmt::HysteriaBean::hysteria_auth_base64; bean->authPayload = auth; } @@ -393,7 +393,7 @@ namespace NekoRay::sub { } if (needFix) RawUpdater_FixEnt(ent); - profileManager->AddProfile(ent, gid_add_to); + NekoGui::profileManager->AddProfile(ent, gid_add_to); update_counter++; } } catch (const YAML::Exception &ex) { @@ -429,10 +429,10 @@ namespace NekoRay::sub { runOnNewThread([=] { auto gid = _sub_gid; if (createNewGroup) { - auto group = ProfileManager::NewGroup(); + auto group = NekoGui::ProfileManager::NewGroup(); group->name = QUrl(str).host(); group->url = str; - profileManager->AddGroup(group); + NekoGui::profileManager->AddGroup(group); gid = group->id; MW_dialog_message("SubUpdater", "NewGroup"); } @@ -444,7 +444,7 @@ namespace NekoRay::sub { void GroupUpdater::Update(const QString &_str, int _sub_gid, bool _not_sub_as_url) { // 创建 rawUpdater - NekoRay::dataStore->imported_count = 0; + NekoGui::dataStore->imported_count = 0; auto rawUpdater = std::make_unique(); rawUpdater->gid_add_to = _sub_gid; @@ -452,7 +452,7 @@ namespace NekoRay::sub { QString sub_user_info; bool asURL = _sub_gid >= 0 || _not_sub_as_url; // 把 _str 当作 url 处理(下载内容) auto content = _str.trimmed(); - auto group = profileManager->GetGroup(_sub_gid); + auto group = NekoGui::profileManager->GetGroup(_sub_gid); if (group != nullptr && group->archive) return; // 网络请求 @@ -472,25 +472,25 @@ namespace NekoRay::sub { MW_show_log("<<<<<<<< " + QObject::tr("Subscription request fininshed: %1").arg(groupName)); } - QList> in; // 更新前 - QList> out_all; // 更新前 + 更新后 - QList> out; // 更新后 - QList> only_in; // 只在更新前有的 - QList> only_out; // 只在更新后有的 - QList> update_del; // 更新前后都有的,删除更新后多余的 + QList> in; // 更新前 + QList> out_all; // 更新前 + 更新后 + QList> out; // 更新后 + QList> only_in; // 只在更新前有的 + QList> only_out; // 只在更新后有的 + QList> update_del; // 更新前后都有的,删除更新后多余的 // 订阅解析前 if (group != nullptr) { in = group->Profiles(); - group->last_update = QDateTime::currentSecsSinceEpoch(); + group->sub_last_update = QDateTime::currentMSecsSinceEpoch() / 1000; group->info = sub_user_info; group->order.clear(); group->Save(); // - if (dataStore->sub_clear) { + if (NekoGui::dataStore->sub_clear) { MW_show_log(QObject::tr("Clearing servers...")); for (const auto &profile: in) { - profileManager->DeleteProfile(profile->id); + NekoGui::profileManager->DeleteProfile(profile->id); } } } @@ -512,15 +512,15 @@ namespace NekoRay::sub { if (group != nullptr) { out_all = group->Profiles(); - ProfileFilter::OnlyInSrc_ByPointer(out_all, in, out); - ProfileFilter::OnlyInSrc(in, out, only_in); - ProfileFilter::OnlyInSrc(out, in, only_out); - ProfileFilter::Common(in, out, update_del, false, true); + NekoGui::ProfileFilter::OnlyInSrc_ByPointer(out_all, in, out); + NekoGui::ProfileFilter::OnlyInSrc(in, out, only_in); + NekoGui::ProfileFilter::OnlyInSrc(out, in, only_out); + NekoGui::ProfileFilter::Common(in, out, update_del, false, true); update_del += only_in; - if (dataStore->sub_clear) update_del = {}; + if (NekoGui::dataStore->sub_clear) update_del = {}; for (const auto &ent: update_del) { - profileManager->DeleteProfile(ent->id); + NekoGui::profileManager->DeleteProfile(ent->id); } QString notice_added; @@ -541,8 +541,8 @@ namespace NekoRay::sub { MW_show_log("<<<<<<<< " + QObject::tr("Change of %1:").arg(group->name) + " " + change); MW_dialog_message("SubUpdater", "finish-dingyue"); } else { - NekoRay::dataStore->imported_count = rawUpdater->update_counter; + NekoGui::dataStore->imported_count = rawUpdater->update_counter; MW_dialog_message("SubUpdater", "finish"); } } -} // namespace NekoRay::sub +} // namespace NekoGui_sub diff --git a/sub/GroupUpdater.hpp b/sub/GroupUpdater.hpp index 4fd9a14..20d380c 100644 --- a/sub/GroupUpdater.hpp +++ b/sub/GroupUpdater.hpp @@ -2,7 +2,7 @@ #include -namespace NekoRay::sub { +namespace NekoGui_sub { class RawUpdater { public: void updateClash(const QString &str); @@ -28,4 +28,4 @@ namespace NekoRay::sub { }; extern GroupUpdater *groupUpdater; -} // namespace NekoRay::sub +} // namespace NekoGui_sub diff --git a/sys/AutoRun.cpp b/sys/AutoRun.cpp index 689e9e3..6e25bc1 100644 --- a/sys/AutoRun.cpp +++ b/sys/AutoRun.cpp @@ -3,7 +3,8 @@ #include #include -#include "main/NekoRay.hpp" +#include "3rdparty/fix_old_qt.h" +#include "main/NekoGui.hpp" // macOS headers (possibly OBJ-c) #if defined(Q_OS_MACOS) @@ -178,7 +179,7 @@ void AutoRun_SetEnabled(bool enable) { appCmdList << "-tray"; - if (NekoRay::dataStore->flag_use_appdata) { + if (NekoGui::dataStore->flag_use_appdata) { appCmdList << "-appdata"; } diff --git a/sys/ExternalProcess.cpp b/sys/ExternalProcess.cpp index de6b35a..fd58d9c 100644 --- a/sys/ExternalProcess.cpp +++ b/sys/ExternalProcess.cpp @@ -1,12 +1,12 @@ #include "ExternalProcess.hpp" -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" #include #include #include #include -namespace NekoRay::sys { +namespace NekoGui_sys { ExternalProcess::ExternalProcess() : QProcess() { // qDebug() << "[Debug] ExternalProcess()" << this << running_ext; @@ -24,7 +24,7 @@ namespace NekoRay::sys { if (managed) { connect(this, &QProcess::readyReadStandardOutput, this, [&]() { auto log = readAllStandardOutput(); - if (logCounter.fetchAndAddRelaxed(log.count("\n")) > NekoRay::dataStore->max_log_line) return; + if (logCounter.fetchAndAddRelaxed(log.count("\n")) > NekoGui::dataStore->max_log_line) return; MW_show_log_ext_vt100(log); }); connect(this, &QProcess::readyReadStandardError, this, [&]() { @@ -54,7 +54,7 @@ namespace NekoRay::sys { QProcess::setEnvironment(env); - if (NekoRay::dataStore->flag_linux_run_core_as_admin && dynamic_cast(this) && program != "pkexec") { + if (NekoGui::dataStore->flag_linux_run_core_as_admin && dynamic_cast(this) && program != "pkexec") { arguments.prepend(program); arguments.prepend("--keep-cwd"); program = "pkexec"; @@ -85,10 +85,10 @@ namespace NekoRay::sys { connect(this, &QProcess::readyReadStandardOutput, this, [&]() { auto log = readAllStandardOutput(); - if (!NekoRay::dataStore->core_running) { + if (!NekoGui::dataStore->core_running) { if (log.contains("grpc server listening")) { // The core really started - NekoRay::dataStore->core_running = true; + NekoGui::dataStore->core_running = true; if (start_profile_when_core_is_up >= 0) { MW_dialog_message("ExternalProcess", "CoreStarted," + Int2String(start_profile_when_core_is_up)); start_profile_when_core_is_up = -1; @@ -98,7 +98,7 @@ namespace NekoRay::sys { QProcess::kill(); } } - if (logCounter.fetchAndAddRelaxed(log.count("\n")) > NekoRay::dataStore->max_log_line) return; + if (logCounter.fetchAndAddRelaxed(log.count("\n")) > NekoGui::dataStore->max_log_line) return; MW_show_log(log); }); connect(this, &QProcess::readyReadStandardError, this, [&]() { @@ -119,10 +119,10 @@ namespace NekoRay::sys { }); connect(this, &QProcess::stateChanged, this, [&](QProcess::ProcessState state) { if (state == QProcess::NotRunning) { - NekoRay::dataStore->core_running = false; + NekoGui::dataStore->core_running = false; } - if (!dataStore->prepare_exit && state == QProcess::NotRunning) { + if (!NekoGui::dataStore->prepare_exit && state == QProcess::NotRunning) { if (failed_to_start) return; // no retry if (restarting) return; @@ -140,7 +140,7 @@ namespace NekoRay::sys { } // Restart - start_profile_when_core_is_up = NekoRay::dataStore->started_id; + start_profile_when_core_is_up = NekoGui::dataStore->started_id; MW_show_log("[Error] " + QObject::tr("Core exited, restarting.")); setTimeout([=] { Restart(); }, this, 1000); } @@ -150,16 +150,16 @@ namespace NekoRay::sys { void CoreProcess::Start() { show_stderr = false; // set extra env - auto v2ray_asset_dir = FindCoreAsset("geoip.dat"); + auto v2ray_asset_dir = NekoGui::FindCoreAsset("geoip.dat"); if (!v2ray_asset_dir.isEmpty()) { v2ray_asset_dir = QFileInfo(v2ray_asset_dir).absolutePath(); env << "V2RAY_LOCATION_ASSET=" + v2ray_asset_dir; } - if (NekoRay::dataStore->core_ray_direct_dns) env << "NKR_CORE_RAY_DIRECT_DNS=1"; - if (NekoRay::dataStore->core_ray_windows_disable_auto_interface) env << "NKR_CORE_RAY_WINDOWS_DISABLE_AUTO_INTERFACE=1"; + if (NekoGui::dataStore->core_ray_direct_dns) env << "NKR_CORE_RAY_DIRECT_DNS=1"; + if (NekoGui::dataStore->core_ray_windows_disable_auto_interface) env << "NKR_CORE_RAY_WINDOWS_DISABLE_AUTO_INTERFACE=1"; // ExternalProcess::Start(); - write((dataStore->core_token + "\n").toUtf8()); + write((NekoGui::dataStore->core_token + "\n").toUtf8()); } void CoreProcess::Restart() { @@ -171,4 +171,4 @@ namespace NekoRay::sys { restarting = false; } -} // namespace NekoRay::sys +} // namespace NekoGui_sys diff --git a/sys/ExternalProcess.hpp b/sys/ExternalProcess.hpp index f7c2886..b70b64f 100644 --- a/sys/ExternalProcess.hpp +++ b/sys/ExternalProcess.hpp @@ -1,8 +1,9 @@ #pragma once +#include #include -namespace NekoRay::sys { +namespace NekoGui_sys { class ExternalProcess : public QProcess { public: QString tag; @@ -44,7 +45,7 @@ namespace NekoRay::sys { }; // 手动管理 - inline std::list> running_ext; + inline std::list> running_ext; inline QAtomicInt logCounter; -} // namespace NekoRay::sys +} // namespace NekoGui_sys diff --git a/sys/windows/MiniDump.cpp b/sys/windows/MiniDump.cpp index c9365f2..6a8fa47 100644 --- a/sys/windows/MiniDump.cpp +++ b/sys/windows/MiniDump.cpp @@ -21,7 +21,7 @@ typedef BOOL(WINAPI *MINIDUMPWRITEDUMP)( CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam); -LONG CreateCrashHandler(EXCEPTION_POINTERS *pException) { +LONG __stdcall CreateCrashHandler(EXCEPTION_POINTERS *pException) { QDir::setCurrent(QApplication::applicationDirPath()); HMODULE DllHandle = NULL; diff --git a/ui/GroupSort.hpp b/ui/GroupSort.hpp index 3e4ca2a..ca49eba 100644 --- a/ui/GroupSort.hpp +++ b/ui/GroupSort.hpp @@ -1,22 +1,20 @@ #pragma once -namespace NekoRay { - // implement in mainwindow - namespace GroupSortMethod { - enum GroupSortMethod { - Raw, - ByType, - ByAddress, - ByName, - ByLatency, - ById, - }; - } - - struct GroupSortAction { - GroupSortMethod::GroupSortMethod method = GroupSortMethod::Raw; - bool save_sort = false; // 保存到文件 - bool descending = false; // 默认升序,开这个就是降序 - bool scroll_to_started = false; +// implement in mainwindow +namespace GroupSortMethod { + enum GroupSortMethod { + Raw, + ByType, + ByAddress, + ByName, + ByLatency, + ById, }; -} // namespace NekoRay +} + +struct GroupSortAction { + GroupSortMethod::GroupSortMethod method = GroupSortMethod::Raw; + bool save_sort = false; // 保存到文件 + bool descending = false; // 默认升序,开这个就是降序 + bool scroll_to_started = false; +}; diff --git a/ui/Icon.cpp b/ui/Icon.cpp index 2e83c34..b248f3c 100644 --- a/ui/Icon.cpp +++ b/ui/Icon.cpp @@ -1,6 +1,6 @@ #include "Icon.hpp" -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" #include diff --git a/ui/dialog_basic_settings.cpp b/ui/dialog_basic_settings.cpp index 43b4ff1..79e1a8f 100644 --- a/ui/dialog_basic_settings.cpp +++ b/ui/dialog_basic_settings.cpp @@ -6,7 +6,7 @@ #include "ui/ThemeManager.hpp" #include "ui/Icon.hpp" #include "main/GuiUtils.hpp" -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" #include #include @@ -72,7 +72,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent) D_LOAD_STRING(inbound_address) D_LOAD_COMBO_STRING(log_level) - CACHE.custom_inbound = NekoRay::dataStore->custom_inbound; + CACHE.custom_inbound = NekoGui::dataStore->custom_inbound; D_LOAD_INT(inbound_socks_port) D_LOAD_INT_ENABLE(inbound_http_port, http_enable) D_LOAD_INT(test_concurrent) @@ -88,9 +88,9 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent) auto str = QInputDialog::getItem(this, ui->sys_proxy_format->text() + " (Windows)", tr("Advanced system proxy settings. Please select a format."), Preset::Windows::system_proxy_format, - Preset::Windows::system_proxy_format.indexOf(NekoRay::dataStore->system_proxy_format), + Preset::Windows::system_proxy_format.indexOf(NekoGui::dataStore->system_proxy_format), false, &ok); - if (ok) NekoRay::dataStore->system_proxy_format = str; + if (ok) NekoGui::dataStore->system_proxy_format = str; }); #else ui->sys_proxy_format->hide(); @@ -106,22 +106,22 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent) D_LOAD_BOOL(start_minimal) D_LOAD_INT(max_log_line) // - if (NekoRay::dataStore->traffic_loop_interval == 500) { + if (NekoGui::dataStore->traffic_loop_interval == 500) { ui->rfsh_r->setCurrentIndex(0); - } else if (NekoRay::dataStore->traffic_loop_interval == 1000) { + } else if (NekoGui::dataStore->traffic_loop_interval == 1000) { ui->rfsh_r->setCurrentIndex(1); - } else if (NekoRay::dataStore->traffic_loop_interval == 2000) { + } else if (NekoGui::dataStore->traffic_loop_interval == 2000) { ui->rfsh_r->setCurrentIndex(2); - } else if (NekoRay::dataStore->traffic_loop_interval == 3000) { + } else if (NekoGui::dataStore->traffic_loop_interval == 3000) { ui->rfsh_r->setCurrentIndex(3); - } else if (NekoRay::dataStore->traffic_loop_interval == 5000) { + } else if (NekoGui::dataStore->traffic_loop_interval == 5000) { ui->rfsh_r->setCurrentIndex(4); } else { ui->rfsh_r->setCurrentIndex(5); } // - ui->language->setCurrentIndex(NekoRay::dataStore->language); - connect(ui->language, QOverload::of(&QComboBox::currentIndexChanged), this, [=](int index) { + ui->language->setCurrentIndex(NekoGui::dataStore->language); + connect(ui->language, static_cast(&QComboBox::currentIndexChanged), this, [=](int index) { CACHE.needRestart = true; }); // @@ -129,29 +129,29 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent) ui->theme->addItems(QStyleFactory::keys()); // bool ok; - auto themeId = NekoRay::dataStore->theme.toInt(&ok); + auto themeId = NekoGui::dataStore->theme.toInt(&ok); if (ok) { ui->theme->setCurrentIndex(themeId); } else { - ui->theme->setCurrentText(NekoRay::dataStore->theme); + ui->theme->setCurrentText(NekoGui::dataStore->theme); } // - connect(ui->theme, QOverload::of(&QComboBox::currentIndexChanged), this, [=](int index) { + connect(ui->theme, static_cast(&QComboBox::currentIndexChanged), this, [=](int index) { if (index + 1 <= built_in_len) { themeManager->ApplyTheme(Int2String(index)); - NekoRay::dataStore->theme = Int2String(index); + NekoGui::dataStore->theme = Int2String(index); } else { themeManager->ApplyTheme(ui->theme->currentText()); - NekoRay::dataStore->theme = ui->theme->currentText(); + NekoGui::dataStore->theme = ui->theme->currentText(); } repaint(); mainwindow->repaint(); - NekoRay::dataStore->Save(); + NekoGui::dataStore->Save(); }); // Subscription - ui->user_agent->setText(NekoRay::dataStore->user_agent); + ui->user_agent->setText(NekoGui::dataStore->user_agent); D_LOAD_BOOL(sub_use_proxy) D_LOAD_BOOL(sub_clear) D_LOAD_BOOL(sub_insecure) @@ -159,9 +159,9 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent) // Core ui->groupBox_core->setTitle(software_core_name); - ui->core_v2ray_asset->setText(NekoRay::dataStore->v2ray_asset_dir); + ui->core_v2ray_asset->setText(NekoGui::dataStore->v2ray_asset_dir); // - CACHE.extraCore = QString2QJsonObject(NekoRay::dataStore->extraCore->core_map); + CACHE.extraCore = QString2QJsonObject(NekoGui::dataStore->extraCore->core_map); if (!CACHE.extraCore.contains("naive")) CACHE.extraCore.insert("naive", ""); if (!CACHE.extraCore.contains("hysteria")) CACHE.extraCore.insert("hysteria", ""); // @@ -215,10 +215,10 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent) int neko_core_new; if (sender() == ui->switch_core_sing_box) { if (IS_NEKO_BOX) return; - neko_core_new = NekoRay::CoreType::SING_BOX; + neko_core_new = NekoGui::CoreType::SING_BOX; } else { if (!IS_NEKO_BOX) return; - neko_core_new = NekoRay::CoreType::V2RAY; + neko_core_new = NekoGui::CoreType::V2RAY; } QString core_name_new = dynamic_cast(sender())->text(); if (QMessageBox::question(this, tr("Confirmation"), @@ -245,8 +245,8 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent) ui->utlsFingerprint->addItems(IS_NEKO_BOX ? Preset::SingBox::UtlsFingerPrint : Preset::V2Ray::UtlsFingerPrint); D_LOAD_BOOL(skip_cert) - ui->enable_js_hook->setCurrentIndex(NekoRay::dataStore->enable_js_hook); - ui->utlsFingerprint->setCurrentText(NekoRay::dataStore->utlsFingerprint); + ui->enable_js_hook->setCurrentIndex(NekoGui::dataStore->enable_js_hook); + ui->utlsFingerprint->setCurrentText(NekoGui::dataStore->utlsFingerprint); } DialogBasicSettings::~DialogBasicSettings() { @@ -258,7 +258,7 @@ void DialogBasicSettings::accept() { D_SAVE_STRING(inbound_address) D_SAVE_COMBO_STRING(log_level) - NekoRay::dataStore->custom_inbound = CACHE.custom_inbound; + NekoGui::dataStore->custom_inbound = CACHE.custom_inbound; D_SAVE_INT(inbound_socks_port) D_SAVE_INT_ENABLE(inbound_http_port, http_enable) D_SAVE_INT(test_concurrent) @@ -266,41 +266,41 @@ void DialogBasicSettings::accept() { // Style - NekoRay::dataStore->language = ui->language->currentIndex(); + NekoGui::dataStore->language = ui->language->currentIndex(); D_SAVE_BOOL(connection_statistics) D_SAVE_BOOL(check_include_pre) D_SAVE_BOOL(start_minimal) D_SAVE_INT(max_log_line) - if (NekoRay::dataStore->max_log_line <= 0) { - NekoRay::dataStore->max_log_line = 200; + if (NekoGui::dataStore->max_log_line <= 0) { + NekoGui::dataStore->max_log_line = 200; } if (ui->rfsh_r->currentIndex() == 0) { - NekoRay::dataStore->traffic_loop_interval = 500; + NekoGui::dataStore->traffic_loop_interval = 500; } else if (ui->rfsh_r->currentIndex() == 1) { - NekoRay::dataStore->traffic_loop_interval = 1000; + NekoGui::dataStore->traffic_loop_interval = 1000; } else if (ui->rfsh_r->currentIndex() == 2) { - NekoRay::dataStore->traffic_loop_interval = 2000; + NekoGui::dataStore->traffic_loop_interval = 2000; } else if (ui->rfsh_r->currentIndex() == 3) { - NekoRay::dataStore->traffic_loop_interval = 3000; + NekoGui::dataStore->traffic_loop_interval = 3000; } else if (ui->rfsh_r->currentIndex() == 4) { - NekoRay::dataStore->traffic_loop_interval = 5000; + NekoGui::dataStore->traffic_loop_interval = 5000; } else { - NekoRay::dataStore->traffic_loop_interval = 0; + NekoGui::dataStore->traffic_loop_interval = 0; } // Subscription - NekoRay::dataStore->user_agent = ui->user_agent->text(); + NekoGui::dataStore->user_agent = ui->user_agent->text(); D_SAVE_BOOL(sub_use_proxy) D_SAVE_BOOL(sub_clear) D_SAVE_BOOL(sub_insecure) // Core - NekoRay::dataStore->v2ray_asset_dir = ui->core_v2ray_asset->text(); - NekoRay::dataStore->extraCore->core_map = QJsonObject2QString(CACHE.extraCore, true); + NekoGui::dataStore->v2ray_asset_dir = ui->core_v2ray_asset->text(); + NekoGui::dataStore->extraCore->core_map = QJsonObject2QString(CACHE.extraCore, true); // Mux D_SAVE_INT(mux_concurrency) @@ -310,11 +310,11 @@ void DialogBasicSettings::accept() { // Security D_SAVE_BOOL(skip_cert) - NekoRay::dataStore->enable_js_hook = ui->enable_js_hook->currentIndex(); - NekoRay::dataStore->utlsFingerprint = ui->utlsFingerprint->currentText(); + NekoGui::dataStore->enable_js_hook = ui->enable_js_hook->currentIndex(); + NekoGui::dataStore->utlsFingerprint = ui->utlsFingerprint->currentText(); // 关闭连接统计,停止刷新前清空记录。 - if (NekoRay::dataStore->traffic_loop_interval == 0 || NekoRay::dataStore->connection_statistics == false) { + if (NekoGui::dataStore->traffic_loop_interval == 0 || NekoGui::dataStore->connection_statistics == false) { MW_dialog_message("", "ClearConnectionList"); } @@ -328,7 +328,7 @@ void DialogBasicSettings::accept() { void DialogBasicSettings::refresh_auth() { ui->inbound_auth->setText({}); - if (NekoRay::dataStore->inbound_auth->NeedAuth()) { + if (NekoGui::dataStore->inbound_auth->NeedAuth()) { ui->inbound_auth->setIcon(Icon::GetMaterialIcon("lock-outline")); } else { ui->inbound_auth->setIcon(Icon::GetMaterialIcon("lock-open-outline")); @@ -367,8 +367,8 @@ void DialogBasicSettings::on_inbound_auth_clicked() { auto pass_l = new QLabel(tr("Password")); auto user = new MyLineEdit; auto pass = new MyLineEdit; - user->setText(NekoRay::dataStore->inbound_auth->username); - pass->setText(NekoRay::dataStore->inbound_auth->password); + user->setText(NekoGui::dataStore->inbound_auth->username); + pass->setText(NekoGui::dataStore->inbound_auth->password); // layout->addWidget(user_l, 0, 0); layout->addWidget(user, 0, 1); @@ -378,8 +378,8 @@ void DialogBasicSettings::on_inbound_auth_clicked() { box->setOrientation(Qt::Horizontal); box->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); connect(box, &QDialogButtonBox::accepted, w, [=] { - NekoRay::dataStore->inbound_auth->username = user->text(); - NekoRay::dataStore->inbound_auth->password = pass->text(); + NekoGui::dataStore->inbound_auth->username = user->text(); + NekoGui::dataStore->inbound_auth->password = pass->text(); MW_dialog_message(Dialog_DialogBasicSettings, "UpdateDataStore"); w->accept(); }); @@ -411,7 +411,7 @@ void DialogBasicSettings::on_core_settings_clicked() { "For NekoRay, this rewrites the underlying(localhost) DNS in VPN mode.\n" "For NekoBox, this rewrites the underlying(localhost) DNS in VPN mode, normal mode, and also URL Test.")); core_box_underlying_dns = new MyLineEdit; - core_box_underlying_dns->setText(NekoRay::dataStore->core_box_underlying_dns); + core_box_underlying_dns->setText(NekoGui::dataStore->core_box_underlying_dns); core_box_underlying_dns->setMinimumWidth(300); layout->addWidget(core_box_underlying_dns_l, ++line, 0); layout->addWidget(core_box_underlying_dns, line, 1); @@ -419,26 +419,26 @@ void DialogBasicSettings::on_core_settings_clicked() { if (IS_NEKO_BOX) { auto core_box_enable_clash_api_l = new QLabel("Enable Clash API"); core_box_enable_clash_api = new QCheckBox; - core_box_enable_clash_api->setChecked(NekoRay::dataStore->core_box_clash_api > 0); + core_box_enable_clash_api->setChecked(NekoGui::dataStore->core_box_clash_api > 0); layout->addWidget(core_box_enable_clash_api_l, ++line, 0); layout->addWidget(core_box_enable_clash_api, line, 1); // auto core_box_clash_api_l = new QLabel("Clash API Listen Port"); core_box_clash_api = new MyLineEdit; - core_box_clash_api->setText(Int2String(std::abs(NekoRay::dataStore->core_box_clash_api))); + core_box_clash_api->setText(Int2String(std::abs(NekoGui::dataStore->core_box_clash_api))); layout->addWidget(core_box_clash_api_l, ++line, 0); layout->addWidget(core_box_clash_api, line, 1); // auto core_box_clash_api_secret_l = new QLabel("Clash API Secret"); core_box_clash_api_secret = new MyLineEdit; - core_box_clash_api_secret->setText(NekoRay::dataStore->core_box_clash_api_secret); + core_box_clash_api_secret->setText(NekoGui::dataStore->core_box_clash_api_secret); layout->addWidget(core_box_clash_api_secret_l, ++line, 0); layout->addWidget(core_box_clash_api_secret, line, 1); } else { auto core_ray_direct_dns_l = new QLabel("NKR_CORE_RAY_DIRECT_DNS"); core_ray_direct_dns_l->setToolTip(tr("If you VPN mode is not working, try to change this option.")); core_ray_direct_dns = new QCheckBox; - core_ray_direct_dns->setChecked(NekoRay::dataStore->core_ray_direct_dns); + core_ray_direct_dns->setChecked(NekoGui::dataStore->core_ray_direct_dns); connect(core_ray_direct_dns, &QCheckBox::clicked, this, [&] { CACHE.needRestart = true; }); layout->addWidget(core_ray_direct_dns_l, ++line, 0); layout->addWidget(core_ray_direct_dns, line, 1); @@ -446,7 +446,7 @@ void DialogBasicSettings::on_core_settings_clicked() { auto core_ray_windows_disable_auto_interface_l = new QLabel("NKR_CORE_RAY_WINDOWS_DISABLE_AUTO_INTERFACE"); core_ray_windows_disable_auto_interface_l->setToolTip(tr("If you VPN mode is not working, try to change this option.")); core_ray_windows_disable_auto_interface = new QCheckBox; - core_ray_windows_disable_auto_interface->setChecked(NekoRay::dataStore->core_ray_windows_disable_auto_interface); + core_ray_windows_disable_auto_interface->setChecked(NekoGui::dataStore->core_ray_windows_disable_auto_interface); connect(core_ray_windows_disable_auto_interface, &QCheckBox::clicked, this, [&] { CACHE.needRestart = true; }); layout->addWidget(core_ray_windows_disable_auto_interface_l, ++line, 0); layout->addWidget(core_ray_windows_disable_auto_interface, line, 1); @@ -457,14 +457,14 @@ void DialogBasicSettings::on_core_settings_clicked() { box->setOrientation(Qt::Horizontal); box->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); connect(box, &QDialogButtonBox::accepted, w, [=] { - NekoRay::dataStore->core_box_underlying_dns = core_box_underlying_dns->text(); + NekoGui::dataStore->core_box_underlying_dns = core_box_underlying_dns->text(); if (IS_NEKO_BOX) { - NekoRay::dataStore->core_box_clash_api = core_box_clash_api->text().toInt() * (core_box_enable_clash_api->isChecked() ? 1 : -1); - NekoRay::dataStore->core_box_clash_api_secret = core_box_clash_api_secret->text(); + NekoGui::dataStore->core_box_clash_api = core_box_clash_api->text().toInt() * (core_box_enable_clash_api->isChecked() ? 1 : -1); + NekoGui::dataStore->core_box_clash_api_secret = core_box_clash_api_secret->text(); } else { - NekoRay::dataStore->core_ray_direct_dns = core_ray_direct_dns->isChecked(); + NekoGui::dataStore->core_ray_direct_dns = core_ray_direct_dns->isChecked(); #ifdef Q_OS_WIN - NekoRay::dataStore->core_ray_windows_disable_auto_interface = core_ray_windows_disable_auto_interface->isChecked(); + NekoGui::dataStore->core_ray_windows_disable_auto_interface = core_ray_windows_disable_auto_interface->isChecked(); #endif } MW_dialog_message(Dialog_DialogBasicSettings, "UpdateDataStore"); diff --git a/ui/dialog_first_setup.cpp b/ui/dialog_first_setup.cpp index 93bfc6c..4fc2499 100644 --- a/ui/dialog_first_setup.cpp +++ b/ui/dialog_first_setup.cpp @@ -1,7 +1,7 @@ #include "dialog_first_setup.h" #include "ui_dialog_first_setup.h" -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" DialogFirstSetup::DialogFirstSetup(QWidget *parent) : QDialog(parent), ui(new Ui::DialogFirstSetup) { ui->setupUi(this); @@ -14,9 +14,9 @@ DialogFirstSetup::~DialogFirstSetup() { void DialogFirstSetup::onButtonClicked() { auto s = sender(); if (s == ui->v2ray) { - NekoRay::coreType = NekoRay::CoreType::V2RAY; + NekoGui::coreType = NekoGui::CoreType::V2RAY; } else if (s == ui->singbox) { - NekoRay::coreType = NekoRay::CoreType::SING_BOX; + NekoGui::coreType = NekoGui::CoreType::SING_BOX; } done(0); } diff --git a/ui/dialog_hotkey.cpp b/ui/dialog_hotkey.cpp index a47cb7a..d53278d 100644 --- a/ui/dialog_hotkey.cpp +++ b/ui/dialog_hotkey.cpp @@ -5,20 +5,20 @@ DialogHotkey::DialogHotkey(QWidget *parent) : QDialog(parent), ui(new Ui::DialogHotkey) { ui->setupUi(this); - ui->show_mainwindow->setKeySequence(NekoRay::dataStore->hotkey_mainwindow); - ui->show_groups->setKeySequence(NekoRay::dataStore->hotkey_group); - ui->show_routes->setKeySequence(NekoRay::dataStore->hotkey_route); - ui->system_proxy->setKeySequence(NekoRay::dataStore->hotkey_system_proxy_menu); + ui->show_mainwindow->setKeySequence(NekoGui::dataStore->hotkey_mainwindow); + ui->show_groups->setKeySequence(NekoGui::dataStore->hotkey_group); + ui->show_routes->setKeySequence(NekoGui::dataStore->hotkey_route); + ui->system_proxy->setKeySequence(NekoGui::dataStore->hotkey_system_proxy_menu); GetMainWindow()->RegisterHotkey(true); } DialogHotkey::~DialogHotkey() { if (result() == QDialog::Accepted) { - NekoRay::dataStore->hotkey_mainwindow = ui->show_mainwindow->keySequence().toString(); - NekoRay::dataStore->hotkey_group = ui->show_groups->keySequence().toString(); - NekoRay::dataStore->hotkey_route = ui->show_routes->keySequence().toString(); - NekoRay::dataStore->hotkey_system_proxy_menu = ui->system_proxy->keySequence().toString(); - NekoRay::dataStore->Save(); + NekoGui::dataStore->hotkey_mainwindow = ui->show_mainwindow->keySequence().toString(); + NekoGui::dataStore->hotkey_group = ui->show_groups->keySequence().toString(); + NekoGui::dataStore->hotkey_route = ui->show_routes->keySequence().toString(); + NekoGui::dataStore->hotkey_system_proxy_menu = ui->system_proxy->keySequence().toString(); + NekoGui::dataStore->Save(); } GetMainWindow()->RegisterHotkey(false); delete ui; diff --git a/ui/dialog_hotkey.h b/ui/dialog_hotkey.h index 124fcfd..6e42508 100644 --- a/ui/dialog_hotkey.h +++ b/ui/dialog_hotkey.h @@ -1,7 +1,7 @@ #pragma once #include -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" QT_BEGIN_NAMESPACE namespace Ui { diff --git a/ui/dialog_manage_groups.cpp b/ui/dialog_manage_groups.cpp index 683d5da..7a86b08 100644 --- a/ui/dialog_manage_groups.cpp +++ b/ui/dialog_manage_groups.cpp @@ -12,7 +12,7 @@ #include #define AddGroupToListIfExist(_id) \ - auto __ent = NekoRay::profileManager->GetGroup(_id); \ + auto __ent = NekoGui::profileManager->GetGroup(_id); \ if (__ent != nullptr) { \ auto wI = new QListWidgetItem(); \ auto w = new GroupItem(this, __ent, wI); \ @@ -24,7 +24,7 @@ DialogManageGroups::DialogManageGroups(QWidget *parent) : QDialog(parent), ui(new Ui::DialogManageGroups) { ui->setupUi(this); - for (auto id: NekoRay::profileManager->_groups) { + for (auto id: NekoGui::profileManager->_groups) { AddGroupToListIfExist(id) } @@ -39,13 +39,13 @@ DialogManageGroups::~DialogManageGroups() { } void DialogManageGroups::on_add_clicked() { - auto ent = NekoRay::ProfileManager::NewGroup(); + auto ent = NekoGui::ProfileManager::NewGroup(); auto dialog = new DialogEditGroup(ent, this); int ret = dialog->exec(); dialog->deleteLater(); if (ret == QDialog::Accepted) { - NekoRay::profileManager->AddGroup(ent); + NekoGui::profileManager->AddGroup(ent); AddGroupToListIfExist(ent->id); MW_dialog_message(Dialog_DialogManageGroups, "refresh-1"); } @@ -53,10 +53,10 @@ void DialogManageGroups::on_add_clicked() { void DialogManageGroups::on_update_all_clicked() { if (QMessageBox::question(this, tr("Confirmation"), tr("Update all subscriptions?")) == QMessageBox::StandardButton::Yes) { - for (const auto &gid: NekoRay::profileManager->_groups) { - auto group = NekoRay::profileManager->GetGroup(gid); + for (const auto &gid: NekoGui::profileManager->_groups) { + auto group = NekoGui::profileManager->GetGroup(gid); if (group == nullptr || group->url.isEmpty()) continue; - UI_update_one_group(NekoRay::profileManager->_groups.indexOf(gid)); + UI_update_one_group(NekoGui::profileManager->_groups.indexOf(gid)); return; } } @@ -65,22 +65,22 @@ void DialogManageGroups::on_update_all_clicked() { void UI_update_one_group(int _order) { // calculate next group int nextOrder = _order; - QSharedPointer nextGroup; + std::shared_ptr nextGroup; forever { nextOrder += 1; - if (nextOrder >= NekoRay::profileManager->_groups.length()) break; - auto nextGid = NekoRay::profileManager->_groups[nextOrder]; - nextGroup = NekoRay::profileManager->GetGroup(nextGid); + if (nextOrder >= NekoGui::profileManager->_groups.length()) break; + auto nextGid = NekoGui::profileManager->_groups[nextOrder]; + nextGroup = NekoGui::profileManager->GetGroup(nextGid); if (nextGroup == nullptr || nextGroup->url.isEmpty()) continue; break; } // calculate this group - auto group = NekoRay::profileManager->GetGroup(NekoRay::profileManager->_groups[_order]); + auto group = NekoGui::profileManager->GetGroup(NekoGui::profileManager->_groups[_order]); if (group == nullptr) return; // v2.2: listener is moved to GroupItem, no refresh here. - NekoRay::sub::groupUpdater->AsyncUpdate(group->url, group->id, [=] { + NekoGui_sub::groupUpdater->AsyncUpdate(group->url, group->id, [=] { if (nextGroup != nullptr) UI_update_one_group(nextOrder); }); } diff --git a/ui/dialog_manage_routes.cpp b/ui/dialog_manage_routes.cpp index de1a6f2..06968e0 100644 --- a/ui/dialog_manage_routes.cpp +++ b/ui/dialog_manage_routes.cpp @@ -68,8 +68,8 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne builtInSchemesMenu->addActions(this->getBuiltInSchemes()); ui->preset->setMenu(builtInSchemesMenu); - QString geoipFn = NekoRay::FindCoreAsset("geoip.dat"); - QString geositeFn = NekoRay::FindCoreAsset("geosite.dat"); + QString geoipFn = NekoGui::FindCoreAsset("geoip.dat"); + QString geositeFn = NekoGui::FindCoreAsset("geosite.dat"); // const auto sourceStringsDomain = Qv2ray::components::GeositeReader::ReadGeoSiteFromFile(geoipFn); directDomainTxt = new AutoCompleteTextEdit("geosite", sourceStringsDomain, this); @@ -89,7 +89,7 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne ui->proxyIPLayout->addWidget(proxyIPTxt, 0, 0); ui->blockIPLayout->addWidget(blockIPTxt, 0, 0); // - REFRESH_ACTIVE_ROUTING(NekoRay::dataStore->active_routing, NekoRay::dataStore->routing) + REFRESH_ACTIVE_ROUTING(NekoGui::dataStore->active_routing, NekoGui::dataStore->routing) ADD_ASTERISK(this) } @@ -101,11 +101,11 @@ DialogManageRoutes::~DialogManageRoutes() { void DialogManageRoutes::accept() { D_C_SAVE_STRING(custom_route_global) bool routeChanged = false; - if (NekoRay::dataStore->active_routing != active_routing) routeChanged = true; - SaveDisplayRouting(NekoRay::dataStore->routing); - NekoRay::dataStore->active_routing = active_routing; - NekoRay::dataStore->routing->fn = ROUTES_PREFIX + NekoRay::dataStore->active_routing; - if (NekoRay::dataStore->routing->Save()) routeChanged = true; + if (NekoGui::dataStore->active_routing != active_routing) routeChanged = true; + SaveDisplayRouting(NekoGui::dataStore->routing); + NekoGui::dataStore->active_routing = active_routing; + NekoGui::dataStore->routing->fn = ROUTES_PREFIX + NekoGui::dataStore->active_routing; + if (NekoGui::dataStore->routing->Save()) routeChanged = true; // QString info = "UpdateDataStore"; if (routeChanged) info += "RouteChanged"; @@ -122,14 +122,13 @@ QList DialogManageRoutes::getBuiltInSchemes() { return list; } -QAction *DialogManageRoutes::schemeToAction(const QString &name, const NekoRay::Routing &scheme) { - auto *action = new QAction(this); - action->setText(name); - connect(action, &QAction::triggered, [this, &scheme] { this->UpdateDisplayRouting((NekoRay::Routing *) &scheme, true); }); +QAction *DialogManageRoutes::schemeToAction(const QString &name, const NekoGui::Routing &scheme) { + auto *action = new QAction(name, this); + connect(action, &QAction::triggered, [this, &scheme] { this->UpdateDisplayRouting((NekoGui::Routing *) &scheme, true); }); return action; } -void DialogManageRoutes::UpdateDisplayRouting(NekoRay::Routing *conf, bool qv) { +void DialogManageRoutes::UpdateDisplayRouting(NekoGui::Routing *conf, bool qv) { // directDomainTxt->setPlainText(conf->direct_domain); proxyDomainTxt->setPlainText(conf->proxy_domain); @@ -156,7 +155,7 @@ void DialogManageRoutes::UpdateDisplayRouting(NekoRay::Routing *conf, bool qv) { ui->direct_dns_strategy->setCurrentText(conf->direct_dns_strategy); } -void DialogManageRoutes::SaveDisplayRouting(NekoRay::Routing *conf) { +void DialogManageRoutes::SaveDisplayRouting(NekoGui::Routing *conf) { conf->direct_ip = directIPTxt->toPlainText(); conf->direct_domain = directDomainTxt->toPlainText(); conf->proxy_ip = proxyIPTxt->toPlainText(); @@ -186,7 +185,7 @@ void DialogManageRoutes::on_load_save_clicked() { layout->addWidget(lineEdit); auto list = new QListWidget; layout->addWidget(list); - for (const auto &name: NekoRay::Routing::List()) { + for (const auto &name: NekoGui::Routing::List()) { list->addItem(name); } connect(list, &QListWidget::currentTextChanged, lineEdit, &QLineEdit::setText); @@ -207,7 +206,7 @@ void DialogManageRoutes::on_load_save_clicked() { connect(load, &QPushButton::clicked, w, [=] { auto fn = lineEdit->text(); if (!fn.isEmpty()) { - auto r = std::make_unique(); + auto r = std::make_unique(); r->load_control_must = true; r->fn = ROUTES_PREFIX + fn; if (r->Load()) { @@ -221,7 +220,7 @@ void DialogManageRoutes::on_load_save_clicked() { connect(save, &QPushButton::clicked, w, [=] { auto fn = lineEdit->text(); if (!fn.isEmpty()) { - auto r = std::make_unique(); + auto r = std::make_unique(); SaveDisplayRouting(r.get()); r->fn = ROUTES_PREFIX + fn; if (QMessageBox::question(nullptr, software_name, tr("Save routing: %1").arg(fn) + "\n" + r->DisplayRouting()) == QMessageBox::Yes) { @@ -233,13 +232,13 @@ void DialogManageRoutes::on_load_save_clicked() { }); connect(remove, &QPushButton::clicked, w, [=] { auto fn = lineEdit->text(); - if (!fn.isEmpty() && NekoRay::Routing::List().length() > 1) { + if (!fn.isEmpty() && NekoGui::Routing::List().length() > 1) { if (QMessageBox::question(nullptr, software_name, tr("Remove routing: %1").arg(fn)) == QMessageBox::Yes) { QFile f(ROUTES_PREFIX + fn); f.remove(); - if (NekoRay::dataStore->active_routing == fn) { - NekoRay::Routing::SetToActive(NekoRay::Routing::List().first()); - REFRESH_ACTIVE_ROUTING(NekoRay::dataStore->active_routing, NekoRay::dataStore->routing) + if (NekoGui::dataStore->active_routing == fn) { + NekoGui::Routing::SetToActive(NekoGui::Routing::List().first()); + REFRESH_ACTIVE_ROUTING(NekoGui::dataStore->active_routing, NekoGui::dataStore->routing) } w->accept(); } diff --git a/ui/dialog_manage_routes.h b/ui/dialog_manage_routes.h index 4765b65..0030622 100644 --- a/ui/dialog_manage_routes.h +++ b/ui/dialog_manage_routes.h @@ -4,7 +4,7 @@ #include #include "3rdparty/qv2ray/v2/ui/QvAutoCompleteTextEdit.hpp" -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" QT_BEGIN_NAMESPACE namespace Ui { @@ -37,8 +37,8 @@ private: Qv2ray::ui::widgets::AutoCompleteTextEdit *blockIPTxt; Qv2ray::ui::widgets::AutoCompleteTextEdit *proxyIPTxt; // - NekoRay::Routing routing_cn_lan = NekoRay::Routing(1); - NekoRay::Routing routing_global = NekoRay::Routing(0); + NekoGui::Routing routing_cn_lan = NekoGui::Routing(1); + NekoGui::Routing routing_global = NekoGui::Routing(0); // QString title_base; QString active_routing; @@ -49,11 +49,11 @@ public slots: QList getBuiltInSchemes(); - QAction *schemeToAction(const QString &name, const NekoRay::Routing &scheme); + QAction *schemeToAction(const QString &name, const NekoGui::Routing &scheme); - void UpdateDisplayRouting(NekoRay::Routing *conf, bool qv); + void UpdateDisplayRouting(NekoGui::Routing *conf, bool qv); - void SaveDisplayRouting(NekoRay::Routing *conf); + void SaveDisplayRouting(NekoGui::Routing *conf); void on_load_save_clicked(); }; diff --git a/ui/dialog_vpn_settings.cpp b/ui/dialog_vpn_settings.cpp index 1275332..919ce86 100644 --- a/ui/dialog_vpn_settings.cpp +++ b/ui/dialog_vpn_settings.cpp @@ -2,7 +2,7 @@ #include "ui_dialog_vpn_settings.h" #include "main/GuiUtils.hpp" -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" #include "ui/mainwindow_interface.h" #include @@ -12,18 +12,18 @@ DialogVPNSettings::DialogVPNSettings(QWidget *parent) : QDialog(parent), ui(new ADD_ASTERISK(this); ui->fake_dns->setVisible(!IS_NEKO_BOX); - ui->fake_dns->setChecked(NekoRay::dataStore->fake_dns); + ui->fake_dns->setChecked(NekoGui::dataStore->fake_dns); // - ui->vpn_implementation->setCurrentIndex(NekoRay::dataStore->vpn_implementation); - ui->vpn_mtu->setCurrentText(Int2String(NekoRay::dataStore->vpn_mtu)); - ui->vpn_ipv6->setChecked(NekoRay::dataStore->vpn_ipv6); - ui->hide_console->setChecked(NekoRay::dataStore->vpn_hide_console); + ui->vpn_implementation->setCurrentIndex(NekoGui::dataStore->vpn_implementation); + ui->vpn_mtu->setCurrentText(Int2String(NekoGui::dataStore->vpn_mtu)); + ui->vpn_ipv6->setChecked(NekoGui::dataStore->vpn_ipv6); + ui->hide_console->setChecked(NekoGui::dataStore->vpn_hide_console); #ifndef Q_OS_WIN ui->hide_console->setVisible(false); #endif - ui->strict_route->setChecked(NekoRay::dataStore->vpn_strict_route); + ui->strict_route->setChecked(NekoGui::dataStore->vpn_strict_route); ui->single_core->setVisible(IS_NEKO_BOX); - ui->single_core->setChecked(NekoRay::dataStore->vpn_internal_tun); + ui->single_core->setChecked(NekoGui::dataStore->vpn_internal_tun); // D_LOAD_STRING(vpn_rule_cidr) D_LOAD_STRING(vpn_rule_process) @@ -37,7 +37,7 @@ DialogVPNSettings::DialogVPNSettings(QWidget *parent) : QDialog(parent), ui(new ui->gb_process_name->setTitle(tr("Bypass Process Name")); } }); - ui->whitelist_mode->setChecked(NekoRay::dataStore->vpn_rule_white); + ui->whitelist_mode->setChecked(NekoGui::dataStore->vpn_rule_white); } DialogVPNSettings::~DialogVPNSettings() { @@ -48,14 +48,14 @@ void DialogVPNSettings::accept() { // auto mtu = ui->vpn_mtu->currentText().toInt(); if (mtu > 10000 || mtu < 1000) mtu = 9000; - NekoRay::dataStore->vpn_implementation = ui->vpn_implementation->currentIndex(); - NekoRay::dataStore->fake_dns = ui->fake_dns->isChecked(); - NekoRay::dataStore->vpn_mtu = mtu; - NekoRay::dataStore->vpn_ipv6 = ui->vpn_ipv6->isChecked(); - NekoRay::dataStore->vpn_hide_console = ui->hide_console->isChecked(); - NekoRay::dataStore->vpn_strict_route = ui->strict_route->isChecked(); - NekoRay::dataStore->vpn_rule_white = ui->whitelist_mode->isChecked(); - NekoRay::dataStore->vpn_internal_tun = ui->single_core->isChecked(); + NekoGui::dataStore->vpn_implementation = ui->vpn_implementation->currentIndex(); + NekoGui::dataStore->fake_dns = ui->fake_dns->isChecked(); + NekoGui::dataStore->vpn_mtu = mtu; + NekoGui::dataStore->vpn_ipv6 = ui->vpn_ipv6->isChecked(); + NekoGui::dataStore->vpn_hide_console = ui->hide_console->isChecked(); + NekoGui::dataStore->vpn_strict_route = ui->strict_route->isChecked(); + NekoGui::dataStore->vpn_rule_white = ui->whitelist_mode->isChecked(); + NekoGui::dataStore->vpn_internal_tun = ui->single_core->isChecked(); // D_SAVE_STRING_QTEXTEDIT(vpn_rule_cidr) D_SAVE_STRING_QTEXTEDIT(vpn_rule_process) diff --git a/ui/edit/dialog_edit_group.cpp b/ui/edit/dialog_edit_group.cpp index 6c07fd5..32e60f4 100644 --- a/ui/edit/dialog_edit_group.cpp +++ b/ui/edit/dialog_edit_group.cpp @@ -5,11 +5,11 @@ #include -DialogEditGroup::DialogEditGroup(const QSharedPointer &ent, QWidget *parent) +DialogEditGroup::DialogEditGroup(const std::shared_ptr &ent, QWidget *parent) : QDialog(parent), ui(new Ui::DialogEditGroup) { ui->setupUi(this); - connect(ui->type, QOverload::of(&QComboBox::currentIndexChanged), this, [=](int index) { + connect(ui->type, static_cast(&QComboBox::currentIndexChanged), this, [=](int index) { ui->cat_sub->setHidden(index == 0); }); @@ -45,7 +45,7 @@ DialogEditGroup::DialogEditGroup(const QSharedPointer &ent, QWid connect(ui->copy_links, &QPushButton::clicked, this, [=] { QStringList links; - for (const auto &profile: NekoRay::profileManager->profiles) { + for (const auto &profile: NekoGui::profileManager->profiles) { if (profile->gid != ent->id) continue; links += profile->bean->ToShareLink(); } @@ -54,7 +54,7 @@ DialogEditGroup::DialogEditGroup(const QSharedPointer &ent, QWid }); connect(ui->copy_links_nkr, &QPushButton::clicked, this, [=] { QStringList links; - for (const auto &profile: NekoRay::profileManager->profiles) { + for (const auto &profile: NekoGui::profileManager->profiles) { if (profile->gid != ent->id) continue; links += profile->bean->ToNekorayShareLink(profile->type); } diff --git a/ui/edit/dialog_edit_group.h b/ui/edit/dialog_edit_group.h index cb0ac07..c6c678e 100644 --- a/ui/edit/dialog_edit_group.h +++ b/ui/edit/dialog_edit_group.h @@ -13,7 +13,7 @@ class DialogEditGroup : public QDialog { Q_OBJECT public: - explicit DialogEditGroup(const QSharedPointer &ent, QWidget *parent = nullptr); + explicit DialogEditGroup(const std::shared_ptr &ent, QWidget *parent = nullptr); ~DialogEditGroup() override; diff --git a/ui/edit/dialog_edit_profile.cpp b/ui/edit/dialog_edit_profile.cpp index 0a33ab4..75817d4 100644 --- a/ui/edit/dialog_edit_profile.cpp +++ b/ui/edit/dialog_edit_profile.cpp @@ -19,7 +19,7 @@ #include #define ADJUST_SIZE runOnUiThread([=] { adjustSize(); adjustPosition(mainwindow); }, this); -#define LOAD_TYPE(a) ui->type->addItem(NekoRay::ProfileManager::NewProxyEntity(a)->bean->DisplayType(), a); +#define LOAD_TYPE(a) ui->type->addItem(NekoGui::ProfileManager::NewProxyEntity(a)->bean->DisplayType(), a); DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId, QWidget *parent) : QDialog(parent), ui(new Ui::DialogEditProfile) { @@ -129,13 +129,13 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId, LOAD_TYPE("chain"); // type changed - connect(ui->type, QOverload::of(&QComboBox::currentIndexChanged), this, [=](int index) { + connect(ui->type, static_cast(&QComboBox::currentIndexChanged), this, [=](int index) { typeSelected(ui->type->itemData(index).toString()); }); ui->apply_to_group->hide(); } else { - this->ent = NekoRay::profileManager->GetProfile(profileOrGroupId); + this->ent = NekoGui::profileManager->GetProfile(profileOrGroupId); if (this->ent == nullptr) return; this->type = ent->type; ui->type->setVisible(false); @@ -199,7 +199,7 @@ void DialogEditProfile::typeSelected(const QString &newType) { } if (newEnt) { - this->ent = NekoRay::ProfileManager::NewProxyEntity(type); + this->ent = NekoGui::ProfileManager::NewProxyEntity(type); this->ent->gid = groupId; } @@ -211,7 +211,7 @@ void DialogEditProfile::typeSelected(const QString &newType) { ui->port_l->setVisible(showAddressPort); // 右边 stream - auto stream = GetStreamSettings(ent->bean.data()); + auto stream = GetStreamSettings(ent->bean.get()); if (stream != nullptr) { ui->right_all_w->setVisible(true); ui->network->setCurrentText(stream->network); @@ -344,7 +344,7 @@ bool DialogEditProfile::onEnd() { } // 右边 stream - auto stream = GetStreamSettings(ent->bean.data()); + auto stream = GetStreamSettings(ent->bean.get()); if (stream != nullptr) { stream->network = ui->network->currentText(); stream->security = ui->security->currentText(); @@ -381,13 +381,13 @@ void DialogEditProfile::accept() { QStringList msg = {"accept"}; if (newEnt) { - auto ok = NekoRay::profileManager->AddProfile(ent); + auto ok = NekoGui::profileManager->AddProfile(ent); if (!ok) { MessageBoxWarning("???", "id exists"); } } else { auto changed = ent->Save(); - if (changed && NekoRay::dataStore->started_id == ent->id) msg << "restart"; + if (changed && NekoGui::dataStore->started_id == ent->id) msg << "restart"; } MW_dialog_message(Dialog_DialogEditProfile, msg.join(",")); @@ -456,7 +456,7 @@ void DialogEditProfile::on_apply_to_group_clicked() { apply_to_group_ui[ui->custom_outbound_edit] = new FloatCheckBox(ui->custom_outbound_edit, this); ui->apply_to_group->setText(tr("Confirm")); } else { - auto group = NekoRay::profileManager->GetGroup(ent->gid); + auto group = NekoGui::profileManager->GetGroup(ent->gid); if (group == nullptr) { MessageBoxWarning("failed", "unknown group"); return; @@ -480,12 +480,12 @@ void DialogEditProfile::on_apply_to_group_clicked() { } } -void DialogEditProfile::do_apply_to_group(const QSharedPointer &group, QWidget *key) { - auto stream = GetStreamSettings(ent->bean.data()); +void DialogEditProfile::do_apply_to_group(const std::shared_ptr &group, QWidget *key) { + auto stream = GetStreamSettings(ent->bean.get()); auto copyStream = [=](void *p) { for (const auto &profile: group->Profiles()) { - auto newStream = GetStreamSettings(profile->bean.data()); + auto newStream = GetStreamSettings(profile->bean.get()); if (newStream == nullptr) continue; if (stream == newStream) continue; newStream->_setValue(stream->_name(p), p); diff --git a/ui/edit/dialog_edit_profile.h b/ui/edit/dialog_edit_profile.h index 6095e14..3e8ae50 100644 --- a/ui/edit/dialog_edit_profile.h +++ b/ui/edit/dialog_edit_profile.h @@ -44,7 +44,7 @@ private: QString type; int groupId; bool newEnt = false; - QSharedPointer ent; + std::shared_ptr ent; QString network_title_base; @@ -60,7 +60,7 @@ private: void editor_cache_updated_impl(); - void do_apply_to_group(const QSharedPointer &group, QWidget *key); + void do_apply_to_group(const std::shared_ptr &group, QWidget *key); }; #endif // DIALOG_EDIT_PROFILE_H diff --git a/ui/edit/edit_chain.cpp b/ui/edit/edit_chain.cpp index 9d3f1e6..cbdec3f 100644 --- a/ui/edit/edit_chain.cpp +++ b/ui/edit/edit_chain.cpp @@ -15,7 +15,7 @@ EditChain::~EditChain() { delete ui; } -void EditChain::onStart(QSharedPointer _ent) { +void EditChain::onStart(std::shared_ptr _ent) { this->ent = _ent; auto bean = this->ent->ChainBean(); @@ -45,7 +45,7 @@ void EditChain::on_select_profile_clicked() { } void EditChain::AddProfileToListIfExist(int profileId) { - auto _ent = NekoRay::profileManager->GetProfile(profileId); + auto _ent = NekoGui::profileManager->GetProfile(profileId); if (_ent != nullptr && _ent->type != "chain") { auto wI = new QListWidgetItem(); wI->setData(114514, profileId); @@ -64,7 +64,7 @@ void EditChain::AddProfileToListIfExist(int profileId) { } void EditChain::ReplaceProfile(ProxyItem *w, int profileId) { - auto _ent = NekoRay::profileManager->GetProfile(profileId); + auto _ent = NekoGui::profileManager->GetProfile(profileId); if (_ent != nullptr && _ent->type != "chain") { w->item->setData(114514, profileId); w->ent = _ent; diff --git a/ui/edit/edit_chain.h b/ui/edit/edit_chain.h index 03640ac..61348d4 100644 --- a/ui/edit/edit_chain.h +++ b/ui/edit/edit_chain.h @@ -19,13 +19,13 @@ public: ~EditChain() override; - void onStart(QSharedPointer _ent) override; + void onStart(std::shared_ptr _ent) override; bool onEnd() override; private: Ui::EditChain *ui; - QSharedPointer ent; + std::shared_ptr ent; void AddProfileToListIfExist(int profileId); diff --git a/ui/edit/edit_custom.cpp b/ui/edit/edit_custom.cpp index 46f0830..97f71e9 100644 --- a/ui/edit/edit_custom.cpp +++ b/ui/edit/edit_custom.cpp @@ -33,12 +33,12 @@ EditCustom::~EditCustom() { P_SAVE_INT(mapping_port) \ P_SAVE_INT(socks_port) -void EditCustom::onStart(QSharedPointer _ent) { +void EditCustom::onStart(std::shared_ptr _ent) { this->ent = _ent; auto bean = this->ent->CustomBean(); // load known core - auto core_map = QString2QJsonObject(NekoRay::dataStore->extraCore->core_map); + auto core_map = QString2QJsonObject(NekoGui::dataStore->extraCore->core_map); for (const auto &key: core_map.keys()) { if (key == "naive" || key == "hysteria") continue; ui->core->addItem(key); @@ -102,7 +102,7 @@ void EditCustom::onStart(QSharedPointer _ent) { th << "%server_port% => " + get_edit_text_serverPort(); MessageBoxInfo(tr("Preview replace"), th.join("\n")); // EditCustom::onEnd - auto tmpEnt = NekoRay::ProfileManager::NewProxyEntity("custom"); + auto tmpEnt = NekoGui::ProfileManager::NewProxyEntity("custom"); auto bean = tmpEnt->CustomBean(); SAVE_CUSTOM_BEAN // 补充 @@ -110,7 +110,7 @@ void EditCustom::onStart(QSharedPointer _ent) { bean->serverPort = get_edit_text_serverPort().toInt(); if (bean->core.isEmpty()) return; // - auto result = NekoRay::BuildConfig(tmpEnt, false, false); + auto result = NekoGui::BuildConfig(tmpEnt, false, false); if (!result->error.isEmpty()) { MessageBoxInfo(software_name, result->error); return; diff --git a/ui/edit/edit_custom.h b/ui/edit/edit_custom.h index 8a9fd14..9de5373 100644 --- a/ui/edit/edit_custom.h +++ b/ui/edit/edit_custom.h @@ -21,13 +21,13 @@ public: ~EditCustom() override; - void onStart(QSharedPointer _ent) override; + void onStart(std::shared_ptr _ent) override; bool onEnd() override; private: Ui::EditCustom *ui; - QSharedPointer ent; + std::shared_ptr ent; private slots: diff --git a/ui/edit/edit_hysteria.cpp b/ui/edit/edit_hysteria.cpp index 5b85af3..e4745e2 100644 --- a/ui/edit/edit_hysteria.cpp +++ b/ui/edit/edit_hysteria.cpp @@ -13,7 +13,7 @@ EditHysteria::~EditHysteria() { delete ui; } -void EditHysteria::onStart(QSharedPointer _ent) { +void EditHysteria::onStart(std::shared_ptr _ent) { this->ent = _ent; auto bean = this->ent->HysteriaBean(); diff --git a/ui/edit/edit_hysteria.h b/ui/edit/edit_hysteria.h index 396307e..9d36055 100644 --- a/ui/edit/edit_hysteria.h +++ b/ui/edit/edit_hysteria.h @@ -17,7 +17,7 @@ public: ~EditHysteria() override; - void onStart(QSharedPointer _ent) override; + void onStart(std::shared_ptr _ent) override; bool onEnd() override; @@ -25,7 +25,7 @@ public: private: Ui::EditHysteria *ui; - QSharedPointer ent; + std::shared_ptr ent; struct { QString caText; diff --git a/ui/edit/edit_naive.cpp b/ui/edit/edit_naive.cpp index bc37666..9286859 100644 --- a/ui/edit/edit_naive.cpp +++ b/ui/edit/edit_naive.cpp @@ -13,7 +13,7 @@ EditNaive::~EditNaive() { delete ui; } -void EditNaive::onStart(QSharedPointer _ent) { +void EditNaive::onStart(std::shared_ptr _ent) { this->ent = _ent; auto bean = this->ent->NaiveBean(); diff --git a/ui/edit/edit_naive.h b/ui/edit/edit_naive.h index d6dde1d..f1334cf 100644 --- a/ui/edit/edit_naive.h +++ b/ui/edit/edit_naive.h @@ -17,7 +17,7 @@ public: ~EditNaive() override; - void onStart(QSharedPointer _ent) override; + void onStart(std::shared_ptr _ent) override; bool onEnd() override; @@ -25,7 +25,7 @@ public: private: Ui::EditNaive *ui; - QSharedPointer ent; + std::shared_ptr ent; struct { QString certificate; diff --git a/ui/edit/edit_shadowsocks.cpp b/ui/edit/edit_shadowsocks.cpp index 8d28fa8..eb4c621 100644 --- a/ui/edit/edit_shadowsocks.cpp +++ b/ui/edit/edit_shadowsocks.cpp @@ -17,7 +17,7 @@ EditShadowSocks::~EditShadowSocks() { delete ui; } -void EditShadowSocks::onStart(QSharedPointer _ent) { +void EditShadowSocks::onStart(std::shared_ptr _ent) { this->ent = _ent; auto bean = this->ent->ShadowSocksBean(); diff --git a/ui/edit/edit_shadowsocks.h b/ui/edit/edit_shadowsocks.h index c2b15ed..d1131b9 100644 --- a/ui/edit/edit_shadowsocks.h +++ b/ui/edit/edit_shadowsocks.h @@ -16,13 +16,13 @@ public: ~EditShadowSocks() override; - void onStart(QSharedPointer _ent) override; + void onStart(std::shared_ptr _ent) override; bool onEnd() override; private: Ui::EditShadowSocks *ui; - QSharedPointer ent; + std::shared_ptr ent; }; #endif // EDIT_SHADOWSOCKS_H diff --git a/ui/edit/edit_socks_http.cpp b/ui/edit/edit_socks_http.cpp index 9e03254..1598c6e 100644 --- a/ui/edit/edit_socks_http.cpp +++ b/ui/edit/edit_socks_http.cpp @@ -12,16 +12,16 @@ EditSocksHttp::~EditSocksHttp() { delete ui; } -void EditSocksHttp::onStart(QSharedPointer _ent) { +void EditSocksHttp::onStart(std::shared_ptr _ent) { this->ent = _ent; auto bean = this->ent->SocksHTTPBean(); - if (bean->socks_http_type == NekoRay::fmt::SocksHttpBean::type_Socks4) { + if (bean->socks_http_type == NekoGui_fmt::SocksHttpBean::type_Socks4) { ui->version->setCurrentIndex(1); } else { ui->version->setCurrentIndex(0); } - if (bean->socks_http_type == NekoRay::fmt::SocksHttpBean::type_HTTP) { + if (bean->socks_http_type == NekoGui_fmt::SocksHttpBean::type_HTTP) { ui->version->setVisible(false); ui->version_l->setVisible(false); } @@ -35,9 +35,9 @@ bool EditSocksHttp::onEnd() { if (ui->version->isVisible()) { if (ui->version->currentIndex() == 1) { - bean->socks_http_type = NekoRay::fmt::SocksHttpBean::type_Socks4; + bean->socks_http_type = NekoGui_fmt::SocksHttpBean::type_Socks4; } else { - bean->socks_http_type = NekoRay::fmt::SocksHttpBean::type_Socks5; + bean->socks_http_type = NekoGui_fmt::SocksHttpBean::type_Socks5; } } diff --git a/ui/edit/edit_socks_http.h b/ui/edit/edit_socks_http.h index 73772f0..ccc3801 100644 --- a/ui/edit/edit_socks_http.h +++ b/ui/edit/edit_socks_http.h @@ -15,11 +15,11 @@ public: ~EditSocksHttp() override; - void onStart(QSharedPointer _ent) override; + void onStart(std::shared_ptr _ent) override; bool onEnd() override; private: Ui::EditSocksHttp *ui; - QSharedPointer ent; + std::shared_ptr ent; }; diff --git a/ui/edit/edit_trojan_vless.cpp b/ui/edit/edit_trojan_vless.cpp index c72e9a8..3d6f053 100644 --- a/ui/edit/edit_trojan_vless.cpp +++ b/ui/edit/edit_trojan_vless.cpp @@ -11,13 +11,13 @@ EditTrojanVLESS::~EditTrojanVLESS() { delete ui; } -void EditTrojanVLESS::onStart(QSharedPointer _ent) { +void EditTrojanVLESS::onStart(std::shared_ptr _ent) { this->ent = _ent; auto bean = this->ent->TrojanVLESSBean(); - if (bean->proxy_type == NekoRay::fmt::TrojanVLESSBean::proxy_VLESS) { + if (bean->proxy_type == NekoGui_fmt::TrojanVLESSBean::proxy_VLESS) { ui->label->setText("UUID"); } - if (!IS_NEKO_BOX || bean->proxy_type != NekoRay::fmt::TrojanVLESSBean::proxy_VLESS) { + if (!IS_NEKO_BOX || bean->proxy_type != NekoGui_fmt::TrojanVLESSBean::proxy_VLESS) { ui->flow->hide(); ui->flow_l->hide(); } diff --git a/ui/edit/edit_trojan_vless.h b/ui/edit/edit_trojan_vless.h index b3417e7..d19b283 100644 --- a/ui/edit/edit_trojan_vless.h +++ b/ui/edit/edit_trojan_vless.h @@ -17,11 +17,11 @@ public: ~EditTrojanVLESS() override; - void onStart(QSharedPointer _ent) override; + void onStart(std::shared_ptr _ent) override; bool onEnd() override; private: Ui::EditTrojanVLESS *ui; - QSharedPointer ent; + std::shared_ptr ent; }; diff --git a/ui/edit/edit_vmess.cpp b/ui/edit/edit_vmess.cpp index 1d1f7ab..0fb05a7 100644 --- a/ui/edit/edit_vmess.cpp +++ b/ui/edit/edit_vmess.cpp @@ -14,7 +14,7 @@ EditVMess::~EditVMess() { delete ui; } -void EditVMess::onStart(QSharedPointer _ent) { +void EditVMess::onStart(std::shared_ptr _ent) { this->ent = _ent; auto bean = this->ent->VMessBean(); diff --git a/ui/edit/edit_vmess.h b/ui/edit/edit_vmess.h index bf40c33..38efa6c 100644 --- a/ui/edit/edit_vmess.h +++ b/ui/edit/edit_vmess.h @@ -17,11 +17,11 @@ public: ~EditVMess() override; - void onStart(QSharedPointer _ent) override; + void onStart(std::shared_ptr _ent) override; bool onEnd() override; private: Ui::EditVMess *ui; - QSharedPointer ent; + std::shared_ptr ent; }; diff --git a/ui/edit/profile_editor.h b/ui/edit/profile_editor.h index 80347ac..cf43847 100644 --- a/ui/edit/profile_editor.h +++ b/ui/edit/profile_editor.h @@ -7,7 +7,7 @@ class ProfileEditor { public: - virtual void onStart(QSharedPointer ent) = 0; + virtual void onStart(std::shared_ptr ent) = 0; virtual bool onEnd() = 0; diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 429a95b..b306fa1 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -17,6 +17,7 @@ #include "ui/dialog_vpn_settings.h" #include "ui/dialog_hotkey.h" +#include "3rdparty/fix_old_qt.h" #include "3rdparty/qrcodegen.hpp" #include "3rdparty/VT100Parser.hpp" #include "3rdparty/qv2ray/v2/components/proxy/QvProxyConfigurator.hpp" @@ -56,30 +57,30 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi }; // Load Manager - auto isLoaded = NekoRay::profileManager->Load(); + auto isLoaded = NekoGui::profileManager->Load(); if (!isLoaded) { - auto defaultGroup = NekoRay::ProfileManager::NewGroup(); + auto defaultGroup = NekoGui::ProfileManager::NewGroup(); defaultGroup->name = tr("Default"); - NekoRay::profileManager->AddGroup(defaultGroup); + NekoGui::profileManager->AddGroup(defaultGroup); } // Setup misc UI - themeManager->ApplyTheme(NekoRay::dataStore->theme); + themeManager->ApplyTheme(NekoGui::dataStore->theme); ui->setupUi(this); connect(ui->menu_start, &QAction::triggered, this, [=]() { neko_start(); }); connect(ui->menu_stop, &QAction::triggered, this, [=]() { neko_stop(); }); connect(ui->tabWidget->tabBar(), &QTabBar::tabMoved, this, [=](int from, int to) { // use tabData to track tab & gid - NekoRay::profileManager->_groups.clear(); + NekoGui::profileManager->_groups.clear(); for (int i = 0; i < ui->tabWidget->tabBar()->count(); i++) { - NekoRay::profileManager->_groups += ui->tabWidget->tabBar()->tabData(i).toInt(); + NekoGui::profileManager->_groups += ui->tabWidget->tabBar()->tabData(i).toInt(); } - NekoRay::profileManager->Save(); + NekoGui::profileManager->Save(); }); ui->label_running->installEventFilter(this); ui->label_inbound->installEventFilter(this); RegisterHotkey(false); - auto last_size = NekoRay::dataStore->mw_size.split("x"); + auto last_size = NekoGui::dataStore->mw_size.split("x"); if (last_size.length() == 2) { auto w = last_size[0].toInt(); auto h = last_size[1].toInt(); @@ -93,11 +94,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi software_name = "NekoBox"; software_core_name = "sing-box"; // replace default values - if (NekoRay::dataStore->log_level == "warning") NekoRay::dataStore->log_level = "info"; - if (!Preset::SingBox::DomainStrategy.contains(NekoRay::dataStore->routing->domain_strategy)) NekoRay::dataStore->routing->domain_strategy = ""; - if (!Preset::SingBox::DomainStrategy.contains(NekoRay::dataStore->routing->outbound_domain_strategy)) NekoRay::dataStore->routing->outbound_domain_strategy = ""; + if (NekoGui::dataStore->log_level == "warning") NekoGui::dataStore->log_level = "info"; + if (!Preset::SingBox::DomainStrategy.contains(NekoGui::dataStore->routing->domain_strategy)) NekoGui::dataStore->routing->domain_strategy = ""; + if (!Preset::SingBox::DomainStrategy.contains(NekoGui::dataStore->routing->outbound_domain_strategy)) NekoGui::dataStore->routing->outbound_domain_strategy = ""; // - if (QDir("dashboard").isEmpty()) { + if (QDir("dashboard").count() == 0) { QDir().mkdir("dashboard"); QFile::copy(":/neko/dashboard-notice.html", "dashboard/index.html"); } @@ -113,7 +114,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi connect(ui->toolButton_update, &QToolButton::clicked, this, [=] { runOnNewThread([=] { CheckUpdate(); }); }); // Setup log UI - ui->splitter->restoreState(DecodeB64IfValid(NekoRay::dataStore->splitter_state)); + ui->splitter->restoreState(DecodeB64IfValid(NekoGui::dataStore->splitter_state)); new SyntaxHighlighter(false, qvLogDocument); qvLogDocument->setUndoRedoEnabled(false); ui->masterLogBrowser->setUndoRedoEnabled(false); @@ -149,17 +150,17 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi // table UI ui->proxyListTable->callback_save_order = [=] { - auto group = NekoRay::profileManager->CurrentGroup(); + auto group = NekoGui::profileManager->CurrentGroup(); group->order = ui->proxyListTable->order; group->Save(); }; ui->proxyListTable->refresh_data = [=](int id) { refresh_proxy_list_impl_refresh_data(id); }; if (auto button = ui->proxyListTable->findChild(QString(), Qt::FindDirectChildrenOnly)) { // Corner Button - connect(button, &QAbstractButton::clicked, this, [=] { refresh_proxy_list_impl(-1, {NekoRay::GroupSortMethod::ById}); }); + connect(button, &QAbstractButton::clicked, this, [=] { refresh_proxy_list_impl(-1, {GroupSortMethod::ById}); }); } connect(ui->proxyListTable->horizontalHeader(), &QHeaderView::sectionClicked, this, [=](int logicalIndex) { - NekoRay::GroupSortAction action; + GroupSortAction action; // 不正确的descending实现 if (proxy_last_order == logicalIndex) { action.descending = true; @@ -170,21 +171,21 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi action.save_sort = true; // 表头 if (logicalIndex == 0) { - action.method = NekoRay::GroupSortMethod::ByType; + action.method = GroupSortMethod::ByType; } else if (logicalIndex == 1) { - action.method = NekoRay::GroupSortMethod::ByAddress; + action.method = GroupSortMethod::ByAddress; } else if (logicalIndex == 2) { - action.method = NekoRay::GroupSortMethod::ByName; + action.method = GroupSortMethod::ByName; } else if (logicalIndex == 3) { - action.method = NekoRay::GroupSortMethod::ByLatency; + action.method = GroupSortMethod::ByLatency; } else { return; } refresh_proxy_list_impl(-1, action); }); connect(ui->proxyListTable->horizontalHeader(), &QHeaderView::sectionResized, this, [=](int logicalIndex, int oldSize, int newSize) { - auto group = NekoRay::profileManager->CurrentGroup(); - if (NekoRay::dataStore->refreshing_group || group == nullptr || !group->manually_column_width) return; + auto group = NekoGui::profileManager->CurrentGroup(); + if (NekoGui::dataStore->refreshing_group || group == nullptr || !group->manually_column_width) return; // save manually column width group->column_width.clear(); for (int i = 0; i < ui->proxyListTable->horizontalHeader()->count(); i++) { @@ -258,25 +259,25 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi connect(ui->menu_open_config_folder, &QAction::triggered, this, [=] { QDesktopServices::openUrl(QUrl::fromLocalFile(QDir::currentPath())); }); ui->menu_program_preference->addActions(ui->menu_preferences->actions()); connect(ui->menu_add_from_clipboard2, &QAction::triggered, ui->menu_add_from_clipboard, &QAction::trigger); - connect(ui->actionRestart_Proxy, &QAction::triggered, this, [=] { if (NekoRay::dataStore->started_id>=0) neko_start(NekoRay::dataStore->started_id); }); + connect(ui->actionRestart_Proxy, &QAction::triggered, this, [=] { if (NekoGui::dataStore->started_id>=0) neko_start(NekoGui::dataStore->started_id); }); connect(ui->actionRestart_Program, &QAction::triggered, this, [=] { MW_dialog_message("", "RestartProgram"); }); connect(ui->actionShow_window, &QAction::triggered, this, [=] { tray->activated(QSystemTrayIcon::ActivationReason::Trigger); }); // connect(ui->menu_program, &QMenu::aboutToShow, this, [=]() { - ui->actionRemember_last_proxy->setChecked(NekoRay::dataStore->remember_enable); + ui->actionRemember_last_proxy->setChecked(NekoGui::dataStore->remember_enable); ui->actionStart_with_system->setChecked(AutoRun_IsEnabled()); - ui->actionAllow_LAN->setChecked(QStringList{"::", "0.0.0.0"}.contains(NekoRay::dataStore->inbound_address)); + ui->actionAllow_LAN->setChecked(QStringList{"::", "0.0.0.0"}.contains(NekoGui::dataStore->inbound_address)); // active server for (const auto &old: ui->menuActive_Server->actions()) { ui->menuActive_Server->removeAction(old); old->deleteLater(); } int active_server_item_count = 0; - for (const auto &pf: NekoRay::profileManager->CurrentGroup()->ProfilesWithOrder()) { - auto a = new QAction(pf->bean->DisplayTypeAndName()); + for (const auto &pf: NekoGui::profileManager->CurrentGroup()->ProfilesWithOrder()) { + auto a = new QAction(pf->bean->DisplayTypeAndName(), this); a->setProperty("id", pf->id); a->setCheckable(true); - if (NekoRay::dataStore->started_id == pf->id) a->setChecked(true); + if (NekoGui::dataStore->started_id == pf->id) a->setChecked(true); ui->menuActive_Server->addAction(a); if (++active_server_item_count == 50) break; } @@ -285,10 +286,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi ui->menuActive_Routing->removeAction(old); old->deleteLater(); } - for (const auto &name: NekoRay::Routing::List()) { - auto a = new QAction(name); + for (const auto &name: NekoGui::Routing::List()) { + auto a = new QAction(name, this); a->setCheckable(true); - a->setChecked(name == NekoRay::dataStore->active_routing); + a->setChecked(name == NekoGui::dataStore->active_routing); ui->menuActive_Routing->addAction(a); } }); @@ -296,7 +297,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi bool ok; auto id = a->property("id").toInt(&ok); if (!ok) return; - if (NekoRay::dataStore->started_id == id) { + if (NekoGui::dataStore->started_id == id) { neko_stop(); } else { neko_start(id); @@ -305,14 +306,14 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi connect(ui->menuActive_Routing, &QMenu::triggered, this, [=](QAction *a) { auto fn = a->text(); if (!fn.isEmpty()) { - NekoRay::Routing r; + NekoGui::Routing r; r.load_control_must = true; r.fn = ROUTES_PREFIX + fn; if (r.Load()) { if (QMessageBox::question(GetMessageBoxParent(), software_name, tr("Load routing and apply: %1").arg(fn) + "\n" + r.DisplayRouting()) == QMessageBox::Yes) { - NekoRay::Routing::SetToActive(fn); - if (NekoRay::dataStore->started_id >= 0) { - neko_start(NekoRay::dataStore->started_id); + NekoGui::Routing::SetToActive(fn); + if (NekoGui::dataStore->started_id >= 0) { + neko_start(NekoGui::dataStore->started_id); } else { refresh_status(); } @@ -321,23 +322,23 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi } }); connect(ui->actionRemember_last_proxy, &QAction::triggered, this, [=](bool checked) { - NekoRay::dataStore->remember_enable = checked; - NekoRay::dataStore->Save(); + NekoGui::dataStore->remember_enable = checked; + NekoGui::dataStore->Save(); }); connect(ui->actionStart_with_system, &QAction::triggered, this, [=](bool checked) { AutoRun_SetEnabled(checked); }); connect(ui->actionAllow_LAN, &QAction::triggered, this, [=](bool checked) { - NekoRay::dataStore->inbound_address = checked ? "::" : "127.0.0.1"; + NekoGui::dataStore->inbound_address = checked ? "::" : "127.0.0.1"; MW_dialog_message("", "UpdateDataStore"); }); // connect(ui->checkBox_VPN, &QCheckBox::clicked, this, [=](bool checked) { neko_set_spmode_vpn(checked); }); connect(ui->checkBox_SystemProxy, &QCheckBox::clicked, this, [=](bool checked) { neko_set_spmode_system_proxy(checked); }); connect(ui->menu_spmode, &QMenu::aboutToShow, this, [=]() { - ui->menu_spmode_disabled->setChecked(!(NekoRay::dataStore->spmode_system_proxy || NekoRay::dataStore->spmode_vpn)); - ui->menu_spmode_system_proxy->setChecked(NekoRay::dataStore->spmode_system_proxy); - ui->menu_spmode_vpn->setChecked(NekoRay::dataStore->spmode_vpn); + ui->menu_spmode_disabled->setChecked(!(NekoGui::dataStore->spmode_system_proxy || NekoGui::dataStore->spmode_vpn)); + ui->menu_spmode_system_proxy->setChecked(NekoGui::dataStore->spmode_system_proxy); + ui->menu_spmode_vpn->setChecked(NekoGui::dataStore->spmode_vpn); }); connect(ui->menu_spmode_system_proxy, &QAction::triggered, this, [=](bool checked) { neko_set_spmode_system_proxy(checked); }); connect(ui->menu_spmode_vpn, &QAction::triggered, this, [=](bool checked) { neko_set_spmode_vpn(checked); }); @@ -393,9 +394,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi refresh_status(); // Prepare core - NekoRay::dataStore->core_token = GetRandomString(32); - NekoRay::dataStore->core_port = MkPort(); - if (NekoRay::dataStore->core_port <= 0) NekoRay::dataStore->core_port = 19810; + NekoGui::dataStore->core_token = GetRandomString(32); + NekoGui::dataStore->core_port = MkPort(); + if (NekoGui::dataStore->core_port <= 0) NekoGui::dataStore->core_port = 19810; auto core_path = QApplication::applicationDirPath() + "/"; core_path += IS_NEKO_BOX ? "nekobox_core" : "nekoray_core"; @@ -403,16 +404,16 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi QStringList args; args.push_back(IS_NEKO_BOX ? "nekobox" : "nekoray"); args.push_back("-port"); - args.push_back(Int2String(NekoRay::dataStore->core_port)); - if (NekoRay::dataStore->flag_debug) args.push_back("-debug"); + args.push_back(Int2String(NekoGui::dataStore->core_port)); + if (NekoGui::dataStore->flag_debug) args.push_back("-debug"); // Start core runOnUiThread( [=] { - core_process = new NekoRay::sys::CoreProcess(core_path, args); + core_process = new NekoGui_sys::CoreProcess(core_path, args); // Remember last started - if (NekoRay::dataStore->remember_enable && NekoRay::dataStore->remember_id >= 0) { - core_process->start_profile_when_core_is_up = NekoRay::dataStore->remember_id; + if (NekoGui::dataStore->remember_enable && NekoGui::dataStore->remember_id >= 0) { + core_process->start_profile_when_core_is_up = NekoGui::dataStore->remember_id; } // Setup core_process->Start(); @@ -421,11 +422,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi DS_cores); // Remember system proxy - if (NekoRay::dataStore->remember_enable) { - if (NekoRay::dataStore->remember_spmode.contains("system_proxy")) { + if (NekoGui::dataStore->remember_enable) { + if (NekoGui::dataStore->remember_spmode.contains("system_proxy")) { neko_set_spmode_system_proxy(true, false); } - if (NekoRay::dataStore->remember_spmode.contains("vpn")) { + if (NekoGui::dataStore->remember_spmode.contains("vpn")) { neko_set_spmode_vpn(true, false); } } @@ -437,10 +438,10 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi t->start(2000); t = new QTimer; - connect(t, &QTimer::timeout, this, [&] { NekoRay::sys::logCounter.fetchAndStoreRelaxed(0); }); + connect(t, &QTimer::timeout, this, [&] { NekoGui_sys::logCounter.fetchAndStoreRelaxed(0); }); t->start(1000); - if (!NekoRay::dataStore->flag_tray) show(); + if (!NekoGui::dataStore->flag_tray) show(); } void MainWindow::closeEvent(QCloseEvent *event) { @@ -457,37 +458,37 @@ MainWindow::~MainWindow() { // Group tab manage inline int tabIndex2GroupId(int index) { - if (NekoRay::profileManager->_groups.length() <= index) return -1; - return NekoRay::profileManager->_groups[index]; + if (NekoGui::profileManager->_groups.length() <= index) return -1; + return NekoGui::profileManager->_groups[index]; } inline int groupId2TabIndex(int gid) { - for (int key = 0; key < NekoRay::profileManager->_groups.count(); key++) { - if (NekoRay::profileManager->_groups[key] == gid) return key; + for (int key = 0; key < NekoGui::profileManager->_groups.count(); key++) { + if (NekoGui::profileManager->_groups[key] == gid) return key; } return 0; } void MainWindow::on_tabWidget_currentChanged(int index) { - if (NekoRay::dataStore->refreshing_group_list) return; - if (tabIndex2GroupId(index) == NekoRay::dataStore->current_group) return; + if (NekoGui::dataStore->refreshing_group_list) return; + if (tabIndex2GroupId(index) == NekoGui::dataStore->current_group) return; show_group(tabIndex2GroupId(index)); } void MainWindow::show_group(int gid) { - if (NekoRay::dataStore->refreshing_group) return; - NekoRay::dataStore->refreshing_group = true; + if (NekoGui::dataStore->refreshing_group) return; + NekoGui::dataStore->refreshing_group = true; - auto group = NekoRay::profileManager->GetGroup(gid); + auto group = NekoGui::profileManager->GetGroup(gid); if (group == nullptr) { MessageBoxWarning(tr("Error"), QString("No such group: %1").arg(gid)); - NekoRay::dataStore->refreshing_group = false; + NekoGui::dataStore->refreshing_group = false; return; } - if (NekoRay::dataStore->current_group != gid) { - NekoRay::dataStore->current_group = gid; - NekoRay::dataStore->Save(); + if (NekoGui::dataStore->current_group != gid) { + NekoGui::dataStore->current_group = gid; + NekoGui::dataStore->Save(); } ui->tabWidget->widget(groupId2TabIndex(gid))->layout()->addWidget(ui->proxyListTable); @@ -508,11 +509,11 @@ void MainWindow::show_group(int gid) { } // show proxies - NekoRay::GroupSortAction gsa; + GroupSortAction gsa; gsa.scroll_to_started = true; refresh_proxy_list_impl(-1, gsa); - NekoRay::dataStore->refreshing_group = false; + NekoGui::dataStore->refreshing_group = false; } // callback @@ -524,14 +525,14 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info) refresh_status(); } if (info.contains("UpdateDataStore")) { - auto changed = NekoRay::dataStore->Save(); + auto changed = NekoGui::dataStore->Save(); if (info.contains("RouteChanged")) changed = true; refresh_proxy_list(); - if (info.contains("VPNChanged") && NekoRay::dataStore->spmode_vpn) { + if (info.contains("VPNChanged") && NekoGui::dataStore->spmode_vpn) { MessageBoxWarning(tr("VPN settings changed"), tr("Restart VPN to take effect.")); - } else if (changed && NekoRay::dataStore->started_id >= 0 && + } else if (changed && NekoGui::dataStore->started_id >= 0 && QMessageBox::question(GetMessageBoxParent(), tr("Confirmation"), tr("Settings changed, restart proxy?")) == QMessageBox::StandardButton::Yes) { - neko_start(NekoRay::dataStore->started_id); + neko_start(NekoGui::dataStore->started_id); } refresh_status(); } @@ -558,7 +559,7 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info) refresh_proxy_list(); if (msg.contains("restart")) { if (QMessageBox::question(GetMessageBoxParent(), tr("Confirmation"), tr("Settings changed, restart proxy?")) == QMessageBox::StandardButton::Yes) { - neko_start(NekoRay::dataStore->started_id); + neko_start(NekoGui::dataStore->started_id); } } } @@ -570,7 +571,7 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info) if (info.startsWith("finish")) { refresh_proxy_list(); if (!info.contains("dingyue")) { - show_log_impl(tr("Imported %1 profile(s)").arg(NekoRay::dataStore->imported_count)); + show_log_impl(tr("Imported %1 profile(s)").arg(NekoGui::dataStore->imported_count)); } } else if (info == "NewGroup") { refresh_groups(); @@ -622,31 +623,31 @@ void MainWindow::on_commitDataRequest() { qDebug() << "Start of data save"; // if (!isMaximized()) { - auto olds = NekoRay::dataStore->mw_size; + auto olds = NekoGui::dataStore->mw_size; auto news = QString("%1x%2").arg(size().width()).arg(size().height()); if (olds != news) { - NekoRay::dataStore->mw_size = news; + NekoGui::dataStore->mw_size = news; } } // - NekoRay::dataStore->splitter_state = ui->splitter->saveState().toBase64(); + NekoGui::dataStore->splitter_state = ui->splitter->saveState().toBase64(); // - auto last_id = NekoRay::dataStore->started_id; - if (NekoRay::dataStore->remember_enable && last_id >= 0) { - NekoRay::dataStore->remember_id = last_id; + auto last_id = NekoGui::dataStore->started_id; + if (NekoGui::dataStore->remember_enable && last_id >= 0) { + NekoGui::dataStore->remember_id = last_id; } // - NekoRay::dataStore->Save(); + NekoGui::dataStore->Save(); qDebug() << "End of data save"; } void MainWindow::on_menu_exit_triggered() { if (mu_exit.tryLock()) { - NekoRay::dataStore->prepare_exit = true; + NekoGui::dataStore->prepare_exit = true; // neko_set_spmode_system_proxy(false, false); neko_set_spmode_vpn(false, false); - if (NekoRay::dataStore->spmode_vpn) { + if (NekoGui::dataStore->spmode_vpn) { mu_exit.unlock(); // retry return; } @@ -654,7 +655,7 @@ void MainWindow::on_menu_exit_triggered() { // on_commitDataRequest(); // - NekoRay::dataStore->save_control_no_save = true; // don't change datastore after this line + NekoGui::dataStore->save_control_no_save = true; // don't change datastore after this line neko_stop(false, true); // hide(); @@ -675,7 +676,7 @@ void MainWindow::on_menu_exit_triggered() { } else if (exit_reason == 2 || exit_reason == 3) { QDir::setCurrent(QApplication::applicationDirPath()); - auto arguments = NekoRay::dataStore->argv; + auto arguments = NekoGui::dataStore->argv; if (arguments.length() > 0) { arguments.removeFirst(); arguments.removeAll("-tray"); @@ -704,10 +705,10 @@ void MainWindow::on_menu_exit_triggered() { return; void MainWindow::neko_set_spmode_system_proxy(bool enable, bool save) { - if (enable != NekoRay::dataStore->spmode_system_proxy) { + if (enable != NekoGui::dataStore->spmode_system_proxy) { if (enable) { #if defined(Q_OS_WIN) || defined(Q_OS_MACOS) - if (!IS_NEKO_BOX && !IsValidPort(NekoRay::dataStore->inbound_http_port)) { + if (!IS_NEKO_BOX && !IsValidPort(NekoGui::dataStore->inbound_http_port)) { auto btn = QMessageBox::warning(this, software_name, tr("Http inbound is not enabled, can't set system proxy."), "OK", tr("Settings"), "", 0, 0); @@ -717,8 +718,8 @@ void MainWindow::neko_set_spmode_system_proxy(bool enable, bool save) { return; } #endif - auto socks_port = NekoRay::dataStore->inbound_socks_port; - auto http_port = NekoRay::dataStore->inbound_http_port; + auto socks_port = NekoGui::dataStore->inbound_socks_port; + auto http_port = NekoGui::dataStore->inbound_http_port; if (IS_NEKO_BOX) http_port = socks_port; SetSystemProxy(http_port, socks_port); } else { @@ -727,19 +728,19 @@ void MainWindow::neko_set_spmode_system_proxy(bool enable, bool save) { } if (save) { - NekoRay::dataStore->remember_spmode.removeAll("system_proxy"); - if (enable && NekoRay::dataStore->remember_enable) { - NekoRay::dataStore->remember_spmode.append("system_proxy"); + NekoGui::dataStore->remember_spmode.removeAll("system_proxy"); + if (enable && NekoGui::dataStore->remember_enable) { + NekoGui::dataStore->remember_spmode.append("system_proxy"); } - NekoRay::dataStore->Save(); + NekoGui::dataStore->Save(); } - NekoRay::dataStore->spmode_system_proxy = enable; + NekoGui::dataStore->spmode_system_proxy = enable; refresh_status(); } void MainWindow::neko_set_spmode_vpn(bool enable, bool save) { - if (enable != NekoRay::dataStore->spmode_vpn) { + if (enable != NekoGui::dataStore->spmode_vpn) { if (enable) { if (IS_NEKO_BOX_INTERNAL_TUN) { bool requestPermission = false; @@ -748,7 +749,7 @@ void MainWindow::neko_set_spmode_vpn(bool enable, bool save) { requestPermission = true; } #else - requestPermission = !NekoRay::isAdmin(); + requestPermission = !NekoGui::isAdmin(); #endif if (requestPermission) { auto n = QMessageBox::warning(GetMessageBoxParent(), software_name, tr("Please run NekoBox as admin"), QMessageBox::Yes | QMessageBox::No); @@ -759,7 +760,7 @@ void MainWindow::neko_set_spmode_vpn(bool enable, bool save) { neko_set_spmode_FAILED } } else { - if (NekoRay::dataStore->need_keep_vpn_off) { + if (NekoGui::dataStore->need_keep_vpn_off) { MessageBoxWarning(software_name, tr("Current server is incompatible with VPN. Please stop the server first, enable VPN mode, and then restart.")); neko_set_spmode_FAILED } @@ -779,17 +780,17 @@ void MainWindow::neko_set_spmode_vpn(bool enable, bool save) { } if (save) { - NekoRay::dataStore->remember_spmode.removeAll("vpn"); - if (enable && NekoRay::dataStore->remember_enable) { - NekoRay::dataStore->remember_spmode.append("vpn"); + NekoGui::dataStore->remember_spmode.removeAll("vpn"); + if (enable && NekoGui::dataStore->remember_enable) { + NekoGui::dataStore->remember_spmode.append("vpn"); } - NekoRay::dataStore->Save(); + NekoGui::dataStore->Save(); } - NekoRay::dataStore->spmode_vpn = enable; + NekoGui::dataStore->spmode_vpn = enable; refresh_status(); - if (NekoRay::dataStore->started_id >= 0) neko_start(NekoRay::dataStore->started_id); + if (NekoGui::dataStore->started_id >= 0) neko_start(NekoGui::dataStore->started_id); } void MainWindow::refresh_status(const QString &traffic_update) { @@ -813,40 +814,40 @@ void MainWindow::refresh_status(const QString &traffic_update) { } // auto display_http = tr("None"); - if (IsValidPort(NekoRay::dataStore->inbound_http_port)) { - display_http = DisplayAddress(NekoRay::dataStore->inbound_address, NekoRay::dataStore->inbound_http_port); + if (IsValidPort(NekoGui::dataStore->inbound_http_port)) { + display_http = DisplayAddress(NekoGui::dataStore->inbound_address, NekoGui::dataStore->inbound_http_port); } - auto display_socks = DisplayAddress(NekoRay::dataStore->inbound_address, NekoRay::dataStore->inbound_socks_port); + auto display_socks = DisplayAddress(NekoGui::dataStore->inbound_address, NekoGui::dataStore->inbound_socks_port); auto inbound_txt = QString("Socks: %1\nHTTP: %2").arg(display_socks, display_http); if (IS_NEKO_BOX) inbound_txt = QString("Mixed: %1").arg(display_socks); ui->label_inbound->setText(inbound_txt); // - ui->checkBox_VPN->setChecked(NekoRay::dataStore->spmode_vpn); - ui->checkBox_SystemProxy->setChecked(NekoRay::dataStore->spmode_system_proxy); + ui->checkBox_VPN->setChecked(NekoGui::dataStore->spmode_vpn); + ui->checkBox_SystemProxy->setChecked(NekoGui::dataStore->spmode_system_proxy); if (select_mode) ui->label_running->setText("[" + tr("Select") + "]"); auto make_title = [=](bool isTray) { QStringList tt; - if (!isTray && NekoRay::isAdmin()) tt << "[Admin]"; + if (!isTray && NekoGui::isAdmin()) tt << "[Admin]"; if (select_mode) tt << "[" + tr("Select") + "]"; if (!title_error.isEmpty()) tt << "[" + title_error + "]"; - if (NekoRay::dataStore->spmode_vpn) tt << "[VPN]"; - if (NekoRay::dataStore->spmode_system_proxy) tt << "[" + tr("System Proxy") + "]"; + if (NekoGui::dataStore->spmode_vpn) tt << "[VPN]"; + if (NekoGui::dataStore->spmode_system_proxy) tt << "[" + tr("System Proxy") + "]"; tt << software_name; if (!isTray) tt << "(" + QString(NKR_VERSION) + ")"; - if (!NekoRay::dataStore->active_routing.isEmpty() && NekoRay::dataStore->active_routing != "Default") { - tt << "[" + NekoRay::dataStore->active_routing + "]"; + if (!NekoGui::dataStore->active_routing.isEmpty() && NekoGui::dataStore->active_routing != "Default") { + tt << "[" + NekoGui::dataStore->active_routing + "]"; } - if (!running.isNull()) tt << running->bean->DisplayTypeAndName(); + if (running != nullptr) tt << running->bean->DisplayTypeAndName(); return tt.join(isTray ? "\n" : " "); }; auto icon_status_new = Icon::NONE; - if (!running.isNull()) { - if (NekoRay::dataStore->spmode_vpn) { + if (running != nullptr) { + if (NekoGui::dataStore->spmode_vpn) { icon_status_new = Icon::VPN; - } else if (NekoRay::dataStore->spmode_system_proxy) { + } else if (NekoGui::dataStore->spmode_system_proxy) { icon_status_new = Icon::SYSTEM_PROXY; } else { icon_status_new = Icon::RUNNING; @@ -870,7 +871,7 @@ void MainWindow::refresh_status(const QString &traffic_update) { // refresh_groups -> show_group -> refresh_proxy_list void MainWindow::refresh_groups() { - NekoRay::dataStore->refreshing_group_list = true; + NekoGui::dataStore->refreshing_group_list = true; // refresh group? for (int i = ui->tabWidget->count() - 1; i > 0; i--) { @@ -878,8 +879,8 @@ void MainWindow::refresh_groups() { } int index = 0; - for (const auto &gid: NekoRay::profileManager->_groups) { - auto group = NekoRay::profileManager->GetGroup(gid); + for (const auto &gid: NekoGui::profileManager->_groups) { + auto group = NekoGui::profileManager->GetGroup(gid); if (index == 0) { ui->tabWidget->setTabText(0, group->name); } else { @@ -895,23 +896,23 @@ void MainWindow::refresh_groups() { } // show after group changed - if (NekoRay::profileManager->CurrentGroup() == nullptr) { - NekoRay::dataStore->current_group = -1; + if (NekoGui::profileManager->CurrentGroup() == nullptr) { + NekoGui::dataStore->current_group = -1; ui->tabWidget->setCurrentIndex(groupId2TabIndex(0)); - show_group(NekoRay::profileManager->_groups.count() > 0 ? NekoRay::profileManager->_groups.first() : 0); + show_group(NekoGui::profileManager->_groups.count() > 0 ? NekoGui::profileManager->_groups.first() : 0); } else { - ui->tabWidget->setCurrentIndex(groupId2TabIndex(NekoRay::dataStore->current_group)); - show_group(NekoRay::dataStore->current_group); + ui->tabWidget->setCurrentIndex(groupId2TabIndex(NekoGui::dataStore->current_group)); + show_group(NekoGui::dataStore->current_group); } - NekoRay::dataStore->refreshing_group_list = false; + NekoGui::dataStore->refreshing_group_list = false; } void MainWindow::refresh_proxy_list(const int &id) { refresh_proxy_list_impl(id, {}); } -void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction groupSortAction) { +void MainWindow::refresh_proxy_list_impl(const int &id, GroupSortAction groupSortAction) { // id < 0 重绘 if (id < 0) { // 清空数据 @@ -919,8 +920,8 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction ui->proxyListTable->setRowCount(0); // 添加行 int row = -1; - for (const auto &profile: NekoRay::profileManager->profiles) { - if (NekoRay::dataStore->current_group != profile->gid) continue; + for (const auto &profile: NekoGui::profileManager->profiles) { + if (NekoGui::dataStore->current_group != profile->gid) continue; row++; ui->proxyListTable->insertRow(row); ui->proxyListTable->row2Id += profile->id; @@ -930,47 +931,47 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction // 显示排序 if (id < 0) { switch (groupSortAction.method) { - case NekoRay::GroupSortMethod::Raw: { - auto group = NekoRay::profileManager->CurrentGroup(); + case GroupSortMethod::Raw: { + auto group = NekoGui::profileManager->CurrentGroup(); if (group == nullptr) return; ui->proxyListTable->order = group->order; break; } - case NekoRay::GroupSortMethod::ById: { + case GroupSortMethod::ById: { // Clear Order ui->proxyListTable->order.clear(); ui->proxyListTable->callback_save_order(); break; } - case NekoRay::GroupSortMethod::ByAddress: - case NekoRay::GroupSortMethod::ByName: - case NekoRay::GroupSortMethod::ByLatency: - case NekoRay::GroupSortMethod::ByType: { + case GroupSortMethod::ByAddress: + case GroupSortMethod::ByName: + case GroupSortMethod::ByLatency: + case GroupSortMethod::ByType: { std::sort(ui->proxyListTable->order.begin(), ui->proxyListTable->order.end(), [=](int a, int b) { QString ms_a; QString ms_b; - if (groupSortAction.method == NekoRay::GroupSortMethod::ByType) { - ms_a = NekoRay::profileManager->GetProfile(a)->bean->DisplayType(); - ms_b = NekoRay::profileManager->GetProfile(b)->bean->DisplayType(); - } else if (groupSortAction.method == NekoRay::GroupSortMethod::ByName) { - ms_a = NekoRay::profileManager->GetProfile(a)->bean->name; - ms_b = NekoRay::profileManager->GetProfile(b)->bean->name; - } else if (groupSortAction.method == NekoRay::GroupSortMethod::ByAddress) { - ms_a = NekoRay::profileManager->GetProfile(a)->bean->DisplayAddress(); - ms_b = NekoRay::profileManager->GetProfile(b)->bean->DisplayAddress(); - } else if (groupSortAction.method == NekoRay::GroupSortMethod::ByLatency) { - ms_a = NekoRay::profileManager->GetProfile(a)->full_test_report; - ms_b = NekoRay::profileManager->GetProfile(b)->full_test_report; + if (groupSortAction.method == GroupSortMethod::ByType) { + ms_a = NekoGui::profileManager->GetProfile(a)->bean->DisplayType(); + ms_b = NekoGui::profileManager->GetProfile(b)->bean->DisplayType(); + } else if (groupSortAction.method == GroupSortMethod::ByName) { + ms_a = NekoGui::profileManager->GetProfile(a)->bean->name; + ms_b = NekoGui::profileManager->GetProfile(b)->bean->name; + } else if (groupSortAction.method == GroupSortMethod::ByAddress) { + ms_a = NekoGui::profileManager->GetProfile(a)->bean->DisplayAddress(); + ms_b = NekoGui::profileManager->GetProfile(b)->bean->DisplayAddress(); + } else if (groupSortAction.method == GroupSortMethod::ByLatency) { + ms_a = NekoGui::profileManager->GetProfile(a)->full_test_report; + ms_b = NekoGui::profileManager->GetProfile(b)->full_test_report; } auto get_latency_for_sort = [](int id) { - auto i = NekoRay::profileManager->GetProfile(id)->latency; + auto i = NekoGui::profileManager->GetProfile(id)->latency; if (i == 0) i = 100000; if (i < 0) i = 99999; return i; }; if (groupSortAction.descending) { - if (groupSortAction.method == NekoRay::GroupSortMethod::ByLatency) { + if (groupSortAction.method == GroupSortMethod::ByLatency) { if (ms_a.isEmpty() && ms_b.isEmpty()) { // compare latency if full_test_report is empty return get_latency_for_sort(a) > get_latency_for_sort(b); @@ -978,9 +979,9 @@ void MainWindow::refresh_proxy_list_impl(const int &id, NekoRay::GroupSortAction } return ms_a > ms_b; } else { - if (groupSortAction.method == NekoRay::GroupSortMethod::ByLatency) { - auto int_a = NekoRay::profileManager->GetProfile(a)->latency; - auto int_b = NekoRay::profileManager->GetProfile(b)->latency; + if (groupSortAction.method == GroupSortMethod::ByLatency) { + auto int_a = NekoGui::profileManager->GetProfile(a)->latency; + auto int_b = NekoGui::profileManager->GetProfile(b)->latency; if (ms_a.isEmpty() && ms_b.isEmpty()) { // compare latency if full_test_report is empty return get_latency_for_sort(a) < get_latency_for_sort(b); @@ -1004,7 +1005,7 @@ void MainWindow::refresh_proxy_list_impl_refresh_data(const int &id) { for (int row = 0; row < ui->proxyListTable->rowCount(); row++) { auto profileId = ui->proxyListTable->row2Id[row]; if (id >= 0 && profileId != id) continue; // refresh ONE item - auto profile = NekoRay::profileManager->GetProfile(profileId); + auto profile = NekoGui::profileManager->GetProfile(profileId); if (profile == nullptr) continue; auto f0 = std::make_unique(); @@ -1012,7 +1013,7 @@ void MainWindow::refresh_proxy_list_impl_refresh_data(const int &id) { // Check state auto check = f0->clone(); - check->setText(profileId == NekoRay::dataStore->started_id ? "✓" : Int2String(row + 1)); + check->setText(profileId == NekoGui::dataStore->started_id ? "✓" : Int2String(row + 1)); ui->proxyListTable->setVerticalHeaderItem(row, check); // C0: Type @@ -1063,13 +1064,13 @@ void MainWindow::on_proxyListTable_itemDoubleClicked(QTableWidgetItem *item) { } void MainWindow::on_menu_add_from_input_triggered() { - auto dialog = new DialogEditProfile("socks", NekoRay::dataStore->current_group, this); + auto dialog = new DialogEditProfile("socks", NekoGui::dataStore->current_group, this); connect(dialog, &QDialog::finished, dialog, &QDialog::deleteLater); } void MainWindow::on_menu_add_from_clipboard_triggered() { auto clipboard = QApplication::clipboard()->text(); - NekoRay::sub::groupUpdater->AsyncUpdate(clipboard); + NekoGui_sub::groupUpdater->AsyncUpdate(clipboard); } void MainWindow::on_menu_clone_triggered() { @@ -1084,7 +1085,7 @@ void MainWindow::on_menu_clone_triggered() { sls << ent->bean->ToNekorayShareLink(ent->type); } - NekoRay::sub::groupUpdater->AsyncUpdate(sls.join("\n")); + NekoGui_sub::groupUpdater->AsyncUpdate(sls.join("\n")); } void MainWindow::on_menu_move_triggered() { @@ -1092,7 +1093,7 @@ void MainWindow::on_menu_move_triggered() { if (ents.isEmpty()) return; auto items = QStringList{}; - for (auto &&group: NekoRay::profileManager->groups) { + for (auto &&group: NekoGui::profileManager->groups) { items += Int2String(group->id) + " " + group->name; } @@ -1104,7 +1105,7 @@ void MainWindow::on_menu_move_triggered() { if (!ok) return; auto gid = SubStrBefore(a, " ").toInt(); for (const auto &ent: ents) { - NekoRay::profileManager->MoveProfile(ent, gid); + NekoGui::profileManager->MoveProfile(ent, gid); } refresh_proxy_list(); } @@ -1115,7 +1116,7 @@ void MainWindow::on_menu_delete_triggered() { if (QMessageBox::question(this, tr("Confirmation"), QString(tr("Remove %1 item(s) ?")).arg(ents.count())) == QMessageBox::StandardButton::Yes) { for (const auto &ent: ents) { - NekoRay::profileManager->DeleteProfile(ent->id); + NekoGui::profileManager->DeleteProfile(ent->id); } refresh_proxy_list(); } @@ -1140,8 +1141,8 @@ void MainWindow::on_menu_profile_debug_info_triggered() { if (btn == 1) { QDesktopServices::openUrl(QUrl::fromLocalFile(QFileInfo(QString("profiles/%1.json").arg(ents.first()->id)).absoluteFilePath())); } else if (btn == 2) { - NekoRay::dataStore->Load(); - NekoRay::profileManager->Load(); + NekoGui::dataStore->Load(); + NekoGui::profileManager->Load(); refresh_proxy_list(); } } @@ -1178,7 +1179,7 @@ void MainWindow::on_menu_export_config_triggered() { auto ent = ents.first(); QString config_core; - auto result = NekoRay::BuildConfig(ent, false, true); + auto result = BuildConfig(ent, false, true); config_core = QJsonObject2QString(result->coreConfig, true); QApplication::clipboard()->setText(config_core); @@ -1190,11 +1191,11 @@ void MainWindow::on_menu_export_config_triggered() { msg.setDefaultButton(QMessageBox::Ok); auto ret = msg.exec(); if (ret == 0) { - result = NekoRay::BuildConfig(ent, false, false); + result = BuildConfig(ent, false, false); config_core = QJsonObject2QString(result->coreConfig, true); QApplication::clipboard()->setText(config_core); } else if (ret == 1) { - result = NekoRay::BuildConfig(ent, true, false); + result = BuildConfig(ent, true, false); config_core = QJsonObject2QString(result->coreConfig, true); QApplication::clipboard()->setText(config_core); } @@ -1308,7 +1309,7 @@ void MainWindow::on_menu_scan_qr_triggered() { MessageBoxInfo(software_name, tr("QR Code not found")); } else { show_log_impl("QR Code Result:\n" + text); - NekoRay::sub::groupUpdater->AsyncUpdate(text); + NekoGui_sub::groupUpdater->AsyncUpdate(text); } #endif } @@ -1331,11 +1332,11 @@ void MainWindow::on_menu_select_all_triggered() { } void MainWindow::on_menu_delete_repeat_triggered() { - QList> out; - QList> out_del; + QList> out; + QList> out_del; - NekoRay::ProfileFilter::Uniq(NekoRay::profileManager->CurrentGroup()->Profiles(), out, true, false); - NekoRay::ProfileFilter::OnlyInSrc_ByPointer(NekoRay::profileManager->CurrentGroup()->Profiles(), out, out_del); + NekoGui::ProfileFilter::Uniq(NekoGui::profileManager->CurrentGroup()->Profiles(), out, true, false); + NekoGui::ProfileFilter::OnlyInSrc_ByPointer(NekoGui::profileManager->CurrentGroup()->Profiles(), out, out_del); int remove_display_count = 0; QString remove_display; @@ -1350,7 +1351,7 @@ void MainWindow::on_menu_delete_repeat_triggered() { if (out_del.length() > 0 && QMessageBox::question(this, tr("Confirmation"), tr("Remove %1 item(s) ?").arg(out_del.length()) + "\n" + remove_display) == QMessageBox::StandardButton::Yes) { for (const auto &ent: out_del) { - NekoRay::profileManager->DeleteProfile(ent->id); + NekoGui::profileManager->DeleteProfile(ent->id); } refresh_proxy_list(); } @@ -1359,18 +1360,18 @@ void MainWindow::on_menu_delete_repeat_triggered() { bool mw_sub_updating = false; void MainWindow::on_menu_update_subscription_triggered() { - auto group = NekoRay::profileManager->CurrentGroup(); + auto group = NekoGui::profileManager->CurrentGroup(); if (group->url.isEmpty()) return; if (mw_sub_updating) return; mw_sub_updating = true; - NekoRay::sub::groupUpdater->AsyncUpdate(group->url, group->id, [&] { mw_sub_updating = false; }); + NekoGui_sub::groupUpdater->AsyncUpdate(group->url, group->id, [&] { mw_sub_updating = false; }); } void MainWindow::on_menu_remove_unavailable_triggered() { - QList> out_del; + QList> out_del; - for (const auto &profile: NekoRay::profileManager->profiles) { - if (NekoRay::dataStore->current_group != profile->gid) continue; + for (const auto &profile: NekoGui::profileManager->profiles) { + if (NekoGui::dataStore->current_group != profile->gid) continue; if (profile->latency < 0) out_del += profile; } @@ -1387,7 +1388,7 @@ void MainWindow::on_menu_remove_unavailable_triggered() { if (out_del.length() > 0 && QMessageBox::question(this, tr("Confirmation"), tr("Remove %1 item(s) ?").arg(out_del.length()) + "\n" + remove_display) == QMessageBox::StandardButton::Yes) { for (const auto &ent: out_del) { - NekoRay::profileManager->DeleteProfile(ent->id); + NekoGui::profileManager->DeleteProfile(ent->id); } refresh_proxy_list(); } @@ -1404,12 +1405,12 @@ void MainWindow::on_menu_resolve_domain_triggered() { } if (mw_sub_updating) return; mw_sub_updating = true; - NekoRay::dataStore->resolve_count = profiles.count(); + NekoGui::dataStore->resolve_count = profiles.count(); for (const auto &profile: profiles) { profile->bean->ResolveDomainToIP([=] { profile->Save(); - if (--NekoRay::dataStore->resolve_count != 0) return; + if (--NekoGui::dataStore->resolve_count != 0) return; refresh_proxy_list(); mw_sub_updating = false; }); @@ -1420,36 +1421,36 @@ void MainWindow::on_proxyListTable_customContextMenuRequested(const QPoint &pos) ui->menu_server->popup(ui->proxyListTable->viewport()->mapToGlobal(pos)); // 弹出菜单 } -QMap> MainWindow::get_now_selected() { +QMap> MainWindow::get_now_selected() { auto items = ui->proxyListTable->selectedItems(); - QMap> map; + QMap> map; for (auto item: items) { auto id = item->data(114514).toInt(); - auto ent = NekoRay::profileManager->GetProfile(id); + auto ent = NekoGui::profileManager->GetProfile(id); if (ent != nullptr) map[id] = ent; } return map; } -QList> MainWindow::get_now_selected_list() { +QList> MainWindow::get_now_selected_list() { auto items = ui->proxyListTable->selectedItems(); - QList> list; + QList> list; for (auto item: items) { auto id = item->data(114514).toInt(); - auto ent = NekoRay::profileManager->GetProfile(id); + auto ent = NekoGui::profileManager->GetProfile(id); if (ent != nullptr && !list.contains(ent)) list += ent; } return list; } -QList> MainWindow::get_selected_or_group() { +QList> MainWindow::get_selected_or_group() { auto selected_or_group = ui->menu_server->property("selected_or_group").toInt(); - QList> profiles; + QList> profiles; if (selected_or_group > 0) { profiles = get_now_selected_list(); - if (profiles.isEmpty() && selected_or_group == 2) profiles = NekoRay::profileManager->CurrentGroup()->ProfilesWithOrder(); + if (profiles.isEmpty() && selected_or_group == 2) profiles = NekoGui::profileManager->CurrentGroup()->ProfilesWithOrder(); } else { - profiles = NekoRay::profileManager->CurrentGroup()->ProfilesWithOrder(); + profiles = NekoGui::profileManager->CurrentGroup()->ProfilesWithOrder(); } return profiles; } @@ -1483,7 +1484,7 @@ void MainWindow::show_log_impl(const QString &log) { if (lines.isEmpty()) return; QStringList newLines; - auto log_ignore = NekoRay::dataStore->log_ignore; + auto log_ignore = NekoGui::dataStore->log_ignore; for (const auto &line: lines) { bool showThisLine = true; for (const auto &str: log_ignore) { @@ -1502,7 +1503,7 @@ void MainWindow::show_log_impl(const QString &log) { auto block = qvLogDocument->begin(); while (block.isValid()) { - if (qvLogDocument->blockCount() > NekoRay::dataStore->max_log_line) { + if (qvLogDocument->blockCount() > NekoGui::dataStore->max_log_line) { QTextCursor cursor(block); block = block.next(); cursor.select(QTextCursor::BlockUnderCursor); @@ -1515,32 +1516,32 @@ void MainWindow::show_log_impl(const QString &log) { } #define ADD_TO_CURRENT_ROUTE(a, b) \ - NekoRay::dataStore->routing->a = (SplitLines(NekoRay::dataStore->routing->a) << (b)).join("\n"); \ - NekoRay::dataStore->routing->Save(); + NekoGui::dataStore->routing->a = (SplitLines(NekoGui::dataStore->routing->a) << (b)).join("\n"); \ + NekoGui::dataStore->routing->Save(); void MainWindow::on_masterLogBrowser_customContextMenuRequested(const QPoint &pos) { QMenu *menu = ui->masterLogBrowser->createStandardContextMenu(); - auto sep = new QAction; + auto sep = new QAction(this); sep->setSeparator(true); menu->addAction(sep); - auto action_add_ignore = new QAction; + auto action_add_ignore = new QAction(this); action_add_ignore->setText(tr("Set ignore keyword")); connect(action_add_ignore, &QAction::triggered, this, [=] { - auto list = NekoRay::dataStore->log_ignore; + auto list = NekoGui::dataStore->log_ignore; auto newStr = ui->masterLogBrowser->textCursor().selectedText().trimmed(); if (!newStr.isEmpty()) list << newStr; bool ok; newStr = QInputDialog::getMultiLineText(GetMessageBoxParent(), tr("Set ignore keyword"), tr("Set the following keywords to ignore?\nSplit by line."), list.join("\n"), &ok); if (ok) { - NekoRay::dataStore->log_ignore = SplitLines(newStr); - NekoRay::dataStore->Save(); + NekoGui::dataStore->log_ignore = SplitLines(newStr); + NekoGui::dataStore->Save(); } }); menu->addAction(action_add_ignore); - auto action_add_route = new QAction; + auto action_add_route = new QAction(this); action_add_route->setText(tr("Save as route")); connect(action_add_route, &QAction::triggered, this, [=] { auto newStr = ui->masterLogBrowser->textCursor().selectedText().trimmed(); @@ -1585,7 +1586,7 @@ void MainWindow::on_masterLogBrowser_customContextMenuRequested(const QPoint &po }); menu->addAction(action_add_route); - auto action_clear = new QAction; + auto action_clear = new QAction(this); action_clear->setText(tr("Clear")); connect(action_clear, &QAction::triggered, this, [=] { qvLogDocument->clear(); @@ -1630,14 +1631,14 @@ void MainWindow::refresh_connection_list(const QJsonArray &arr) { } last_arr = arr; - if (NekoRay::dataStore->flag_debug) qDebug() << arr; + if (NekoGui::dataStore->flag_debug) qDebug() << arr; ui->tableWidget_conn->setRowCount(0); int row = -1; for (const auto &_item: arr) { auto item = _item.toObject(); - if (NekoRay::dataStore->ignoreConnTag.contains(item["Tag"].toString())) continue; + if (NekoGui::dataStore->ignoreConnTag.contains(item["Tag"].toString())) continue; row++; ui->tableWidget_conn->insertRow(row); @@ -1688,7 +1689,7 @@ void MainWindow::refresh_connection_list(const QJsonArray &arr) { #include -inline QList> RegisteredHotkey; +inline QList> RegisteredHotkey; void MainWindow::RegisterHotkey(bool unregister) { while (!RegisteredHotkey.isEmpty()) { @@ -1698,10 +1699,10 @@ void MainWindow::RegisterHotkey(bool unregister) { if (unregister) return; QStringList regstr{ - NekoRay::dataStore->hotkey_mainwindow, - NekoRay::dataStore->hotkey_group, - NekoRay::dataStore->hotkey_route, - NekoRay::dataStore->hotkey_system_proxy_menu, + NekoGui::dataStore->hotkey_mainwindow, + NekoGui::dataStore->hotkey_group, + NekoGui::dataStore->hotkey_route, + NekoGui::dataStore->hotkey_system_proxy_menu, }; for (const auto &key: regstr) { @@ -1711,7 +1712,7 @@ void MainWindow::RegisterHotkey(bool unregister) { for (const auto &key: regstr) { QKeySequence k(key); if (k.isEmpty()) continue; - auto hk = QSharedPointer(new QHotkey(k, true)); + auto hk = std::make_shared(k, true); if (hk->isRegistered()) { RegisteredHotkey += hk; connect(hk.get(), &QHotkey::activated, this, [=] { HotkeyEvent(key); }); @@ -1724,13 +1725,13 @@ void MainWindow::RegisterHotkey(bool unregister) { void MainWindow::HotkeyEvent(const QString &key) { if (key.isEmpty()) return; runOnUiThread([=] { - if (key == NekoRay::dataStore->hotkey_mainwindow) { + if (key == NekoGui::dataStore->hotkey_mainwindow) { tray->activated(QSystemTrayIcon::ActivationReason::Trigger); - } else if (key == NekoRay::dataStore->hotkey_group) { + } else if (key == NekoGui::dataStore->hotkey_group) { on_menu_manage_groups_triggered(); - } else if (key == NekoRay::dataStore->hotkey_route) { + } else if (key == NekoGui::dataStore->hotkey_route) { on_menu_routing_settings_triggered(); - } else if (key == NekoRay::dataStore->hotkey_system_proxy_menu) { + } else if (key == NekoGui::dataStore->hotkey_system_proxy_menu) { ui->menu_spmode->popup(QCursor::pos()); } }); @@ -1753,15 +1754,15 @@ bool MainWindow::StartVPNProcess() { } // auto protectPath = QDir::currentPath() + "/protect"; - auto configPath = NekoRay::WriteVPNSingBoxConfig(); - auto scriptPath = NekoRay::WriteVPNLinuxScript(protectPath, configPath); + auto configPath = NekoGui::WriteVPNSingBoxConfig(); + auto scriptPath = NekoGui::WriteVPNLinuxScript(protectPath, configPath); // #ifdef Q_OS_WIN runOnNewThread([=] { vpn_pid = 1; // TODO get pid? WinCommander::runProcessElevated(QApplication::applicationDirPath() + "/nekobox_core.exe", {"--disable-color", "run", "-c", configPath}, "", - NekoRay::dataStore->vpn_hide_console ? WinCommander::SW_HIDE : WinCommander::SW_SHOWMINIMIZED); // blocking + NekoGui::dataStore->vpn_hide_console ? WinCommander::SW_HIDE : WinCommander::SW_SHOWMINIMIZED); // blocking vpn_pid = 0; runOnUiThread([=] { neko_set_spmode_vpn(false); }); }); diff --git a/ui/mainwindow.h b/ui/mainwindow.h index 9849561..9789d76 100644 --- a/ui/mainwindow.h +++ b/ui/mainwindow.h @@ -2,7 +2,7 @@ #include -#include "main/NekoRay.hpp" +#include "main/NekoGui.hpp" #ifndef MW_INTERFACE @@ -23,7 +23,7 @@ #endif -namespace NekoRay::sys { +namespace NekoGui_sys { class CoreProcess; } @@ -141,7 +141,7 @@ private: QShortcut *shortcut_ctrl_f = new QShortcut(QKeySequence("Ctrl+F"), this); QShortcut *shortcut_esc = new QShortcut(QKeySequence("Esc"), this); // - NekoRay::sys::CoreProcess *core_process; + NekoGui_sys::CoreProcess *core_process; qint64 vpn_pid = 0; // bool qvLogAutoScoll = true; @@ -149,7 +149,7 @@ private: // QString title_error; int icon_status = -1; - QSharedPointer running; + std::shared_ptr running; QString traffic_update_cache; QTime last_test_time; // @@ -161,15 +161,15 @@ private: QSemaphore sem_stopped; int exit_reason = 0; - QMap> get_now_selected(); + QMap> get_now_selected(); - QList> get_now_selected_list(); + QList> get_now_selected_list(); - QList> get_selected_or_group(); + QList> get_selected_or_group(); void dialog_message_impl(const QString &sender, const QString &info); - void refresh_proxy_list_impl(const int &id = -1, NekoRay::GroupSortAction groupSortAction = {}); + void refresh_proxy_list_impl(const int &id = -1, GroupSortAction groupSortAction = {}); void refresh_proxy_list_impl_refresh_data(const int &id = -1); diff --git a/ui/mainwindow_grpc.cpp b/ui/mainwindow_grpc.cpp index 93cd076..f9a6fd0 100644 --- a/ui/mainwindow_grpc.cpp +++ b/ui/mainwindow_grpc.cpp @@ -3,7 +3,7 @@ #include "db/Database.hpp" #include "db/ConfigBuilder.hpp" -#include "db/TrafficLooper.hpp" +#include "db/traffic/TrafficLooper.hpp" #include "rpc/gRPC.h" #include "ui/widget/MessageBoxTimer.h" @@ -16,11 +16,11 @@ // ext core -std::list> CreateExtCFromExtR(const std::list> &extRs, bool start) { +std::list> CreateExtCFromExtR(const std::list> &extRs, bool start) { // plz run and start in same thread - std::list> l; + std::list> l; for (const auto &extR: extRs) { - QSharedPointer extC(new NekoRay::sys::ExternalProcess()); + std::shared_ptr extC(new NekoGui_sys::ExternalProcess()); extC->tag = extR->tag; extC->program = extR->program; extC->arguments = extR->arguments; @@ -35,7 +35,7 @@ std::list> CreateExtCFromExtR(cons // grpc #ifndef NKR_NO_GRPC -using namespace NekoRay::rpc; +using namespace NekoGui_rpc; #endif void MainWindow::setup_grpc() { @@ -45,10 +45,10 @@ void MainWindow::setup_grpc() { [=](const QString &errStr) { MW_show_log("[Error] gRPC: " + errStr); }, - "127.0.0.1:" + Int2String(NekoRay::dataStore->core_port), NekoRay::dataStore->core_token); + "127.0.0.1:" + Int2String(NekoGui::dataStore->core_port), NekoGui::dataStore->core_token); // Looper - runOnNewThread([=] { NekoRay::traffic::trafficLooper->Loop(); }); + runOnNewThread([=] { NekoGui_traffic::trafficLooper->Loop(); }); #endif } @@ -59,7 +59,7 @@ inline bool speedtesting = false; void MainWindow::speedtest_current_group(int mode) { auto profiles = get_selected_or_group(); if (profiles.isEmpty()) return; - auto group = NekoRay::profileManager->CurrentGroup(); + auto group = NekoGui::profileManager->CurrentGroup(); if (group->archive) return; #ifndef NKR_NO_GRPC @@ -82,7 +82,7 @@ void MainWindow::speedtest_current_group(int mode) { runOnNewThread([this, profiles, mode, full_test_flags]() { QMutex lock_write; QMutex lock_return; - int threadN = NekoRay::dataStore->test_concurrent; + int threadN = NekoGui::dataStore->test_concurrent; int threadN_finished = 0; auto profiles_test = profiles; // copy @@ -106,13 +106,13 @@ void MainWindow::speedtest_current_group(int mode) { libcore::TestReq req; req.set_mode((libcore::TestMode) mode); req.set_timeout(3000); - req.set_url(NekoRay::dataStore->test_url.toStdString()); + req.set_url(NekoGui::dataStore->test_url.toStdString()); // - std::list> extCs; + std::list> extCs; if (mode == libcore::TestMode::UrlTest || mode == libcore::FullTest) { - auto c = NekoRay::BuildConfig(profile, true, false); + auto c = BuildConfig(profile, true, false); // TODO refactor external test if (!c->extRs.empty()) { extCs = CreateExtCFromExtR(c->extRs, true); @@ -177,7 +177,7 @@ void MainWindow::speedtest_current() { libcore::TestReq req; req.set_mode(libcore::UrlTest); req.set_timeout(3000); - req.set_url(NekoRay::dataStore->test_url.toStdString()); + req.set_url(NekoGui::dataStore->test_url.toStdString()); bool rpcOK; auto result = defaultClient->Test(&rpcOK, req); @@ -202,15 +202,15 @@ void MainWindow::speedtest_current() { void MainWindow::stop_core_daemon() { #ifndef NKR_NO_GRPC - NekoRay::rpc::defaultClient->Exit(); + NekoGui_rpc::defaultClient->Exit(); #endif } void MainWindow::neko_start(int _id) { - if (NekoRay::dataStore->prepare_exit) return; + if (NekoGui::dataStore->prepare_exit) return; auto ents = get_now_selected(); - auto ent = (_id < 0 && !ents.isEmpty()) ? ents.first() : NekoRay::profileManager->GetProfile(_id); + auto ent = (_id < 0 && !ents.isEmpty()) ? ents.first() : NekoGui::profileManager->GetProfile(_id); if (ent == nullptr) return; if (select_mode) { @@ -220,10 +220,10 @@ void MainWindow::neko_start(int _id) { return; } - auto group = NekoRay::profileManager->GetGroup(ent->gid); + auto group = NekoGui::profileManager->GetGroup(ent->gid); if (group == nullptr || group->archive) return; - auto result = NekoRay::BuildConfig(ent, false, false); + auto result = BuildConfig(ent, false, false); if (!result->error.isEmpty()) { MessageBoxWarning("BuildConfig return error", result->error); return; @@ -233,8 +233,8 @@ void MainWindow::neko_start(int _id) { #ifndef NKR_NO_GRPC libcore::LoadConfigReq req; req.set_core_config(QJsonObject2QString(result->coreConfig, true).toStdString()); - req.set_enable_nekoray_connections(NekoRay::dataStore->connection_statistics); - if (NekoRay::dataStore->traffic_loop_interval > 0) { + req.set_enable_nekoray_connections(NekoGui::dataStore->connection_statistics); + if (NekoGui::dataStore->traffic_loop_interval > 0) { req.add_stats_outbounds("proxy"); req.add_stats_outbounds("bypass"); } @@ -248,20 +248,20 @@ void MainWindow::neko_start(int _id) { return false; } // - NekoRay::traffic::trafficLooper->proxy = result->outboundStat.get(); - NekoRay::traffic::trafficLooper->items = result->outboundStats; - NekoRay::dataStore->ignoreConnTag = result->ignoreConnTag; - NekoRay::traffic::trafficLooper->loop_enabled = true; + NekoGui_traffic::trafficLooper->proxy = result->outboundStat.get(); + NekoGui_traffic::trafficLooper->items = result->outboundStats; + NekoGui::dataStore->ignoreConnTag = result->ignoreConnTag; + NekoGui_traffic::trafficLooper->loop_enabled = true; #endif runOnUiThread( [=] { auto extCs = CreateExtCFromExtR(result->extRs, true); - NekoRay::sys::running_ext.splice(NekoRay::sys::running_ext.end(), extCs); + NekoGui_sys::running_ext.splice(NekoGui_sys::running_ext.end(), extCs); }, DS_cores); - NekoRay::dataStore->UpdateStartedId(ent->id); + NekoGui::dataStore->UpdateStartedId(ent->id); running = ent; runOnUiThread([=] { @@ -284,7 +284,7 @@ void MainWindow::neko_start(int _id) { mu_stopping.unlock(); // check core state - if (!NekoRay::dataStore->core_running) { + if (!NekoGui::dataStore->core_running) { runOnUiThread( [=] { show_log_impl("Try to start the config, but the core has not listened to the grpc port, so restart it..."); @@ -304,7 +304,7 @@ void MainWindow::neko_start(int _id) { runOnNewThread([=] { // stop current running - if (NekoRay::dataStore->started_id >= 0) { + if (NekoGui::dataStore->started_id >= 0) { runOnUiThread([=] { neko_stop(false, true); }); sem_stopped.acquire(); } @@ -324,7 +324,7 @@ void MainWindow::neko_start(int _id) { } void MainWindow::neko_stop(bool crash, bool sem) { - auto id = NekoRay::dataStore->started_id; + auto id = NekoGui::dataStore->started_id; if (id < 0) { if (sem) sem_stopped.release(); return; @@ -333,25 +333,25 @@ void MainWindow::neko_stop(bool crash, bool sem) { auto neko_stop_stage2 = [=] { runOnUiThread( [=] { - while (!NekoRay::sys::running_ext.empty()) { - auto extC = NekoRay::sys::running_ext.front(); + while (!NekoGui_sys::running_ext.empty()) { + auto extC = NekoGui_sys::running_ext.front(); extC->Kill(); - NekoRay::sys::running_ext.pop_front(); + NekoGui_sys::running_ext.pop_front(); } }, DS_cores); #ifndef NKR_NO_GRPC - NekoRay::traffic::trafficLooper->loop_enabled = false; - NekoRay::traffic::trafficLooper->loop_mutex.lock(); - if (NekoRay::dataStore->traffic_loop_interval != 0) { - NekoRay::traffic::trafficLooper->UpdateAll(); - for (const auto &item: NekoRay::traffic::trafficLooper->items) { - NekoRay::profileManager->GetProfile(item->id)->Save(); + NekoGui_traffic::trafficLooper->loop_enabled = false; + NekoGui_traffic::trafficLooper->loop_mutex.lock(); + if (NekoGui::dataStore->traffic_loop_interval != 0) { + NekoGui_traffic::trafficLooper->UpdateAll(); + for (const auto &item: NekoGui_traffic::trafficLooper->items) { + NekoGui::profileManager->GetProfile(item->id)->Save(); runOnUiThread([=] { refresh_proxy_list(item->id); }); } } - NekoRay::traffic::trafficLooper->loop_mutex.unlock(); + NekoGui_traffic::trafficLooper->loop_mutex.unlock(); if (!crash) { bool rpcOK; @@ -365,8 +365,8 @@ void MainWindow::neko_stop(bool crash, bool sem) { } #endif - NekoRay::dataStore->UpdateStartedId(-1919); - NekoRay::dataStore->need_keep_vpn_off = false; + NekoGui::dataStore->UpdateStartedId(-1919); + NekoGui::dataStore->need_keep_vpn_off = false; running = nullptr; runOnUiThread([=] { @@ -411,8 +411,8 @@ void MainWindow::CheckUpdate() { bool ok; libcore::UpdateReq request; request.set_action(libcore::UpdateAction::Check); - request.set_check_pre_release(NekoRay::dataStore->check_include_pre); - auto response = NekoRay::rpc::defaultClient->Update(&ok, request); + request.set_check_pre_release(NekoGui::dataStore->check_include_pre); + auto response = NekoGui_rpc::defaultClient->Update(&ok, request); if (!ok) return; auto err = response.error(); @@ -431,7 +431,7 @@ void MainWindow::CheckUpdate() { } runOnUiThread([=] { - auto allow_updater = !NekoRay::dataStore->flag_use_appdata; + auto allow_updater = !NekoGui::dataStore->flag_use_appdata; auto note_pre_release = response.is_pre_release() ? " (Pre-release)" : ""; QMessageBox box(QMessageBox::Question, QObject::tr("Update") + note_pre_release, QObject::tr("Update found: %1\nRelease note:\n%2").arg(response.assets_name().c_str(), response.release_note().c_str())); @@ -450,7 +450,7 @@ void MainWindow::CheckUpdate() { bool ok2; libcore::UpdateReq request2; request2.set_action(libcore::UpdateAction::Download); - auto response2 = NekoRay::rpc::defaultClient->Update(&ok2, request2); + auto response2 = NekoGui_rpc::defaultClient->Update(&ok2, request2); runOnUiThread([=] { if (response2.error().empty()) { auto q = QMessageBox::question(nullptr, QObject::tr("Update"), diff --git a/ui/widget/GroupItem.cpp b/ui/widget/GroupItem.cpp index 8a64f8b..19f307d 100644 --- a/ui/widget/GroupItem.cpp +++ b/ui/widget/GroupItem.cpp @@ -41,7 +41,7 @@ QString ParseSubInfo(const QString &info) { return result; } -GroupItem::GroupItem(QWidget *parent, const QSharedPointer &ent, QListWidgetItem *item) : QWidget(parent), ui(new Ui::GroupItem) { +GroupItem::GroupItem(QWidget *parent, const std::shared_ptr &ent, QListWidgetItem *item) : QWidget(parent), ui(new Ui::GroupItem) { ui->setupUi(this); this->setLayoutDirection(Qt::LeftToRight); @@ -50,7 +50,7 @@ GroupItem::GroupItem(QWidget *parent, const QSharedPointer &ent, if (ent == nullptr) return; connect(this, &GroupItem::edit_clicked, this, &GroupItem::on_edit_clicked); - connect(NekoRay::sub::groupUpdater, &NekoRay::sub::GroupUpdater::asyncUpdateCallback, this, [=](int gid) { if (gid == this->ent->id) refresh_data(); }); + connect(NekoGui_sub::groupUpdater, &NekoGui_sub::GroupUpdater::asyncUpdateCallback, this, [=](int gid) { if (gid == this->ent->id) refresh_data(); }); refresh_data(); } @@ -74,8 +74,8 @@ void GroupItem::refresh_data() { } else { ui->url->setText(ent->url); QStringList info; - if (ent->last_update != 0) { - info << tr("Last update: %1").arg(DisplayTime(ent->last_update, QLocale::ShortFormat)); + if (ent->sub_last_update != 0) { + info << tr("Last update: %1").arg(DisplayTime(ent->sub_last_update, QLocale::ShortFormat)); } auto subinfo = ParseSubInfo(ent->info); if (!ent->info.isEmpty()) { @@ -98,7 +98,7 @@ void GroupItem::refresh_data() { } void GroupItem::on_update_sub_clicked() { - NekoRay::sub::groupUpdater->AsyncUpdate(ent->url, ent->id); + NekoGui_sub::groupUpdater->AsyncUpdate(ent->url, ent->id); } void GroupItem::on_edit_clicked() { @@ -114,10 +114,10 @@ void GroupItem::on_edit_clicked() { } void GroupItem::on_remove_clicked() { - if (NekoRay::profileManager->groups.count() == 1) return; + if (NekoGui::profileManager->groups.count() == 1) return; if (QMessageBox::question(this, tr("Confirmation"), tr("Remove %1?").arg(ent->name)) == QMessageBox::StandardButton::Yes) { - NekoRay::profileManager->DeleteGroup(ent->id); + NekoGui::profileManager->DeleteGroup(ent->id); MW_dialog_message(Dialog_DialogManageGroups, "refresh-1"); delete item; } diff --git a/ui/widget/GroupItem.h b/ui/widget/GroupItem.h index 0781879..61c7e58 100644 --- a/ui/widget/GroupItem.h +++ b/ui/widget/GroupItem.h @@ -15,13 +15,13 @@ class GroupItem : public QWidget { Q_OBJECT public: - explicit GroupItem(QWidget *parent, const QSharedPointer &ent, QListWidgetItem *item); + explicit GroupItem(QWidget *parent, const std::shared_ptr &ent, QListWidgetItem *item); ~GroupItem() override; void refresh_data(); - QSharedPointer ent; + std::shared_ptr ent; QListWidgetItem *item; private: diff --git a/ui/widget/ProxyItem.cpp b/ui/widget/ProxyItem.cpp index edc2b47..f8c1587 100644 --- a/ui/widget/ProxyItem.cpp +++ b/ui/widget/ProxyItem.cpp @@ -3,7 +3,7 @@ #include -ProxyItem::ProxyItem(QWidget *parent, const QSharedPointer &ent, QListWidgetItem *item) +ProxyItem::ProxyItem(QWidget *parent, const std::shared_ptr &ent, QListWidgetItem *item) : QWidget(parent), ui(new Ui::ProxyItem) { ui->setupUi(this); this->setLayoutDirection(Qt::LeftToRight); diff --git a/ui/widget/ProxyItem.h b/ui/widget/ProxyItem.h index 208c243..ac8058f 100644 --- a/ui/widget/ProxyItem.h +++ b/ui/widget/ProxyItem.h @@ -17,7 +17,7 @@ class ProxyItem : public QWidget { Q_OBJECT public: - explicit ProxyItem(QWidget *parent, const QSharedPointer &ent, QListWidgetItem *item); + explicit ProxyItem(QWidget *parent, const std::shared_ptr &ent, QListWidgetItem *item); ~ProxyItem() override; @@ -25,7 +25,7 @@ public: QPushButton *get_change_button(); - QSharedPointer ent; + std::shared_ptr ent; QListWidgetItem *item; bool remove_confirm = false;