minor refactor

This commit is contained in:
arm64v8a
2023-05-22 11:07:14 +09:00
parent 1b050dd3fb
commit c5122b77e4
98 changed files with 1173 additions and 1142 deletions

View File

@@ -60,7 +60,7 @@ uint WinCommander::runProcessElevated(const QString &path,
LPCTSTR pszParameters = (LPCTSTR)params.utf16(); LPCTSTR pszParameters = (LPCTSTR)params.utf16();
QString dir; QString dir;
if (workingDir.isEmpty()) if (workingDir.count() == 0)
dir = QDir::toNativeSeparators(QDir::currentPath()); dir = QDir::toNativeSeparators(QDir::currentPath());
else else
dir = QDir::toNativeSeparators(workingDir); dir = QDir::toNativeSeparators(workingDir);

4
3rdparty/base64.cpp vendored
View File

@@ -1,5 +1,9 @@
#include "base64.h" #include "base64.h"
#ifndef qsizetype
#define qsizetype size_t
#endif
namespace Qt515Base64 { namespace Qt515Base64 {
namespace { namespace {
struct fromBase64_helper_result { struct fromBase64_helper_result {

11
3rdparty/fix_old_qt.h vendored Normal file
View File

@@ -0,0 +1,11 @@
#pragma once
#include <QString>
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
inline QString qEnvironmentVariable(const char *varName) {
return qgetenv(varName);
}
#endif

View File

@@ -16,9 +16,10 @@
#include <QStandardPaths> #include <QStandardPaths>
#include <QProcess> #include <QProcess>
#include "3rdparty/fix_old_qt.h"
#include "3rdparty/qv2ray/wrapper.hpp" #include "3rdparty/qv2ray/wrapper.hpp"
#include "fmt/Preset.hpp" #include "fmt/Preset.hpp"
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
#define QV_MODULE_NAME "SystemProxy" #define QV_MODULE_NAME "SystemProxy"
@@ -253,7 +254,7 @@ namespace Qv2ray::components::proxy {
#endif #endif
#ifdef Q_OS_WIN #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]; if (str.isEmpty()) str = Preset::Windows::system_proxy_format[0];
str = str.replace("{ip}", address) str = str.replace("{ip}", address)
.replace("{http_port}", Int2String(httpPort)) .replace("{http_port}", Int2String(httpPort))

View File

@@ -118,7 +118,7 @@ namespace Qv2ray::ui {
} }
void SyntaxHighlighter::highlightBlock(const QString &text) { void SyntaxHighlighter::highlightBlock(const QString &text) {
for (const HighlightingRule &rule: qAsConst(highlightingRules)) { for (const HighlightingRule &rule: highlightingRules) {
QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text); QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text);
while (matchIterator.hasNext()) { while (matchIterator.hasNext()) {

View File

@@ -55,7 +55,8 @@
#include <QTextCharFormat> #include <QTextCharFormat>
#include <QTextDocument> #include <QTextDocument>
namespace Qv2ray::ui { namespace Qv2ray {
namespace ui {
class SyntaxHighlighter : public QSyntaxHighlighter { class SyntaxHighlighter : public QSyntaxHighlighter {
Q_OBJECT Q_OBJECT
@@ -85,6 +86,7 @@ namespace Qv2ray::ui {
QTextCharFormat ipHostFormat; QTextCharFormat ipHostFormat;
QTextCharFormat v2rayComponentFormat; QTextCharFormat v2rayComponentFormat;
}; };
} // namespace Qv2ray::ui } // namespace ui
} // namespace Qv2ray
using namespace Qv2ray::ui; using namespace Qv2ray::ui;

View File

@@ -70,7 +70,7 @@ namespace Qv2ray::ui::widgets {
c->setWidget(this); c->setWidget(this);
c->setCompletionMode(QCompleter::PopupCompletion); c->setCompletionMode(QCompleter::PopupCompletion);
c->setCaseSensitivity(Qt::CaseInsensitive); c->setCaseSensitivity(Qt::CaseInsensitive);
QObject::connect(c, QOverload<const QString &>::of(&QCompleter::activated), this, &AutoCompleteTextEdit::insertCompletion); QObject::connect(c, static_cast<void (QCompleter::*)(const QString &)>(&QCompleter::activated), this, &AutoCompleteTextEdit::insertCompletion);
} }
AutoCompleteTextEdit::~AutoCompleteTextEdit() { AutoCompleteTextEdit::~AutoCompleteTextEdit() {

View File

@@ -55,7 +55,9 @@ QT_BEGIN_NAMESPACE
class QCompleter; class QCompleter;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Qv2ray::ui::widgets { namespace Qv2ray {
namespace ui {
namespace widgets {
class AutoCompleteTextEdit : public QPlainTextEdit { class AutoCompleteTextEdit : public QPlainTextEdit {
Q_OBJECT Q_OBJECT
@@ -77,5 +79,7 @@ namespace Qv2ray::ui::widgets {
QString prefix; QString prefix;
QCompleter *c = nullptr; QCompleter *c = nullptr;
}; };
} // namespace Qv2ray::ui::widgets } // namespace widgets
} // namespace ui
} // namespace Qv2ray
using namespace Qv2ray::ui::widgets; using namespace Qv2ray::ui::widgets;

View File

@@ -1,6 +1,6 @@
#include "w_JsonEditor.hpp" #include "w_JsonEditor.hpp"
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
JsonEditor::JsonEditor(const QJsonObject& rootObject, QWidget* parent) : QDialog(parent) { JsonEditor::JsonEditor(const QJsonObject& rootObject, QWidget* parent) : QDialog(parent) {
setupUi(this); setupUi(this);

View File

@@ -7,10 +7,12 @@
#define LOG(...) Qv2ray::base::log_internal(__VA_ARGS__) #define LOG(...) Qv2ray::base::log_internal(__VA_ARGS__)
#define DEBUG(...) Qv2ray::base::log_internal(__VA_ARGS__) #define DEBUG(...) Qv2ray::base::log_internal(__VA_ARGS__)
namespace Qv2ray::base { namespace Qv2ray {
namespace base {
template<typename... T> template<typename... T>
inline void log_internal(T... v) {} inline void log_internal(T... v) {}
} // namespace Qv2ray::base } // namespace base
} // namespace Qv2ray
#define JsonToString(a) QJsonObject2QString(a, false) #define JsonToString(a) QJsonObject2QString(a, false)
#define JsonFromString(a) QString2QJsonObject(a) #define JsonFromString(a) QString2QJsonObject(a)

View File

@@ -138,8 +138,8 @@ set(PROJECT_SOURCES
${PLATFORM_SOURCES} ${PLATFORM_SOURCES}
main/main.cpp main/main.cpp
main/NekoRay.cpp main/NekoGui.cpp
main/NekoRay_Utils.cpp main/NekoGui_Utils.cpp
main/QJS.cpp main/QJS.cpp
main/HTTPRequestHelper.cpp main/HTTPRequestHelper.cpp
@@ -161,7 +161,7 @@ set(PROJECT_SOURCES
rpc/gRPC.cpp rpc/gRPC.cpp
db/Database.cpp db/Database.cpp
db/TrafficLooper.cpp db/traffic/TrafficLooper.cpp
db/ProfileFilter.cpp db/ProfileFilter.cpp
db/ConfigBuilder.cpp db/ConfigBuilder.cpp

View File

@@ -8,12 +8,12 @@
#include <QFile> #include <QFile>
#include <QFileInfo> #include <QFileInfo>
#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 dataStore->core_box_underlying_dns.isEmpty() ? "underlying://0.0.0.0" : 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_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<BuildConfigResult> &result) { QStringList getAutoBypassExternalProcessPaths(const std::shared_ptr<BuildConfigResult> &result) {
QStringList paths; QStringList paths;
for (const auto &extR: result->extRs) { for (const auto &extR: result->extRs) {
auto path = extR->program; auto path = extR->program;
@@ -54,15 +54,15 @@ namespace NekoRay {
// Common // Common
QSharedPointer<BuildConfigResult> BuildConfig(const QSharedPointer<ProxyEntity> &ent, bool forTest, bool forExport) { std::shared_ptr<BuildConfigResult> BuildConfig(const std::shared_ptr<ProxyEntity> &ent, bool forTest, bool forExport) {
auto result = QSharedPointer<BuildConfigResult>(new BuildConfigResult); auto result = std::make_shared<BuildConfigResult>();
auto status = QSharedPointer<BuildConfigStatus>(new BuildConfigStatus); auto status = std::make_shared<BuildConfigStatus>();
status->ent = ent; status->ent = ent;
status->result = result; status->result = result;
status->forTest = forTest; status->forTest = forTest;
status->forExport = forExport; status->forExport = forExport;
auto customBean = dynamic_cast<fmt::CustomBean *>(ent->bean.get()); auto customBean = dynamic_cast<NekoGui_fmt::CustomBean *>(ent->bean.get());
if (customBean != nullptr && customBean->core == "internal-full") { if (customBean != nullptr && customBean->core == "internal-full") {
result->coreConfig = QString2QJsonObject(customBean->config_simple); result->coreConfig = QString2QJsonObject(customBean->config_simple);
} else { } else {
@@ -92,9 +92,9 @@ namespace NekoRay {
return result; return result;
} }
QString BuildChain(int chainId, const QSharedPointer<BuildConfigStatus> &status) { QString BuildChain(int chainId, const std::shared_ptr<BuildConfigStatus> &status) {
// Make list // Make list
QList<QSharedPointer<ProxyEntity>> ents; QList<std::shared_ptr<ProxyEntity>> ents;
auto ent = status->ent; auto ent = status->ent;
auto result = status->result; auto result = status->result;
@@ -155,7 +155,7 @@ namespace NekoRay {
// V2Ray // V2Ray
void BuildConfigV2Ray(const QSharedPointer<BuildConfigStatus> &status) { void BuildConfigV2Ray(const std::shared_ptr<BuildConfigStatus> &status) {
// Log // Log
auto logObj = QJsonObject{{"loglevel", dataStore->log_level}}; auto logObj = QJsonObject{{"loglevel", dataStore->log_level}};
status->result->coreConfig.insert("log", logObj); status->result->coreConfig.insert("log", logObj);
@@ -397,8 +397,8 @@ namespace NekoRay {
status->result->coreConfig.insert("stats", QJsonObject()); status->result->coreConfig.insert("stats", QJsonObject());
} }
QString BuildChainInternal(int chainId, const QList<QSharedPointer<ProxyEntity>> &ents, QString BuildChainInternal(int chainId, const QList<std::shared_ptr<ProxyEntity>> &ents,
const QSharedPointer<BuildConfigStatus> &status) { const std::shared_ptr<BuildConfigStatus> &status) {
QString chainTag = "c-" + Int2String(chainId); QString chainTag = "c-" + Int2String(chainId);
QString chainTagOut; QString chainTagOut;
bool muxApplied = false; bool muxApplied = false;
@@ -550,7 +550,7 @@ namespace NekoRay {
// Outbound // Outbound
QJsonObject outbound; QJsonObject outbound;
auto stream = GetStreamSettings(ent->bean.data()); auto stream = GetStreamSettings(ent->bean.get());
if (thisExternalStat > 0) { if (thisExternalStat > 0) {
auto extR = ent->bean->BuildExternal(ext_mapping_port, ext_socks_port, thisExternalStat); auto extR = ent->bean->BuildExternal(ext_mapping_port, ext_socks_port, thisExternalStat);
@@ -563,7 +563,7 @@ namespace NekoRay {
return {}; return {};
} }
extR.tag = ent->bean->DisplayType(); extR.tag = ent->bean->DisplayType();
status->result->extRs.emplace_back(std::make_shared<fmt::ExternalBuildResult>(extR)); status->result->extRs.emplace_back(std::make_shared<NekoGui_fmt::ExternalBuildResult>(extR));
// SOCKS OUTBOUND // SOCKS OUTBOUND
if (IS_NEKO_BOX) { if (IS_NEKO_BOX) {
@@ -664,7 +664,7 @@ namespace NekoRay {
// Bypass Lookup for the first profile // Bypass Lookup for the first profile
auto serverAddress = ent->bean->serverAddress; auto serverAddress = ent->bean->serverAddress;
auto customBean = dynamic_cast<fmt::CustomBean *>(ent->bean.get()); auto customBean = dynamic_cast<NekoGui_fmt::CustomBean *>(ent->bean.get());
if (customBean != nullptr && customBean->core == "internal") { if (customBean != nullptr && customBean->core == "internal") {
auto server = QString2QJsonObject(customBean->config_simple)["server"].toString(); auto server = QString2QJsonObject(customBean->config_simple)["server"].toString();
if (!server.isEmpty()) serverAddress = server; if (!server.isEmpty()) serverAddress = server;
@@ -685,7 +685,7 @@ namespace NekoRay {
// SingBox // SingBox
void BuildConfigSingBox(const QSharedPointer<BuildConfigStatus> &status) { void BuildConfigSingBox(const std::shared_ptr<BuildConfigStatus> &status) {
// Log // Log
status->result->coreConfig["log"] = QJsonObject{{"level", dataStore->log_level}}; status->result->coreConfig["log"] = QJsonObject{{"level", dataStore->log_level}};
@@ -921,7 +921,7 @@ namespace NekoRay {
// tun user rule // tun user rule
if (IS_NEKO_BOX_INTERNAL_TUN && dataStore->spmode_vpn) { 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(); QString process_name_rule = dataStore->vpn_rule_process.trimmed();
if (!process_name_rule.isEmpty()) { if (!process_name_rule.isEmpty()) {
@@ -984,10 +984,10 @@ namespace NekoRay {
// experimental // experimental
QJsonObject experimentalObj; QJsonObject experimentalObj;
if (!status->forTest && NekoRay::dataStore->core_box_clash_api > 0) { if (!status->forTest && dataStore->core_box_clash_api > 0) {
QJsonObject clash_api = { QJsonObject clash_api = {
{"external_controller", "127.0.0.1:" + Int2String(NekoRay::dataStore->core_box_clash_api)}, {"external_controller", "127.0.0.1:" + Int2String(dataStore->core_box_clash_api)},
{"secret", NekoRay::dataStore->core_box_clash_api_secret}, {"secret", dataStore->core_box_clash_api_secret},
{"external_ui", "dashboard"}, {"external_ui", "dashboard"},
}; };
experimentalObj["clash_api"] = clash_api; experimentalObj["clash_api"] = clash_api;
@@ -998,8 +998,8 @@ namespace NekoRay {
QString WriteVPNSingBoxConfig() { QString WriteVPNSingBoxConfig() {
// tun user rule // tun user rule
auto match_out = NekoRay::dataStore->vpn_rule_white ? "nekoray-socks" : "direct"; auto match_out = dataStore->vpn_rule_white ? "nekoray-socks" : "direct";
auto no_match_out = NekoRay::dataStore->vpn_rule_white ? "direct" : "nekoray-socks"; auto no_match_out = dataStore->vpn_rule_white ? "direct" : "nekoray-socks";
QString process_name_rule = dataStore->vpn_rule_process.trimmed(); QString process_name_rule = dataStore->vpn_rule_process.trimmed();
if (!process_name_rule.isEmpty()) { if (!process_name_rule.isEmpty()) {
@@ -1090,4 +1090,4 @@ namespace NekoRay {
return QFileInfo(file2).absoluteFilePath(); return QFileInfo(file2).absoluteFilePath();
} }
} // namespace NekoRay } // namespace NekoGui

View File

@@ -3,23 +3,23 @@
#include "ProxyEntity.hpp" #include "ProxyEntity.hpp"
#include "sys/ExternalProcess.hpp" #include "sys/ExternalProcess.hpp"
namespace NekoRay { namespace NekoGui {
class BuildConfigResult { class BuildConfigResult {
public: public:
QString error; QString error;
QJsonObject coreConfig; QJsonObject coreConfig;
QList<QSharedPointer<traffic::TrafficData>> outboundStats; // all, but not including "bypass" "block" QList<std::shared_ptr<NekoGui_traffic::TrafficData>> outboundStats; // all, but not including "bypass" "block"
QSharedPointer<traffic::TrafficData> outboundStat; // main std::shared_ptr<NekoGui_traffic::TrafficData> outboundStat; // main
QStringList ignoreConnTag; QStringList ignoreConnTag;
std::list<std::shared_ptr<NekoRay::fmt::ExternalBuildResult>> extRs; std::list<std::shared_ptr<NekoGui_fmt::ExternalBuildResult>> extRs;
}; };
class BuildConfigStatus { class BuildConfigStatus {
public: public:
QSharedPointer<BuildConfigResult> result; std::shared_ptr<BuildConfigResult> result;
QSharedPointer<ProxyEntity> ent; std::shared_ptr<ProxyEntity> ent;
bool forTest; bool forTest;
bool forExport; bool forExport;
@@ -44,18 +44,18 @@ namespace NekoRay {
QJsonArray outbounds; QJsonArray outbounds;
}; };
QSharedPointer<BuildConfigResult> BuildConfig(const QSharedPointer<ProxyEntity> &ent, bool forTest, bool forExport); std::shared_ptr<BuildConfigResult> BuildConfig(const std::shared_ptr<ProxyEntity> &ent, bool forTest, bool forExport);
void BuildConfigV2Ray(const QSharedPointer<BuildConfigStatus> &status); void BuildConfigV2Ray(const std::shared_ptr<BuildConfigStatus> &status);
void BuildConfigSingBox(const QSharedPointer<BuildConfigStatus> &status); void BuildConfigSingBox(const std::shared_ptr<BuildConfigStatus> &status);
QString BuildChain(int chainId, const QSharedPointer<BuildConfigStatus> &status); QString BuildChain(int chainId, const std::shared_ptr<BuildConfigStatus> &status);
QString BuildChainInternal(int chainId, const QList<QSharedPointer<ProxyEntity>> &ents, QString BuildChainInternal(int chainId, const QList<std::shared_ptr<ProxyEntity>> &ents,
const QSharedPointer<BuildConfigStatus> &status); const std::shared_ptr<BuildConfigStatus> &status);
QString WriteVPNSingBoxConfig(); QString WriteVPNSingBoxConfig();
QString WriteVPNLinuxScript(const QString &protectPath, const QString &configPath); QString WriteVPNLinuxScript(const QString &protectPath, const QString &configPath);
} // namespace NekoRay } // namespace NekoGui

View File

@@ -5,7 +5,7 @@
#include <QFile> #include <QFile>
#include <QColor> #include <QColor>
namespace NekoRay { namespace NekoGui {
ProfileManager *profileManager = new ProfileManager(); ProfileManager *profileManager = new ProfileManager();
@@ -40,7 +40,7 @@ namespace NekoRay {
void ProfileManager::SaveManager() { void ProfileManager::SaveManager() {
} }
QSharedPointer<ProxyEntity> ProfileManager::LoadProxyEntity(const QString &jsonPath) { std::shared_ptr<ProxyEntity> ProfileManager::LoadProxyEntity(const QString &jsonPath) {
// Load type // Load type
ProxyEntity ent0(nullptr, nullptr); ProxyEntity ent0(nullptr, nullptr);
ent0.fn = jsonPath; ent0.fn = jsonPath;
@@ -48,7 +48,7 @@ namespace NekoRay {
auto type = ent0.type; auto type = ent0.type;
// Load content // Load content
QSharedPointer<ProxyEntity> ent; std::shared_ptr<ProxyEntity> ent;
bool validType = validJson; bool validType = validJson;
if (validType) { if (validType) {
@@ -66,45 +66,45 @@ namespace NekoRay {
// 新建的不给 fn 和 id // 新建的不给 fn 和 id
QSharedPointer<ProxyEntity> ProfileManager::NewProxyEntity(const QString &type) { std::shared_ptr<ProxyEntity> ProfileManager::NewProxyEntity(const QString &type) {
fmt::AbstractBean *bean; NekoGui_fmt::AbstractBean *bean;
if (type == "socks") { 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") { } 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") { } else if (type == "shadowsocks") {
bean = new fmt::ShadowSocksBean(); bean = new NekoGui_fmt::ShadowSocksBean();
} else if (type == "chain") { } else if (type == "chain") {
bean = new fmt::ChainBean(); bean = new NekoGui_fmt::ChainBean();
} else if (type == "vmess") { } else if (type == "vmess") {
bean = new fmt::VMessBean(); bean = new NekoGui_fmt::VMessBean();
} else if (type == "trojan") { } 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") { } 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") { } else if (type == "naive") {
bean = new fmt::NaiveBean(); bean = new NekoGui_fmt::NaiveBean();
} else if (type == "hysteria") { } else if (type == "hysteria") {
bean = new fmt::HysteriaBean(); bean = new NekoGui_fmt::HysteriaBean();
} else if (type == "custom") { } else if (type == "custom") {
bean = new fmt::CustomBean(); bean = new NekoGui_fmt::CustomBean();
} else { } else {
bean = new fmt::AbstractBean(-114514); bean = new NekoGui_fmt::AbstractBean(-114514);
} }
auto ent = QSharedPointer<ProxyEntity>(new ProxyEntity(bean, type)); auto ent = std::make_shared<ProxyEntity>(bean, type);
return ent; return ent;
} }
QSharedPointer<Group> ProfileManager::NewGroup() { std::shared_ptr<Group> ProfileManager::NewGroup() {
auto ent = QSharedPointer<Group>(new Group()); auto ent = std::make_shared<Group>();
return ent; return ent;
} }
// ProxyEntity // ProxyEntity
ProxyEntity::ProxyEntity(fmt::AbstractBean *bean, const QString &type_) { ProxyEntity::ProxyEntity(NekoGui_fmt::AbstractBean *bean, const QString &type_) {
if (type_ != nullptr) this->type = type_; if (type_ != nullptr) this->type = type_;
_add(new configItem("type", &type, itemType::string)); _add(new configItem("type", &type, itemType::string));
@@ -115,7 +115,7 @@ namespace NekoRay {
// 可以不关联 bean只加载 ProxyEntity 的信息 // 可以不关联 bean只加载 ProxyEntity 的信息
if (bean != nullptr) { if (bean != nullptr) {
this->bean = QSharedPointer<fmt::AbstractBean>(bean); this->bean = std::shared_ptr<NekoGui_fmt::AbstractBean>(bean);
// 有虚函数就要在这里 dynamic_cast // 有虚函数就要在这里 dynamic_cast
_add(new configItem("bean", dynamic_cast<JsonStore *>(bean), itemType::jsonStore)); _add(new configItem("bean", dynamic_cast<JsonStore *>(bean), itemType::jsonStore));
_add(new configItem("traffic", dynamic_cast<JsonStore *>(traffic_data.get()), itemType::jsonStore)); _add(new configItem("traffic", dynamic_cast<JsonStore *>(traffic_data.get()), itemType::jsonStore));
@@ -158,7 +158,7 @@ namespace NekoRay {
} }
} }
bool ProfileManager::AddProfile(const QSharedPointer<ProxyEntity> &ent, int gid) { bool ProfileManager::AddProfile(const std::shared_ptr<ProxyEntity> &ent, int gid) {
if (ent->id >= 0) { if (ent->id >= 0) {
return false; return false;
} }
@@ -183,7 +183,7 @@ namespace NekoRay {
QFile(QString("profiles/%1.json").arg(id)).remove(); QFile(QString("profiles/%1.json").arg(id)).remove();
} }
void ProfileManager::MoveProfile(const QSharedPointer<ProxyEntity> &ent, int gid) { void ProfileManager::MoveProfile(const std::shared_ptr<ProxyEntity> &ent, int gid) {
if (gid == ent->gid || gid < 0) return; if (gid == ent->gid || gid < 0) return;
auto oldGroup = GetGroup(ent->gid); auto oldGroup = GetGroup(ent->gid);
if (oldGroup != nullptr && !oldGroup->order.isEmpty()) { if (oldGroup != nullptr && !oldGroup->order.isEmpty()) {
@@ -199,7 +199,7 @@ namespace NekoRay {
ent->Save(); ent->Save();
} }
QSharedPointer<ProxyEntity> ProfileManager::GetProfile(int id) { std::shared_ptr<ProxyEntity> ProfileManager::GetProfile(int id) {
return profiles.value(id, nullptr); return profiles.value(id, nullptr);
} }
@@ -212,13 +212,13 @@ namespace NekoRay {
_add(new configItem("order", &order, itemType::integerList)); _add(new configItem("order", &order, itemType::integerList));
_add(new configItem("url", &url, itemType::string)); _add(new configItem("url", &url, itemType::string));
_add(new configItem("info", &info, 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("manually_column_width", &manually_column_width, itemType::boolean));
_add(new configItem("column_width", &column_width, itemType::integerList)); _add(new configItem("column_width", &column_width, itemType::integerList));
} }
QSharedPointer<Group> ProfileManager::LoadGroup(const QString &jsonPath) { std::shared_ptr<Group> ProfileManager::LoadGroup(const QString &jsonPath) {
QSharedPointer<Group> ent = QSharedPointer<Group>(new Group()); auto ent = std::make_shared<Group>();
ent->fn = jsonPath; ent->fn = jsonPath;
ent->Load(); ent->Load();
return ent; return ent;
@@ -232,7 +232,7 @@ namespace NekoRay {
} }
} }
bool ProfileManager::AddGroup(const QSharedPointer<Group> &ent) { bool ProfileManager::AddGroup(const std::shared_ptr<Group> &ent) {
if (ent->id >= 0) { if (ent->id >= 0) {
return false; return false;
} }
@@ -262,27 +262,27 @@ namespace NekoRay {
QFile(QString("groups/%1.json").arg(gid)).remove(); QFile(QString("groups/%1.json").arg(gid)).remove();
} }
QSharedPointer<Group> ProfileManager::GetGroup(int id) { std::shared_ptr<Group> ProfileManager::GetGroup(int id) {
return groups.value(id, nullptr); return groups.value(id, nullptr);
} }
QSharedPointer<Group> ProfileManager::CurrentGroup() { std::shared_ptr<Group> ProfileManager::CurrentGroup() {
return GetGroup(NekoRay::dataStore->current_group); return GetGroup(dataStore->current_group);
} }
QList<QSharedPointer<ProxyEntity>> Group::Profiles() const { QList<std::shared_ptr<ProxyEntity>> Group::Profiles() const {
QList<QSharedPointer<ProxyEntity>> ret; QList<std::shared_ptr<ProxyEntity>> ret;
for (const auto &ent: profileManager->profiles) { for (const auto &ent: profileManager->profiles) {
if (id == ent->gid) ret += ent; if (id == ent->gid) ret += ent;
} }
return ret; return ret;
} }
QList<QSharedPointer<ProxyEntity>> Group::ProfilesWithOrder() const { QList<std::shared_ptr<ProxyEntity>> Group::ProfilesWithOrder() const {
if (order.isEmpty()) { if (order.isEmpty()) {
return Profiles(); return Profiles();
} else { } else {
QList<QSharedPointer<ProxyEntity>> ret; QList<std::shared_ptr<ProxyEntity>> ret;
for (auto _id: order) { for (auto _id: order) {
auto ent = profileManager->GetProfile(_id); auto ent = profileManager->GetProfile(_id);
if (ent != nullptr) ret += ent; if (ent != nullptr) ret += ent;
@@ -291,4 +291,4 @@ namespace NekoRay {
} }
} }
} // namespace NekoRay } // namespace NekoGui

View File

@@ -1,15 +1,15 @@
#pragma once #pragma once
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
#include "ProxyEntity.hpp" #include "ProxyEntity.hpp"
#include "Group.hpp" #include "Group.hpp"
namespace NekoRay { namespace NekoGui {
class ProfileManager : public JsonStore { class ProfileManager : public JsonStore {
public: public:
// Manager // Manager
QMap<int, QSharedPointer<ProxyEntity>> profiles; QMap<int, std::shared_ptr<ProxyEntity>> profiles;
QMap<int, QSharedPointer<Group>> groups; QMap<int, std::shared_ptr<Group>> groups;
// JSON // JSON
QList<int> _profiles; QList<int> _profiles;
@@ -17,25 +17,25 @@ namespace NekoRay {
ProfileManager(); ProfileManager();
[[nodiscard]] static QSharedPointer<ProxyEntity> NewProxyEntity(const QString &type); [[nodiscard]] static std::shared_ptr<ProxyEntity> NewProxyEntity(const QString &type);
[[nodiscard]] static QSharedPointer<Group> NewGroup(); [[nodiscard]] static std::shared_ptr<Group> NewGroup();
bool AddProfile(const QSharedPointer<ProxyEntity> &ent, int gid = -1); bool AddProfile(const std::shared_ptr<ProxyEntity> &ent, int gid = -1);
void DeleteProfile(int id); void DeleteProfile(int id);
void MoveProfile(const QSharedPointer<ProxyEntity> &ent, int gid); void MoveProfile(const std::shared_ptr<ProxyEntity> &ent, int gid);
QSharedPointer<ProxyEntity> GetProfile(int id); std::shared_ptr<ProxyEntity> GetProfile(int id);
bool AddGroup(const QSharedPointer<Group> &ent); bool AddGroup(const std::shared_ptr<Group> &ent);
void DeleteGroup(int gid); void DeleteGroup(int gid);
QSharedPointer<Group> GetGroup(int id); std::shared_ptr<Group> GetGroup(int id);
QSharedPointer<Group> CurrentGroup(); std::shared_ptr<Group> CurrentGroup();
private: private:
void LoadManager(); void LoadManager();
@@ -46,10 +46,10 @@ namespace NekoRay {
[[nodiscard]] int NewGroupID() const; [[nodiscard]] int NewGroupID() const;
static QSharedPointer<ProxyEntity> LoadProxyEntity(const QString &jsonPath); static std::shared_ptr<ProxyEntity> LoadProxyEntity(const QString &jsonPath);
static QSharedPointer<Group> LoadGroup(const QString &jsonPath); static std::shared_ptr<Group> LoadGroup(const QString &jsonPath);
}; };
extern ProfileManager *profileManager; extern ProfileManager *profileManager;
} // namespace NekoRay } // namespace NekoGui

View File

@@ -1,9 +1,9 @@
#pragma once #pragma once
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
#include "ProxyEntity.hpp" #include "ProxyEntity.hpp"
namespace NekoRay { namespace NekoGui {
class Group : public JsonStore { class Group : public JsonStore {
public: public:
int id = -1; int id = -1;
@@ -11,7 +11,7 @@ namespace NekoRay {
QString name = ""; QString name = "";
QString url = ""; QString url = "";
QString info = ""; QString info = "";
qint64 last_update = 0; qint64 sub_last_update = 0;
// list ui // list ui
bool manually_column_width = false; bool manually_column_width = false;
@@ -21,9 +21,9 @@ namespace NekoRay {
Group(); Group();
// 按 id 顺序 // 按 id 顺序
[[nodiscard]] QList<QSharedPointer<ProxyEntity>> Profiles() const; [[nodiscard]] QList<std::shared_ptr<ProxyEntity>> Profiles() const;
// 按 显示 顺序 // 按 显示 顺序
[[nodiscard]] QList<QSharedPointer<ProxyEntity>> ProfilesWithOrder() const; [[nodiscard]] QList<std::shared_ptr<ProxyEntity>> ProfilesWithOrder() const;
}; };
} // namespace NekoRay } // namespace NekoGui

View File

@@ -1,10 +1,10 @@
#include "ProfileFilter.hpp" #include "ProfileFilter.hpp"
namespace NekoRay { namespace NekoGui {
void ProfileFilter::Uniq(const QList<QSharedPointer<ProxyEntity>> &in, void ProfileFilter::Uniq(const QList<std::shared_ptr<ProxyEntity>> &in,
QList<QSharedPointer<ProxyEntity>> &out, QList<std::shared_ptr<ProxyEntity>> &out,
bool by_address, bool keep_last) { bool by_address, bool keep_last) {
QMap<QString, QSharedPointer<ProxyEntity>> hashMap; QMap<QString, std::shared_ptr<ProxyEntity>> hashMap;
for (const auto &ent: in) { for (const auto &ent: in) {
QString key = by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType()) QString key = by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType())
@@ -22,11 +22,11 @@ namespace NekoRay {
} }
} }
void ProfileFilter::Common(const QList<QSharedPointer<ProxyEntity>> &src, void ProfileFilter::Common(const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<QSharedPointer<ProxyEntity>> &dst, const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<QSharedPointer<ProxyEntity>> &out, QList<std::shared_ptr<ProxyEntity>> &out,
bool by_address, bool keep_last) { bool by_address, bool keep_last) {
QMap<QString, QSharedPointer<ProxyEntity>> hashMap; QMap<QString, std::shared_ptr<ProxyEntity>> hashMap;
for (const auto &ent: src) { for (const auto &ent: src) {
QString key = by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType()) QString key = by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType())
@@ -46,9 +46,9 @@ namespace NekoRay {
} }
} }
void ProfileFilter::OnlyInSrc(const QList<QSharedPointer<ProxyEntity>> &src, void ProfileFilter::OnlyInSrc(const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<QSharedPointer<ProxyEntity>> &dst, const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<QSharedPointer<ProxyEntity>> &out, QList<std::shared_ptr<ProxyEntity>> &out,
bool by_address) { bool by_address) {
QMap<QString, bool> hashMap; QMap<QString, bool> hashMap;
@@ -64,12 +64,12 @@ namespace NekoRay {
} }
} }
void ProfileFilter::OnlyInSrc_ByPointer(const QList<QSharedPointer<ProxyEntity>> &src, void ProfileFilter::OnlyInSrc_ByPointer(const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<QSharedPointer<ProxyEntity>> &dst, const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<QSharedPointer<ProxyEntity>> &out) { QList<std::shared_ptr<ProxyEntity>> &out) {
for (const auto &ent: src) { for (const auto &ent: src) {
if (!dst.contains(ent)) out += ent; if (!dst.contains(ent)) out += ent;
} }
} }
} // namespace NekoRay } // namespace NekoGui

View File

@@ -2,34 +2,34 @@
#include "ProxyEntity.hpp" #include "ProxyEntity.hpp"
namespace NekoRay { namespace NekoGui {
class ProfileFilter { class ProfileFilter {
public: public:
static void Uniq( static void Uniq(
const QList<QSharedPointer<ProxyEntity>> &in, const QList<std::shared_ptr<ProxyEntity>> &in,
QList<QSharedPointer<ProxyEntity>> &out, QList<std::shared_ptr<ProxyEntity>> &out,
bool by_address = false, // def by bean bool by_address = false, // def by bean
bool keep_last = false // def keep first bool keep_last = false // def keep first
); );
static void Common( static void Common(
const QList<QSharedPointer<ProxyEntity>> &src, const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<QSharedPointer<ProxyEntity>> &dst, const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<QSharedPointer<ProxyEntity>> &out, QList<std::shared_ptr<ProxyEntity>> &out,
bool by_address = false, // def by bean bool by_address = false, // def by bean
bool keep_last = false // def keep first bool keep_last = false // def keep first
); );
static void OnlyInSrc( static void OnlyInSrc(
const QList<QSharedPointer<ProxyEntity>> &src, const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<QSharedPointer<ProxyEntity>> &dst, const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<QSharedPointer<NekoRay::ProxyEntity>> &out, QList<std::shared_ptr<ProxyEntity>> &out,
bool by_address = false // def by bean bool by_address = false // def by bean
); );
static void OnlyInSrc_ByPointer( static void OnlyInSrc_ByPointer(
const QList<QSharedPointer<ProxyEntity>> &src, const QList<std::shared_ptr<ProxyEntity>> &src,
const QList<QSharedPointer<ProxyEntity>> &dst, const QList<std::shared_ptr<ProxyEntity>> &dst,
QList<QSharedPointer<ProxyEntity>> &out); QList<std::shared_ptr<ProxyEntity>> &out);
}; };
} // namespace NekoRay } // namespace NekoGui

View File

@@ -1,11 +1,10 @@
#pragma once #pragma once
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
#include "TrafficData.hpp" #include "db/traffic/TrafficData.hpp"
#include "fmt/AbstractBean.hpp" #include "fmt/AbstractBean.hpp"
namespace NekoRay { namespace NekoGui_fmt {
namespace fmt {
class SocksHttpBean; class SocksHttpBean;
class ShadowSocksBean; class ShadowSocksBean;
@@ -21,8 +20,9 @@ namespace NekoRay {
class CustomBean; class CustomBean;
class ChainBean; class ChainBean;
}; // namespace fmt }; // namespace NekoGui_fmt
namespace NekoGui {
class ProxyEntity : public JsonStore { class ProxyEntity : public JsonStore {
public: public:
QString type; QString type;
@@ -30,47 +30,47 @@ namespace NekoRay {
int id = -1; int id = -1;
int gid = 0; int gid = 0;
int latency = 0; int latency = 0;
QSharedPointer<fmt::AbstractBean> bean; std::shared_ptr<NekoGui_fmt::AbstractBean> bean;
QSharedPointer<traffic::TrafficData> traffic_data = QSharedPointer<traffic::TrafficData>(new traffic::TrafficData("")); std::shared_ptr<NekoGui_traffic::TrafficData> traffic_data = std::make_shared<NekoGui_traffic::TrafficData>("");
QString full_test_report; QString full_test_report;
ProxyEntity(fmt::AbstractBean *bean, const QString &type_); ProxyEntity(NekoGui_fmt::AbstractBean *bean, const QString &type_);
[[nodiscard]] QString DisplayLatency() const; [[nodiscard]] QString DisplayLatency() const;
[[nodiscard]] QColor DisplayLatencyColor() const; [[nodiscard]] QColor DisplayLatencyColor() const;
[[nodiscard]] fmt::ChainBean *ChainBean() const { [[nodiscard]] NekoGui_fmt::ChainBean *ChainBean() const {
return (fmt::ChainBean *) bean.get(); return (NekoGui_fmt::ChainBean *) bean.get();
}; };
[[nodiscard]] fmt::SocksHttpBean *SocksHTTPBean() const { [[nodiscard]] NekoGui_fmt::SocksHttpBean *SocksHTTPBean() const {
return (fmt::SocksHttpBean *) bean.get(); return (NekoGui_fmt::SocksHttpBean *) bean.get();
}; };
[[nodiscard]] fmt::ShadowSocksBean *ShadowSocksBean() const { [[nodiscard]] NekoGui_fmt::ShadowSocksBean *ShadowSocksBean() const {
return (fmt::ShadowSocksBean *) bean.get(); return (NekoGui_fmt::ShadowSocksBean *) bean.get();
}; };
[[nodiscard]] fmt::VMessBean *VMessBean() const { [[nodiscard]] NekoGui_fmt::VMessBean *VMessBean() const {
return (fmt::VMessBean *) bean.get(); return (NekoGui_fmt::VMessBean *) bean.get();
}; };
[[nodiscard]] fmt::TrojanVLESSBean *TrojanVLESSBean() const { [[nodiscard]] NekoGui_fmt::TrojanVLESSBean *TrojanVLESSBean() const {
return (fmt::TrojanVLESSBean *) bean.get(); return (NekoGui_fmt::TrojanVLESSBean *) bean.get();
}; };
[[nodiscard]] fmt::NaiveBean *NaiveBean() const { [[nodiscard]] NekoGui_fmt::NaiveBean *NaiveBean() const {
return (fmt::NaiveBean *) bean.get(); return (NekoGui_fmt::NaiveBean *) bean.get();
}; };
[[nodiscard]] fmt::HysteriaBean *HysteriaBean() const { [[nodiscard]] NekoGui_fmt::HysteriaBean *HysteriaBean() const {
return (fmt::HysteriaBean *) bean.get(); return (NekoGui_fmt::HysteriaBean *) bean.get();
}; };
[[nodiscard]] fmt::CustomBean *CustomBean() const { [[nodiscard]] NekoGui_fmt::CustomBean *CustomBean() const {
return (fmt::CustomBean *) bean.get(); return (NekoGui_fmt::CustomBean *) bean.get();
}; };
}; };
} // namespace NekoRay } // namespace NekoGui

View File

@@ -1,8 +1,8 @@
#pragma once #pragma once
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
namespace NekoRay::traffic { namespace NekoGui_traffic {
class TrafficData : public JsonStore { class TrafficData : public JsonStore {
public: public:
int id = -1; // ent id int id = -1; // ent id
@@ -37,4 +37,4 @@ namespace NekoRay::traffic {
return UNICODE_LRO + QString("%1↑ %2↓").arg(ReadableSize(uplink), ReadableSize(downlink)); return UNICODE_LRO + QString("%1↑ %2↓").arg(ReadableSize(uplink), ReadableSize(downlink));
} }
}; };
} // namespace NekoRay::traffic } // namespace NekoGui_traffic

View File

@@ -9,7 +9,7 @@
#include <QJsonDocument> #include <QJsonDocument>
#include <QElapsedTimer> #include <QElapsedTimer>
namespace NekoRay::traffic { namespace NekoGui_traffic {
TrafficLooper *trafficLooper = new TrafficLooper; TrafficLooper *trafficLooper = new TrafficLooper;
QElapsedTimer elapsedTimer; QElapsedTimer elapsedTimer;
@@ -23,8 +23,8 @@ namespace NekoRay::traffic {
if (interval <= 0) return nullptr; if (interval <= 0) return nullptr;
// query // query
auto uplink = NekoRay::rpc::defaultClient->QueryStats(item->tag, "uplink"); auto uplink = NekoGui_rpc::defaultClient->QueryStats(item->tag, "uplink");
auto downlink = NekoRay::rpc::defaultClient->QueryStats(item->tag, "downlink"); auto downlink = NekoGui_rpc::defaultClient->QueryStats(item->tag, "downlink");
// add diff // add diff
item->downlink += downlink; item->downlink += downlink;
@@ -45,7 +45,7 @@ namespace NekoRay::traffic {
QJsonArray TrafficLooper::get_connection_list() { QJsonArray TrafficLooper::get_connection_list() {
#ifndef NKR_NO_GRPC #ifndef NKR_NO_GRPC
auto str = NekoRay::rpc::defaultClient->ListConnections(); auto str = NekoGui_rpc::defaultClient->ListConnections();
QJsonDocument jsonDocument = QJsonDocument::fromJson(str.c_str()); QJsonDocument jsonDocument = QJsonDocument::fromJson(str.c_str());
return jsonDocument.array(); return jsonDocument.array();
#else #else
@@ -79,10 +79,10 @@ namespace NekoRay::traffic {
void TrafficLooper::Loop() { void TrafficLooper::Loop() {
elapsedTimer.start(); elapsedTimer.start();
while (true) { 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; if (sleep_ms < 500 || sleep_ms > 5000) sleep_ms = 1000;
QThread::msleep(sleep_ms); 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 // profile start and stop
if (!loop_enabled) { if (!loop_enabled) {
@@ -109,7 +109,7 @@ namespace NekoRay::traffic {
// do conn list update // do conn list update
QJsonArray conn_list; QJsonArray conn_list;
if (dataStore->connection_statistics) { if (NekoGui::dataStore->connection_statistics) {
conn_list = get_connection_list(); conn_list = get_connection_list();
} }
@@ -125,11 +125,11 @@ namespace NekoRay::traffic {
if (item->id < 0) continue; if (item->id < 0) continue;
m->refresh_proxy_list(item->id); m->refresh_proxy_list(item->id);
} }
if (dataStore->connection_statistics) { if (NekoGui::dataStore->connection_statistics) {
m->refresh_connection_list(conn_list); m->refresh_connection_list(conn_list);
} }
}); });
} }
} }
} // namespace NekoRay::traffic } // namespace NekoGui_traffic

View File

@@ -1,20 +1,19 @@
#pragma once #pragma once
#include <QSharedPointer>
#include <QString> #include <QString>
#include <QList> #include <QList>
#include <QMutex> #include <QMutex>
#include "TrafficData.hpp" #include "TrafficData.hpp"
namespace NekoRay::traffic { namespace NekoGui_traffic {
class TrafficLooper { class TrafficLooper {
public: public:
bool loop_enabled = false; bool loop_enabled = false;
bool looping = false; bool looping = false;
QMutex loop_mutex; QMutex loop_mutex;
QList<QSharedPointer<TrafficData>> items; QList<std::shared_ptr<TrafficData>> items;
TrafficData *proxy = nullptr; TrafficData *proxy = nullptr;
void UpdateAll(); void UpdateAll();
@@ -30,4 +29,4 @@ namespace NekoRay::traffic {
}; };
extern TrafficLooper *trafficLooper; extern TrafficLooper *trafficLooper;
} // namespace NekoRay::traffic } // namespace NekoGui_traffic

View File

@@ -4,7 +4,7 @@
#include <QHostInfo> #include <QHostInfo>
#include <QUrl> #include <QUrl>
namespace NekoRay::fmt { namespace NekoGui_fmt {
AbstractBean::AbstractBean(int version) { AbstractBean::AbstractBean(int version) {
this->version = version; this->version = version;
_add(new configItem("_v", &this->version, itemType::integer)); _add(new configItem("_v", &this->version, itemType::integer));
@@ -52,6 +52,7 @@ namespace NekoRay::fmt {
return; return;
} }
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) // TODO older QT
QHostInfo::lookupHost(serverAddress, QApplication::instance(), [=](const QHostInfo &host) { QHostInfo::lookupHost(serverAddress, QApplication::instance(), [=](const QHostInfo &host) {
auto addr = host.addresses(); auto addr = host.addresses();
if (!addr.isEmpty()) { if (!addr.isEmpty()) {
@@ -73,5 +74,6 @@ namespace NekoRay::fmt {
} }
onFinished(); onFinished();
}); });
#endif
} }
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -3,9 +3,9 @@
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
namespace NekoRay::fmt { namespace NekoGui_fmt {
struct CoreObjOutboundBuildResult { struct CoreObjOutboundBuildResult {
public: public:
QJsonObject outbound; QJsonObject outbound;
@@ -68,4 +68,4 @@ namespace NekoRay::fmt {
virtual QString ToShareLink() { return {}; }; virtual QString ToShareLink() { return {}; };
}; };
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -1,7 +1,7 @@
#include "db/ProxyEntity.hpp" #include "db/ProxyEntity.hpp"
#include "fmt/includes.h" #include "fmt/includes.h"
namespace NekoRay::fmt { namespace NekoGui_fmt {
void V2rayStreamSettings::BuildStreamSettingsSingBox(QJsonObject *outbound) { void V2rayStreamSettings::BuildStreamSettingsSingBox(QJsonObject *outbound) {
// https://sing-box.sagernet.org/configuration/shared/v2ray-transport // https://sing-box.sagernet.org/configuration/shared/v2ray-transport
@@ -44,7 +44,7 @@ namespace NekoRay::fmt {
// 对应字段 tls // 对应字段 tls
if (security == "tls") { if (security == "tls") {
QJsonObject tls{{"enabled", true}}; 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 (!sni.trimmed().isEmpty()) tls["server_name"] = sni;
if (!certificate.trimmed().isEmpty()) { if (!certificate.trimmed().isEmpty()) {
tls["certificate"] = certificate.trimmed(); tls["certificate"] = certificate.trimmed();
@@ -52,7 +52,7 @@ namespace NekoRay::fmt {
if (!alpn.trimmed().isEmpty()) { if (!alpn.trimmed().isEmpty()) {
tls["alpn"] = QList2QJsonArray(alpn.split(",")); tls["alpn"] = QList2QJsonArray(alpn.split(","));
} }
auto fp = utlsFingerprint.isEmpty() ? NekoRay::dataStore->utlsFingerprint : utlsFingerprint; auto fp = utlsFingerprint.isEmpty() ? NekoGui::dataStore->utlsFingerprint : utlsFingerprint;
if (!fp.isEmpty()) { if (!fp.isEmpty()) {
tls["utls"] = QJsonObject{ tls["utls"] = QJsonObject{
{"enabled", true}, {"enabled", true},
@@ -194,4 +194,4 @@ namespace NekoRay::fmt {
return result; return result;
} }
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -7,7 +7,7 @@
auto streamSettings = stream->BuildStreamSettingsV2Ray(); \ auto streamSettings = stream->BuildStreamSettingsV2Ray(); \
outbound["streamSettings"] = streamSettings; outbound["streamSettings"] = streamSettings;
namespace NekoRay::fmt { namespace NekoGui_fmt {
QJsonObject V2rayStreamSettings::BuildStreamSettingsV2Ray() { QJsonObject V2rayStreamSettings::BuildStreamSettingsV2Ray() {
QJsonObject streamSettings{{"network", network}}; QJsonObject streamSettings{{"network", network}};
@@ -56,10 +56,10 @@ namespace NekoRay::fmt {
} }
if (security == "tls") { if (security == "tls") {
auto fp = utlsFingerprint.isEmpty() ? NekoRay::dataStore->utlsFingerprint : utlsFingerprint; auto fp = utlsFingerprint.isEmpty() ? NekoGui::dataStore->utlsFingerprint : utlsFingerprint;
bool v5_utls = !fp.isEmpty(); bool v5_utls = !fp.isEmpty();
QJsonObject tls; 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 (!sni.trimmed().isEmpty()) tls["serverName"] = sni;
if (!certificate.trimmed().isEmpty()) { if (!certificate.trimmed().isEmpty()) {
tls["disableSystemRoot"] = true; tls["disableSystemRoot"] = true;
@@ -212,4 +212,4 @@ namespace NekoRay::fmt {
return result; return result;
} }
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -19,7 +19,7 @@
f.close(); \ f.close(); \
auto TempFile = QFileInfo(f).absoluteFilePath(); auto TempFile = QFileInfo(f).absoluteFilePath();
namespace NekoRay::fmt { namespace NekoGui_fmt {
// -1: Cannot use this config // -1: Cannot use this config
// 0: Internal // 0: Internal
// 1: Mapping External // 1: Mapping External
@@ -27,7 +27,7 @@ namespace NekoRay::fmt {
int NaiveBean::NeedExternal(bool isFirstProfile) { int NaiveBean::NeedExternal(bool isFirstProfile) {
if (isFirstProfile) { if (isFirstProfile) {
if (dataStore->spmode_vpn) { if (NekoGui::dataStore->spmode_vpn) {
return 1; return 1;
} }
return 2; return 2;
@@ -38,7 +38,7 @@ namespace NekoRay::fmt {
int HysteriaBean::NeedExternal(bool isFirstProfile) { int HysteriaBean::NeedExternal(bool isFirstProfile) {
auto hysteriaCore = [=] { auto hysteriaCore = [=] {
if (isFirstProfile) { 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 1;
} }
return 2; return 2;
@@ -69,7 +69,7 @@ namespace NekoRay::fmt {
} }
ExternalBuildResult NaiveBean::BuildExternal(int mapping_port, int socks_port, int external_stat) { 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 is_direct = external_stat == 2;
auto domain_address = sni.isEmpty() ? serverAddress : sni; 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 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; QJsonObject config;
@@ -166,7 +166,7 @@ namespace NekoRay::fmt {
} }
ExternalBuildResult CustomBean::BuildExternal(int mapping_port, int socks_port, int external_stat) { 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? result.arguments = command; // TODO split?
@@ -206,4 +206,4 @@ namespace NekoRay::fmt {
return result; return result;
} }
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -3,7 +3,7 @@
#include <QUrlQuery> #include <QUrlQuery>
namespace NekoRay::fmt { namespace NekoGui_fmt {
QString SocksHttpBean::ToShareLink() { QString SocksHttpBean::ToShareLink() {
QUrl url; QUrl url;
if (socks_http_type == type_HTTP) { // http if (socks_http_type == type_HTTP) { // http
@@ -151,4 +151,4 @@ namespace NekoRay::fmt {
return url.toString(QUrl::FullyEncoded); return url.toString(QUrl::FullyEncoded);
} }
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -1,8 +1,8 @@
#pragma once #pragma once
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
namespace NekoRay::fmt { namespace NekoGui_fmt {
class ChainBean : public AbstractBean { class ChainBean : public AbstractBean {
public: public:
QList<int> list; // in to out QList<int> list; // in to out
@@ -15,4 +15,4 @@ namespace NekoRay::fmt {
QString DisplayAddress() override { return ""; }; QString DisplayAddress() override { return ""; };
}; };
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -2,7 +2,7 @@
#include "fmt/AbstractBean.hpp" #include "fmt/AbstractBean.hpp"
namespace NekoRay::fmt { namespace NekoGui_fmt {
class CustomBean : public AbstractBean { class CustomBean : public AbstractBean {
public: public:
QString core; QString core;
@@ -55,4 +55,4 @@ namespace NekoRay::fmt {
CoreObjOutboundBuildResult BuildCoreObjV2Ray() override; CoreObjOutboundBuildResult BuildCoreObjV2Ray() override;
}; };
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -2,7 +2,7 @@
#include "fmt/AbstractBean.hpp" #include "fmt/AbstractBean.hpp"
namespace NekoRay::fmt { namespace NekoGui_fmt {
class HysteriaBean : public AbstractBean { class HysteriaBean : public AbstractBean {
public: public:
static constexpr int hysteria_protocol_udp = 0; static constexpr int hysteria_protocol_udp = 0;
@@ -77,4 +77,4 @@ namespace NekoRay::fmt {
QString ToShareLink() override; QString ToShareLink() override;
}; };
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -3,7 +3,7 @@
#include <QUrlQuery> #include <QUrlQuery>
namespace NekoRay::fmt { namespace NekoGui_fmt {
#define DECODE_V2RAY_N_1 \ #define DECODE_V2RAY_N_1 \
QString linkN = DecodeB64IfValid(SubStrBefore(SubStrAfter(link, "://"), "#"), QByteArray::Base64Option::Base64UrlEncoding); \ 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(); auto protocolStr = (query.hasQueryItem("protocol") ? query.queryItemValue("protocol") : "udp").toLower();
if (protocolStr == "faketcp") { if (protocolStr == "faketcp") {
protocol = fmt::HysteriaBean::hysteria_protocol_facktcp; protocol = NekoGui_fmt::HysteriaBean::hysteria_protocol_facktcp;
} else if (protocolStr.startsWith("wechat")) { } else if (protocolStr.startsWith("wechat")) {
protocol = fmt::HysteriaBean::hysteria_protocol_wechat_video; protocol = NekoGui_fmt::HysteriaBean::hysteria_protocol_wechat_video;
} }
if (query.hasQueryItem("auth")) { if (query.hasQueryItem("auth")) {
authPayload = query.queryItemValue("auth"); authPayload = query.queryItemValue("auth");
authPayloadType = fmt::HysteriaBean::hysteria_auth_string; authPayloadType = NekoGui_fmt::HysteriaBean::hysteria_auth_string;
} }
alpn = query.queryItemValue("alpn"); alpn = query.queryItemValue("alpn");
@@ -212,4 +212,4 @@ namespace NekoRay::fmt {
return true; return true;
} }
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -2,7 +2,7 @@
#include "fmt/AbstractBean.hpp" #include "fmt/AbstractBean.hpp"
namespace NekoRay::fmt { namespace NekoGui_fmt {
class NaiveBean : public AbstractBean { class NaiveBean : public AbstractBean {
public: public:
QString username = ""; QString username = "";
@@ -35,4 +35,4 @@ namespace NekoRay::fmt {
QString ToShareLink() override; QString ToShareLink() override;
}; };
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -3,7 +3,7 @@
#include "fmt/AbstractBean.hpp" #include "fmt/AbstractBean.hpp"
#include "fmt/V2RayStreamSettings.hpp" #include "fmt/V2RayStreamSettings.hpp"
namespace NekoRay::fmt { namespace NekoGui_fmt {
class ShadowSocksBean : public AbstractBean { class ShadowSocksBean : public AbstractBean {
public: public:
QString method = "aes-128-gcm"; QString method = "aes-128-gcm";
@@ -11,7 +11,7 @@ namespace NekoRay::fmt {
QString plugin = ""; QString plugin = "";
bool uot = false; bool uot = false;
QSharedPointer<V2rayStreamSettings> stream = QSharedPointer<V2rayStreamSettings>(new V2rayStreamSettings()); std::shared_ptr<V2rayStreamSettings> stream = std::make_shared<V2rayStreamSettings>();
ShadowSocksBean() : AbstractBean(0) { ShadowSocksBean() : AbstractBean(0) {
_add(new configItem("method", &method, itemType::string)); _add(new configItem("method", &method, itemType::string));
@@ -31,4 +31,4 @@ namespace NekoRay::fmt {
QString ToShareLink() override; QString ToShareLink() override;
}; };
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -3,7 +3,7 @@
#include "fmt/AbstractBean.hpp" #include "fmt/AbstractBean.hpp"
#include "fmt/V2RayStreamSettings.hpp" #include "fmt/V2RayStreamSettings.hpp"
namespace NekoRay::fmt { namespace NekoGui_fmt {
class SocksHttpBean : public AbstractBean { class SocksHttpBean : public AbstractBean {
public: public:
static constexpr int type_HTTP = -80; static constexpr int type_HTTP = -80;
@@ -14,7 +14,7 @@ namespace NekoRay::fmt {
QString username = ""; QString username = "";
QString password = ""; QString password = "";
QSharedPointer<V2rayStreamSettings> stream = QSharedPointer<V2rayStreamSettings>(new V2rayStreamSettings()); std::shared_ptr<V2rayStreamSettings> stream = std::make_shared<V2rayStreamSettings>();
explicit SocksHttpBean(int _socks_http_type) : AbstractBean(0) { explicit SocksHttpBean(int _socks_http_type) : AbstractBean(0) {
this->socks_http_type = _socks_http_type; this->socks_http_type = _socks_http_type;
@@ -34,4 +34,4 @@ namespace NekoRay::fmt {
QString ToShareLink() override; QString ToShareLink() override;
}; };
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -3,7 +3,7 @@
#include "fmt/AbstractBean.hpp" #include "fmt/AbstractBean.hpp"
#include "fmt/V2RayStreamSettings.hpp" #include "fmt/V2RayStreamSettings.hpp"
namespace NekoRay::fmt { namespace NekoGui_fmt {
class TrojanVLESSBean : public AbstractBean { class TrojanVLESSBean : public AbstractBean {
public: public:
static constexpr int proxy_Trojan = 0; static constexpr int proxy_Trojan = 0;
@@ -13,7 +13,7 @@ namespace NekoRay::fmt {
QString password = ""; QString password = "";
QString flow = ""; QString flow = "";
QSharedPointer<V2rayStreamSettings> stream = QSharedPointer<V2rayStreamSettings>(new V2rayStreamSettings()); std::shared_ptr<V2rayStreamSettings> stream = std::make_shared<V2rayStreamSettings>();
explicit TrojanVLESSBean(int _proxy_type) : AbstractBean(0) { explicit TrojanVLESSBean(int _proxy_type) : AbstractBean(0) {
proxy_type = _proxy_type; proxy_type = _proxy_type;
@@ -32,4 +32,4 @@ namespace NekoRay::fmt {
QString ToShareLink() override; QString ToShareLink() override;
}; };
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -2,7 +2,7 @@
#include "AbstractBean.hpp" #include "AbstractBean.hpp"
namespace NekoRay::fmt { namespace NekoGui_fmt {
class V2rayStreamSettings : public JsonStore { class V2rayStreamSettings : public JsonStore {
public: public:
QString network = "tcp"; QString network = "tcp";
@@ -56,10 +56,10 @@ namespace NekoRay::fmt {
if (bean == nullptr) return nullptr; if (bean == nullptr) return nullptr;
auto stream_item = bean->_get("stream"); auto stream_item = bean->_get("stream");
if (stream_item != nullptr) { if (stream_item != nullptr) {
auto stream_store = (NekoRay::JsonStore *) stream_item->ptr; auto stream_store = (JsonStore *) stream_item->ptr;
auto stream = (NekoRay::fmt::V2rayStreamSettings *) stream_store; auto stream = (NekoGui_fmt::V2rayStreamSettings *) stream_store;
return stream; return stream;
} }
return nullptr; return nullptr;
} }
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -3,14 +3,14 @@
#include "fmt/AbstractBean.hpp" #include "fmt/AbstractBean.hpp"
#include "fmt/V2RayStreamSettings.hpp" #include "fmt/V2RayStreamSettings.hpp"
namespace NekoRay::fmt { namespace NekoGui_fmt {
class VMessBean : public AbstractBean { class VMessBean : public AbstractBean {
public: public:
QString uuid = ""; QString uuid = "";
int aid = 0; int aid = 0;
QString security = "auto"; QString security = "auto";
QSharedPointer<V2rayStreamSettings> stream = QSharedPointer<V2rayStreamSettings>(new V2rayStreamSettings()); std::shared_ptr<V2rayStreamSettings> stream = std::make_shared<V2rayStreamSettings>();
VMessBean() : AbstractBean(0) { VMessBean() : AbstractBean(0) {
_add(new configItem("id", &uuid, itemType::string)); _add(new configItem("id", &uuid, itemType::string));
@@ -29,4 +29,4 @@ namespace NekoRay::fmt {
QString ToShareLink() override; QString ToShareLink() override;
}; };
} // namespace NekoRay::fmt } // namespace NekoGui_fmt

View File

@@ -1,6 +1,6 @@
#pragma once #pragma once
namespace NekoRay { namespace NekoGui {
namespace DomainMatcher { namespace DomainMatcher {
enum DomainMatcher { enum DomainMatcher {
DEFAULT, DEFAULT,
@@ -22,4 +22,4 @@ namespace NekoRay {
SING_BOX, SING_BOX,
}; };
} }
} // namespace NekoRay } // namespace NekoGui

View File

@@ -19,48 +19,48 @@
#define P_C_LOAD_STRING(a) CACHE.a = bean->a; #define P_C_LOAD_STRING(a) CACHE.a = bean->a;
#define P_C_SAVE_STRING(a) bean->a = CACHE.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_LOAD_STRING(a) CACHE.a = NekoGui::dataStore->a;
#define D_C_SAVE_STRING(a) NekoRay::dataStore->a = CACHE.a; #define D_C_SAVE_STRING(a) NekoGui::dataStore->a = CACHE.a;
#define P_LOAD_STRING(a) ui->a->setText(bean->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(a) bean->a = ui->a->text();
#define P_SAVE_STRING_QTEXTEDIT(a) bean->a = ui->a->toPlainText(); #define P_SAVE_STRING_QTEXTEDIT(a) bean->a = ui->a->toPlainText();
#define D_LOAD_STRING(a) ui->a->setText(NekoRay::dataStore->a); #define D_LOAD_STRING(a) ui->a->setText(NekoGui::dataStore->a);
#define D_SAVE_STRING(a) NekoRay::dataStore->a = ui->a->text(); #define D_SAVE_STRING(a) NekoGui::dataStore->a = ui->a->text();
#define D_SAVE_STRING_QTEXTEDIT(a) NekoRay::dataStore->a = ui->a->toPlainText(); #define D_SAVE_STRING_QTEXTEDIT(a) NekoGui::dataStore->a = ui->a->toPlainText();
#define P_LOAD_INT(a) \ #define P_LOAD_INT(a) \
ui->a->setText(Int2String(bean->a)); \ ui->a->setText(Int2String(bean->a)); \
ui->a->setValidator(QRegExpValidator_Number); ui->a->setValidator(QRegExpValidator_Number);
#define P_SAVE_INT(a) bean->a = ui->a->text().toInt(); #define P_SAVE_INT(a) bean->a = ui->a->text().toInt();
#define D_LOAD_INT(a) \ #define D_LOAD_INT(a) \
ui->a->setText(Int2String(NekoRay::dataStore->a)); \ ui->a->setText(Int2String(NekoGui::dataStore->a)); \
ui->a->setValidator(QRegExpValidator_Number); 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_LOAD_COMBO_STRING(a) ui->a->setCurrentText(bean->a);
#define P_SAVE_COMBO_STRING(a) bean->a = ui->a->currentText(); #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_LOAD_COMBO_STRING(a) ui->a->setCurrentText(NekoGui::dataStore->a);
#define D_SAVE_COMBO_STRING(a) NekoRay::dataStore->a = ui->a->currentText(); #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_LOAD_COMBO_INT(a) ui->a->setCurrentIndex(bean->a);
#define P_SAVE_COMBO_INT(a) bean->a = ui->a->currentIndex(); #define P_SAVE_COMBO_INT(a) bean->a = ui->a->currentIndex();
#define D_LOAD_BOOL(a) ui->a->setChecked(NekoRay::dataStore->a); #define D_LOAD_BOOL(a) ui->a->setChecked(NekoGui::dataStore->a);
#define D_SAVE_BOOL(a) NekoRay::dataStore->a = ui->a->isChecked(); #define D_SAVE_BOOL(a) NekoGui::dataStore->a = ui->a->isChecked();
#define P_LOAD_BOOL(a) ui->a->setChecked(bean->a); #define P_LOAD_BOOL(a) ui->a->setChecked(bean->a);
#define P_SAVE_BOOL(a) bean->a = ui->a->isChecked(); #define P_SAVE_BOOL(a) bean->a = ui->a->isChecked();
#define D_LOAD_INT_ENABLE(i, e) \ #define D_LOAD_INT_ENABLE(i, e) \
if (NekoRay::dataStore->i > 0) { \ if (NekoGui::dataStore->i > 0) { \
ui->e->setChecked(true); \ ui->e->setChecked(true); \
ui->i->setText(Int2String(NekoRay::dataStore->i)); \ ui->i->setText(Int2String(NekoGui::dataStore->i)); \
} else { \ } else { \
ui->e->setChecked(false); \ ui->e->setChecked(false); \
ui->i->setText(Int2String(-NekoRay::dataStore->i)); \ ui->i->setText(Int2String(-NekoGui::dataStore->i)); \
} \ } \
ui->i->setValidator(QRegExpValidator_Number); ui->i->setValidator(QRegExpValidator_Number);
#define D_SAVE_INT_ENABLE(i, e) \ #define D_SAVE_INT_ENABLE(i, e) \
if (ui->e->isChecked()) { \ if (ui->e->isChecked()) { \
NekoRay::dataStore->i = ui->i->text().toInt(); \ NekoGui::dataStore->i = ui->i->text().toInt(); \
} else { \ } else { \
NekoRay::dataStore->i = -ui->i->text().toInt(); \ NekoGui::dataStore->i = -ui->i->text().toInt(); \
} }
#define C_EDIT_JSON_ALLOW_EMPTY(a) \ #define C_EDIT_JSON_ALLOW_EMPTY(a) \

View File

@@ -5,27 +5,27 @@
#include <QEventLoop> #include <QEventLoop>
#include <QMetaEnum> #include <QMetaEnum>
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
namespace NekoRay::network { namespace NekoGui_network {
NekoHTTPResponse NetworkRequestHelper::HttpGet(const QUrl &url) { NekoHTTPResponse NetworkRequestHelper::HttpGet(const QUrl &url) {
QNetworkRequest request; QNetworkRequest request;
QNetworkAccessManager accessManager; QNetworkAccessManager accessManager;
request.setUrl(url); request.setUrl(url);
// Set proxy // Set proxy
if (NekoRay::dataStore->sub_use_proxy) { if (NekoGui::dataStore->sub_use_proxy) {
QNetworkProxy p; QNetworkProxy p;
// Note: sing-box mixed socks5 protocol error // Note: sing-box mixed socks5 protocol error
p.setType(IS_NEKO_BOX ? QNetworkProxy::HttpProxy : QNetworkProxy::Socks5Proxy); p.setType(IS_NEKO_BOX ? QNetworkProxy::HttpProxy : QNetworkProxy::Socks5Proxy);
p.setHostName("127.0.0.1"); p.setHostName("127.0.0.1");
p.setPort(NekoRay::dataStore->inbound_socks_port); p.setPort(NekoGui::dataStore->inbound_socks_port);
if (dataStore->inbound_auth->NeedAuth()) { if (NekoGui::dataStore->inbound_auth->NeedAuth()) {
p.setUser(dataStore->inbound_auth->username); p.setUser(NekoGui::dataStore->inbound_auth->username);
p.setPassword(dataStore->inbound_auth->password); p.setPassword(NekoGui::dataStore->inbound_auth->password);
} }
accessManager.setProxy(p); 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.")}; return NekoHTTPResponse{QObject::tr("Request with proxy but no profile started.")};
} }
} }
@@ -34,9 +34,11 @@ namespace NekoRay::network {
accessManager.proxy().setCapabilities(cap | QNetworkProxy::HostNameLookupCapability); accessManager.proxy().setCapabilities(cap | QNetworkProxy::HostNameLookupCapability);
} }
// Set attribute // Set attribute
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
request.setHeader(QNetworkRequest::KnownHeaders::UserAgentHeader, NekoRay::dataStore->user_agent); #endif
if (NekoRay::dataStore->sub_insecure) { request.setHeader(QNetworkRequest::KnownHeaders::UserAgentHeader, NekoGui::dataStore->user_agent);
if (NekoGui::dataStore->sub_insecure) {
QSslConfiguration c; QSslConfiguration c;
c.setPeerVerifyMode(QSslSocket::PeerVerifyMode::VerifyNone); c.setPeerVerifyMode(QSslSocket::PeerVerifyMode::VerifyNone);
request.setSslConfiguration(c); request.setSslConfiguration(c);
@@ -48,7 +50,7 @@ namespace NekoRay::network {
for (const auto &err: errors) { for (const auto &err: errors) {
error_str << err.errorString(); 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 ""; return "";
} }
} // namespace NekoRay::network } // namespace NekoGui_network

View File

@@ -6,7 +6,7 @@
#include <QObject> #include <QObject>
#include <functional> #include <functional>
namespace NekoRay::network { namespace NekoGui_network {
struct NekoHTTPResponse { struct NekoHTTPResponse {
QString error; QString error;
QByteArray data; QByteArray data;
@@ -26,6 +26,6 @@ namespace NekoRay::network {
static QString GetHeader(const QList<QPair<QByteArray, QByteArray>> &header, const QString &name); static QString GetHeader(const QList<QPair<QByteArray, QByteArray>> &header, const QString &name);
}; };
} // namespace NekoRay::network } // namespace NekoGui_network
using namespace NekoRay::network; using namespace NekoGui_network;

View File

@@ -1,10 +1,9 @@
#include "NekoRay.hpp" #include "NekoGui.hpp"
#include <QFile> #include <QFile>
#include <QDir> #include <QDir>
#include <QApplication> #include <QApplication>
#include <QFileInfo> #include <QFileInfo>
#include <QSharedPointer>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray> #include <QJsonArray>
#include <QJsonDocument> #include <QJsonDocument>
@@ -15,191 +14,11 @@
#include <unistd.h> #include <unistd.h>
#endif #endif
namespace NekoRay { namespace NekoGui_ConfigItem {
DataStore *dataStore = new DataStore();
// datastore
DataStore::DataStore() : JsonStore() {
_add(new configItem("extraCore", dynamic_cast<JsonStore *>(extraCore), itemType::jsonStore));
_add(new configItem("inbound_auth", dynamic_cast<JsonStore *>(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", &current_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();
}
// 添加关联 // 添加关联
void JsonStore::_add(configItem *item) { void JsonStore::_add(configItem *item) {
_map.insert(item->name, QSharedPointer<configItem>(item)); _map.insert(item->name, std::shared_ptr<configItem>(item));
} }
QString JsonStore::_name(void *p) { QString JsonStore::_name(void *p) {
@@ -209,7 +28,7 @@ namespace NekoRay {
return {}; return {};
} }
QSharedPointer<configItem> JsonStore::_get(const QString &name) { std::shared_ptr<configItem> JsonStore::_get(const QString &name) {
// 直接 [] 会设置一个 nullptr ,所以先判断是否存在 // 直接 [] 会设置一个 nullptr ,所以先判断是否存在
if (_map.contains(name)) { if (_map.contains(name)) {
return _map[name]; return _map[name];
@@ -222,16 +41,16 @@ namespace NekoRay {
if (item == nullptr) return; if (item == nullptr) return;
switch (item->type) { switch (item->type) {
case NekoRay::itemType::string: case itemType::string:
*(QString *) item->ptr = *(QString *) p; *(QString *) item->ptr = *(QString *) p;
break; break;
case NekoRay::itemType::boolean: case itemType::boolean:
*(bool *) item->ptr = *(bool *) p; *(bool *) item->ptr = *(bool *) p;
break; break;
case NekoRay::itemType::integer: case itemType::integer:
*(int *) item->ptr = *(int *) p; *(int *) item->ptr = *(int *) p;
break; break;
case NekoRay::itemType::integer64: case itemType::integer64:
*(long long *) item->ptr = *(long long *) p; *(long long *) item->ptr = *(long long *) p;
break; break;
// others... // others...
@@ -394,10 +213,192 @@ namespace NekoRay {
return ok; return ok;
} }
} // namespace NekoGui_ConfigItem
namespace NekoGui {
DataStore *dataStore = new DataStore();
// datastore
DataStore::DataStore() : JsonStore() {
_add(new configItem("extraCore", dynamic_cast<JsonStore *>(extraCore), itemType::jsonStore));
_add(new configItem("inbound_auth", dynamic_cast<JsonStore *>(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", &current_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) { QString FindCoreAsset(const QString &name) {
QStringList search{dataStore->v2ray_asset_dir}; QStringList search{NekoGui::dataStore->v2ray_asset_dir};
search << QApplication::applicationDirPath(); search << QApplication::applicationDirPath();
search << "/usr/share/v2ray"; search << "/usr/share/v2ray";
search << "/usr/local/share/v2ray"; search << "/usr/local/share/v2ray";
@@ -422,7 +423,7 @@ namespace NekoRay {
bool isAdmin() { bool isAdmin() {
if (isAdminCache >= 0) return isAdminCache; 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 #ifdef Q_OS_WIN
admin = Windows_IsInAdmin(); admin = Windows_IsInAdmin();
#else #else
@@ -433,4 +434,4 @@ namespace NekoRay {
return admin; return admin;
}; };
} // namespace NekoRay } // namespace NekoGui

21
main/NekoGui.hpp Normal file
View File

@@ -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 + "/")

View File

@@ -1,6 +1,6 @@
// DO NOT INCLUDE THIS // DO NOT INCLUDE THIS
namespace NekoRay { namespace NekoGui_ConfigItem {
// config 工具 // config 工具
enum itemType { enum itemType {
string, string,
@@ -28,7 +28,7 @@ namespace NekoRay {
// 可格式化对象 // 可格式化对象
class JsonStore { class JsonStore {
public: public:
QMap<QString, QSharedPointer<configItem>> _map; QMap<QString, std::shared_ptr<configItem>> _map;
std::function<void()> callback_after_load = nullptr; std::function<void()> callback_after_load = nullptr;
std::function<void()> callback_before_save = nullptr; std::function<void()> callback_before_save = nullptr;
@@ -49,7 +49,7 @@ namespace NekoRay {
QString _name(void *p); QString _name(void *p);
QSharedPointer<configItem> _get(const QString &name); std::shared_ptr<configItem> _get(const QString &name);
void _setValue(const QString &name, void *p); void _setValue(const QString &name, void *p);
@@ -65,4 +65,6 @@ namespace NekoRay {
bool Load(); bool Load();
}; };
} // namespace NekoRay } // namespace NekoGui_ConfigItem
using namespace NekoGui_ConfigItem;

View File

@@ -1,6 +1,6 @@
// DO NOT INCLUDE THIS // DO NOT INCLUDE THIS
namespace NekoRay { namespace NekoGui {
class Routing : public JsonStore { class Routing : public JsonStore {
public: public:
@@ -175,4 +175,4 @@ namespace NekoRay {
extern DataStore *dataStore; extern DataStore *dataStore;
} // namespace NekoRay } // namespace NekoGui

View File

@@ -1,4 +1,4 @@
#include "NekoRay_Utils.hpp" #include "NekoGui_Utils.hpp"
#include "3rdparty/base64.h" #include "3rdparty/base64.h"
#include "3rdparty/QThreadCreateThread.hpp" #include "3rdparty/QThreadCreateThread.hpp"
@@ -189,7 +189,7 @@ bool IsIpAddressV6(const QString &str) {
QString DisplayTime(long long time, int formatType) { QString DisplayTime(long long time, int formatType) {
QDateTime t; QDateTime t;
t.setSecsSinceEpoch(time); t.setMSecsSinceEpoch(time * 1000);
return QLocale().toString(t, QLocale::FormatType(formatType)); return QLocale().toString(t, QLocale::FormatType(formatType));
} }

View File

@@ -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 + "/")

View File

@@ -5,9 +5,9 @@
#endif #endif
#include "3rdparty/qjs/nekoray_qjs.h" #include "3rdparty/qjs/nekoray_qjs.h"
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
namespace NekoRay::qjs { namespace qjs {
#ifndef NKR_NO_QUICKJS #ifndef NKR_NO_QUICKJS
namespace exception { namespace exception {
static void js_dump_obj(JSContext *ctx, QString &out, JSValueConst val) { 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)); this->neko_ctx = malloc(sizeof(nekoray_qjs_context));
nekoray_qjs_new_arg arg; nekoray_qjs_new_arg arg;
arg.neko_ctx = NEKO_CTX; 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; arg.func_log = func_log;
nekoray_qjs_new(arg); nekoray_qjs_new(arg);
#endif #endif
@@ -139,10 +139,10 @@ namespace NekoRay::qjs {
QByteArray ReadHookJS() { QByteArray ReadHookJS() {
#ifndef NKR_NO_QUICKJS #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())); return ReadFile(QString("./hook.%1.js").arg(software_name.toLower()));
} }
#endif #endif
return {}; return {};
} }
} // namespace NekoRay::qjs } // namespace qjs

View File

@@ -3,7 +3,7 @@
class QByteArray; class QByteArray;
class QString; class QString;
namespace NekoRay::qjs { namespace qjs {
class QJS { class QJS {
public: public:
QJS(); QJS();
@@ -20,4 +20,4 @@ namespace NekoRay::qjs {
}; };
QByteArray ReadHookJS(); QByteArray ReadHookJS();
} // namespace NekoRay::qjs } // namespace qjs

View File

@@ -10,7 +10,7 @@
#include <QThread> #include <QThread>
#include "3rdparty/RunGuard.hpp" #include "3rdparty/RunGuard.hpp"
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
#include "ui/mainwindow_interface.h" #include "ui/mainwindow_interface.h"
#include "ui/dialog_first_setup.h" #include "ui/dialog_first_setup.h"
@@ -58,10 +58,12 @@ int main(int argc, char* argv[]) {
#endif #endif
// pre-init QApplication // 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); QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);
#endif #endif
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
QApplication::setAttribute(Qt::AA_DontUseNativeDialogs); QApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
#endif
QApplication::setQuitOnLastWindowClosed(false); QApplication::setQuitOnLastWindowClosed(false);
auto preQApp = new QApplication(argc, argv); auto preQApp = new QApplication(argc, argv);
@@ -77,31 +79,31 @@ int main(int argc, char* argv[]) {
#endif #endif
// Flags // Flags
NekoRay::dataStore->argv = QApplication::arguments(); NekoGui::dataStore->argv = QApplication::arguments();
if (NekoRay::dataStore->argv.contains("-many")) NekoRay::dataStore->flag_many = true; if (NekoGui::dataStore->argv.contains("-many")) NekoGui::dataStore->flag_many = true;
if (NekoRay::dataStore->argv.contains("-appdata")) { if (NekoGui::dataStore->argv.contains("-appdata")) {
NekoRay::dataStore->flag_use_appdata = true; NekoGui::dataStore->flag_use_appdata = true;
int appdataIndex = NekoRay::dataStore->argv.indexOf("-appdata"); int appdataIndex = NekoGui::dataStore->argv.indexOf("-appdata");
if (NekoRay::dataStore->argv.size() > appdataIndex + 1 && !NekoRay::dataStore->argv.at(appdataIndex + 1).startsWith("-")) { if (NekoGui::dataStore->argv.size() > appdataIndex + 1 && !NekoGui::dataStore->argv.at(appdataIndex + 1).startsWith("-")) {
NekoRay::dataStore->appdataDir = NekoRay::dataStore->argv.at(appdataIndex + 1); NekoGui::dataStore->appdataDir = NekoGui::dataStore->argv.at(appdataIndex + 1);
} }
} }
if (NekoRay::dataStore->argv.contains("-tray")) NekoRay::dataStore->flag_tray = true; if (NekoGui::dataStore->argv.contains("-tray")) NekoGui::dataStore->flag_tray = true;
if (NekoRay::dataStore->argv.contains("-debug")) NekoRay::dataStore->flag_debug = true; if (NekoGui::dataStore->argv.contains("-debug")) NekoGui::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("-flag_linux_run_core_as_admin")) NekoGui::dataStore->flag_linux_run_core_as_admin = true;
#ifdef NKR_CPP_USE_APPDATA #ifdef NKR_CPP_USE_APPDATA
NekoRay::dataStore->flag_use_appdata = true; // Example: Package & MacOS NekoGui::dataStore->flag_use_appdata = true; // Example: Package & MacOS
#endif #endif
#ifdef NKR_CPP_DEBUG #ifdef NKR_CPP_DEBUG
NekoRay::dataStore->flag_debug = true; NekoGui::dataStore->flag_debug = true;
#endif #endif
// dirs & clean // dirs & clean
auto wd = QDir(QApplication::applicationDirPath()); auto wd = QDir(QApplication::applicationDirPath());
if (NekoRay::dataStore->flag_use_appdata) { if (NekoGui::dataStore->flag_use_appdata) {
QApplication::setApplicationName("nekoray"); QApplication::setApplicationName("nekoray");
if (!NekoRay::dataStore->appdataDir.isEmpty()) { if (!NekoGui::dataStore->appdataDir.isEmpty()) {
wd.setPath(NekoRay::dataStore->appdataDir); wd.setPath(NekoGui::dataStore->appdataDir);
} else { } else {
wd.setPath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation)); wd.setPath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
} }
@@ -111,13 +113,6 @@ int main(int argc, char* argv[]) {
QDir::setCurrent(wd.absoluteFilePath("config")); QDir::setCurrent(wd.absoluteFilePath("config"));
QDir("temp").removeRecursively(); 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 // init QApplication
delete preQApp; delete preQApp;
QApplication a(argc, argv); QApplication a(argc, argv);
@@ -130,7 +125,7 @@ int main(int argc, char* argv[]) {
RunGuard guard("nekoray" + wd.absolutePath()); RunGuard guard("nekoray" + wd.absolutePath());
quint64 guard_data_in = GetRandomUint64(); quint64 guard_data_in = GetRandomUint64();
quint64 guard_data_out = 0; 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 // Some Good System
if (guard.isAnotherRunning(&guard_data_out)) { if (guard.isAnotherRunning(&guard_data_out)) {
// Wake up a running instance // Wake up a running instance
@@ -151,10 +146,17 @@ int main(int argc, char* argv[]) {
MF_release_runguard = [&] { guard.release(); }; MF_release_runguard = [&] { guard.release(); };
// icons // icons
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
QIcon::setFallbackSearchPaths(QStringList{ QIcon::setFallbackSearchPaths(QStringList{
":/nekoray", ":/nekoray",
":/icon", ":/icon",
}); });
#else
QIcon::setThemeSearchPaths(QStringList{
":/nekoray",
":/icon",
});
#endif
// icon for no theme // icon for no theme
if (QIcon::themeName().isEmpty()) { if (QIcon::themeName().isEmpty()) {
@@ -164,23 +166,23 @@ int main(int argc, char* argv[]) {
// Load coreType // Load coreType
auto coreLoaded = ReadFileText("groups/coreType"); auto coreLoaded = ReadFileText("groups/coreType");
if (coreLoaded.isEmpty()) { if (coreLoaded.isEmpty()) {
NekoRay::coreType = -1; NekoGui::coreType = -1;
loadTranslate(QLocale().name()); loadTranslate(QLocale().name());
auto dialogFirstSetup = new DialogFirstSetup; auto dialogFirstSetup = new DialogFirstSetup;
dialogFirstSetup->exec(); dialogFirstSetup->exec();
dialogFirstSetup->deleteLater(); dialogFirstSetup->deleteLater();
if (NekoRay::coreType < 0) { if (NekoGui::coreType < 0) {
return 0; return 0;
} else { } else {
QDir().mkdir("groups"); QDir().mkdir("groups");
QFile file; QFile file;
file.setFileName("groups/coreType"); file.setFileName("groups/coreType");
file.open(QIODevice::ReadWrite | QIODevice::Truncate); file.open(QIODevice::ReadWrite | QIODevice::Truncate);
file.write(Int2String(NekoRay::coreType).toUtf8()); file.write(Int2String(NekoGui::coreType).toUtf8());
file.close(); file.close();
} }
} else { } else {
NekoRay::coreType = coreLoaded.toInt(); NekoGui::coreType = coreLoaded.toInt();
} }
// Dir // Dir
@@ -201,35 +203,35 @@ int main(int argc, char* argv[]) {
} }
// Load dataStore // Load dataStore
switch (NekoRay::coreType) { switch (NekoGui::coreType) {
case NekoRay::CoreType::V2RAY: case NekoGui::CoreType::V2RAY:
NekoRay::dataStore->fn = "groups/nekoray.json"; NekoGui::dataStore->fn = "groups/nekoray.json";
break; break;
case NekoRay::CoreType::SING_BOX: case NekoGui::CoreType::SING_BOX:
NekoRay::dataStore->fn = "groups/nekobox.json"; NekoGui::dataStore->fn = "groups/nekobox.json";
break; break;
default: default:
MessageBoxWarning("Error", "Unknown coreType."); MessageBoxWarning("Error", "Unknown coreType.");
return 0; return 0;
} }
auto isLoaded = NekoRay::dataStore->Load(); auto isLoaded = NekoGui::dataStore->Load();
if (!isLoaded) { if (!isLoaded) {
NekoRay::dataStore->Save(); NekoGui::dataStore->Save();
} }
// Datastore & Flags // Datastore & Flags
if (NekoRay::dataStore->start_minimal) NekoRay::dataStore->flag_tray = true; if (NekoGui::dataStore->start_minimal) NekoGui::dataStore->flag_tray = true;
// load routing // load routing
NekoRay::dataStore->routing->fn = ROUTES_PREFIX + NekoRay::dataStore->active_routing; NekoGui::dataStore->routing->fn = ROUTES_PREFIX + NekoGui::dataStore->active_routing;
isLoaded = NekoRay::dataStore->routing->Load(); isLoaded = NekoGui::dataStore->routing->Load();
if (!isLoaded) { if (!isLoaded) {
NekoRay::dataStore->routing->Save(); NekoGui::dataStore->routing->Save();
} }
// Translate // Translate
QString locale; QString locale;
switch (NekoRay::dataStore->language) { switch (NekoGui::dataStore->language) {
case 1: // English case 1: // English
break; break;
case 2: case 2:
@@ -262,13 +264,13 @@ int main(int argc, char* argv[]) {
}); });
// Do preset update // 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) { 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 { } 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(); UI_InitMainWindow();

View File

@@ -5,7 +5,7 @@
#ifndef NKR_NO_GRPC #ifndef NKR_NO_GRPC
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
#include <QCoreApplication> #include <QCoreApplication>
#include <QNetworkAccessManager> #include <QNetworkAccessManager>
@@ -166,7 +166,7 @@ namespace QtGrpc {
QNetworkReply::NetworkError Call(const QString &methodName, QNetworkReply::NetworkError Call(const QString &methodName,
const google::protobuf::Message &req, google::protobuf::Message *rsp, const google::protobuf::Message &req, google::protobuf::Message *rsp,
int timeout_ms = 0) { 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; std::string reqStr;
req.SerializeToString(&reqStr); req.SerializeToString(&reqStr);
@@ -200,7 +200,7 @@ namespace QtGrpc {
}; };
} // namespace QtGrpc } // namespace QtGrpc
namespace NekoRay::rpc { namespace NekoGui_rpc {
Client::Client(std::function<void(const QString &)> onError, const QString &target, const QString &token) { Client::Client(std::function<void(const QString &)> onError, const QString &target, const QString &token) {
this->make_grpc_channel = [=]() { return std::make_unique<QtGrpc::Http2GrpcChannelPrivate>(target, token, "libcore.LibcoreService"); }; this->make_grpc_channel = [=]() { return std::make_unique<QtGrpc::Http2GrpcChannelPrivate>(target, token, "libcore.LibcoreService"); };
@@ -299,6 +299,6 @@ namespace NekoRay::rpc {
return reply; return reply;
} }
} }
} // namespace NekoRay::rpc } // namespace NekoGui_rpc
#endif #endif

View File

@@ -9,7 +9,7 @@ namespace QtGrpc {
class Http2GrpcChannelPrivate; class Http2GrpcChannelPrivate;
} }
namespace NekoRay::rpc { namespace NekoGui_rpc {
class Client { class Client {
public: public:
explicit Client(std::function<void(const QString &)> onError, const QString &target, const QString &token); explicit Client(std::function<void(const QString &)> onError, const QString &target, const QString &token);
@@ -39,5 +39,5 @@ namespace NekoRay::rpc {
}; };
inline Client *defaultClient; inline Client *defaultClient;
} // namespace NekoRay::rpc } // namespace NekoGui_rpc
#endif #endif

View File

@@ -16,13 +16,13 @@
#endif #endif
namespace NekoRay::sub { namespace NekoGui_sub {
GroupUpdater *groupUpdater = new GroupUpdater; GroupUpdater *groupUpdater = new GroupUpdater;
void RawUpdater_FixEnt(const QSharedPointer<ProxyEntity> &ent) { void RawUpdater_FixEnt(const std::shared_ptr<NekoGui::ProxyEntity> &ent) {
if (ent == nullptr) return; if (ent == nullptr) return;
auto stream = fmt::GetStreamSettings(ent->bean.get()); auto stream = NekoGui_fmt::GetStreamSettings(ent->bean.get());
if (stream == nullptr) return; if (stream == nullptr) return;
// 1. "security" // 1. "security"
if (stream->security == "none" || stream->security == "0" || stream->security == "false") { if (stream->security == "none" || stream->security == "0" || stream->security == "false") {
@@ -58,7 +58,7 @@ namespace NekoRay::sub {
return; return;
} }
QSharedPointer<ProxyEntity> ent; std::shared_ptr<NekoGui::ProxyEntity> ent;
bool needFix = true; bool needFix = true;
// Nekoray format // Nekoray format
@@ -66,7 +66,7 @@ namespace NekoRay::sub {
needFix = false; needFix = false;
auto link = QUrl(str); auto link = QUrl(str);
if (!link.isValid()) return; if (!link.isValid()) return;
ent = ProfileManager::NewProxyEntity(link.host()); ent = NekoGui::ProfileManager::NewProxyEntity(link.host());
if (ent->bean->version == -114514) return; if (ent->bean->version == -114514) return;
auto j = DecodeB64IfValid(link.fragment().toUtf8(), QByteArray::Base64UrlEncoding); auto j = DecodeB64IfValid(link.fragment().toUtf8(), QByteArray::Base64UrlEncoding);
if (j.isEmpty()) return; if (j.isEmpty()) return;
@@ -77,42 +77,42 @@ namespace NekoRay::sub {
// SOCKS // SOCKS
if (str.startsWith("socks5://") || str.startsWith("socks4://") || if (str.startsWith("socks5://") || str.startsWith("socks4://") ||
str.startsWith("socks4a://") || str.startsWith("socks://")) { str.startsWith("socks4a://") || str.startsWith("socks://")) {
ent = ProfileManager::NewProxyEntity("socks"); ent = NekoGui::ProfileManager::NewProxyEntity("socks");
auto ok = ent->SocksHTTPBean()->TryParseLink(str); auto ok = ent->SocksHTTPBean()->TryParseLink(str);
if (!ok) return; if (!ok) return;
} }
// HTTP // HTTP
if (str.startsWith("http://") || str.startsWith("https://")) { if (str.startsWith("http://") || str.startsWith("https://")) {
ent = ProfileManager::NewProxyEntity("http"); ent = NekoGui::ProfileManager::NewProxyEntity("http");
auto ok = ent->SocksHTTPBean()->TryParseLink(str); auto ok = ent->SocksHTTPBean()->TryParseLink(str);
if (!ok) return; if (!ok) return;
} }
// ShadowSocks // ShadowSocks
if (str.startsWith("ss://")) { if (str.startsWith("ss://")) {
ent = ProfileManager::NewProxyEntity("shadowsocks"); ent = NekoGui::ProfileManager::NewProxyEntity("shadowsocks");
auto ok = ent->ShadowSocksBean()->TryParseLink(str); auto ok = ent->ShadowSocksBean()->TryParseLink(str);
if (!ok) return; if (!ok) return;
} }
// VMess // VMess
if (str.startsWith("vmess://")) { if (str.startsWith("vmess://")) {
ent = ProfileManager::NewProxyEntity("vmess"); ent = NekoGui::ProfileManager::NewProxyEntity("vmess");
auto ok = ent->VMessBean()->TryParseLink(str); auto ok = ent->VMessBean()->TryParseLink(str);
if (!ok) return; if (!ok) return;
} }
// VLESS // VLESS
if (str.startsWith("vless://")) { if (str.startsWith("vless://")) {
ent = ProfileManager::NewProxyEntity("vless"); ent = NekoGui::ProfileManager::NewProxyEntity("vless");
auto ok = ent->TrojanVLESSBean()->TryParseLink(str); auto ok = ent->TrojanVLESSBean()->TryParseLink(str);
if (!ok) return; if (!ok) return;
} }
// Trojan // Trojan
if (str.startsWith("trojan://")) { if (str.startsWith("trojan://")) {
ent = ProfileManager::NewProxyEntity("trojan"); ent = NekoGui::ProfileManager::NewProxyEntity("trojan");
auto ok = ent->TrojanVLESSBean()->TryParseLink(str); auto ok = ent->TrojanVLESSBean()->TryParseLink(str);
if (!ok) return; if (!ok) return;
} }
@@ -120,7 +120,7 @@ namespace NekoRay::sub {
// Naive // Naive
if (str.startsWith("naive+")) { if (str.startsWith("naive+")) {
needFix = false; needFix = false;
ent = ProfileManager::NewProxyEntity("naive"); ent = NekoGui::ProfileManager::NewProxyEntity("naive");
auto ok = ent->NaiveBean()->TryParseLink(str); auto ok = ent->NaiveBean()->TryParseLink(str);
if (!ok) return; if (!ok) return;
} }
@@ -128,7 +128,7 @@ namespace NekoRay::sub {
// Hysteria // Hysteria
if (str.startsWith("hysteria://")) { if (str.startsWith("hysteria://")) {
needFix = false; needFix = false;
ent = ProfileManager::NewProxyEntity("hysteria"); ent = NekoGui::ProfileManager::NewProxyEntity("hysteria");
auto ok = ent->HysteriaBean()->TryParseLink(str); auto ok = ent->HysteriaBean()->TryParseLink(str);
if (!ok) return; if (!ok) return;
} }
@@ -139,7 +139,7 @@ namespace NekoRay::sub {
if (needFix) RawUpdater_FixEnt(ent); if (needFix) RawUpdater_FixEnt(ent);
// End // End
profileManager->AddProfile(ent, gid_add_to); NekoGui::profileManager->AddProfile(ent, gid_add_to);
update_counter++; update_counter++;
} }
@@ -217,7 +217,7 @@ namespace NekoRay::sub {
if (type == "ss" || type == "ssr") type = "shadowsocks"; if (type == "ss" || type == "ssr") type = "shadowsocks";
if (type == "socks5") type = "socks"; if (type == "socks5") type = "socks";
auto ent = ProfileManager::NewProxyEntity(type); auto ent = NekoGui::ProfileManager::NewProxyEntity(type);
if (ent->bean->version == -114514) continue; if (ent->bean->version == -114514) continue;
bool needFix = false; 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_str = FIRST_OR_SECOND(Node2QString(proxy["auth_str"]), Node2QString(proxy["auth-str"]));
auto auth = Node2QString(proxy["auth"]); auto auth = Node2QString(proxy["auth"]);
if (!auth_str.isEmpty()) { if (!auth_str.isEmpty()) {
bean->authPayloadType = fmt::HysteriaBean::hysteria_auth_string; bean->authPayloadType = NekoGui_fmt::HysteriaBean::hysteria_auth_string;
bean->authPayload = auth_str; bean->authPayload = auth_str;
} }
if (!auth.isEmpty()) { if (!auth.isEmpty()) {
bean->authPayloadType = fmt::HysteriaBean::hysteria_auth_base64; bean->authPayloadType = NekoGui_fmt::HysteriaBean::hysteria_auth_base64;
bean->authPayload = auth; bean->authPayload = auth;
} }
@@ -393,7 +393,7 @@ namespace NekoRay::sub {
} }
if (needFix) RawUpdater_FixEnt(ent); if (needFix) RawUpdater_FixEnt(ent);
profileManager->AddProfile(ent, gid_add_to); NekoGui::profileManager->AddProfile(ent, gid_add_to);
update_counter++; update_counter++;
} }
} catch (const YAML::Exception &ex) { } catch (const YAML::Exception &ex) {
@@ -429,10 +429,10 @@ namespace NekoRay::sub {
runOnNewThread([=] { runOnNewThread([=] {
auto gid = _sub_gid; auto gid = _sub_gid;
if (createNewGroup) { if (createNewGroup) {
auto group = ProfileManager::NewGroup(); auto group = NekoGui::ProfileManager::NewGroup();
group->name = QUrl(str).host(); group->name = QUrl(str).host();
group->url = str; group->url = str;
profileManager->AddGroup(group); NekoGui::profileManager->AddGroup(group);
gid = group->id; gid = group->id;
MW_dialog_message("SubUpdater", "NewGroup"); 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) { void GroupUpdater::Update(const QString &_str, int _sub_gid, bool _not_sub_as_url) {
// 创建 rawUpdater // 创建 rawUpdater
NekoRay::dataStore->imported_count = 0; NekoGui::dataStore->imported_count = 0;
auto rawUpdater = std::make_unique<RawUpdater>(); auto rawUpdater = std::make_unique<RawUpdater>();
rawUpdater->gid_add_to = _sub_gid; rawUpdater->gid_add_to = _sub_gid;
@@ -452,7 +452,7 @@ namespace NekoRay::sub {
QString sub_user_info; QString sub_user_info;
bool asURL = _sub_gid >= 0 || _not_sub_as_url; // 把 _str 当作 url 处理(下载内容) bool asURL = _sub_gid >= 0 || _not_sub_as_url; // 把 _str 当作 url 处理(下载内容)
auto content = _str.trimmed(); auto content = _str.trimmed();
auto group = profileManager->GetGroup(_sub_gid); auto group = NekoGui::profileManager->GetGroup(_sub_gid);
if (group != nullptr && group->archive) return; if (group != nullptr && group->archive) return;
// 网络请求 // 网络请求
@@ -472,25 +472,25 @@ namespace NekoRay::sub {
MW_show_log("<<<<<<<< " + QObject::tr("Subscription request fininshed: %1").arg(groupName)); MW_show_log("<<<<<<<< " + QObject::tr("Subscription request fininshed: %1").arg(groupName));
} }
QList<QSharedPointer<ProxyEntity>> in; // 更新前 QList<std::shared_ptr<NekoGui::ProxyEntity>> in; // 更新前
QList<QSharedPointer<ProxyEntity>> out_all; // 更新前 + 更新后 QList<std::shared_ptr<NekoGui::ProxyEntity>> out_all; // 更新前 + 更新后
QList<QSharedPointer<ProxyEntity>> out; // 更新后 QList<std::shared_ptr<NekoGui::ProxyEntity>> out; // 更新后
QList<QSharedPointer<ProxyEntity>> only_in; // 只在更新前有的 QList<std::shared_ptr<NekoGui::ProxyEntity>> only_in; // 只在更新前有的
QList<QSharedPointer<ProxyEntity>> only_out; // 只在更新后有的 QList<std::shared_ptr<NekoGui::ProxyEntity>> only_out; // 只在更新后有的
QList<QSharedPointer<ProxyEntity>> update_del; // 更新前后都有的,删除更新后多余的 QList<std::shared_ptr<NekoGui::ProxyEntity>> update_del; // 更新前后都有的,删除更新后多余的
// 订阅解析前 // 订阅解析前
if (group != nullptr) { if (group != nullptr) {
in = group->Profiles(); in = group->Profiles();
group->last_update = QDateTime::currentSecsSinceEpoch(); group->sub_last_update = QDateTime::currentMSecsSinceEpoch() / 1000;
group->info = sub_user_info; group->info = sub_user_info;
group->order.clear(); group->order.clear();
group->Save(); group->Save();
// //
if (dataStore->sub_clear) { if (NekoGui::dataStore->sub_clear) {
MW_show_log(QObject::tr("Clearing servers...")); MW_show_log(QObject::tr("Clearing servers..."));
for (const auto &profile: in) { for (const auto &profile: in) {
profileManager->DeleteProfile(profile->id); NekoGui::profileManager->DeleteProfile(profile->id);
} }
} }
} }
@@ -512,15 +512,15 @@ namespace NekoRay::sub {
if (group != nullptr) { if (group != nullptr) {
out_all = group->Profiles(); out_all = group->Profiles();
ProfileFilter::OnlyInSrc_ByPointer(out_all, in, out); NekoGui::ProfileFilter::OnlyInSrc_ByPointer(out_all, in, out);
ProfileFilter::OnlyInSrc(in, out, only_in); NekoGui::ProfileFilter::OnlyInSrc(in, out, only_in);
ProfileFilter::OnlyInSrc(out, in, only_out); NekoGui::ProfileFilter::OnlyInSrc(out, in, only_out);
ProfileFilter::Common(in, out, update_del, false, true); NekoGui::ProfileFilter::Common(in, out, update_del, false, true);
update_del += only_in; update_del += only_in;
if (dataStore->sub_clear) update_del = {}; if (NekoGui::dataStore->sub_clear) update_del = {};
for (const auto &ent: update_del) { for (const auto &ent: update_del) {
profileManager->DeleteProfile(ent->id); NekoGui::profileManager->DeleteProfile(ent->id);
} }
QString notice_added; QString notice_added;
@@ -541,8 +541,8 @@ namespace NekoRay::sub {
MW_show_log("<<<<<<<< " + QObject::tr("Change of %1:").arg(group->name) + " " + change); MW_show_log("<<<<<<<< " + QObject::tr("Change of %1:").arg(group->name) + " " + change);
MW_dialog_message("SubUpdater", "finish-dingyue"); MW_dialog_message("SubUpdater", "finish-dingyue");
} else { } else {
NekoRay::dataStore->imported_count = rawUpdater->update_counter; NekoGui::dataStore->imported_count = rawUpdater->update_counter;
MW_dialog_message("SubUpdater", "finish"); MW_dialog_message("SubUpdater", "finish");
} }
} }
} // namespace NekoRay::sub } // namespace NekoGui_sub

View File

@@ -2,7 +2,7 @@
#include <QString> #include <QString>
namespace NekoRay::sub { namespace NekoGui_sub {
class RawUpdater { class RawUpdater {
public: public:
void updateClash(const QString &str); void updateClash(const QString &str);
@@ -28,4 +28,4 @@ namespace NekoRay::sub {
}; };
extern GroupUpdater *groupUpdater; extern GroupUpdater *groupUpdater;
} // namespace NekoRay::sub } // namespace NekoGui_sub

View File

@@ -3,7 +3,8 @@
#include <QApplication> #include <QApplication>
#include <QDir> #include <QDir>
#include "main/NekoRay.hpp" #include "3rdparty/fix_old_qt.h"
#include "main/NekoGui.hpp"
// macOS headers (possibly OBJ-c) // macOS headers (possibly OBJ-c)
#if defined(Q_OS_MACOS) #if defined(Q_OS_MACOS)
@@ -178,7 +179,7 @@ void AutoRun_SetEnabled(bool enable) {
appCmdList << "-tray"; appCmdList << "-tray";
if (NekoRay::dataStore->flag_use_appdata) { if (NekoGui::dataStore->flag_use_appdata) {
appCmdList << "-appdata"; appCmdList << "-appdata";
} }

View File

@@ -1,12 +1,12 @@
#include "ExternalProcess.hpp" #include "ExternalProcess.hpp"
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
#include <QTimer> #include <QTimer>
#include <QDir> #include <QDir>
#include <QApplication> #include <QApplication>
#include <QElapsedTimer> #include <QElapsedTimer>
namespace NekoRay::sys { namespace NekoGui_sys {
ExternalProcess::ExternalProcess() : QProcess() { ExternalProcess::ExternalProcess() : QProcess() {
// qDebug() << "[Debug] ExternalProcess()" << this << running_ext; // qDebug() << "[Debug] ExternalProcess()" << this << running_ext;
@@ -24,7 +24,7 @@ namespace NekoRay::sys {
if (managed) { if (managed) {
connect(this, &QProcess::readyReadStandardOutput, this, [&]() { connect(this, &QProcess::readyReadStandardOutput, this, [&]() {
auto log = readAllStandardOutput(); 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); MW_show_log_ext_vt100(log);
}); });
connect(this, &QProcess::readyReadStandardError, this, [&]() { connect(this, &QProcess::readyReadStandardError, this, [&]() {
@@ -54,7 +54,7 @@ namespace NekoRay::sys {
QProcess::setEnvironment(env); QProcess::setEnvironment(env);
if (NekoRay::dataStore->flag_linux_run_core_as_admin && dynamic_cast<CoreProcess *>(this) && program != "pkexec") { if (NekoGui::dataStore->flag_linux_run_core_as_admin && dynamic_cast<CoreProcess *>(this) && program != "pkexec") {
arguments.prepend(program); arguments.prepend(program);
arguments.prepend("--keep-cwd"); arguments.prepend("--keep-cwd");
program = "pkexec"; program = "pkexec";
@@ -85,10 +85,10 @@ namespace NekoRay::sys {
connect(this, &QProcess::readyReadStandardOutput, this, [&]() { connect(this, &QProcess::readyReadStandardOutput, this, [&]() {
auto log = readAllStandardOutput(); auto log = readAllStandardOutput();
if (!NekoRay::dataStore->core_running) { if (!NekoGui::dataStore->core_running) {
if (log.contains("grpc server listening")) { if (log.contains("grpc server listening")) {
// The core really started // The core really started
NekoRay::dataStore->core_running = true; NekoGui::dataStore->core_running = true;
if (start_profile_when_core_is_up >= 0) { if (start_profile_when_core_is_up >= 0) {
MW_dialog_message("ExternalProcess", "CoreStarted," + Int2String(start_profile_when_core_is_up)); MW_dialog_message("ExternalProcess", "CoreStarted," + Int2String(start_profile_when_core_is_up));
start_profile_when_core_is_up = -1; start_profile_when_core_is_up = -1;
@@ -98,7 +98,7 @@ namespace NekoRay::sys {
QProcess::kill(); 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); MW_show_log(log);
}); });
connect(this, &QProcess::readyReadStandardError, this, [&]() { connect(this, &QProcess::readyReadStandardError, this, [&]() {
@@ -119,10 +119,10 @@ namespace NekoRay::sys {
}); });
connect(this, &QProcess::stateChanged, this, [&](QProcess::ProcessState state) { connect(this, &QProcess::stateChanged, this, [&](QProcess::ProcessState state) {
if (state == QProcess::NotRunning) { 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 (failed_to_start) return; // no retry
if (restarting) return; if (restarting) return;
@@ -140,7 +140,7 @@ namespace NekoRay::sys {
} }
// Restart // 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.")); MW_show_log("[Error] " + QObject::tr("Core exited, restarting."));
setTimeout([=] { Restart(); }, this, 1000); setTimeout([=] { Restart(); }, this, 1000);
} }
@@ -150,16 +150,16 @@ namespace NekoRay::sys {
void CoreProcess::Start() { void CoreProcess::Start() {
show_stderr = false; show_stderr = false;
// set extra env // set extra env
auto v2ray_asset_dir = FindCoreAsset("geoip.dat"); auto v2ray_asset_dir = NekoGui::FindCoreAsset("geoip.dat");
if (!v2ray_asset_dir.isEmpty()) { if (!v2ray_asset_dir.isEmpty()) {
v2ray_asset_dir = QFileInfo(v2ray_asset_dir).absolutePath(); v2ray_asset_dir = QFileInfo(v2ray_asset_dir).absolutePath();
env << "V2RAY_LOCATION_ASSET=" + v2ray_asset_dir; env << "V2RAY_LOCATION_ASSET=" + v2ray_asset_dir;
} }
if (NekoRay::dataStore->core_ray_direct_dns) env << "NKR_CORE_RAY_DIRECT_DNS=1"; if (NekoGui::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_windows_disable_auto_interface) env << "NKR_CORE_RAY_WINDOWS_DISABLE_AUTO_INTERFACE=1";
// //
ExternalProcess::Start(); ExternalProcess::Start();
write((dataStore->core_token + "\n").toUtf8()); write((NekoGui::dataStore->core_token + "\n").toUtf8());
} }
void CoreProcess::Restart() { void CoreProcess::Restart() {
@@ -171,4 +171,4 @@ namespace NekoRay::sys {
restarting = false; restarting = false;
} }
} // namespace NekoRay::sys } // namespace NekoGui_sys

View File

@@ -1,8 +1,9 @@
#pragma once #pragma once
#include <memory>
#include <QProcess> #include <QProcess>
namespace NekoRay::sys { namespace NekoGui_sys {
class ExternalProcess : public QProcess { class ExternalProcess : public QProcess {
public: public:
QString tag; QString tag;
@@ -44,7 +45,7 @@ namespace NekoRay::sys {
}; };
// 手动管理 // 手动管理
inline std::list<QSharedPointer<ExternalProcess>> running_ext; inline std::list<std::shared_ptr<ExternalProcess>> running_ext;
inline QAtomicInt logCounter; inline QAtomicInt logCounter;
} // namespace NekoRay::sys } // namespace NekoGui_sys

View File

@@ -21,7 +21,7 @@ typedef BOOL(WINAPI *MINIDUMPWRITEDUMP)(
CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam); CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
LONG CreateCrashHandler(EXCEPTION_POINTERS *pException) { LONG __stdcall CreateCrashHandler(EXCEPTION_POINTERS *pException) {
QDir::setCurrent(QApplication::applicationDirPath()); QDir::setCurrent(QApplication::applicationDirPath());
HMODULE DllHandle = NULL; HMODULE DllHandle = NULL;

View File

@@ -1,6 +1,5 @@
#pragma once #pragma once
namespace NekoRay {
// implement in mainwindow // implement in mainwindow
namespace GroupSortMethod { namespace GroupSortMethod {
enum GroupSortMethod { enum GroupSortMethod {
@@ -19,4 +18,3 @@ namespace NekoRay {
bool descending = false; // 默认升序,开这个就是降序 bool descending = false; // 默认升序,开这个就是降序
bool scroll_to_started = false; bool scroll_to_started = false;
}; };
} // namespace NekoRay

View File

@@ -1,6 +1,6 @@
#include "Icon.hpp" #include "Icon.hpp"
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
#include <QPainter> #include <QPainter>

View File

@@ -6,7 +6,7 @@
#include "ui/ThemeManager.hpp" #include "ui/ThemeManager.hpp"
#include "ui/Icon.hpp" #include "ui/Icon.hpp"
#include "main/GuiUtils.hpp" #include "main/GuiUtils.hpp"
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
#include <QStyleFactory> #include <QStyleFactory>
#include <QFileDialog> #include <QFileDialog>
@@ -72,7 +72,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
D_LOAD_STRING(inbound_address) D_LOAD_STRING(inbound_address)
D_LOAD_COMBO_STRING(log_level) 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(inbound_socks_port)
D_LOAD_INT_ENABLE(inbound_http_port, http_enable) D_LOAD_INT_ENABLE(inbound_http_port, http_enable)
D_LOAD_INT(test_concurrent) D_LOAD_INT(test_concurrent)
@@ -88,9 +88,9 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
auto str = QInputDialog::getItem(this, ui->sys_proxy_format->text() + " (Windows)", auto str = QInputDialog::getItem(this, ui->sys_proxy_format->text() + " (Windows)",
tr("Advanced system proxy settings. Please select a format."), tr("Advanced system proxy settings. Please select a format."),
Preset::Windows::system_proxy_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); false, &ok);
if (ok) NekoRay::dataStore->system_proxy_format = str; if (ok) NekoGui::dataStore->system_proxy_format = str;
}); });
#else #else
ui->sys_proxy_format->hide(); ui->sys_proxy_format->hide();
@@ -106,22 +106,22 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
D_LOAD_BOOL(start_minimal) D_LOAD_BOOL(start_minimal)
D_LOAD_INT(max_log_line) 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); 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); 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); 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); 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); ui->rfsh_r->setCurrentIndex(4);
} else { } else {
ui->rfsh_r->setCurrentIndex(5); ui->rfsh_r->setCurrentIndex(5);
} }
// //
ui->language->setCurrentIndex(NekoRay::dataStore->language); ui->language->setCurrentIndex(NekoGui::dataStore->language);
connect(ui->language, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) { connect(ui->language, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [=](int index) {
CACHE.needRestart = true; CACHE.needRestart = true;
}); });
// //
@@ -129,29 +129,29 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
ui->theme->addItems(QStyleFactory::keys()); ui->theme->addItems(QStyleFactory::keys());
// //
bool ok; bool ok;
auto themeId = NekoRay::dataStore->theme.toInt(&ok); auto themeId = NekoGui::dataStore->theme.toInt(&ok);
if (ok) { if (ok) {
ui->theme->setCurrentIndex(themeId); ui->theme->setCurrentIndex(themeId);
} else { } else {
ui->theme->setCurrentText(NekoRay::dataStore->theme); ui->theme->setCurrentText(NekoGui::dataStore->theme);
} }
// //
connect(ui->theme, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) { connect(ui->theme, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [=](int index) {
if (index + 1 <= built_in_len) { if (index + 1 <= built_in_len) {
themeManager->ApplyTheme(Int2String(index)); themeManager->ApplyTheme(Int2String(index));
NekoRay::dataStore->theme = Int2String(index); NekoGui::dataStore->theme = Int2String(index);
} else { } else {
themeManager->ApplyTheme(ui->theme->currentText()); themeManager->ApplyTheme(ui->theme->currentText());
NekoRay::dataStore->theme = ui->theme->currentText(); NekoGui::dataStore->theme = ui->theme->currentText();
} }
repaint(); repaint();
mainwindow->repaint(); mainwindow->repaint();
NekoRay::dataStore->Save(); NekoGui::dataStore->Save();
}); });
// Subscription // 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_use_proxy)
D_LOAD_BOOL(sub_clear) D_LOAD_BOOL(sub_clear)
D_LOAD_BOOL(sub_insecure) D_LOAD_BOOL(sub_insecure)
@@ -159,9 +159,9 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
// Core // Core
ui->groupBox_core->setTitle(software_core_name); 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("naive")) CACHE.extraCore.insert("naive", "");
if (!CACHE.extraCore.contains("hysteria")) CACHE.extraCore.insert("hysteria", ""); if (!CACHE.extraCore.contains("hysteria")) CACHE.extraCore.insert("hysteria", "");
// //
@@ -215,10 +215,10 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
int neko_core_new; int neko_core_new;
if (sender() == ui->switch_core_sing_box) { if (sender() == ui->switch_core_sing_box) {
if (IS_NEKO_BOX) return; if (IS_NEKO_BOX) return;
neko_core_new = NekoRay::CoreType::SING_BOX; neko_core_new = NekoGui::CoreType::SING_BOX;
} else { } else {
if (!IS_NEKO_BOX) return; if (!IS_NEKO_BOX) return;
neko_core_new = NekoRay::CoreType::V2RAY; neko_core_new = NekoGui::CoreType::V2RAY;
} }
QString core_name_new = dynamic_cast<QRadioButton *>(sender())->text(); QString core_name_new = dynamic_cast<QRadioButton *>(sender())->text();
if (QMessageBox::question(this, tr("Confirmation"), 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); ui->utlsFingerprint->addItems(IS_NEKO_BOX ? Preset::SingBox::UtlsFingerPrint : Preset::V2Ray::UtlsFingerPrint);
D_LOAD_BOOL(skip_cert) D_LOAD_BOOL(skip_cert)
ui->enable_js_hook->setCurrentIndex(NekoRay::dataStore->enable_js_hook); ui->enable_js_hook->setCurrentIndex(NekoGui::dataStore->enable_js_hook);
ui->utlsFingerprint->setCurrentText(NekoRay::dataStore->utlsFingerprint); ui->utlsFingerprint->setCurrentText(NekoGui::dataStore->utlsFingerprint);
} }
DialogBasicSettings::~DialogBasicSettings() { DialogBasicSettings::~DialogBasicSettings() {
@@ -258,7 +258,7 @@ void DialogBasicSettings::accept() {
D_SAVE_STRING(inbound_address) D_SAVE_STRING(inbound_address)
D_SAVE_COMBO_STRING(log_level) 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(inbound_socks_port)
D_SAVE_INT_ENABLE(inbound_http_port, http_enable) D_SAVE_INT_ENABLE(inbound_http_port, http_enable)
D_SAVE_INT(test_concurrent) D_SAVE_INT(test_concurrent)
@@ -266,41 +266,41 @@ void DialogBasicSettings::accept() {
// Style // Style
NekoRay::dataStore->language = ui->language->currentIndex(); NekoGui::dataStore->language = ui->language->currentIndex();
D_SAVE_BOOL(connection_statistics) D_SAVE_BOOL(connection_statistics)
D_SAVE_BOOL(check_include_pre) D_SAVE_BOOL(check_include_pre)
D_SAVE_BOOL(start_minimal) D_SAVE_BOOL(start_minimal)
D_SAVE_INT(max_log_line) D_SAVE_INT(max_log_line)
if (NekoRay::dataStore->max_log_line <= 0) { if (NekoGui::dataStore->max_log_line <= 0) {
NekoRay::dataStore->max_log_line = 200; NekoGui::dataStore->max_log_line = 200;
} }
if (ui->rfsh_r->currentIndex() == 0) { 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) { } 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) { } 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) { } 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) { } else if (ui->rfsh_r->currentIndex() == 4) {
NekoRay::dataStore->traffic_loop_interval = 5000; NekoGui::dataStore->traffic_loop_interval = 5000;
} else { } else {
NekoRay::dataStore->traffic_loop_interval = 0; NekoGui::dataStore->traffic_loop_interval = 0;
} }
// Subscription // 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_use_proxy)
D_SAVE_BOOL(sub_clear) D_SAVE_BOOL(sub_clear)
D_SAVE_BOOL(sub_insecure) D_SAVE_BOOL(sub_insecure)
// Core // Core
NekoRay::dataStore->v2ray_asset_dir = ui->core_v2ray_asset->text(); NekoGui::dataStore->v2ray_asset_dir = ui->core_v2ray_asset->text();
NekoRay::dataStore->extraCore->core_map = QJsonObject2QString(CACHE.extraCore, true); NekoGui::dataStore->extraCore->core_map = QJsonObject2QString(CACHE.extraCore, true);
// Mux // Mux
D_SAVE_INT(mux_concurrency) D_SAVE_INT(mux_concurrency)
@@ -310,11 +310,11 @@ void DialogBasicSettings::accept() {
// Security // Security
D_SAVE_BOOL(skip_cert) D_SAVE_BOOL(skip_cert)
NekoRay::dataStore->enable_js_hook = ui->enable_js_hook->currentIndex(); NekoGui::dataStore->enable_js_hook = ui->enable_js_hook->currentIndex();
NekoRay::dataStore->utlsFingerprint = ui->utlsFingerprint->currentText(); 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"); MW_dialog_message("", "ClearConnectionList");
} }
@@ -328,7 +328,7 @@ void DialogBasicSettings::accept() {
void DialogBasicSettings::refresh_auth() { void DialogBasicSettings::refresh_auth() {
ui->inbound_auth->setText({}); ui->inbound_auth->setText({});
if (NekoRay::dataStore->inbound_auth->NeedAuth()) { if (NekoGui::dataStore->inbound_auth->NeedAuth()) {
ui->inbound_auth->setIcon(Icon::GetMaterialIcon("lock-outline")); ui->inbound_auth->setIcon(Icon::GetMaterialIcon("lock-outline"));
} else { } else {
ui->inbound_auth->setIcon(Icon::GetMaterialIcon("lock-open-outline")); 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 pass_l = new QLabel(tr("Password"));
auto user = new MyLineEdit; auto user = new MyLineEdit;
auto pass = new MyLineEdit; auto pass = new MyLineEdit;
user->setText(NekoRay::dataStore->inbound_auth->username); user->setText(NekoGui::dataStore->inbound_auth->username);
pass->setText(NekoRay::dataStore->inbound_auth->password); pass->setText(NekoGui::dataStore->inbound_auth->password);
// //
layout->addWidget(user_l, 0, 0); layout->addWidget(user_l, 0, 0);
layout->addWidget(user, 0, 1); layout->addWidget(user, 0, 1);
@@ -378,8 +378,8 @@ void DialogBasicSettings::on_inbound_auth_clicked() {
box->setOrientation(Qt::Horizontal); box->setOrientation(Qt::Horizontal);
box->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); box->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
connect(box, &QDialogButtonBox::accepted, w, [=] { connect(box, &QDialogButtonBox::accepted, w, [=] {
NekoRay::dataStore->inbound_auth->username = user->text(); NekoGui::dataStore->inbound_auth->username = user->text();
NekoRay::dataStore->inbound_auth->password = pass->text(); NekoGui::dataStore->inbound_auth->password = pass->text();
MW_dialog_message(Dialog_DialogBasicSettings, "UpdateDataStore"); MW_dialog_message(Dialog_DialogBasicSettings, "UpdateDataStore");
w->accept(); 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 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.")); "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 = 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); core_box_underlying_dns->setMinimumWidth(300);
layout->addWidget(core_box_underlying_dns_l, ++line, 0); layout->addWidget(core_box_underlying_dns_l, ++line, 0);
layout->addWidget(core_box_underlying_dns, line, 1); layout->addWidget(core_box_underlying_dns, line, 1);
@@ -419,26 +419,26 @@ void DialogBasicSettings::on_core_settings_clicked() {
if (IS_NEKO_BOX) { if (IS_NEKO_BOX) {
auto core_box_enable_clash_api_l = new QLabel("Enable Clash API"); auto core_box_enable_clash_api_l = new QLabel("Enable Clash API");
core_box_enable_clash_api = new QCheckBox; 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_l, ++line, 0);
layout->addWidget(core_box_enable_clash_api, line, 1); layout->addWidget(core_box_enable_clash_api, line, 1);
// //
auto core_box_clash_api_l = new QLabel("Clash API Listen Port"); auto core_box_clash_api_l = new QLabel("Clash API Listen Port");
core_box_clash_api = new MyLineEdit; 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_l, ++line, 0);
layout->addWidget(core_box_clash_api, line, 1); layout->addWidget(core_box_clash_api, line, 1);
// //
auto core_box_clash_api_secret_l = new QLabel("Clash API Secret"); auto core_box_clash_api_secret_l = new QLabel("Clash API Secret");
core_box_clash_api_secret = new MyLineEdit; 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_l, ++line, 0);
layout->addWidget(core_box_clash_api_secret, line, 1); layout->addWidget(core_box_clash_api_secret, line, 1);
} else { } else {
auto core_ray_direct_dns_l = new QLabel("NKR_CORE_RAY_DIRECT_DNS"); 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_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 = 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; }); 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_l, ++line, 0);
layout->addWidget(core_ray_direct_dns, line, 1); 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"); 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_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 = 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; }); 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_l, ++line, 0);
layout->addWidget(core_ray_windows_disable_auto_interface, line, 1); 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->setOrientation(Qt::Horizontal);
box->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok); box->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
connect(box, &QDialogButtonBox::accepted, w, [=] { 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) { if (IS_NEKO_BOX) {
NekoRay::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 = 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_secret = core_box_clash_api_secret->text();
} else { } 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 #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 #endif
} }
MW_dialog_message(Dialog_DialogBasicSettings, "UpdateDataStore"); MW_dialog_message(Dialog_DialogBasicSettings, "UpdateDataStore");

View File

@@ -1,7 +1,7 @@
#include "dialog_first_setup.h" #include "dialog_first_setup.h"
#include "ui_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) { DialogFirstSetup::DialogFirstSetup(QWidget *parent) : QDialog(parent), ui(new Ui::DialogFirstSetup) {
ui->setupUi(this); ui->setupUi(this);
@@ -14,9 +14,9 @@ DialogFirstSetup::~DialogFirstSetup() {
void DialogFirstSetup::onButtonClicked() { void DialogFirstSetup::onButtonClicked() {
auto s = sender(); auto s = sender();
if (s == ui->v2ray) { if (s == ui->v2ray) {
NekoRay::coreType = NekoRay::CoreType::V2RAY; NekoGui::coreType = NekoGui::CoreType::V2RAY;
} else if (s == ui->singbox) { } else if (s == ui->singbox) {
NekoRay::coreType = NekoRay::CoreType::SING_BOX; NekoGui::coreType = NekoGui::CoreType::SING_BOX;
} }
done(0); done(0);
} }

View File

@@ -5,20 +5,20 @@
DialogHotkey::DialogHotkey(QWidget *parent) : QDialog(parent), ui(new Ui::DialogHotkey) { DialogHotkey::DialogHotkey(QWidget *parent) : QDialog(parent), ui(new Ui::DialogHotkey) {
ui->setupUi(this); ui->setupUi(this);
ui->show_mainwindow->setKeySequence(NekoRay::dataStore->hotkey_mainwindow); ui->show_mainwindow->setKeySequence(NekoGui::dataStore->hotkey_mainwindow);
ui->show_groups->setKeySequence(NekoRay::dataStore->hotkey_group); ui->show_groups->setKeySequence(NekoGui::dataStore->hotkey_group);
ui->show_routes->setKeySequence(NekoRay::dataStore->hotkey_route); ui->show_routes->setKeySequence(NekoGui::dataStore->hotkey_route);
ui->system_proxy->setKeySequence(NekoRay::dataStore->hotkey_system_proxy_menu); ui->system_proxy->setKeySequence(NekoGui::dataStore->hotkey_system_proxy_menu);
GetMainWindow()->RegisterHotkey(true); GetMainWindow()->RegisterHotkey(true);
} }
DialogHotkey::~DialogHotkey() { DialogHotkey::~DialogHotkey() {
if (result() == QDialog::Accepted) { if (result() == QDialog::Accepted) {
NekoRay::dataStore->hotkey_mainwindow = ui->show_mainwindow->keySequence().toString(); NekoGui::dataStore->hotkey_mainwindow = ui->show_mainwindow->keySequence().toString();
NekoRay::dataStore->hotkey_group = ui->show_groups->keySequence().toString(); NekoGui::dataStore->hotkey_group = ui->show_groups->keySequence().toString();
NekoRay::dataStore->hotkey_route = ui->show_routes->keySequence().toString(); NekoGui::dataStore->hotkey_route = ui->show_routes->keySequence().toString();
NekoRay::dataStore->hotkey_system_proxy_menu = ui->system_proxy->keySequence().toString(); NekoGui::dataStore->hotkey_system_proxy_menu = ui->system_proxy->keySequence().toString();
NekoRay::dataStore->Save(); NekoGui::dataStore->Save();
} }
GetMainWindow()->RegisterHotkey(false); GetMainWindow()->RegisterHotkey(false);
delete ui; delete ui;

View File

@@ -1,7 +1,7 @@
#pragma once #pragma once
#include <QDialog> #include <QDialog>
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { namespace Ui {

View File

@@ -12,7 +12,7 @@
#include <QMessageBox> #include <QMessageBox>
#define AddGroupToListIfExist(_id) \ #define AddGroupToListIfExist(_id) \
auto __ent = NekoRay::profileManager->GetGroup(_id); \ auto __ent = NekoGui::profileManager->GetGroup(_id); \
if (__ent != nullptr) { \ if (__ent != nullptr) { \
auto wI = new QListWidgetItem(); \ auto wI = new QListWidgetItem(); \
auto w = new GroupItem(this, __ent, wI); \ auto w = new GroupItem(this, __ent, wI); \
@@ -24,7 +24,7 @@
DialogManageGroups::DialogManageGroups(QWidget *parent) : QDialog(parent), ui(new Ui::DialogManageGroups) { DialogManageGroups::DialogManageGroups(QWidget *parent) : QDialog(parent), ui(new Ui::DialogManageGroups) {
ui->setupUi(this); ui->setupUi(this);
for (auto id: NekoRay::profileManager->_groups) { for (auto id: NekoGui::profileManager->_groups) {
AddGroupToListIfExist(id) AddGroupToListIfExist(id)
} }
@@ -39,13 +39,13 @@ DialogManageGroups::~DialogManageGroups() {
} }
void DialogManageGroups::on_add_clicked() { void DialogManageGroups::on_add_clicked() {
auto ent = NekoRay::ProfileManager::NewGroup(); auto ent = NekoGui::ProfileManager::NewGroup();
auto dialog = new DialogEditGroup(ent, this); auto dialog = new DialogEditGroup(ent, this);
int ret = dialog->exec(); int ret = dialog->exec();
dialog->deleteLater(); dialog->deleteLater();
if (ret == QDialog::Accepted) { if (ret == QDialog::Accepted) {
NekoRay::profileManager->AddGroup(ent); NekoGui::profileManager->AddGroup(ent);
AddGroupToListIfExist(ent->id); AddGroupToListIfExist(ent->id);
MW_dialog_message(Dialog_DialogManageGroups, "refresh-1"); MW_dialog_message(Dialog_DialogManageGroups, "refresh-1");
} }
@@ -53,10 +53,10 @@ void DialogManageGroups::on_add_clicked() {
void DialogManageGroups::on_update_all_clicked() { void DialogManageGroups::on_update_all_clicked() {
if (QMessageBox::question(this, tr("Confirmation"), tr("Update all subscriptions?")) == QMessageBox::StandardButton::Yes) { if (QMessageBox::question(this, tr("Confirmation"), tr("Update all subscriptions?")) == QMessageBox::StandardButton::Yes) {
for (const auto &gid: NekoRay::profileManager->_groups) { for (const auto &gid: NekoGui::profileManager->_groups) {
auto group = NekoRay::profileManager->GetGroup(gid); auto group = NekoGui::profileManager->GetGroup(gid);
if (group == nullptr || group->url.isEmpty()) continue; 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; return;
} }
} }
@@ -65,22 +65,22 @@ void DialogManageGroups::on_update_all_clicked() {
void UI_update_one_group(int _order) { void UI_update_one_group(int _order) {
// calculate next group // calculate next group
int nextOrder = _order; int nextOrder = _order;
QSharedPointer<NekoRay::Group> nextGroup; std::shared_ptr<NekoGui::Group> nextGroup;
forever { forever {
nextOrder += 1; nextOrder += 1;
if (nextOrder >= NekoRay::profileManager->_groups.length()) break; if (nextOrder >= NekoGui::profileManager->_groups.length()) break;
auto nextGid = NekoRay::profileManager->_groups[nextOrder]; auto nextGid = NekoGui::profileManager->_groups[nextOrder];
nextGroup = NekoRay::profileManager->GetGroup(nextGid); nextGroup = NekoGui::profileManager->GetGroup(nextGid);
if (nextGroup == nullptr || nextGroup->url.isEmpty()) continue; if (nextGroup == nullptr || nextGroup->url.isEmpty()) continue;
break; break;
} }
// calculate this group // 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; if (group == nullptr) return;
// v2.2: listener is moved to GroupItem, no refresh here. // 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); if (nextGroup != nullptr) UI_update_one_group(nextOrder);
}); });
} }

View File

@@ -68,8 +68,8 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
builtInSchemesMenu->addActions(this->getBuiltInSchemes()); builtInSchemesMenu->addActions(this->getBuiltInSchemes());
ui->preset->setMenu(builtInSchemesMenu); ui->preset->setMenu(builtInSchemesMenu);
QString geoipFn = NekoRay::FindCoreAsset("geoip.dat"); QString geoipFn = NekoGui::FindCoreAsset("geoip.dat");
QString geositeFn = NekoRay::FindCoreAsset("geosite.dat"); QString geositeFn = NekoGui::FindCoreAsset("geosite.dat");
// //
const auto sourceStringsDomain = Qv2ray::components::GeositeReader::ReadGeoSiteFromFile(geoipFn); const auto sourceStringsDomain = Qv2ray::components::GeositeReader::ReadGeoSiteFromFile(geoipFn);
directDomainTxt = new AutoCompleteTextEdit("geosite", sourceStringsDomain, this); 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->proxyIPLayout->addWidget(proxyIPTxt, 0, 0);
ui->blockIPLayout->addWidget(blockIPTxt, 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) ADD_ASTERISK(this)
} }
@@ -101,11 +101,11 @@ DialogManageRoutes::~DialogManageRoutes() {
void DialogManageRoutes::accept() { void DialogManageRoutes::accept() {
D_C_SAVE_STRING(custom_route_global) D_C_SAVE_STRING(custom_route_global)
bool routeChanged = false; bool routeChanged = false;
if (NekoRay::dataStore->active_routing != active_routing) routeChanged = true; if (NekoGui::dataStore->active_routing != active_routing) routeChanged = true;
SaveDisplayRouting(NekoRay::dataStore->routing); SaveDisplayRouting(NekoGui::dataStore->routing);
NekoRay::dataStore->active_routing = active_routing; NekoGui::dataStore->active_routing = active_routing;
NekoRay::dataStore->routing->fn = ROUTES_PREFIX + NekoRay::dataStore->active_routing; NekoGui::dataStore->routing->fn = ROUTES_PREFIX + NekoGui::dataStore->active_routing;
if (NekoRay::dataStore->routing->Save()) routeChanged = true; if (NekoGui::dataStore->routing->Save()) routeChanged = true;
// //
QString info = "UpdateDataStore"; QString info = "UpdateDataStore";
if (routeChanged) info += "RouteChanged"; if (routeChanged) info += "RouteChanged";
@@ -122,14 +122,13 @@ QList<QAction *> DialogManageRoutes::getBuiltInSchemes() {
return list; return list;
} }
QAction *DialogManageRoutes::schemeToAction(const QString &name, const NekoRay::Routing &scheme) { QAction *DialogManageRoutes::schemeToAction(const QString &name, const NekoGui::Routing &scheme) {
auto *action = new QAction(this); auto *action = new QAction(name, this);
action->setText(name); connect(action, &QAction::triggered, [this, &scheme] { this->UpdateDisplayRouting((NekoGui::Routing *) &scheme, true); });
connect(action, &QAction::triggered, [this, &scheme] { this->UpdateDisplayRouting((NekoRay::Routing *) &scheme, true); });
return action; return action;
} }
void DialogManageRoutes::UpdateDisplayRouting(NekoRay::Routing *conf, bool qv) { void DialogManageRoutes::UpdateDisplayRouting(NekoGui::Routing *conf, bool qv) {
// //
directDomainTxt->setPlainText(conf->direct_domain); directDomainTxt->setPlainText(conf->direct_domain);
proxyDomainTxt->setPlainText(conf->proxy_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); 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_ip = directIPTxt->toPlainText();
conf->direct_domain = directDomainTxt->toPlainText(); conf->direct_domain = directDomainTxt->toPlainText();
conf->proxy_ip = proxyIPTxt->toPlainText(); conf->proxy_ip = proxyIPTxt->toPlainText();
@@ -186,7 +185,7 @@ void DialogManageRoutes::on_load_save_clicked() {
layout->addWidget(lineEdit); layout->addWidget(lineEdit);
auto list = new QListWidget; auto list = new QListWidget;
layout->addWidget(list); layout->addWidget(list);
for (const auto &name: NekoRay::Routing::List()) { for (const auto &name: NekoGui::Routing::List()) {
list->addItem(name); list->addItem(name);
} }
connect(list, &QListWidget::currentTextChanged, lineEdit, &QLineEdit::setText); connect(list, &QListWidget::currentTextChanged, lineEdit, &QLineEdit::setText);
@@ -207,7 +206,7 @@ void DialogManageRoutes::on_load_save_clicked() {
connect(load, &QPushButton::clicked, w, [=] { connect(load, &QPushButton::clicked, w, [=] {
auto fn = lineEdit->text(); auto fn = lineEdit->text();
if (!fn.isEmpty()) { if (!fn.isEmpty()) {
auto r = std::make_unique<NekoRay::Routing>(); auto r = std::make_unique<NekoGui::Routing>();
r->load_control_must = true; r->load_control_must = true;
r->fn = ROUTES_PREFIX + fn; r->fn = ROUTES_PREFIX + fn;
if (r->Load()) { if (r->Load()) {
@@ -221,7 +220,7 @@ void DialogManageRoutes::on_load_save_clicked() {
connect(save, &QPushButton::clicked, w, [=] { connect(save, &QPushButton::clicked, w, [=] {
auto fn = lineEdit->text(); auto fn = lineEdit->text();
if (!fn.isEmpty()) { if (!fn.isEmpty()) {
auto r = std::make_unique<NekoRay::Routing>(); auto r = std::make_unique<NekoGui::Routing>();
SaveDisplayRouting(r.get()); SaveDisplayRouting(r.get());
r->fn = ROUTES_PREFIX + fn; r->fn = ROUTES_PREFIX + fn;
if (QMessageBox::question(nullptr, software_name, tr("Save routing: %1").arg(fn) + "\n" + r->DisplayRouting()) == QMessageBox::Yes) { 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, [=] { connect(remove, &QPushButton::clicked, w, [=] {
auto fn = lineEdit->text(); 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) { if (QMessageBox::question(nullptr, software_name, tr("Remove routing: %1").arg(fn)) == QMessageBox::Yes) {
QFile f(ROUTES_PREFIX + fn); QFile f(ROUTES_PREFIX + fn);
f.remove(); f.remove();
if (NekoRay::dataStore->active_routing == fn) { if (NekoGui::dataStore->active_routing == fn) {
NekoRay::Routing::SetToActive(NekoRay::Routing::List().first()); NekoGui::Routing::SetToActive(NekoGui::Routing::List().first());
REFRESH_ACTIVE_ROUTING(NekoRay::dataStore->active_routing, NekoRay::dataStore->routing) REFRESH_ACTIVE_ROUTING(NekoGui::dataStore->active_routing, NekoGui::dataStore->routing)
} }
w->accept(); w->accept();
} }

View File

@@ -4,7 +4,7 @@
#include <QMenu> #include <QMenu>
#include "3rdparty/qv2ray/v2/ui/QvAutoCompleteTextEdit.hpp" #include "3rdparty/qv2ray/v2/ui/QvAutoCompleteTextEdit.hpp"
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { namespace Ui {
@@ -37,8 +37,8 @@ private:
Qv2ray::ui::widgets::AutoCompleteTextEdit *blockIPTxt; Qv2ray::ui::widgets::AutoCompleteTextEdit *blockIPTxt;
Qv2ray::ui::widgets::AutoCompleteTextEdit *proxyIPTxt; Qv2ray::ui::widgets::AutoCompleteTextEdit *proxyIPTxt;
// //
NekoRay::Routing routing_cn_lan = NekoRay::Routing(1); NekoGui::Routing routing_cn_lan = NekoGui::Routing(1);
NekoRay::Routing routing_global = NekoRay::Routing(0); NekoGui::Routing routing_global = NekoGui::Routing(0);
// //
QString title_base; QString title_base;
QString active_routing; QString active_routing;
@@ -49,11 +49,11 @@ public slots:
QList<QAction *> getBuiltInSchemes(); QList<QAction *> 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(); void on_load_save_clicked();
}; };

View File

@@ -2,7 +2,7 @@
#include "ui_dialog_vpn_settings.h" #include "ui_dialog_vpn_settings.h"
#include "main/GuiUtils.hpp" #include "main/GuiUtils.hpp"
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
#include "ui/mainwindow_interface.h" #include "ui/mainwindow_interface.h"
#include <QMessageBox> #include <QMessageBox>
@@ -12,18 +12,18 @@ DialogVPNSettings::DialogVPNSettings(QWidget *parent) : QDialog(parent), ui(new
ADD_ASTERISK(this); ADD_ASTERISK(this);
ui->fake_dns->setVisible(!IS_NEKO_BOX); 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_implementation->setCurrentIndex(NekoGui::dataStore->vpn_implementation);
ui->vpn_mtu->setCurrentText(Int2String(NekoRay::dataStore->vpn_mtu)); ui->vpn_mtu->setCurrentText(Int2String(NekoGui::dataStore->vpn_mtu));
ui->vpn_ipv6->setChecked(NekoRay::dataStore->vpn_ipv6); ui->vpn_ipv6->setChecked(NekoGui::dataStore->vpn_ipv6);
ui->hide_console->setChecked(NekoRay::dataStore->vpn_hide_console); ui->hide_console->setChecked(NekoGui::dataStore->vpn_hide_console);
#ifndef Q_OS_WIN #ifndef Q_OS_WIN
ui->hide_console->setVisible(false); ui->hide_console->setVisible(false);
#endif #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->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_cidr)
D_LOAD_STRING(vpn_rule_process) 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->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() { DialogVPNSettings::~DialogVPNSettings() {
@@ -48,14 +48,14 @@ void DialogVPNSettings::accept() {
// //
auto mtu = ui->vpn_mtu->currentText().toInt(); auto mtu = ui->vpn_mtu->currentText().toInt();
if (mtu > 10000 || mtu < 1000) mtu = 9000; if (mtu > 10000 || mtu < 1000) mtu = 9000;
NekoRay::dataStore->vpn_implementation = ui->vpn_implementation->currentIndex(); NekoGui::dataStore->vpn_implementation = ui->vpn_implementation->currentIndex();
NekoRay::dataStore->fake_dns = ui->fake_dns->isChecked(); NekoGui::dataStore->fake_dns = ui->fake_dns->isChecked();
NekoRay::dataStore->vpn_mtu = mtu; NekoGui::dataStore->vpn_mtu = mtu;
NekoRay::dataStore->vpn_ipv6 = ui->vpn_ipv6->isChecked(); NekoGui::dataStore->vpn_ipv6 = ui->vpn_ipv6->isChecked();
NekoRay::dataStore->vpn_hide_console = ui->hide_console->isChecked(); NekoGui::dataStore->vpn_hide_console = ui->hide_console->isChecked();
NekoRay::dataStore->vpn_strict_route = ui->strict_route->isChecked(); NekoGui::dataStore->vpn_strict_route = ui->strict_route->isChecked();
NekoRay::dataStore->vpn_rule_white = ui->whitelist_mode->isChecked(); NekoGui::dataStore->vpn_rule_white = ui->whitelist_mode->isChecked();
NekoRay::dataStore->vpn_internal_tun = ui->single_core->isChecked(); NekoGui::dataStore->vpn_internal_tun = ui->single_core->isChecked();
// //
D_SAVE_STRING_QTEXTEDIT(vpn_rule_cidr) D_SAVE_STRING_QTEXTEDIT(vpn_rule_cidr)
D_SAVE_STRING_QTEXTEDIT(vpn_rule_process) D_SAVE_STRING_QTEXTEDIT(vpn_rule_process)

View File

@@ -5,11 +5,11 @@
#include <QClipboard> #include <QClipboard>
DialogEditGroup::DialogEditGroup(const QSharedPointer<NekoRay::Group> &ent, QWidget *parent) DialogEditGroup::DialogEditGroup(const std::shared_ptr<NekoGui::Group> &ent, QWidget *parent)
: QDialog(parent), ui(new Ui::DialogEditGroup) { : QDialog(parent), ui(new Ui::DialogEditGroup) {
ui->setupUi(this); ui->setupUi(this);
connect(ui->type, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) { connect(ui->type, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [=](int index) {
ui->cat_sub->setHidden(index == 0); ui->cat_sub->setHidden(index == 0);
}); });
@@ -45,7 +45,7 @@ DialogEditGroup::DialogEditGroup(const QSharedPointer<NekoRay::Group> &ent, QWid
connect(ui->copy_links, &QPushButton::clicked, this, [=] { connect(ui->copy_links, &QPushButton::clicked, this, [=] {
QStringList links; QStringList links;
for (const auto &profile: NekoRay::profileManager->profiles) { for (const auto &profile: NekoGui::profileManager->profiles) {
if (profile->gid != ent->id) continue; if (profile->gid != ent->id) continue;
links += profile->bean->ToShareLink(); links += profile->bean->ToShareLink();
} }
@@ -54,7 +54,7 @@ DialogEditGroup::DialogEditGroup(const QSharedPointer<NekoRay::Group> &ent, QWid
}); });
connect(ui->copy_links_nkr, &QPushButton::clicked, this, [=] { connect(ui->copy_links_nkr, &QPushButton::clicked, this, [=] {
QStringList links; QStringList links;
for (const auto &profile: NekoRay::profileManager->profiles) { for (const auto &profile: NekoGui::profileManager->profiles) {
if (profile->gid != ent->id) continue; if (profile->gid != ent->id) continue;
links += profile->bean->ToNekorayShareLink(profile->type); links += profile->bean->ToNekorayShareLink(profile->type);
} }

View File

@@ -13,7 +13,7 @@ class DialogEditGroup : public QDialog {
Q_OBJECT Q_OBJECT
public: public:
explicit DialogEditGroup(const QSharedPointer<NekoRay::Group> &ent, QWidget *parent = nullptr); explicit DialogEditGroup(const std::shared_ptr<NekoGui::Group> &ent, QWidget *parent = nullptr);
~DialogEditGroup() override; ~DialogEditGroup() override;

View File

@@ -19,7 +19,7 @@
#include <QInputDialog> #include <QInputDialog>
#define ADJUST_SIZE runOnUiThread([=] { adjustSize(); adjustPosition(mainwindow); }, this); #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) DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId, QWidget *parent)
: QDialog(parent), ui(new Ui::DialogEditProfile) { : QDialog(parent), ui(new Ui::DialogEditProfile) {
@@ -129,13 +129,13 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId,
LOAD_TYPE("chain"); LOAD_TYPE("chain");
// type changed // type changed
connect(ui->type, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) { connect(ui->type, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [=](int index) {
typeSelected(ui->type->itemData(index).toString()); typeSelected(ui->type->itemData(index).toString());
}); });
ui->apply_to_group->hide(); ui->apply_to_group->hide();
} else { } else {
this->ent = NekoRay::profileManager->GetProfile(profileOrGroupId); this->ent = NekoGui::profileManager->GetProfile(profileOrGroupId);
if (this->ent == nullptr) return; if (this->ent == nullptr) return;
this->type = ent->type; this->type = ent->type;
ui->type->setVisible(false); ui->type->setVisible(false);
@@ -199,7 +199,7 @@ void DialogEditProfile::typeSelected(const QString &newType) {
} }
if (newEnt) { if (newEnt) {
this->ent = NekoRay::ProfileManager::NewProxyEntity(type); this->ent = NekoGui::ProfileManager::NewProxyEntity(type);
this->ent->gid = groupId; this->ent->gid = groupId;
} }
@@ -211,7 +211,7 @@ void DialogEditProfile::typeSelected(const QString &newType) {
ui->port_l->setVisible(showAddressPort); ui->port_l->setVisible(showAddressPort);
// 右边 stream // 右边 stream
auto stream = GetStreamSettings(ent->bean.data()); auto stream = GetStreamSettings(ent->bean.get());
if (stream != nullptr) { if (stream != nullptr) {
ui->right_all_w->setVisible(true); ui->right_all_w->setVisible(true);
ui->network->setCurrentText(stream->network); ui->network->setCurrentText(stream->network);
@@ -344,7 +344,7 @@ bool DialogEditProfile::onEnd() {
} }
// 右边 stream // 右边 stream
auto stream = GetStreamSettings(ent->bean.data()); auto stream = GetStreamSettings(ent->bean.get());
if (stream != nullptr) { if (stream != nullptr) {
stream->network = ui->network->currentText(); stream->network = ui->network->currentText();
stream->security = ui->security->currentText(); stream->security = ui->security->currentText();
@@ -381,13 +381,13 @@ void DialogEditProfile::accept() {
QStringList msg = {"accept"}; QStringList msg = {"accept"};
if (newEnt) { if (newEnt) {
auto ok = NekoRay::profileManager->AddProfile(ent); auto ok = NekoGui::profileManager->AddProfile(ent);
if (!ok) { if (!ok) {
MessageBoxWarning("???", "id exists"); MessageBoxWarning("???", "id exists");
} }
} else { } else {
auto changed = ent->Save(); 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(",")); 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); apply_to_group_ui[ui->custom_outbound_edit] = new FloatCheckBox(ui->custom_outbound_edit, this);
ui->apply_to_group->setText(tr("Confirm")); ui->apply_to_group->setText(tr("Confirm"));
} else { } else {
auto group = NekoRay::profileManager->GetGroup(ent->gid); auto group = NekoGui::profileManager->GetGroup(ent->gid);
if (group == nullptr) { if (group == nullptr) {
MessageBoxWarning("failed", "unknown group"); MessageBoxWarning("failed", "unknown group");
return; return;
@@ -480,12 +480,12 @@ void DialogEditProfile::on_apply_to_group_clicked() {
} }
} }
void DialogEditProfile::do_apply_to_group(const QSharedPointer<NekoRay::Group> &group, QWidget *key) { void DialogEditProfile::do_apply_to_group(const std::shared_ptr<NekoGui::Group> &group, QWidget *key) {
auto stream = GetStreamSettings(ent->bean.data()); auto stream = GetStreamSettings(ent->bean.get());
auto copyStream = [=](void *p) { auto copyStream = [=](void *p) {
for (const auto &profile: group->Profiles()) { for (const auto &profile: group->Profiles()) {
auto newStream = GetStreamSettings(profile->bean.data()); auto newStream = GetStreamSettings(profile->bean.get());
if (newStream == nullptr) continue; if (newStream == nullptr) continue;
if (stream == newStream) continue; if (stream == newStream) continue;
newStream->_setValue(stream->_name(p), p); newStream->_setValue(stream->_name(p), p);

View File

@@ -44,7 +44,7 @@ private:
QString type; QString type;
int groupId; int groupId;
bool newEnt = false; bool newEnt = false;
QSharedPointer<NekoRay::ProxyEntity> ent; std::shared_ptr<NekoGui::ProxyEntity> ent;
QString network_title_base; QString network_title_base;
@@ -60,7 +60,7 @@ private:
void editor_cache_updated_impl(); void editor_cache_updated_impl();
void do_apply_to_group(const QSharedPointer<NekoRay::Group> &group, QWidget *key); void do_apply_to_group(const std::shared_ptr<NekoGui::Group> &group, QWidget *key);
}; };
#endif // DIALOG_EDIT_PROFILE_H #endif // DIALOG_EDIT_PROFILE_H

View File

@@ -15,7 +15,7 @@ EditChain::~EditChain() {
delete ui; delete ui;
} }
void EditChain::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) { void EditChain::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
this->ent = _ent; this->ent = _ent;
auto bean = this->ent->ChainBean(); auto bean = this->ent->ChainBean();
@@ -45,7 +45,7 @@ void EditChain::on_select_profile_clicked() {
} }
void EditChain::AddProfileToListIfExist(int profileId) { void EditChain::AddProfileToListIfExist(int profileId) {
auto _ent = NekoRay::profileManager->GetProfile(profileId); auto _ent = NekoGui::profileManager->GetProfile(profileId);
if (_ent != nullptr && _ent->type != "chain") { if (_ent != nullptr && _ent->type != "chain") {
auto wI = new QListWidgetItem(); auto wI = new QListWidgetItem();
wI->setData(114514, profileId); wI->setData(114514, profileId);
@@ -64,7 +64,7 @@ void EditChain::AddProfileToListIfExist(int profileId) {
} }
void EditChain::ReplaceProfile(ProxyItem *w, 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") { if (_ent != nullptr && _ent->type != "chain") {
w->item->setData(114514, profileId); w->item->setData(114514, profileId);
w->ent = _ent; w->ent = _ent;

View File

@@ -19,13 +19,13 @@ public:
~EditChain() override; ~EditChain() override;
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override; void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
bool onEnd() override; bool onEnd() override;
private: private:
Ui::EditChain *ui; Ui::EditChain *ui;
QSharedPointer<NekoRay::ProxyEntity> ent; std::shared_ptr<NekoGui::ProxyEntity> ent;
void AddProfileToListIfExist(int profileId); void AddProfileToListIfExist(int profileId);

View File

@@ -33,12 +33,12 @@ EditCustom::~EditCustom() {
P_SAVE_INT(mapping_port) \ P_SAVE_INT(mapping_port) \
P_SAVE_INT(socks_port) P_SAVE_INT(socks_port)
void EditCustom::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) { void EditCustom::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
this->ent = _ent; this->ent = _ent;
auto bean = this->ent->CustomBean(); auto bean = this->ent->CustomBean();
// load known core // 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()) { for (const auto &key: core_map.keys()) {
if (key == "naive" || key == "hysteria") continue; if (key == "naive" || key == "hysteria") continue;
ui->core->addItem(key); ui->core->addItem(key);
@@ -102,7 +102,7 @@ void EditCustom::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
th << "%server_port% => " + get_edit_text_serverPort(); th << "%server_port% => " + get_edit_text_serverPort();
MessageBoxInfo(tr("Preview replace"), th.join("\n")); MessageBoxInfo(tr("Preview replace"), th.join("\n"));
// EditCustom::onEnd // EditCustom::onEnd
auto tmpEnt = NekoRay::ProfileManager::NewProxyEntity("custom"); auto tmpEnt = NekoGui::ProfileManager::NewProxyEntity("custom");
auto bean = tmpEnt->CustomBean(); auto bean = tmpEnt->CustomBean();
SAVE_CUSTOM_BEAN SAVE_CUSTOM_BEAN
// 补充 // 补充
@@ -110,7 +110,7 @@ void EditCustom::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
bean->serverPort = get_edit_text_serverPort().toInt(); bean->serverPort = get_edit_text_serverPort().toInt();
if (bean->core.isEmpty()) return; if (bean->core.isEmpty()) return;
// //
auto result = NekoRay::BuildConfig(tmpEnt, false, false); auto result = NekoGui::BuildConfig(tmpEnt, false, false);
if (!result->error.isEmpty()) { if (!result->error.isEmpty()) {
MessageBoxInfo(software_name, result->error); MessageBoxInfo(software_name, result->error);
return; return;

View File

@@ -21,13 +21,13 @@ public:
~EditCustom() override; ~EditCustom() override;
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override; void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
bool onEnd() override; bool onEnd() override;
private: private:
Ui::EditCustom *ui; Ui::EditCustom *ui;
QSharedPointer<NekoRay::ProxyEntity> ent; std::shared_ptr<NekoGui::ProxyEntity> ent;
private slots: private slots:

View File

@@ -13,7 +13,7 @@ EditHysteria::~EditHysteria() {
delete ui; delete ui;
} }
void EditHysteria::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) { void EditHysteria::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
this->ent = _ent; this->ent = _ent;
auto bean = this->ent->HysteriaBean(); auto bean = this->ent->HysteriaBean();

View File

@@ -17,7 +17,7 @@ public:
~EditHysteria() override; ~EditHysteria() override;
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override; void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
bool onEnd() override; bool onEnd() override;
@@ -25,7 +25,7 @@ public:
private: private:
Ui::EditHysteria *ui; Ui::EditHysteria *ui;
QSharedPointer<NekoRay::ProxyEntity> ent; std::shared_ptr<NekoGui::ProxyEntity> ent;
struct { struct {
QString caText; QString caText;

View File

@@ -13,7 +13,7 @@ EditNaive::~EditNaive() {
delete ui; delete ui;
} }
void EditNaive::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) { void EditNaive::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
this->ent = _ent; this->ent = _ent;
auto bean = this->ent->NaiveBean(); auto bean = this->ent->NaiveBean();

View File

@@ -17,7 +17,7 @@ public:
~EditNaive() override; ~EditNaive() override;
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override; void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
bool onEnd() override; bool onEnd() override;
@@ -25,7 +25,7 @@ public:
private: private:
Ui::EditNaive *ui; Ui::EditNaive *ui;
QSharedPointer<NekoRay::ProxyEntity> ent; std::shared_ptr<NekoGui::ProxyEntity> ent;
struct { struct {
QString certificate; QString certificate;

View File

@@ -17,7 +17,7 @@ EditShadowSocks::~EditShadowSocks() {
delete ui; delete ui;
} }
void EditShadowSocks::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) { void EditShadowSocks::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
this->ent = _ent; this->ent = _ent;
auto bean = this->ent->ShadowSocksBean(); auto bean = this->ent->ShadowSocksBean();

View File

@@ -16,13 +16,13 @@ public:
~EditShadowSocks() override; ~EditShadowSocks() override;
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override; void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
bool onEnd() override; bool onEnd() override;
private: private:
Ui::EditShadowSocks *ui; Ui::EditShadowSocks *ui;
QSharedPointer<NekoRay::ProxyEntity> ent; std::shared_ptr<NekoGui::ProxyEntity> ent;
}; };
#endif // EDIT_SHADOWSOCKS_H #endif // EDIT_SHADOWSOCKS_H

View File

@@ -12,16 +12,16 @@ EditSocksHttp::~EditSocksHttp() {
delete ui; delete ui;
} }
void EditSocksHttp::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) { void EditSocksHttp::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
this->ent = _ent; this->ent = _ent;
auto bean = this->ent->SocksHTTPBean(); 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); ui->version->setCurrentIndex(1);
} else { } else {
ui->version->setCurrentIndex(0); 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->setVisible(false);
ui->version_l->setVisible(false); ui->version_l->setVisible(false);
} }
@@ -35,9 +35,9 @@ bool EditSocksHttp::onEnd() {
if (ui->version->isVisible()) { if (ui->version->isVisible()) {
if (ui->version->currentIndex() == 1) { if (ui->version->currentIndex() == 1) {
bean->socks_http_type = NekoRay::fmt::SocksHttpBean::type_Socks4; bean->socks_http_type = NekoGui_fmt::SocksHttpBean::type_Socks4;
} else { } else {
bean->socks_http_type = NekoRay::fmt::SocksHttpBean::type_Socks5; bean->socks_http_type = NekoGui_fmt::SocksHttpBean::type_Socks5;
} }
} }

View File

@@ -15,11 +15,11 @@ public:
~EditSocksHttp() override; ~EditSocksHttp() override;
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override; void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
bool onEnd() override; bool onEnd() override;
private: private:
Ui::EditSocksHttp *ui; Ui::EditSocksHttp *ui;
QSharedPointer<NekoRay::ProxyEntity> ent; std::shared_ptr<NekoGui::ProxyEntity> ent;
}; };

View File

@@ -11,13 +11,13 @@ EditTrojanVLESS::~EditTrojanVLESS() {
delete ui; delete ui;
} }
void EditTrojanVLESS::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) { void EditTrojanVLESS::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
this->ent = _ent; this->ent = _ent;
auto bean = this->ent->TrojanVLESSBean(); 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"); 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->hide();
ui->flow_l->hide(); ui->flow_l->hide();
} }

View File

@@ -17,11 +17,11 @@ public:
~EditTrojanVLESS() override; ~EditTrojanVLESS() override;
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override; void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
bool onEnd() override; bool onEnd() override;
private: private:
Ui::EditTrojanVLESS *ui; Ui::EditTrojanVLESS *ui;
QSharedPointer<NekoRay::ProxyEntity> ent; std::shared_ptr<NekoGui::ProxyEntity> ent;
}; };

View File

@@ -14,7 +14,7 @@ EditVMess::~EditVMess() {
delete ui; delete ui;
} }
void EditVMess::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) { void EditVMess::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
this->ent = _ent; this->ent = _ent;
auto bean = this->ent->VMessBean(); auto bean = this->ent->VMessBean();

View File

@@ -17,11 +17,11 @@ public:
~EditVMess() override; ~EditVMess() override;
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override; void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
bool onEnd() override; bool onEnd() override;
private: private:
Ui::EditVMess *ui; Ui::EditVMess *ui;
QSharedPointer<NekoRay::ProxyEntity> ent; std::shared_ptr<NekoGui::ProxyEntity> ent;
}; };

View File

@@ -7,7 +7,7 @@
class ProfileEditor { class ProfileEditor {
public: public:
virtual void onStart(QSharedPointer<NekoRay::ProxyEntity> ent) = 0; virtual void onStart(std::shared_ptr<NekoGui::ProxyEntity> ent) = 0;
virtual bool onEnd() = 0; virtual bool onEnd() = 0;

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@
#include <QMainWindow> #include <QMainWindow>
#include "main/NekoRay.hpp" #include "main/NekoGui.hpp"
#ifndef MW_INTERFACE #ifndef MW_INTERFACE
@@ -23,7 +23,7 @@
#endif #endif
namespace NekoRay::sys { namespace NekoGui_sys {
class CoreProcess; class CoreProcess;
} }
@@ -141,7 +141,7 @@ private:
QShortcut *shortcut_ctrl_f = new QShortcut(QKeySequence("Ctrl+F"), this); QShortcut *shortcut_ctrl_f = new QShortcut(QKeySequence("Ctrl+F"), this);
QShortcut *shortcut_esc = new QShortcut(QKeySequence("Esc"), this); QShortcut *shortcut_esc = new QShortcut(QKeySequence("Esc"), this);
// //
NekoRay::sys::CoreProcess *core_process; NekoGui_sys::CoreProcess *core_process;
qint64 vpn_pid = 0; qint64 vpn_pid = 0;
// //
bool qvLogAutoScoll = true; bool qvLogAutoScoll = true;
@@ -149,7 +149,7 @@ private:
// //
QString title_error; QString title_error;
int icon_status = -1; int icon_status = -1;
QSharedPointer<NekoRay::ProxyEntity> running; std::shared_ptr<NekoGui::ProxyEntity> running;
QString traffic_update_cache; QString traffic_update_cache;
QTime last_test_time; QTime last_test_time;
// //
@@ -161,15 +161,15 @@ private:
QSemaphore sem_stopped; QSemaphore sem_stopped;
int exit_reason = 0; int exit_reason = 0;
QMap<int, QSharedPointer<NekoRay::ProxyEntity>> get_now_selected(); QMap<int, std::shared_ptr<NekoGui::ProxyEntity>> get_now_selected();
QList<QSharedPointer<NekoRay::ProxyEntity>> get_now_selected_list(); QList<std::shared_ptr<NekoGui::ProxyEntity>> get_now_selected_list();
QList<QSharedPointer<NekoRay::ProxyEntity>> get_selected_or_group(); QList<std::shared_ptr<NekoGui::ProxyEntity>> get_selected_or_group();
void dialog_message_impl(const QString &sender, const QString &info); 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); void refresh_proxy_list_impl_refresh_data(const int &id = -1);

View File

@@ -3,7 +3,7 @@
#include "db/Database.hpp" #include "db/Database.hpp"
#include "db/ConfigBuilder.hpp" #include "db/ConfigBuilder.hpp"
#include "db/TrafficLooper.hpp" #include "db/traffic/TrafficLooper.hpp"
#include "rpc/gRPC.h" #include "rpc/gRPC.h"
#include "ui/widget/MessageBoxTimer.h" #include "ui/widget/MessageBoxTimer.h"
@@ -16,11 +16,11 @@
// ext core // ext core
std::list<QSharedPointer<NekoRay::sys::ExternalProcess>> CreateExtCFromExtR(const std::list<std::shared_ptr<NekoRay::fmt::ExternalBuildResult>> &extRs, bool start) { std::list<std::shared_ptr<NekoGui_sys::ExternalProcess>> CreateExtCFromExtR(const std::list<std::shared_ptr<NekoGui_fmt::ExternalBuildResult>> &extRs, bool start) {
// plz run and start in same thread // plz run and start in same thread
std::list<QSharedPointer<NekoRay::sys::ExternalProcess>> l; std::list<std::shared_ptr<NekoGui_sys::ExternalProcess>> l;
for (const auto &extR: extRs) { for (const auto &extR: extRs) {
QSharedPointer<NekoRay::sys::ExternalProcess> extC(new NekoRay::sys::ExternalProcess()); std::shared_ptr<NekoGui_sys::ExternalProcess> extC(new NekoGui_sys::ExternalProcess());
extC->tag = extR->tag; extC->tag = extR->tag;
extC->program = extR->program; extC->program = extR->program;
extC->arguments = extR->arguments; extC->arguments = extR->arguments;
@@ -35,7 +35,7 @@ std::list<QSharedPointer<NekoRay::sys::ExternalProcess>> CreateExtCFromExtR(cons
// grpc // grpc
#ifndef NKR_NO_GRPC #ifndef NKR_NO_GRPC
using namespace NekoRay::rpc; using namespace NekoGui_rpc;
#endif #endif
void MainWindow::setup_grpc() { void MainWindow::setup_grpc() {
@@ -45,10 +45,10 @@ void MainWindow::setup_grpc() {
[=](const QString &errStr) { [=](const QString &errStr) {
MW_show_log("[Error] gRPC: " + 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 // Looper
runOnNewThread([=] { NekoRay::traffic::trafficLooper->Loop(); }); runOnNewThread([=] { NekoGui_traffic::trafficLooper->Loop(); });
#endif #endif
} }
@@ -59,7 +59,7 @@ inline bool speedtesting = false;
void MainWindow::speedtest_current_group(int mode) { void MainWindow::speedtest_current_group(int mode) {
auto profiles = get_selected_or_group(); auto profiles = get_selected_or_group();
if (profiles.isEmpty()) return; if (profiles.isEmpty()) return;
auto group = NekoRay::profileManager->CurrentGroup(); auto group = NekoGui::profileManager->CurrentGroup();
if (group->archive) return; if (group->archive) return;
#ifndef NKR_NO_GRPC #ifndef NKR_NO_GRPC
@@ -82,7 +82,7 @@ void MainWindow::speedtest_current_group(int mode) {
runOnNewThread([this, profiles, mode, full_test_flags]() { runOnNewThread([this, profiles, mode, full_test_flags]() {
QMutex lock_write; QMutex lock_write;
QMutex lock_return; QMutex lock_return;
int threadN = NekoRay::dataStore->test_concurrent; int threadN = NekoGui::dataStore->test_concurrent;
int threadN_finished = 0; int threadN_finished = 0;
auto profiles_test = profiles; // copy auto profiles_test = profiles; // copy
@@ -106,13 +106,13 @@ void MainWindow::speedtest_current_group(int mode) {
libcore::TestReq req; libcore::TestReq req;
req.set_mode((libcore::TestMode) mode); req.set_mode((libcore::TestMode) mode);
req.set_timeout(3000); req.set_timeout(3000);
req.set_url(NekoRay::dataStore->test_url.toStdString()); req.set_url(NekoGui::dataStore->test_url.toStdString());
// //
std::list<QSharedPointer<NekoRay::sys::ExternalProcess>> extCs; std::list<std::shared_ptr<NekoGui_sys::ExternalProcess>> extCs;
if (mode == libcore::TestMode::UrlTest || mode == libcore::FullTest) { 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 // TODO refactor external test
if (!c->extRs.empty()) { if (!c->extRs.empty()) {
extCs = CreateExtCFromExtR(c->extRs, true); extCs = CreateExtCFromExtR(c->extRs, true);
@@ -177,7 +177,7 @@ void MainWindow::speedtest_current() {
libcore::TestReq req; libcore::TestReq req;
req.set_mode(libcore::UrlTest); req.set_mode(libcore::UrlTest);
req.set_timeout(3000); req.set_timeout(3000);
req.set_url(NekoRay::dataStore->test_url.toStdString()); req.set_url(NekoGui::dataStore->test_url.toStdString());
bool rpcOK; bool rpcOK;
auto result = defaultClient->Test(&rpcOK, req); auto result = defaultClient->Test(&rpcOK, req);
@@ -202,15 +202,15 @@ void MainWindow::speedtest_current() {
void MainWindow::stop_core_daemon() { void MainWindow::stop_core_daemon() {
#ifndef NKR_NO_GRPC #ifndef NKR_NO_GRPC
NekoRay::rpc::defaultClient->Exit(); NekoGui_rpc::defaultClient->Exit();
#endif #endif
} }
void MainWindow::neko_start(int _id) { void MainWindow::neko_start(int _id) {
if (NekoRay::dataStore->prepare_exit) return; if (NekoGui::dataStore->prepare_exit) return;
auto ents = get_now_selected(); 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 (ent == nullptr) return;
if (select_mode) { if (select_mode) {
@@ -220,10 +220,10 @@ void MainWindow::neko_start(int _id) {
return; return;
} }
auto group = NekoRay::profileManager->GetGroup(ent->gid); auto group = NekoGui::profileManager->GetGroup(ent->gid);
if (group == nullptr || group->archive) return; if (group == nullptr || group->archive) return;
auto result = NekoRay::BuildConfig(ent, false, false); auto result = BuildConfig(ent, false, false);
if (!result->error.isEmpty()) { if (!result->error.isEmpty()) {
MessageBoxWarning("BuildConfig return error", result->error); MessageBoxWarning("BuildConfig return error", result->error);
return; return;
@@ -233,8 +233,8 @@ void MainWindow::neko_start(int _id) {
#ifndef NKR_NO_GRPC #ifndef NKR_NO_GRPC
libcore::LoadConfigReq req; libcore::LoadConfigReq req;
req.set_core_config(QJsonObject2QString(result->coreConfig, true).toStdString()); req.set_core_config(QJsonObject2QString(result->coreConfig, true).toStdString());
req.set_enable_nekoray_connections(NekoRay::dataStore->connection_statistics); req.set_enable_nekoray_connections(NekoGui::dataStore->connection_statistics);
if (NekoRay::dataStore->traffic_loop_interval > 0) { if (NekoGui::dataStore->traffic_loop_interval > 0) {
req.add_stats_outbounds("proxy"); req.add_stats_outbounds("proxy");
req.add_stats_outbounds("bypass"); req.add_stats_outbounds("bypass");
} }
@@ -248,20 +248,20 @@ void MainWindow::neko_start(int _id) {
return false; return false;
} }
// //
NekoRay::traffic::trafficLooper->proxy = result->outboundStat.get(); NekoGui_traffic::trafficLooper->proxy = result->outboundStat.get();
NekoRay::traffic::trafficLooper->items = result->outboundStats; NekoGui_traffic::trafficLooper->items = result->outboundStats;
NekoRay::dataStore->ignoreConnTag = result->ignoreConnTag; NekoGui::dataStore->ignoreConnTag = result->ignoreConnTag;
NekoRay::traffic::trafficLooper->loop_enabled = true; NekoGui_traffic::trafficLooper->loop_enabled = true;
#endif #endif
runOnUiThread( runOnUiThread(
[=] { [=] {
auto extCs = CreateExtCFromExtR(result->extRs, true); 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); DS_cores);
NekoRay::dataStore->UpdateStartedId(ent->id); NekoGui::dataStore->UpdateStartedId(ent->id);
running = ent; running = ent;
runOnUiThread([=] { runOnUiThread([=] {
@@ -284,7 +284,7 @@ void MainWindow::neko_start(int _id) {
mu_stopping.unlock(); mu_stopping.unlock();
// check core state // check core state
if (!NekoRay::dataStore->core_running) { if (!NekoGui::dataStore->core_running) {
runOnUiThread( runOnUiThread(
[=] { [=] {
show_log_impl("Try to start the config, but the core has not listened to the grpc port, so restart it..."); 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([=] { runOnNewThread([=] {
// stop current running // stop current running
if (NekoRay::dataStore->started_id >= 0) { if (NekoGui::dataStore->started_id >= 0) {
runOnUiThread([=] { neko_stop(false, true); }); runOnUiThread([=] { neko_stop(false, true); });
sem_stopped.acquire(); sem_stopped.acquire();
} }
@@ -324,7 +324,7 @@ void MainWindow::neko_start(int _id) {
} }
void MainWindow::neko_stop(bool crash, bool sem) { void MainWindow::neko_stop(bool crash, bool sem) {
auto id = NekoRay::dataStore->started_id; auto id = NekoGui::dataStore->started_id;
if (id < 0) { if (id < 0) {
if (sem) sem_stopped.release(); if (sem) sem_stopped.release();
return; return;
@@ -333,25 +333,25 @@ void MainWindow::neko_stop(bool crash, bool sem) {
auto neko_stop_stage2 = [=] { auto neko_stop_stage2 = [=] {
runOnUiThread( runOnUiThread(
[=] { [=] {
while (!NekoRay::sys::running_ext.empty()) { while (!NekoGui_sys::running_ext.empty()) {
auto extC = NekoRay::sys::running_ext.front(); auto extC = NekoGui_sys::running_ext.front();
extC->Kill(); extC->Kill();
NekoRay::sys::running_ext.pop_front(); NekoGui_sys::running_ext.pop_front();
} }
}, },
DS_cores); DS_cores);
#ifndef NKR_NO_GRPC #ifndef NKR_NO_GRPC
NekoRay::traffic::trafficLooper->loop_enabled = false; NekoGui_traffic::trafficLooper->loop_enabled = false;
NekoRay::traffic::trafficLooper->loop_mutex.lock(); NekoGui_traffic::trafficLooper->loop_mutex.lock();
if (NekoRay::dataStore->traffic_loop_interval != 0) { if (NekoGui::dataStore->traffic_loop_interval != 0) {
NekoRay::traffic::trafficLooper->UpdateAll(); NekoGui_traffic::trafficLooper->UpdateAll();
for (const auto &item: NekoRay::traffic::trafficLooper->items) { for (const auto &item: NekoGui_traffic::trafficLooper->items) {
NekoRay::profileManager->GetProfile(item->id)->Save(); NekoGui::profileManager->GetProfile(item->id)->Save();
runOnUiThread([=] { refresh_proxy_list(item->id); }); runOnUiThread([=] { refresh_proxy_list(item->id); });
} }
} }
NekoRay::traffic::trafficLooper->loop_mutex.unlock(); NekoGui_traffic::trafficLooper->loop_mutex.unlock();
if (!crash) { if (!crash) {
bool rpcOK; bool rpcOK;
@@ -365,8 +365,8 @@ void MainWindow::neko_stop(bool crash, bool sem) {
} }
#endif #endif
NekoRay::dataStore->UpdateStartedId(-1919); NekoGui::dataStore->UpdateStartedId(-1919);
NekoRay::dataStore->need_keep_vpn_off = false; NekoGui::dataStore->need_keep_vpn_off = false;
running = nullptr; running = nullptr;
runOnUiThread([=] { runOnUiThread([=] {
@@ -411,8 +411,8 @@ void MainWindow::CheckUpdate() {
bool ok; bool ok;
libcore::UpdateReq request; libcore::UpdateReq request;
request.set_action(libcore::UpdateAction::Check); request.set_action(libcore::UpdateAction::Check);
request.set_check_pre_release(NekoRay::dataStore->check_include_pre); request.set_check_pre_release(NekoGui::dataStore->check_include_pre);
auto response = NekoRay::rpc::defaultClient->Update(&ok, request); auto response = NekoGui_rpc::defaultClient->Update(&ok, request);
if (!ok) return; if (!ok) return;
auto err = response.error(); auto err = response.error();
@@ -431,7 +431,7 @@ void MainWindow::CheckUpdate() {
} }
runOnUiThread([=] { 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)" : ""; auto note_pre_release = response.is_pre_release() ? " (Pre-release)" : "";
QMessageBox box(QMessageBox::Question, QObject::tr("Update") + note_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())); 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; bool ok2;
libcore::UpdateReq request2; libcore::UpdateReq request2;
request2.set_action(libcore::UpdateAction::Download); request2.set_action(libcore::UpdateAction::Download);
auto response2 = NekoRay::rpc::defaultClient->Update(&ok2, request2); auto response2 = NekoGui_rpc::defaultClient->Update(&ok2, request2);
runOnUiThread([=] { runOnUiThread([=] {
if (response2.error().empty()) { if (response2.error().empty()) {
auto q = QMessageBox::question(nullptr, QObject::tr("Update"), auto q = QMessageBox::question(nullptr, QObject::tr("Update"),

View File

@@ -41,7 +41,7 @@ QString ParseSubInfo(const QString &info) {
return result; return result;
} }
GroupItem::GroupItem(QWidget *parent, const QSharedPointer<NekoRay::Group> &ent, QListWidgetItem *item) : QWidget(parent), ui(new Ui::GroupItem) { GroupItem::GroupItem(QWidget *parent, const std::shared_ptr<NekoGui::Group> &ent, QListWidgetItem *item) : QWidget(parent), ui(new Ui::GroupItem) {
ui->setupUi(this); ui->setupUi(this);
this->setLayoutDirection(Qt::LeftToRight); this->setLayoutDirection(Qt::LeftToRight);
@@ -50,7 +50,7 @@ GroupItem::GroupItem(QWidget *parent, const QSharedPointer<NekoRay::Group> &ent,
if (ent == nullptr) return; if (ent == nullptr) return;
connect(this, &GroupItem::edit_clicked, this, &GroupItem::on_edit_clicked); 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(); refresh_data();
} }
@@ -74,8 +74,8 @@ void GroupItem::refresh_data() {
} else { } else {
ui->url->setText(ent->url); ui->url->setText(ent->url);
QStringList info; QStringList info;
if (ent->last_update != 0) { if (ent->sub_last_update != 0) {
info << tr("Last update: %1").arg(DisplayTime(ent->last_update, QLocale::ShortFormat)); info << tr("Last update: %1").arg(DisplayTime(ent->sub_last_update, QLocale::ShortFormat));
} }
auto subinfo = ParseSubInfo(ent->info); auto subinfo = ParseSubInfo(ent->info);
if (!ent->info.isEmpty()) { if (!ent->info.isEmpty()) {
@@ -98,7 +98,7 @@ void GroupItem::refresh_data() {
} }
void GroupItem::on_update_sub_clicked() { 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() { void GroupItem::on_edit_clicked() {
@@ -114,10 +114,10 @@ void GroupItem::on_edit_clicked() {
} }
void GroupItem::on_remove_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)) == if (QMessageBox::question(this, tr("Confirmation"), tr("Remove %1?").arg(ent->name)) ==
QMessageBox::StandardButton::Yes) { QMessageBox::StandardButton::Yes) {
NekoRay::profileManager->DeleteGroup(ent->id); NekoGui::profileManager->DeleteGroup(ent->id);
MW_dialog_message(Dialog_DialogManageGroups, "refresh-1"); MW_dialog_message(Dialog_DialogManageGroups, "refresh-1");
delete item; delete item;
} }

View File

@@ -15,13 +15,13 @@ class GroupItem : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit GroupItem(QWidget *parent, const QSharedPointer<NekoRay::Group> &ent, QListWidgetItem *item); explicit GroupItem(QWidget *parent, const std::shared_ptr<NekoGui::Group> &ent, QListWidgetItem *item);
~GroupItem() override; ~GroupItem() override;
void refresh_data(); void refresh_data();
QSharedPointer<NekoRay::Group> ent; std::shared_ptr<NekoGui::Group> ent;
QListWidgetItem *item; QListWidgetItem *item;
private: private:

View File

@@ -3,7 +3,7 @@
#include <QMessageBox> #include <QMessageBox>
ProxyItem::ProxyItem(QWidget *parent, const QSharedPointer<NekoRay::ProxyEntity> &ent, QListWidgetItem *item) ProxyItem::ProxyItem(QWidget *parent, const std::shared_ptr<NekoGui::ProxyEntity> &ent, QListWidgetItem *item)
: QWidget(parent), ui(new Ui::ProxyItem) { : QWidget(parent), ui(new Ui::ProxyItem) {
ui->setupUi(this); ui->setupUi(this);
this->setLayoutDirection(Qt::LeftToRight); this->setLayoutDirection(Qt::LeftToRight);

View File

@@ -17,7 +17,7 @@ class ProxyItem : public QWidget {
Q_OBJECT Q_OBJECT
public: public:
explicit ProxyItem(QWidget *parent, const QSharedPointer<NekoRay::ProxyEntity> &ent, QListWidgetItem *item); explicit ProxyItem(QWidget *parent, const std::shared_ptr<NekoGui::ProxyEntity> &ent, QListWidgetItem *item);
~ProxyItem() override; ~ProxyItem() override;
@@ -25,7 +25,7 @@ public:
QPushButton *get_change_button(); QPushButton *get_change_button();
QSharedPointer<NekoRay::ProxyEntity> ent; std::shared_ptr<NekoGui::ProxyEntity> ent;
QListWidgetItem *item; QListWidgetItem *item;
bool remove_confirm = false; bool remove_confirm = false;