mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 12:34:37 +03:00
minor refactor
This commit is contained in:
2
3rdparty/WinCommander.cpp
vendored
2
3rdparty/WinCommander.cpp
vendored
@@ -60,7 +60,7 @@ uint WinCommander::runProcessElevated(const QString &path,
|
||||
|
||||
LPCTSTR pszParameters = (LPCTSTR)params.utf16();
|
||||
QString dir;
|
||||
if (workingDir.isEmpty())
|
||||
if (workingDir.count() == 0)
|
||||
dir = QDir::toNativeSeparators(QDir::currentPath());
|
||||
else
|
||||
dir = QDir::toNativeSeparators(workingDir);
|
||||
|
||||
4
3rdparty/base64.cpp
vendored
4
3rdparty/base64.cpp
vendored
@@ -1,5 +1,9 @@
|
||||
#include "base64.h"
|
||||
|
||||
#ifndef qsizetype
|
||||
#define qsizetype size_t
|
||||
#endif
|
||||
|
||||
namespace Qt515Base64 {
|
||||
namespace {
|
||||
struct fromBase64_helper_result {
|
||||
|
||||
11
3rdparty/fix_old_qt.h
vendored
Normal file
11
3rdparty/fix_old_qt.h
vendored
Normal 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
|
||||
@@ -16,9 +16,10 @@
|
||||
#include <QStandardPaths>
|
||||
#include <QProcess>
|
||||
|
||||
#include "3rdparty/fix_old_qt.h"
|
||||
#include "3rdparty/qv2ray/wrapper.hpp"
|
||||
#include "fmt/Preset.hpp"
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
#define QV_MODULE_NAME "SystemProxy"
|
||||
|
||||
@@ -253,7 +254,7 @@ namespace Qv2ray::components::proxy {
|
||||
#endif
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
QString str = NekoRay::dataStore->system_proxy_format;
|
||||
QString str = NekoGui::dataStore->system_proxy_format;
|
||||
if (str.isEmpty()) str = Preset::Windows::system_proxy_format[0];
|
||||
str = str.replace("{ip}", address)
|
||||
.replace("{http_port}", Int2String(httpPort))
|
||||
|
||||
2
3rdparty/qv2ray/v2/ui/LogHighlighter.cpp
vendored
2
3rdparty/qv2ray/v2/ui/LogHighlighter.cpp
vendored
@@ -118,7 +118,7 @@ namespace Qv2ray::ui {
|
||||
}
|
||||
|
||||
void SyntaxHighlighter::highlightBlock(const QString &text) {
|
||||
for (const HighlightingRule &rule: qAsConst(highlightingRules)) {
|
||||
for (const HighlightingRule &rule: highlightingRules) {
|
||||
QRegularExpressionMatchIterator matchIterator = rule.pattern.globalMatch(text);
|
||||
|
||||
while (matchIterator.hasNext()) {
|
||||
|
||||
6
3rdparty/qv2ray/v2/ui/LogHighlighter.hpp
vendored
6
3rdparty/qv2ray/v2/ui/LogHighlighter.hpp
vendored
@@ -55,7 +55,8 @@
|
||||
#include <QTextCharFormat>
|
||||
#include <QTextDocument>
|
||||
|
||||
namespace Qv2ray::ui {
|
||||
namespace Qv2ray {
|
||||
namespace ui {
|
||||
class SyntaxHighlighter : public QSyntaxHighlighter {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -85,6 +86,7 @@ namespace Qv2ray::ui {
|
||||
QTextCharFormat ipHostFormat;
|
||||
QTextCharFormat v2rayComponentFormat;
|
||||
};
|
||||
} // namespace Qv2ray::ui
|
||||
} // namespace ui
|
||||
} // namespace Qv2ray
|
||||
|
||||
using namespace Qv2ray::ui;
|
||||
|
||||
@@ -70,7 +70,7 @@ namespace Qv2ray::ui::widgets {
|
||||
c->setWidget(this);
|
||||
c->setCompletionMode(QCompleter::PopupCompletion);
|
||||
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() {
|
||||
|
||||
@@ -55,7 +55,9 @@ QT_BEGIN_NAMESPACE
|
||||
class QCompleter;
|
||||
QT_END_NAMESPACE
|
||||
|
||||
namespace Qv2ray::ui::widgets {
|
||||
namespace Qv2ray {
|
||||
namespace ui {
|
||||
namespace widgets {
|
||||
class AutoCompleteTextEdit : public QPlainTextEdit {
|
||||
Q_OBJECT
|
||||
|
||||
@@ -77,5 +79,7 @@ namespace Qv2ray::ui::widgets {
|
||||
QString prefix;
|
||||
QCompleter *c = nullptr;
|
||||
};
|
||||
} // namespace Qv2ray::ui::widgets
|
||||
} // namespace widgets
|
||||
} // namespace ui
|
||||
} // namespace Qv2ray
|
||||
using namespace Qv2ray::ui::widgets;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "w_JsonEditor.hpp"
|
||||
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
JsonEditor::JsonEditor(const QJsonObject& rootObject, QWidget* parent) : QDialog(parent) {
|
||||
setupUi(this);
|
||||
|
||||
6
3rdparty/qv2ray/wrapper.hpp
vendored
6
3rdparty/qv2ray/wrapper.hpp
vendored
@@ -7,10 +7,12 @@
|
||||
|
||||
#define LOG(...) Qv2ray::base::log_internal(__VA_ARGS__)
|
||||
#define DEBUG(...) Qv2ray::base::log_internal(__VA_ARGS__)
|
||||
namespace Qv2ray::base {
|
||||
namespace Qv2ray {
|
||||
namespace base {
|
||||
template<typename... T>
|
||||
inline void log_internal(T... v) {}
|
||||
} // namespace Qv2ray::base
|
||||
} // namespace base
|
||||
} // namespace Qv2ray
|
||||
|
||||
#define JsonToString(a) QJsonObject2QString(a, false)
|
||||
#define JsonFromString(a) QString2QJsonObject(a)
|
||||
|
||||
@@ -138,8 +138,8 @@ set(PROJECT_SOURCES
|
||||
${PLATFORM_SOURCES}
|
||||
|
||||
main/main.cpp
|
||||
main/NekoRay.cpp
|
||||
main/NekoRay_Utils.cpp
|
||||
main/NekoGui.cpp
|
||||
main/NekoGui_Utils.cpp
|
||||
main/QJS.cpp
|
||||
main/HTTPRequestHelper.cpp
|
||||
|
||||
@@ -161,7 +161,7 @@ set(PROJECT_SOURCES
|
||||
rpc/gRPC.cpp
|
||||
|
||||
db/Database.cpp
|
||||
db/TrafficLooper.cpp
|
||||
db/traffic/TrafficLooper.cpp
|
||||
db/ProfileFilter.cpp
|
||||
db/ConfigBuilder.cpp
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
#include <QFile>
|
||||
#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_EXPORT NekoRay::dataStore->core_box_underlying_dns.isEmpty() ? (status->forExport ? "local" : "underlying://0.0.0.0") : NekoRay::dataStore->core_box_underlying_dns
|
||||
#define BOX_UNDERLYING_DNS dataStore->core_box_underlying_dns.isEmpty() ? "underlying://0.0.0.0" : dataStore->core_box_underlying_dns
|
||||
#define BOX_UNDERLYING_DNS_EXPORT dataStore->core_box_underlying_dns.isEmpty() ? (status->forExport ? "local" : "underlying://0.0.0.0") : dataStore->core_box_underlying_dns
|
||||
|
||||
namespace NekoRay {
|
||||
namespace NekoGui {
|
||||
|
||||
QStringList getAutoBypassExternalProcessPaths(const QSharedPointer<BuildConfigResult> &result) {
|
||||
QStringList getAutoBypassExternalProcessPaths(const std::shared_ptr<BuildConfigResult> &result) {
|
||||
QStringList paths;
|
||||
for (const auto &extR: result->extRs) {
|
||||
auto path = extR->program;
|
||||
@@ -54,15 +54,15 @@ namespace NekoRay {
|
||||
|
||||
// Common
|
||||
|
||||
QSharedPointer<BuildConfigResult> BuildConfig(const QSharedPointer<ProxyEntity> &ent, bool forTest, bool forExport) {
|
||||
auto result = QSharedPointer<BuildConfigResult>(new BuildConfigResult);
|
||||
auto status = QSharedPointer<BuildConfigStatus>(new BuildConfigStatus);
|
||||
std::shared_ptr<BuildConfigResult> BuildConfig(const std::shared_ptr<ProxyEntity> &ent, bool forTest, bool forExport) {
|
||||
auto result = std::make_shared<BuildConfigResult>();
|
||||
auto status = std::make_shared<BuildConfigStatus>();
|
||||
status->ent = ent;
|
||||
status->result = result;
|
||||
status->forTest = forTest;
|
||||
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") {
|
||||
result->coreConfig = QString2QJsonObject(customBean->config_simple);
|
||||
} else {
|
||||
@@ -92,9 +92,9 @@ namespace NekoRay {
|
||||
return result;
|
||||
}
|
||||
|
||||
QString BuildChain(int chainId, const QSharedPointer<BuildConfigStatus> &status) {
|
||||
QString BuildChain(int chainId, const std::shared_ptr<BuildConfigStatus> &status) {
|
||||
// Make list
|
||||
QList<QSharedPointer<ProxyEntity>> ents;
|
||||
QList<std::shared_ptr<ProxyEntity>> ents;
|
||||
auto ent = status->ent;
|
||||
auto result = status->result;
|
||||
|
||||
@@ -155,7 +155,7 @@ namespace NekoRay {
|
||||
|
||||
// V2Ray
|
||||
|
||||
void BuildConfigV2Ray(const QSharedPointer<BuildConfigStatus> &status) {
|
||||
void BuildConfigV2Ray(const std::shared_ptr<BuildConfigStatus> &status) {
|
||||
// Log
|
||||
auto logObj = QJsonObject{{"loglevel", dataStore->log_level}};
|
||||
status->result->coreConfig.insert("log", logObj);
|
||||
@@ -397,8 +397,8 @@ namespace NekoRay {
|
||||
status->result->coreConfig.insert("stats", QJsonObject());
|
||||
}
|
||||
|
||||
QString BuildChainInternal(int chainId, const QList<QSharedPointer<ProxyEntity>> &ents,
|
||||
const QSharedPointer<BuildConfigStatus> &status) {
|
||||
QString BuildChainInternal(int chainId, const QList<std::shared_ptr<ProxyEntity>> &ents,
|
||||
const std::shared_ptr<BuildConfigStatus> &status) {
|
||||
QString chainTag = "c-" + Int2String(chainId);
|
||||
QString chainTagOut;
|
||||
bool muxApplied = false;
|
||||
@@ -550,7 +550,7 @@ namespace NekoRay {
|
||||
// Outbound
|
||||
|
||||
QJsonObject outbound;
|
||||
auto stream = GetStreamSettings(ent->bean.data());
|
||||
auto stream = GetStreamSettings(ent->bean.get());
|
||||
|
||||
if (thisExternalStat > 0) {
|
||||
auto extR = ent->bean->BuildExternal(ext_mapping_port, ext_socks_port, thisExternalStat);
|
||||
@@ -563,7 +563,7 @@ namespace NekoRay {
|
||||
return {};
|
||||
}
|
||||
extR.tag = ent->bean->DisplayType();
|
||||
status->result->extRs.emplace_back(std::make_shared<fmt::ExternalBuildResult>(extR));
|
||||
status->result->extRs.emplace_back(std::make_shared<NekoGui_fmt::ExternalBuildResult>(extR));
|
||||
|
||||
// SOCKS OUTBOUND
|
||||
if (IS_NEKO_BOX) {
|
||||
@@ -664,7 +664,7 @@ namespace NekoRay {
|
||||
// Bypass Lookup for the first profile
|
||||
auto serverAddress = ent->bean->serverAddress;
|
||||
|
||||
auto customBean = dynamic_cast<fmt::CustomBean *>(ent->bean.get());
|
||||
auto customBean = dynamic_cast<NekoGui_fmt::CustomBean *>(ent->bean.get());
|
||||
if (customBean != nullptr && customBean->core == "internal") {
|
||||
auto server = QString2QJsonObject(customBean->config_simple)["server"].toString();
|
||||
if (!server.isEmpty()) serverAddress = server;
|
||||
@@ -685,7 +685,7 @@ namespace NekoRay {
|
||||
|
||||
// SingBox
|
||||
|
||||
void BuildConfigSingBox(const QSharedPointer<BuildConfigStatus> &status) {
|
||||
void BuildConfigSingBox(const std::shared_ptr<BuildConfigStatus> &status) {
|
||||
// Log
|
||||
status->result->coreConfig["log"] = QJsonObject{{"level", dataStore->log_level}};
|
||||
|
||||
@@ -921,7 +921,7 @@ namespace NekoRay {
|
||||
|
||||
// tun user rule
|
||||
if (IS_NEKO_BOX_INTERNAL_TUN && dataStore->spmode_vpn) {
|
||||
auto match_out = NekoRay::dataStore->vpn_rule_white ? "proxy" : "bypass";
|
||||
auto match_out = dataStore->vpn_rule_white ? "proxy" : "bypass";
|
||||
|
||||
QString process_name_rule = dataStore->vpn_rule_process.trimmed();
|
||||
if (!process_name_rule.isEmpty()) {
|
||||
@@ -984,10 +984,10 @@ namespace NekoRay {
|
||||
// experimental
|
||||
QJsonObject experimentalObj;
|
||||
|
||||
if (!status->forTest && NekoRay::dataStore->core_box_clash_api > 0) {
|
||||
if (!status->forTest && dataStore->core_box_clash_api > 0) {
|
||||
QJsonObject clash_api = {
|
||||
{"external_controller", "127.0.0.1:" + Int2String(NekoRay::dataStore->core_box_clash_api)},
|
||||
{"secret", NekoRay::dataStore->core_box_clash_api_secret},
|
||||
{"external_controller", "127.0.0.1:" + Int2String(dataStore->core_box_clash_api)},
|
||||
{"secret", dataStore->core_box_clash_api_secret},
|
||||
{"external_ui", "dashboard"},
|
||||
};
|
||||
experimentalObj["clash_api"] = clash_api;
|
||||
@@ -998,8 +998,8 @@ namespace NekoRay {
|
||||
|
||||
QString WriteVPNSingBoxConfig() {
|
||||
// tun user rule
|
||||
auto match_out = NekoRay::dataStore->vpn_rule_white ? "nekoray-socks" : "direct";
|
||||
auto no_match_out = NekoRay::dataStore->vpn_rule_white ? "direct" : "nekoray-socks";
|
||||
auto match_out = dataStore->vpn_rule_white ? "nekoray-socks" : "direct";
|
||||
auto no_match_out = dataStore->vpn_rule_white ? "direct" : "nekoray-socks";
|
||||
|
||||
QString process_name_rule = dataStore->vpn_rule_process.trimmed();
|
||||
if (!process_name_rule.isEmpty()) {
|
||||
@@ -1090,4 +1090,4 @@ namespace NekoRay {
|
||||
return QFileInfo(file2).absoluteFilePath();
|
||||
}
|
||||
|
||||
} // namespace NekoRay
|
||||
} // namespace NekoGui
|
||||
@@ -3,23 +3,23 @@
|
||||
#include "ProxyEntity.hpp"
|
||||
#include "sys/ExternalProcess.hpp"
|
||||
|
||||
namespace NekoRay {
|
||||
namespace NekoGui {
|
||||
class BuildConfigResult {
|
||||
public:
|
||||
QString error;
|
||||
QJsonObject coreConfig;
|
||||
|
||||
QList<QSharedPointer<traffic::TrafficData>> outboundStats; // all, but not including "bypass" "block"
|
||||
QSharedPointer<traffic::TrafficData> outboundStat; // main
|
||||
QList<std::shared_ptr<NekoGui_traffic::TrafficData>> outboundStats; // all, but not including "bypass" "block"
|
||||
std::shared_ptr<NekoGui_traffic::TrafficData> outboundStat; // main
|
||||
QStringList ignoreConnTag;
|
||||
|
||||
std::list<std::shared_ptr<NekoRay::fmt::ExternalBuildResult>> extRs;
|
||||
std::list<std::shared_ptr<NekoGui_fmt::ExternalBuildResult>> extRs;
|
||||
};
|
||||
|
||||
class BuildConfigStatus {
|
||||
public:
|
||||
QSharedPointer<BuildConfigResult> result;
|
||||
QSharedPointer<ProxyEntity> ent;
|
||||
std::shared_ptr<BuildConfigResult> result;
|
||||
std::shared_ptr<ProxyEntity> ent;
|
||||
bool forTest;
|
||||
bool forExport;
|
||||
|
||||
@@ -44,18 +44,18 @@ namespace NekoRay {
|
||||
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,
|
||||
const QSharedPointer<BuildConfigStatus> &status);
|
||||
QString BuildChainInternal(int chainId, const QList<std::shared_ptr<ProxyEntity>> &ents,
|
||||
const std::shared_ptr<BuildConfigStatus> &status);
|
||||
|
||||
QString WriteVPNSingBoxConfig();
|
||||
|
||||
QString WriteVPNLinuxScript(const QString &protectPath, const QString &configPath);
|
||||
} // namespace NekoRay
|
||||
} // namespace NekoGui
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
#include <QFile>
|
||||
#include <QColor>
|
||||
|
||||
namespace NekoRay {
|
||||
namespace NekoGui {
|
||||
|
||||
ProfileManager *profileManager = new ProfileManager();
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace NekoRay {
|
||||
void ProfileManager::SaveManager() {
|
||||
}
|
||||
|
||||
QSharedPointer<ProxyEntity> ProfileManager::LoadProxyEntity(const QString &jsonPath) {
|
||||
std::shared_ptr<ProxyEntity> ProfileManager::LoadProxyEntity(const QString &jsonPath) {
|
||||
// Load type
|
||||
ProxyEntity ent0(nullptr, nullptr);
|
||||
ent0.fn = jsonPath;
|
||||
@@ -48,7 +48,7 @@ namespace NekoRay {
|
||||
auto type = ent0.type;
|
||||
|
||||
// Load content
|
||||
QSharedPointer<ProxyEntity> ent;
|
||||
std::shared_ptr<ProxyEntity> ent;
|
||||
bool validType = validJson;
|
||||
|
||||
if (validType) {
|
||||
@@ -66,45 +66,45 @@ namespace NekoRay {
|
||||
|
||||
// 新建的不给 fn 和 id
|
||||
|
||||
QSharedPointer<ProxyEntity> ProfileManager::NewProxyEntity(const QString &type) {
|
||||
fmt::AbstractBean *bean;
|
||||
std::shared_ptr<ProxyEntity> ProfileManager::NewProxyEntity(const QString &type) {
|
||||
NekoGui_fmt::AbstractBean *bean;
|
||||
|
||||
if (type == "socks") {
|
||||
bean = new fmt::SocksHttpBean(NekoRay::fmt::SocksHttpBean::type_Socks5);
|
||||
bean = new NekoGui_fmt::SocksHttpBean(NekoGui_fmt::SocksHttpBean::type_Socks5);
|
||||
} else if (type == "http") {
|
||||
bean = new fmt::SocksHttpBean(NekoRay::fmt::SocksHttpBean::type_HTTP);
|
||||
bean = new NekoGui_fmt::SocksHttpBean(NekoGui_fmt::SocksHttpBean::type_HTTP);
|
||||
} else if (type == "shadowsocks") {
|
||||
bean = new fmt::ShadowSocksBean();
|
||||
bean = new NekoGui_fmt::ShadowSocksBean();
|
||||
} else if (type == "chain") {
|
||||
bean = new fmt::ChainBean();
|
||||
bean = new NekoGui_fmt::ChainBean();
|
||||
} else if (type == "vmess") {
|
||||
bean = new fmt::VMessBean();
|
||||
bean = new NekoGui_fmt::VMessBean();
|
||||
} else if (type == "trojan") {
|
||||
bean = new fmt::TrojanVLESSBean(fmt::TrojanVLESSBean::proxy_Trojan);
|
||||
bean = new NekoGui_fmt::TrojanVLESSBean(NekoGui_fmt::TrojanVLESSBean::proxy_Trojan);
|
||||
} else if (type == "vless") {
|
||||
bean = new fmt::TrojanVLESSBean(fmt::TrojanVLESSBean::proxy_VLESS);
|
||||
bean = new NekoGui_fmt::TrojanVLESSBean(NekoGui_fmt::TrojanVLESSBean::proxy_VLESS);
|
||||
} else if (type == "naive") {
|
||||
bean = new fmt::NaiveBean();
|
||||
bean = new NekoGui_fmt::NaiveBean();
|
||||
} else if (type == "hysteria") {
|
||||
bean = new fmt::HysteriaBean();
|
||||
bean = new NekoGui_fmt::HysteriaBean();
|
||||
} else if (type == "custom") {
|
||||
bean = new fmt::CustomBean();
|
||||
bean = new NekoGui_fmt::CustomBean();
|
||||
} else {
|
||||
bean = new fmt::AbstractBean(-114514);
|
||||
bean = new NekoGui_fmt::AbstractBean(-114514);
|
||||
}
|
||||
|
||||
auto ent = QSharedPointer<ProxyEntity>(new ProxyEntity(bean, type));
|
||||
auto ent = std::make_shared<ProxyEntity>(bean, type);
|
||||
return ent;
|
||||
}
|
||||
|
||||
QSharedPointer<Group> ProfileManager::NewGroup() {
|
||||
auto ent = QSharedPointer<Group>(new Group());
|
||||
std::shared_ptr<Group> ProfileManager::NewGroup() {
|
||||
auto ent = std::make_shared<Group>();
|
||||
return ent;
|
||||
}
|
||||
|
||||
// ProxyEntity
|
||||
|
||||
ProxyEntity::ProxyEntity(fmt::AbstractBean *bean, const QString &type_) {
|
||||
ProxyEntity::ProxyEntity(NekoGui_fmt::AbstractBean *bean, const QString &type_) {
|
||||
if (type_ != nullptr) this->type = type_;
|
||||
|
||||
_add(new configItem("type", &type, itemType::string));
|
||||
@@ -115,7 +115,7 @@ namespace NekoRay {
|
||||
|
||||
// 可以不关联 bean,只加载 ProxyEntity 的信息
|
||||
if (bean != nullptr) {
|
||||
this->bean = QSharedPointer<fmt::AbstractBean>(bean);
|
||||
this->bean = std::shared_ptr<NekoGui_fmt::AbstractBean>(bean);
|
||||
// 有虚函数就要在这里 dynamic_cast
|
||||
_add(new configItem("bean", dynamic_cast<JsonStore *>(bean), 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) {
|
||||
return false;
|
||||
}
|
||||
@@ -183,7 +183,7 @@ namespace NekoRay {
|
||||
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;
|
||||
auto oldGroup = GetGroup(ent->gid);
|
||||
if (oldGroup != nullptr && !oldGroup->order.isEmpty()) {
|
||||
@@ -199,7 +199,7 @@ namespace NekoRay {
|
||||
ent->Save();
|
||||
}
|
||||
|
||||
QSharedPointer<ProxyEntity> ProfileManager::GetProfile(int id) {
|
||||
std::shared_ptr<ProxyEntity> ProfileManager::GetProfile(int id) {
|
||||
return profiles.value(id, nullptr);
|
||||
}
|
||||
|
||||
@@ -212,13 +212,13 @@ namespace NekoRay {
|
||||
_add(new configItem("order", &order, itemType::integerList));
|
||||
_add(new configItem("url", &url, itemType::string));
|
||||
_add(new configItem("info", &info, itemType::string));
|
||||
_add(new configItem("lastup", &last_update, itemType::integer64));
|
||||
_add(new configItem("lastup", &sub_last_update, itemType::integer64));
|
||||
_add(new configItem("manually_column_width", &manually_column_width, itemType::boolean));
|
||||
_add(new configItem("column_width", &column_width, itemType::integerList));
|
||||
}
|
||||
|
||||
QSharedPointer<Group> ProfileManager::LoadGroup(const QString &jsonPath) {
|
||||
QSharedPointer<Group> ent = QSharedPointer<Group>(new Group());
|
||||
std::shared_ptr<Group> ProfileManager::LoadGroup(const QString &jsonPath) {
|
||||
auto ent = std::make_shared<Group>();
|
||||
ent->fn = jsonPath;
|
||||
ent->Load();
|
||||
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) {
|
||||
return false;
|
||||
}
|
||||
@@ -262,27 +262,27 @@ namespace NekoRay {
|
||||
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);
|
||||
}
|
||||
|
||||
QSharedPointer<Group> ProfileManager::CurrentGroup() {
|
||||
return GetGroup(NekoRay::dataStore->current_group);
|
||||
std::shared_ptr<Group> ProfileManager::CurrentGroup() {
|
||||
return GetGroup(dataStore->current_group);
|
||||
}
|
||||
|
||||
QList<QSharedPointer<ProxyEntity>> Group::Profiles() const {
|
||||
QList<QSharedPointer<ProxyEntity>> ret;
|
||||
QList<std::shared_ptr<ProxyEntity>> Group::Profiles() const {
|
||||
QList<std::shared_ptr<ProxyEntity>> ret;
|
||||
for (const auto &ent: profileManager->profiles) {
|
||||
if (id == ent->gid) ret += ent;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
QList<QSharedPointer<ProxyEntity>> Group::ProfilesWithOrder() const {
|
||||
QList<std::shared_ptr<ProxyEntity>> Group::ProfilesWithOrder() const {
|
||||
if (order.isEmpty()) {
|
||||
return Profiles();
|
||||
} else {
|
||||
QList<QSharedPointer<ProxyEntity>> ret;
|
||||
QList<std::shared_ptr<ProxyEntity>> ret;
|
||||
for (auto _id: order) {
|
||||
auto ent = profileManager->GetProfile(_id);
|
||||
if (ent != nullptr) ret += ent;
|
||||
@@ -291,4 +291,4 @@ namespace NekoRay {
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace NekoRay
|
||||
} // namespace NekoGui
|
||||
@@ -1,15 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
#include "ProxyEntity.hpp"
|
||||
#include "Group.hpp"
|
||||
|
||||
namespace NekoRay {
|
||||
namespace NekoGui {
|
||||
class ProfileManager : public JsonStore {
|
||||
public:
|
||||
// Manager
|
||||
QMap<int, QSharedPointer<ProxyEntity>> profiles;
|
||||
QMap<int, QSharedPointer<Group>> groups;
|
||||
QMap<int, std::shared_ptr<ProxyEntity>> profiles;
|
||||
QMap<int, std::shared_ptr<Group>> groups;
|
||||
|
||||
// JSON
|
||||
QList<int> _profiles;
|
||||
@@ -17,25 +17,25 @@ namespace NekoRay {
|
||||
|
||||
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 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);
|
||||
|
||||
QSharedPointer<Group> GetGroup(int id);
|
||||
std::shared_ptr<Group> GetGroup(int id);
|
||||
|
||||
QSharedPointer<Group> CurrentGroup();
|
||||
std::shared_ptr<Group> CurrentGroup();
|
||||
|
||||
private:
|
||||
void LoadManager();
|
||||
@@ -46,10 +46,10 @@ namespace NekoRay {
|
||||
|
||||
[[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;
|
||||
} // namespace NekoRay
|
||||
} // namespace NekoGui
|
||||
|
||||
12
db/Group.hpp
12
db/Group.hpp
@@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
#include "ProxyEntity.hpp"
|
||||
|
||||
namespace NekoRay {
|
||||
namespace NekoGui {
|
||||
class Group : public JsonStore {
|
||||
public:
|
||||
int id = -1;
|
||||
@@ -11,7 +11,7 @@ namespace NekoRay {
|
||||
QString name = "";
|
||||
QString url = "";
|
||||
QString info = "";
|
||||
qint64 last_update = 0;
|
||||
qint64 sub_last_update = 0;
|
||||
|
||||
// list ui
|
||||
bool manually_column_width = false;
|
||||
@@ -21,9 +21,9 @@ namespace NekoRay {
|
||||
Group();
|
||||
|
||||
// 按 id 顺序
|
||||
[[nodiscard]] QList<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
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
#include "ProfileFilter.hpp"
|
||||
|
||||
namespace NekoRay {
|
||||
void ProfileFilter::Uniq(const QList<QSharedPointer<ProxyEntity>> &in,
|
||||
QList<QSharedPointer<ProxyEntity>> &out,
|
||||
namespace NekoGui {
|
||||
void ProfileFilter::Uniq(const QList<std::shared_ptr<ProxyEntity>> &in,
|
||||
QList<std::shared_ptr<ProxyEntity>> &out,
|
||||
bool by_address, bool keep_last) {
|
||||
QMap<QString, QSharedPointer<ProxyEntity>> hashMap;
|
||||
QMap<QString, std::shared_ptr<ProxyEntity>> hashMap;
|
||||
|
||||
for (const auto &ent: in) {
|
||||
QString key = by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType())
|
||||
@@ -22,11 +22,11 @@ namespace NekoRay {
|
||||
}
|
||||
}
|
||||
|
||||
void ProfileFilter::Common(const QList<QSharedPointer<ProxyEntity>> &src,
|
||||
const QList<QSharedPointer<ProxyEntity>> &dst,
|
||||
QList<QSharedPointer<ProxyEntity>> &out,
|
||||
void ProfileFilter::Common(const QList<std::shared_ptr<ProxyEntity>> &src,
|
||||
const QList<std::shared_ptr<ProxyEntity>> &dst,
|
||||
QList<std::shared_ptr<ProxyEntity>> &out,
|
||||
bool by_address, bool keep_last) {
|
||||
QMap<QString, QSharedPointer<ProxyEntity>> hashMap;
|
||||
QMap<QString, std::shared_ptr<ProxyEntity>> hashMap;
|
||||
|
||||
for (const auto &ent: src) {
|
||||
QString key = by_address ? (ent->bean->DisplayAddress() + ent->bean->DisplayType())
|
||||
@@ -46,9 +46,9 @@ namespace NekoRay {
|
||||
}
|
||||
}
|
||||
|
||||
void ProfileFilter::OnlyInSrc(const QList<QSharedPointer<ProxyEntity>> &src,
|
||||
const QList<QSharedPointer<ProxyEntity>> &dst,
|
||||
QList<QSharedPointer<ProxyEntity>> &out,
|
||||
void ProfileFilter::OnlyInSrc(const QList<std::shared_ptr<ProxyEntity>> &src,
|
||||
const QList<std::shared_ptr<ProxyEntity>> &dst,
|
||||
QList<std::shared_ptr<ProxyEntity>> &out,
|
||||
bool by_address) {
|
||||
QMap<QString, bool> hashMap;
|
||||
|
||||
@@ -64,12 +64,12 @@ namespace NekoRay {
|
||||
}
|
||||
}
|
||||
|
||||
void ProfileFilter::OnlyInSrc_ByPointer(const QList<QSharedPointer<ProxyEntity>> &src,
|
||||
const QList<QSharedPointer<ProxyEntity>> &dst,
|
||||
QList<QSharedPointer<ProxyEntity>> &out) {
|
||||
void ProfileFilter::OnlyInSrc_ByPointer(const QList<std::shared_ptr<ProxyEntity>> &src,
|
||||
const QList<std::shared_ptr<ProxyEntity>> &dst,
|
||||
QList<std::shared_ptr<ProxyEntity>> &out) {
|
||||
for (const auto &ent: src) {
|
||||
if (!dst.contains(ent)) out += ent;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace NekoRay
|
||||
} // namespace NekoGui
|
||||
@@ -2,34 +2,34 @@
|
||||
|
||||
#include "ProxyEntity.hpp"
|
||||
|
||||
namespace NekoRay {
|
||||
namespace NekoGui {
|
||||
class ProfileFilter {
|
||||
public:
|
||||
static void Uniq(
|
||||
const QList<QSharedPointer<ProxyEntity>> &in,
|
||||
QList<QSharedPointer<ProxyEntity>> &out,
|
||||
const QList<std::shared_ptr<ProxyEntity>> &in,
|
||||
QList<std::shared_ptr<ProxyEntity>> &out,
|
||||
bool by_address = false, // def by bean
|
||||
bool keep_last = false // def keep first
|
||||
);
|
||||
|
||||
static void Common(
|
||||
const QList<QSharedPointer<ProxyEntity>> &src,
|
||||
const QList<QSharedPointer<ProxyEntity>> &dst,
|
||||
QList<QSharedPointer<ProxyEntity>> &out,
|
||||
const QList<std::shared_ptr<ProxyEntity>> &src,
|
||||
const QList<std::shared_ptr<ProxyEntity>> &dst,
|
||||
QList<std::shared_ptr<ProxyEntity>> &out,
|
||||
bool by_address = false, // def by bean
|
||||
bool keep_last = false // def keep first
|
||||
);
|
||||
|
||||
static void OnlyInSrc(
|
||||
const QList<QSharedPointer<ProxyEntity>> &src,
|
||||
const QList<QSharedPointer<ProxyEntity>> &dst,
|
||||
QList<QSharedPointer<NekoRay::ProxyEntity>> &out,
|
||||
const QList<std::shared_ptr<ProxyEntity>> &src,
|
||||
const QList<std::shared_ptr<ProxyEntity>> &dst,
|
||||
QList<std::shared_ptr<ProxyEntity>> &out,
|
||||
bool by_address = false // def by bean
|
||||
);
|
||||
|
||||
static void OnlyInSrc_ByPointer(
|
||||
const QList<QSharedPointer<ProxyEntity>> &src,
|
||||
const QList<QSharedPointer<ProxyEntity>> &dst,
|
||||
QList<QSharedPointer<ProxyEntity>> &out);
|
||||
const QList<std::shared_ptr<ProxyEntity>> &src,
|
||||
const QList<std::shared_ptr<ProxyEntity>> &dst,
|
||||
QList<std::shared_ptr<ProxyEntity>> &out);
|
||||
};
|
||||
} // namespace NekoRay
|
||||
} // namespace NekoGui
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "TrafficData.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
#include "db/traffic/TrafficData.hpp"
|
||||
#include "fmt/AbstractBean.hpp"
|
||||
|
||||
namespace NekoRay {
|
||||
namespace fmt {
|
||||
namespace NekoGui_fmt {
|
||||
class SocksHttpBean;
|
||||
|
||||
class ShadowSocksBean;
|
||||
@@ -21,8 +20,9 @@ namespace NekoRay {
|
||||
class CustomBean;
|
||||
|
||||
class ChainBean;
|
||||
}; // namespace fmt
|
||||
}; // namespace NekoGui_fmt
|
||||
|
||||
namespace NekoGui {
|
||||
class ProxyEntity : public JsonStore {
|
||||
public:
|
||||
QString type;
|
||||
@@ -30,47 +30,47 @@ namespace NekoRay {
|
||||
int id = -1;
|
||||
int gid = 0;
|
||||
int latency = 0;
|
||||
QSharedPointer<fmt::AbstractBean> bean;
|
||||
QSharedPointer<traffic::TrafficData> traffic_data = QSharedPointer<traffic::TrafficData>(new traffic::TrafficData(""));
|
||||
std::shared_ptr<NekoGui_fmt::AbstractBean> bean;
|
||||
std::shared_ptr<NekoGui_traffic::TrafficData> traffic_data = std::make_shared<NekoGui_traffic::TrafficData>("");
|
||||
|
||||
QString full_test_report;
|
||||
|
||||
ProxyEntity(fmt::AbstractBean *bean, const QString &type_);
|
||||
ProxyEntity(NekoGui_fmt::AbstractBean *bean, const QString &type_);
|
||||
|
||||
[[nodiscard]] QString DisplayLatency() const;
|
||||
|
||||
[[nodiscard]] QColor DisplayLatencyColor() const;
|
||||
|
||||
[[nodiscard]] fmt::ChainBean *ChainBean() const {
|
||||
return (fmt::ChainBean *) bean.get();
|
||||
[[nodiscard]] NekoGui_fmt::ChainBean *ChainBean() const {
|
||||
return (NekoGui_fmt::ChainBean *) bean.get();
|
||||
};
|
||||
|
||||
[[nodiscard]] fmt::SocksHttpBean *SocksHTTPBean() const {
|
||||
return (fmt::SocksHttpBean *) bean.get();
|
||||
[[nodiscard]] NekoGui_fmt::SocksHttpBean *SocksHTTPBean() const {
|
||||
return (NekoGui_fmt::SocksHttpBean *) bean.get();
|
||||
};
|
||||
|
||||
[[nodiscard]] fmt::ShadowSocksBean *ShadowSocksBean() const {
|
||||
return (fmt::ShadowSocksBean *) bean.get();
|
||||
[[nodiscard]] NekoGui_fmt::ShadowSocksBean *ShadowSocksBean() const {
|
||||
return (NekoGui_fmt::ShadowSocksBean *) bean.get();
|
||||
};
|
||||
|
||||
[[nodiscard]] fmt::VMessBean *VMessBean() const {
|
||||
return (fmt::VMessBean *) bean.get();
|
||||
[[nodiscard]] NekoGui_fmt::VMessBean *VMessBean() const {
|
||||
return (NekoGui_fmt::VMessBean *) bean.get();
|
||||
};
|
||||
|
||||
[[nodiscard]] fmt::TrojanVLESSBean *TrojanVLESSBean() const {
|
||||
return (fmt::TrojanVLESSBean *) bean.get();
|
||||
[[nodiscard]] NekoGui_fmt::TrojanVLESSBean *TrojanVLESSBean() const {
|
||||
return (NekoGui_fmt::TrojanVLESSBean *) bean.get();
|
||||
};
|
||||
|
||||
[[nodiscard]] fmt::NaiveBean *NaiveBean() const {
|
||||
return (fmt::NaiveBean *) bean.get();
|
||||
[[nodiscard]] NekoGui_fmt::NaiveBean *NaiveBean() const {
|
||||
return (NekoGui_fmt::NaiveBean *) bean.get();
|
||||
};
|
||||
|
||||
[[nodiscard]] fmt::HysteriaBean *HysteriaBean() const {
|
||||
return (fmt::HysteriaBean *) bean.get();
|
||||
[[nodiscard]] NekoGui_fmt::HysteriaBean *HysteriaBean() const {
|
||||
return (NekoGui_fmt::HysteriaBean *) bean.get();
|
||||
};
|
||||
|
||||
[[nodiscard]] fmt::CustomBean *CustomBean() const {
|
||||
return (fmt::CustomBean *) bean.get();
|
||||
[[nodiscard]] NekoGui_fmt::CustomBean *CustomBean() const {
|
||||
return (NekoGui_fmt::CustomBean *) bean.get();
|
||||
};
|
||||
};
|
||||
} // namespace NekoRay
|
||||
} // namespace NekoGui
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
namespace NekoRay::traffic {
|
||||
namespace NekoGui_traffic {
|
||||
class TrafficData : public JsonStore {
|
||||
public:
|
||||
int id = -1; // ent id
|
||||
@@ -37,4 +37,4 @@ namespace NekoRay::traffic {
|
||||
return UNICODE_LRO + QString("%1↑ %2↓").arg(ReadableSize(uplink), ReadableSize(downlink));
|
||||
}
|
||||
};
|
||||
} // namespace NekoRay::traffic
|
||||
} // namespace NekoGui_traffic
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <QJsonDocument>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
namespace NekoRay::traffic {
|
||||
namespace NekoGui_traffic {
|
||||
|
||||
TrafficLooper *trafficLooper = new TrafficLooper;
|
||||
QElapsedTimer elapsedTimer;
|
||||
@@ -23,8 +23,8 @@ namespace NekoRay::traffic {
|
||||
if (interval <= 0) return nullptr;
|
||||
|
||||
// query
|
||||
auto uplink = NekoRay::rpc::defaultClient->QueryStats(item->tag, "uplink");
|
||||
auto downlink = NekoRay::rpc::defaultClient->QueryStats(item->tag, "downlink");
|
||||
auto uplink = NekoGui_rpc::defaultClient->QueryStats(item->tag, "uplink");
|
||||
auto downlink = NekoGui_rpc::defaultClient->QueryStats(item->tag, "downlink");
|
||||
|
||||
// add diff
|
||||
item->downlink += downlink;
|
||||
@@ -45,7 +45,7 @@ namespace NekoRay::traffic {
|
||||
|
||||
QJsonArray TrafficLooper::get_connection_list() {
|
||||
#ifndef NKR_NO_GRPC
|
||||
auto str = NekoRay::rpc::defaultClient->ListConnections();
|
||||
auto str = NekoGui_rpc::defaultClient->ListConnections();
|
||||
QJsonDocument jsonDocument = QJsonDocument::fromJson(str.c_str());
|
||||
return jsonDocument.array();
|
||||
#else
|
||||
@@ -79,10 +79,10 @@ namespace NekoRay::traffic {
|
||||
void TrafficLooper::Loop() {
|
||||
elapsedTimer.start();
|
||||
while (true) {
|
||||
auto sleep_ms = dataStore->traffic_loop_interval;
|
||||
auto sleep_ms = NekoGui::dataStore->traffic_loop_interval;
|
||||
if (sleep_ms < 500 || sleep_ms > 5000) sleep_ms = 1000;
|
||||
QThread::msleep(sleep_ms);
|
||||
if (dataStore->traffic_loop_interval == 0) continue; // user disabled
|
||||
if (NekoGui::dataStore->traffic_loop_interval == 0) continue; // user disabled
|
||||
|
||||
// profile start and stop
|
||||
if (!loop_enabled) {
|
||||
@@ -109,7 +109,7 @@ namespace NekoRay::traffic {
|
||||
|
||||
// do conn list update
|
||||
QJsonArray conn_list;
|
||||
if (dataStore->connection_statistics) {
|
||||
if (NekoGui::dataStore->connection_statistics) {
|
||||
conn_list = get_connection_list();
|
||||
}
|
||||
|
||||
@@ -125,11 +125,11 @@ namespace NekoRay::traffic {
|
||||
if (item->id < 0) continue;
|
||||
m->refresh_proxy_list(item->id);
|
||||
}
|
||||
if (dataStore->connection_statistics) {
|
||||
if (NekoGui::dataStore->connection_statistics) {
|
||||
m->refresh_connection_list(conn_list);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace NekoRay::traffic
|
||||
} // namespace NekoGui_traffic
|
||||
@@ -1,20 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include <QSharedPointer>
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include <QMutex>
|
||||
|
||||
#include "TrafficData.hpp"
|
||||
|
||||
namespace NekoRay::traffic {
|
||||
namespace NekoGui_traffic {
|
||||
class TrafficLooper {
|
||||
public:
|
||||
bool loop_enabled = false;
|
||||
bool looping = false;
|
||||
QMutex loop_mutex;
|
||||
|
||||
QList<QSharedPointer<TrafficData>> items;
|
||||
QList<std::shared_ptr<TrafficData>> items;
|
||||
TrafficData *proxy = nullptr;
|
||||
|
||||
void UpdateAll();
|
||||
@@ -30,4 +29,4 @@ namespace NekoRay::traffic {
|
||||
};
|
||||
|
||||
extern TrafficLooper *trafficLooper;
|
||||
} // namespace NekoRay::traffic
|
||||
} // namespace NekoGui_traffic
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QHostInfo>
|
||||
#include <QUrl>
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
AbstractBean::AbstractBean(int version) {
|
||||
this->version = version;
|
||||
_add(new configItem("_v", &this->version, itemType::integer));
|
||||
@@ -52,6 +52,7 @@ namespace NekoRay::fmt {
|
||||
return;
|
||||
}
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) // TODO older QT
|
||||
QHostInfo::lookupHost(serverAddress, QApplication::instance(), [=](const QHostInfo &host) {
|
||||
auto addr = host.addresses();
|
||||
if (!addr.isEmpty()) {
|
||||
@@ -73,5 +74,6 @@ namespace NekoRay::fmt {
|
||||
}
|
||||
onFinished();
|
||||
});
|
||||
#endif
|
||||
}
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
struct CoreObjOutboundBuildResult {
|
||||
public:
|
||||
QJsonObject outbound;
|
||||
@@ -68,4 +68,4 @@ namespace NekoRay::fmt {
|
||||
virtual QString ToShareLink() { return {}; };
|
||||
};
|
||||
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "db/ProxyEntity.hpp"
|
||||
#include "fmt/includes.h"
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
void V2rayStreamSettings::BuildStreamSettingsSingBox(QJsonObject *outbound) {
|
||||
// https://sing-box.sagernet.org/configuration/shared/v2ray-transport
|
||||
|
||||
@@ -44,7 +44,7 @@ namespace NekoRay::fmt {
|
||||
// 对应字段 tls
|
||||
if (security == "tls") {
|
||||
QJsonObject tls{{"enabled", true}};
|
||||
if (allow_insecure || dataStore->skip_cert) tls["insecure"] = true;
|
||||
if (allow_insecure || NekoGui::dataStore->skip_cert) tls["insecure"] = true;
|
||||
if (!sni.trimmed().isEmpty()) tls["server_name"] = sni;
|
||||
if (!certificate.trimmed().isEmpty()) {
|
||||
tls["certificate"] = certificate.trimmed();
|
||||
@@ -52,7 +52,7 @@ namespace NekoRay::fmt {
|
||||
if (!alpn.trimmed().isEmpty()) {
|
||||
tls["alpn"] = QList2QJsonArray(alpn.split(","));
|
||||
}
|
||||
auto fp = utlsFingerprint.isEmpty() ? NekoRay::dataStore->utlsFingerprint : utlsFingerprint;
|
||||
auto fp = utlsFingerprint.isEmpty() ? NekoGui::dataStore->utlsFingerprint : utlsFingerprint;
|
||||
if (!fp.isEmpty()) {
|
||||
tls["utls"] = QJsonObject{
|
||||
{"enabled", true},
|
||||
@@ -194,4 +194,4 @@ namespace NekoRay::fmt {
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
auto streamSettings = stream->BuildStreamSettingsV2Ray(); \
|
||||
outbound["streamSettings"] = streamSettings;
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
QJsonObject V2rayStreamSettings::BuildStreamSettingsV2Ray() {
|
||||
QJsonObject streamSettings{{"network", network}};
|
||||
|
||||
@@ -56,10 +56,10 @@ namespace NekoRay::fmt {
|
||||
}
|
||||
|
||||
if (security == "tls") {
|
||||
auto fp = utlsFingerprint.isEmpty() ? NekoRay::dataStore->utlsFingerprint : utlsFingerprint;
|
||||
auto fp = utlsFingerprint.isEmpty() ? NekoGui::dataStore->utlsFingerprint : utlsFingerprint;
|
||||
bool v5_utls = !fp.isEmpty();
|
||||
QJsonObject tls;
|
||||
if (allow_insecure || dataStore->skip_cert) tls["allowInsecure"] = true;
|
||||
if (allow_insecure || NekoGui::dataStore->skip_cert) tls["allowInsecure"] = true;
|
||||
if (!sni.trimmed().isEmpty()) tls["serverName"] = sni;
|
||||
if (!certificate.trimmed().isEmpty()) {
|
||||
tls["disableSystemRoot"] = true;
|
||||
@@ -212,4 +212,4 @@ namespace NekoRay::fmt {
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
@@ -19,7 +19,7 @@
|
||||
f.close(); \
|
||||
auto TempFile = QFileInfo(f).absoluteFilePath();
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
// -1: Cannot use this config
|
||||
// 0: Internal
|
||||
// 1: Mapping External
|
||||
@@ -27,7 +27,7 @@ namespace NekoRay::fmt {
|
||||
|
||||
int NaiveBean::NeedExternal(bool isFirstProfile) {
|
||||
if (isFirstProfile) {
|
||||
if (dataStore->spmode_vpn) {
|
||||
if (NekoGui::dataStore->spmode_vpn) {
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
@@ -38,7 +38,7 @@ namespace NekoRay::fmt {
|
||||
int HysteriaBean::NeedExternal(bool isFirstProfile) {
|
||||
auto hysteriaCore = [=] {
|
||||
if (isFirstProfile) {
|
||||
if (dataStore->spmode_vpn && protocol != hysteria_protocol_facktcp && hopPort.trimmed().isEmpty()) {
|
||||
if (NekoGui::dataStore->spmode_vpn && protocol != hysteria_protocol_facktcp && hopPort.trimmed().isEmpty()) {
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
@@ -69,7 +69,7 @@ namespace NekoRay::fmt {
|
||||
}
|
||||
|
||||
ExternalBuildResult NaiveBean::BuildExternal(int mapping_port, int socks_port, int external_stat) {
|
||||
ExternalBuildResult result{dataStore->extraCore->Get("naive")};
|
||||
ExternalBuildResult result{NekoGui::dataStore->extraCore->Get("naive")};
|
||||
|
||||
auto is_direct = external_stat == 2;
|
||||
auto domain_address = sni.isEmpty() ? serverAddress : sni;
|
||||
@@ -105,7 +105,7 @@ namespace NekoRay::fmt {
|
||||
}
|
||||
|
||||
ExternalBuildResult HysteriaBean::BuildExternal(int mapping_port, int socks_port, int external_stat) {
|
||||
ExternalBuildResult result{dataStore->extraCore->Get("hysteria")};
|
||||
ExternalBuildResult result{NekoGui::dataStore->extraCore->Get("hysteria")};
|
||||
|
||||
QJsonObject config;
|
||||
|
||||
@@ -166,7 +166,7 @@ namespace NekoRay::fmt {
|
||||
}
|
||||
|
||||
ExternalBuildResult CustomBean::BuildExternal(int mapping_port, int socks_port, int external_stat) {
|
||||
ExternalBuildResult result{dataStore->extraCore->Get(core)};
|
||||
ExternalBuildResult result{NekoGui::dataStore->extraCore->Get(core)};
|
||||
|
||||
result.arguments = command; // TODO split?
|
||||
|
||||
@@ -206,4 +206,4 @@ namespace NekoRay::fmt {
|
||||
|
||||
return result;
|
||||
}
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <QUrlQuery>
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
QString SocksHttpBean::ToShareLink() {
|
||||
QUrl url;
|
||||
if (socks_http_type == type_HTTP) { // http
|
||||
@@ -151,4 +151,4 @@ namespace NekoRay::fmt {
|
||||
return url.toString(QUrl::FullyEncoded);
|
||||
}
|
||||
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
@@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
class ChainBean : public AbstractBean {
|
||||
public:
|
||||
QList<int> list; // in to out
|
||||
@@ -15,4 +15,4 @@ namespace NekoRay::fmt {
|
||||
|
||||
QString DisplayAddress() override { return ""; };
|
||||
};
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "fmt/AbstractBean.hpp"
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
class CustomBean : public AbstractBean {
|
||||
public:
|
||||
QString core;
|
||||
@@ -55,4 +55,4 @@ namespace NekoRay::fmt {
|
||||
|
||||
CoreObjOutboundBuildResult BuildCoreObjV2Ray() override;
|
||||
};
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "fmt/AbstractBean.hpp"
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
class HysteriaBean : public AbstractBean {
|
||||
public:
|
||||
static constexpr int hysteria_protocol_udp = 0;
|
||||
@@ -77,4 +77,4 @@ namespace NekoRay::fmt {
|
||||
|
||||
QString ToShareLink() override;
|
||||
};
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include <QUrlQuery>
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
|
||||
#define DECODE_V2RAY_N_1 \
|
||||
QString linkN = DecodeB64IfValid(SubStrBefore(SubStrAfter(link, "://"), "#"), QByteArray::Base64Option::Base64UrlEncoding); \
|
||||
@@ -193,14 +193,14 @@ namespace NekoRay::fmt {
|
||||
|
||||
auto protocolStr = (query.hasQueryItem("protocol") ? query.queryItemValue("protocol") : "udp").toLower();
|
||||
if (protocolStr == "faketcp") {
|
||||
protocol = fmt::HysteriaBean::hysteria_protocol_facktcp;
|
||||
protocol = NekoGui_fmt::HysteriaBean::hysteria_protocol_facktcp;
|
||||
} else if (protocolStr.startsWith("wechat")) {
|
||||
protocol = fmt::HysteriaBean::hysteria_protocol_wechat_video;
|
||||
protocol = NekoGui_fmt::HysteriaBean::hysteria_protocol_wechat_video;
|
||||
}
|
||||
|
||||
if (query.hasQueryItem("auth")) {
|
||||
authPayload = query.queryItemValue("auth");
|
||||
authPayloadType = fmt::HysteriaBean::hysteria_auth_string;
|
||||
authPayloadType = NekoGui_fmt::HysteriaBean::hysteria_auth_string;
|
||||
}
|
||||
|
||||
alpn = query.queryItemValue("alpn");
|
||||
@@ -212,4 +212,4 @@ namespace NekoRay::fmt {
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "fmt/AbstractBean.hpp"
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
class NaiveBean : public AbstractBean {
|
||||
public:
|
||||
QString username = "";
|
||||
@@ -35,4 +35,4 @@ namespace NekoRay::fmt {
|
||||
|
||||
QString ToShareLink() override;
|
||||
};
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "fmt/AbstractBean.hpp"
|
||||
#include "fmt/V2RayStreamSettings.hpp"
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
class ShadowSocksBean : public AbstractBean {
|
||||
public:
|
||||
QString method = "aes-128-gcm";
|
||||
@@ -11,7 +11,7 @@ namespace NekoRay::fmt {
|
||||
QString plugin = "";
|
||||
bool uot = false;
|
||||
|
||||
QSharedPointer<V2rayStreamSettings> stream = QSharedPointer<V2rayStreamSettings>(new V2rayStreamSettings());
|
||||
std::shared_ptr<V2rayStreamSettings> stream = std::make_shared<V2rayStreamSettings>();
|
||||
|
||||
ShadowSocksBean() : AbstractBean(0) {
|
||||
_add(new configItem("method", &method, itemType::string));
|
||||
@@ -31,4 +31,4 @@ namespace NekoRay::fmt {
|
||||
|
||||
QString ToShareLink() override;
|
||||
};
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "fmt/AbstractBean.hpp"
|
||||
#include "fmt/V2RayStreamSettings.hpp"
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
class SocksHttpBean : public AbstractBean {
|
||||
public:
|
||||
static constexpr int type_HTTP = -80;
|
||||
@@ -14,7 +14,7 @@ namespace NekoRay::fmt {
|
||||
QString username = "";
|
||||
QString password = "";
|
||||
|
||||
QSharedPointer<V2rayStreamSettings> stream = QSharedPointer<V2rayStreamSettings>(new V2rayStreamSettings());
|
||||
std::shared_ptr<V2rayStreamSettings> stream = std::make_shared<V2rayStreamSettings>();
|
||||
|
||||
explicit SocksHttpBean(int _socks_http_type) : AbstractBean(0) {
|
||||
this->socks_http_type = _socks_http_type;
|
||||
@@ -34,4 +34,4 @@ namespace NekoRay::fmt {
|
||||
|
||||
QString ToShareLink() override;
|
||||
};
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include "fmt/AbstractBean.hpp"
|
||||
#include "fmt/V2RayStreamSettings.hpp"
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
class TrojanVLESSBean : public AbstractBean {
|
||||
public:
|
||||
static constexpr int proxy_Trojan = 0;
|
||||
@@ -13,7 +13,7 @@ namespace NekoRay::fmt {
|
||||
QString password = "";
|
||||
QString flow = "";
|
||||
|
||||
QSharedPointer<V2rayStreamSettings> stream = QSharedPointer<V2rayStreamSettings>(new V2rayStreamSettings());
|
||||
std::shared_ptr<V2rayStreamSettings> stream = std::make_shared<V2rayStreamSettings>();
|
||||
|
||||
explicit TrojanVLESSBean(int _proxy_type) : AbstractBean(0) {
|
||||
proxy_type = _proxy_type;
|
||||
@@ -32,4 +32,4 @@ namespace NekoRay::fmt {
|
||||
|
||||
QString ToShareLink() override;
|
||||
};
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "AbstractBean.hpp"
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
class V2rayStreamSettings : public JsonStore {
|
||||
public:
|
||||
QString network = "tcp";
|
||||
@@ -56,10 +56,10 @@ namespace NekoRay::fmt {
|
||||
if (bean == nullptr) return nullptr;
|
||||
auto stream_item = bean->_get("stream");
|
||||
if (stream_item != nullptr) {
|
||||
auto stream_store = (NekoRay::JsonStore *) stream_item->ptr;
|
||||
auto stream = (NekoRay::fmt::V2rayStreamSettings *) stream_store;
|
||||
auto stream_store = (JsonStore *) stream_item->ptr;
|
||||
auto stream = (NekoGui_fmt::V2rayStreamSettings *) stream_store;
|
||||
return stream;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
|
||||
@@ -3,14 +3,14 @@
|
||||
#include "fmt/AbstractBean.hpp"
|
||||
#include "fmt/V2RayStreamSettings.hpp"
|
||||
|
||||
namespace NekoRay::fmt {
|
||||
namespace NekoGui_fmt {
|
||||
class VMessBean : public AbstractBean {
|
||||
public:
|
||||
QString uuid = "";
|
||||
int aid = 0;
|
||||
QString security = "auto";
|
||||
|
||||
QSharedPointer<V2rayStreamSettings> stream = QSharedPointer<V2rayStreamSettings>(new V2rayStreamSettings());
|
||||
std::shared_ptr<V2rayStreamSettings> stream = std::make_shared<V2rayStreamSettings>();
|
||||
|
||||
VMessBean() : AbstractBean(0) {
|
||||
_add(new configItem("id", &uuid, itemType::string));
|
||||
@@ -29,4 +29,4 @@ namespace NekoRay::fmt {
|
||||
|
||||
QString ToShareLink() override;
|
||||
};
|
||||
} // namespace NekoRay::fmt
|
||||
} // namespace NekoGui_fmt
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
namespace NekoRay {
|
||||
namespace NekoGui {
|
||||
namespace DomainMatcher {
|
||||
enum DomainMatcher {
|
||||
DEFAULT,
|
||||
@@ -22,4 +22,4 @@ namespace NekoRay {
|
||||
SING_BOX,
|
||||
};
|
||||
}
|
||||
} // namespace NekoRay
|
||||
} // namespace NekoGui
|
||||
|
||||
@@ -19,48 +19,48 @@
|
||||
|
||||
#define P_C_LOAD_STRING(a) CACHE.a = bean->a;
|
||||
#define P_C_SAVE_STRING(a) bean->a = CACHE.a;
|
||||
#define D_C_LOAD_STRING(a) CACHE.a = NekoRay::dataStore->a;
|
||||
#define D_C_SAVE_STRING(a) NekoRay::dataStore->a = CACHE.a;
|
||||
#define D_C_LOAD_STRING(a) CACHE.a = NekoGui::dataStore->a;
|
||||
#define D_C_SAVE_STRING(a) NekoGui::dataStore->a = CACHE.a;
|
||||
|
||||
#define P_LOAD_STRING(a) ui->a->setText(bean->a);
|
||||
#define P_SAVE_STRING(a) bean->a = ui->a->text();
|
||||
#define P_SAVE_STRING_QTEXTEDIT(a) bean->a = ui->a->toPlainText();
|
||||
#define D_LOAD_STRING(a) ui->a->setText(NekoRay::dataStore->a);
|
||||
#define D_SAVE_STRING(a) NekoRay::dataStore->a = ui->a->text();
|
||||
#define D_SAVE_STRING_QTEXTEDIT(a) NekoRay::dataStore->a = ui->a->toPlainText();
|
||||
#define D_LOAD_STRING(a) ui->a->setText(NekoGui::dataStore->a);
|
||||
#define D_SAVE_STRING(a) NekoGui::dataStore->a = ui->a->text();
|
||||
#define D_SAVE_STRING_QTEXTEDIT(a) NekoGui::dataStore->a = ui->a->toPlainText();
|
||||
#define P_LOAD_INT(a) \
|
||||
ui->a->setText(Int2String(bean->a)); \
|
||||
ui->a->setValidator(QRegExpValidator_Number);
|
||||
#define P_SAVE_INT(a) bean->a = ui->a->text().toInt();
|
||||
#define D_LOAD_INT(a) \
|
||||
ui->a->setText(Int2String(NekoRay::dataStore->a)); \
|
||||
ui->a->setText(Int2String(NekoGui::dataStore->a)); \
|
||||
ui->a->setValidator(QRegExpValidator_Number);
|
||||
#define D_SAVE_INT(a) NekoRay::dataStore->a = ui->a->text().toInt();
|
||||
#define D_SAVE_INT(a) NekoGui::dataStore->a = ui->a->text().toInt();
|
||||
#define P_LOAD_COMBO_STRING(a) ui->a->setCurrentText(bean->a);
|
||||
#define P_SAVE_COMBO_STRING(a) bean->a = ui->a->currentText();
|
||||
#define D_LOAD_COMBO_STRING(a) ui->a->setCurrentText(NekoRay::dataStore->a);
|
||||
#define D_SAVE_COMBO_STRING(a) NekoRay::dataStore->a = ui->a->currentText();
|
||||
#define D_LOAD_COMBO_STRING(a) ui->a->setCurrentText(NekoGui::dataStore->a);
|
||||
#define D_SAVE_COMBO_STRING(a) NekoGui::dataStore->a = ui->a->currentText();
|
||||
#define P_LOAD_COMBO_INT(a) ui->a->setCurrentIndex(bean->a);
|
||||
#define P_SAVE_COMBO_INT(a) bean->a = ui->a->currentIndex();
|
||||
#define D_LOAD_BOOL(a) ui->a->setChecked(NekoRay::dataStore->a);
|
||||
#define D_SAVE_BOOL(a) NekoRay::dataStore->a = ui->a->isChecked();
|
||||
#define D_LOAD_BOOL(a) ui->a->setChecked(NekoGui::dataStore->a);
|
||||
#define D_SAVE_BOOL(a) NekoGui::dataStore->a = ui->a->isChecked();
|
||||
#define P_LOAD_BOOL(a) ui->a->setChecked(bean->a);
|
||||
#define P_SAVE_BOOL(a) bean->a = ui->a->isChecked();
|
||||
|
||||
#define D_LOAD_INT_ENABLE(i, e) \
|
||||
if (NekoRay::dataStore->i > 0) { \
|
||||
if (NekoGui::dataStore->i > 0) { \
|
||||
ui->e->setChecked(true); \
|
||||
ui->i->setText(Int2String(NekoRay::dataStore->i)); \
|
||||
ui->i->setText(Int2String(NekoGui::dataStore->i)); \
|
||||
} else { \
|
||||
ui->e->setChecked(false); \
|
||||
ui->i->setText(Int2String(-NekoRay::dataStore->i)); \
|
||||
ui->i->setText(Int2String(-NekoGui::dataStore->i)); \
|
||||
} \
|
||||
ui->i->setValidator(QRegExpValidator_Number);
|
||||
#define D_SAVE_INT_ENABLE(i, e) \
|
||||
if (ui->e->isChecked()) { \
|
||||
NekoRay::dataStore->i = ui->i->text().toInt(); \
|
||||
NekoGui::dataStore->i = ui->i->text().toInt(); \
|
||||
} else { \
|
||||
NekoRay::dataStore->i = -ui->i->text().toInt(); \
|
||||
NekoGui::dataStore->i = -ui->i->text().toInt(); \
|
||||
}
|
||||
|
||||
#define C_EDIT_JSON_ALLOW_EMPTY(a) \
|
||||
|
||||
@@ -5,27 +5,27 @@
|
||||
#include <QEventLoop>
|
||||
#include <QMetaEnum>
|
||||
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
namespace NekoRay::network {
|
||||
namespace NekoGui_network {
|
||||
|
||||
NekoHTTPResponse NetworkRequestHelper::HttpGet(const QUrl &url) {
|
||||
QNetworkRequest request;
|
||||
QNetworkAccessManager accessManager;
|
||||
request.setUrl(url);
|
||||
// Set proxy
|
||||
if (NekoRay::dataStore->sub_use_proxy) {
|
||||
if (NekoGui::dataStore->sub_use_proxy) {
|
||||
QNetworkProxy p;
|
||||
// Note: sing-box mixed socks5 protocol error
|
||||
p.setType(IS_NEKO_BOX ? QNetworkProxy::HttpProxy : QNetworkProxy::Socks5Proxy);
|
||||
p.setHostName("127.0.0.1");
|
||||
p.setPort(NekoRay::dataStore->inbound_socks_port);
|
||||
if (dataStore->inbound_auth->NeedAuth()) {
|
||||
p.setUser(dataStore->inbound_auth->username);
|
||||
p.setPassword(dataStore->inbound_auth->password);
|
||||
p.setPort(NekoGui::dataStore->inbound_socks_port);
|
||||
if (NekoGui::dataStore->inbound_auth->NeedAuth()) {
|
||||
p.setUser(NekoGui::dataStore->inbound_auth->username);
|
||||
p.setPassword(NekoGui::dataStore->inbound_auth->password);
|
||||
}
|
||||
accessManager.setProxy(p);
|
||||
if (NekoRay::dataStore->started_id < 0) {
|
||||
if (NekoGui::dataStore->started_id < 0) {
|
||||
return NekoHTTPResponse{QObject::tr("Request with proxy but no profile started.")};
|
||||
}
|
||||
}
|
||||
@@ -34,9 +34,11 @@ namespace NekoRay::network {
|
||||
accessManager.proxy().setCapabilities(cap | QNetworkProxy::HostNameLookupCapability);
|
||||
}
|
||||
// Set attribute
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
|
||||
request.setHeader(QNetworkRequest::KnownHeaders::UserAgentHeader, NekoRay::dataStore->user_agent);
|
||||
if (NekoRay::dataStore->sub_insecure) {
|
||||
#endif
|
||||
request.setHeader(QNetworkRequest::KnownHeaders::UserAgentHeader, NekoGui::dataStore->user_agent);
|
||||
if (NekoGui::dataStore->sub_insecure) {
|
||||
QSslConfiguration c;
|
||||
c.setPeerVerifyMode(QSslSocket::PeerVerifyMode::VerifyNone);
|
||||
request.setSslConfiguration(c);
|
||||
@@ -48,7 +50,7 @@ namespace NekoRay::network {
|
||||
for (const auto &err: errors) {
|
||||
error_str << err.errorString();
|
||||
}
|
||||
MW_show_log(QString("SSL Errors: %1 %2").arg(error_str.join(","), NekoRay::dataStore->sub_insecure ? "(Ignored)" : ""));
|
||||
MW_show_log(QString("SSL Errors: %1 %2").arg(error_str.join(","), NekoGui::dataStore->sub_insecure ? "(Ignored)" : ""));
|
||||
});
|
||||
//
|
||||
{
|
||||
@@ -70,4 +72,4 @@ namespace NekoRay::network {
|
||||
return "";
|
||||
}
|
||||
|
||||
} // namespace NekoRay::network
|
||||
} // namespace NekoGui_network
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include <QObject>
|
||||
#include <functional>
|
||||
|
||||
namespace NekoRay::network {
|
||||
namespace NekoGui_network {
|
||||
struct NekoHTTPResponse {
|
||||
QString error;
|
||||
QByteArray data;
|
||||
@@ -26,6 +26,6 @@ namespace NekoRay::network {
|
||||
|
||||
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;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
#include "NekoRay.hpp"
|
||||
#include "NekoGui.hpp"
|
||||
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QSharedPointer>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
@@ -15,191 +14,11 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
namespace NekoRay {
|
||||
|
||||
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", ¤t_group, itemType::integer));
|
||||
_add(new configItem("inbound_address", &inbound_address, itemType::string));
|
||||
_add(new configItem("inbound_socks_port", &inbound_socks_port, itemType::integer));
|
||||
_add(new configItem("inbound_http_port", &inbound_http_port, itemType::integer));
|
||||
_add(new configItem("log_level", &log_level, itemType::string));
|
||||
_add(new configItem("mux_protocol", &mux_protocol, itemType::string));
|
||||
_add(new configItem("mux_concurrency", &mux_concurrency, itemType::integer));
|
||||
_add(new configItem("mux_default_on", &mux_default_on, itemType::boolean));
|
||||
_add(new configItem("traffic_loop_interval", &traffic_loop_interval, itemType::integer));
|
||||
_add(new configItem("test_concurrent", &test_concurrent, itemType::integer));
|
||||
_add(new configItem("theme", &theme, itemType::string));
|
||||
_add(new configItem("custom_inbound", &custom_inbound, itemType::string));
|
||||
_add(new configItem("custom_route", &custom_route_global, itemType::string));
|
||||
_add(new configItem("v2ray_asset_dir", &v2ray_asset_dir, itemType::string));
|
||||
_add(new configItem("sub_use_proxy", &sub_use_proxy, itemType::boolean));
|
||||
_add(new configItem("remember_id", &remember_id, itemType::integer));
|
||||
_add(new configItem("remember_enable", &remember_enable, itemType::boolean));
|
||||
_add(new configItem("language", &language, itemType::integer));
|
||||
_add(new configItem("spmode2", &remember_spmode, itemType::stringList));
|
||||
_add(new configItem("skip_cert", &skip_cert, itemType::boolean));
|
||||
_add(new configItem("hk_mw", &hotkey_mainwindow, itemType::string));
|
||||
_add(new configItem("hk_group", &hotkey_group, itemType::string));
|
||||
_add(new configItem("hk_route", &hotkey_route, itemType::string));
|
||||
_add(new configItem("hk_spmenu", &hotkey_system_proxy_menu, itemType::string));
|
||||
_add(new configItem("fakedns", &fake_dns, itemType::boolean));
|
||||
_add(new configItem("active_routing", &active_routing, itemType::string));
|
||||
_add(new configItem("mw_size", &mw_size, itemType::string));
|
||||
_add(new configItem("conn_stat", &connection_statistics, itemType::boolean));
|
||||
_add(new configItem("vpn_impl", &vpn_implementation, itemType::integer));
|
||||
_add(new configItem("vpn_mtu", &vpn_mtu, itemType::integer));
|
||||
_add(new configItem("vpn_ipv6", &vpn_ipv6, itemType::boolean));
|
||||
_add(new configItem("vpn_hide_console", &vpn_hide_console, itemType::boolean));
|
||||
_add(new configItem("vpn_strict_route", &vpn_strict_route, itemType::boolean));
|
||||
_add(new configItem("vpn_bypass_process", &vpn_rule_process, itemType::string));
|
||||
_add(new configItem("vpn_bypass_cidr", &vpn_rule_cidr, itemType::string));
|
||||
_add(new configItem("vpn_rule_white", &vpn_rule_white, itemType::boolean));
|
||||
_add(new configItem("check_include_pre", &check_include_pre, itemType::boolean));
|
||||
_add(new configItem("sp_format", &system_proxy_format, itemType::string));
|
||||
_add(new configItem("sub_clear", &sub_clear, itemType::boolean));
|
||||
_add(new configItem("sub_insecure", &sub_insecure, itemType::boolean));
|
||||
_add(new configItem("enable_js_hook", &enable_js_hook, itemType::integer));
|
||||
_add(new configItem("log_ignore", &log_ignore, itemType::stringList));
|
||||
_add(new configItem("start_minimal", &start_minimal, itemType::boolean));
|
||||
_add(new configItem("max_log_line", &max_log_line, itemType::integer));
|
||||
_add(new configItem("splitter_state", &splitter_state, itemType::string));
|
||||
_add(new configItem("utlsFingerprint", &utlsFingerprint, itemType::string));
|
||||
_add(new configItem("core_box_clash_api", &core_box_clash_api, itemType::integer));
|
||||
_add(new configItem("core_box_clash_api_secret", &core_box_clash_api_secret, itemType::string));
|
||||
_add(new configItem("core_box_underlying_dns", &core_box_underlying_dns, itemType::string));
|
||||
_add(new configItem("core_ray_direct_dns", &core_ray_direct_dns, itemType::boolean));
|
||||
_add(new configItem("vpn_internal_tun", &vpn_internal_tun, itemType::boolean));
|
||||
#ifdef Q_OS_WIN
|
||||
_add(new configItem("core_ray_windows_disable_auto_interface", &core_ray_windows_disable_auto_interface, itemType::boolean));
|
||||
#endif
|
||||
}
|
||||
|
||||
void DataStore::UpdateStartedId(int id) {
|
||||
started_id = id;
|
||||
if (remember_enable) {
|
||||
remember_id = id;
|
||||
Save();
|
||||
} else if (remember_id >= 0) {
|
||||
remember_id = -1919;
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
// preset routing
|
||||
Routing::Routing(int preset) : JsonStore() {
|
||||
if (preset == 1) {
|
||||
direct_ip =
|
||||
"geoip:cn\n"
|
||||
"geoip:private";
|
||||
direct_domain = "geosite:cn";
|
||||
proxy_ip = "";
|
||||
proxy_domain = "";
|
||||
block_ip = "";
|
||||
block_domain =
|
||||
"geosite:category-ads-all\n"
|
||||
"domain:appcenter.ms\n"
|
||||
"domain:app-measurement.com\n"
|
||||
"domain:firebase.io\n"
|
||||
"domain:crashlytics.com\n"
|
||||
"domain:google-analytics.com";
|
||||
}
|
||||
_add(new configItem("direct_ip", &this->direct_ip, itemType::string));
|
||||
_add(new configItem("direct_domain", &this->direct_domain, itemType::string));
|
||||
_add(new configItem("proxy_ip", &this->proxy_ip, itemType::string));
|
||||
_add(new configItem("proxy_domain", &this->proxy_domain, itemType::string));
|
||||
_add(new configItem("block_ip", &this->block_ip, itemType::string));
|
||||
_add(new configItem("block_domain", &this->block_domain, itemType::string));
|
||||
_add(new configItem("def_outbound", &this->def_outbound, itemType::string));
|
||||
_add(new configItem("custom", &this->custom, itemType::string));
|
||||
//
|
||||
_add(new configItem("remote_dns", &this->remote_dns, itemType::string));
|
||||
_add(new configItem("remote_dns_strategy", &this->remote_dns_strategy, itemType::string));
|
||||
_add(new configItem("direct_dns", &this->direct_dns, itemType::string));
|
||||
_add(new configItem("direct_dns_strategy", &this->direct_dns_strategy, itemType::string));
|
||||
_add(new configItem("domain_strategy", &this->domain_strategy, itemType::string));
|
||||
_add(new configItem("outbound_domain_strategy", &this->outbound_domain_strategy, itemType::string));
|
||||
_add(new configItem("dns_routing", &this->dns_routing, itemType::boolean));
|
||||
_add(new configItem("sniffing_mode", &this->sniffing_mode, itemType::integer));
|
||||
_add(new configItem("use_dns_object", &this->use_dns_object, itemType::boolean));
|
||||
_add(new configItem("dns_object", &this->dns_object, itemType::string));
|
||||
}
|
||||
|
||||
QString Routing::DisplayRouting() const {
|
||||
return QString("[Proxy] %1\n[Proxy] %2\n[Direct] %3\n[Direct] %4\n[Block] %5\n[Block] %6\n[Default Outbound] %7\n[DNS] %8")
|
||||
.arg(SplitLinesSkipSharp(proxy_domain).join(","))
|
||||
.arg(SplitLinesSkipSharp(proxy_ip).join(","))
|
||||
.arg(SplitLinesSkipSharp(direct_domain).join(","))
|
||||
.arg(SplitLinesSkipSharp(direct_ip).join(","))
|
||||
.arg(SplitLinesSkipSharp(block_domain).join(","))
|
||||
.arg(SplitLinesSkipSharp(block_ip).join(","))
|
||||
.arg(def_outbound)
|
||||
.arg(use_dns_object ? "DNS Object" : "Simple DNS");
|
||||
}
|
||||
|
||||
QStringList Routing::List() {
|
||||
QStringList l;
|
||||
QDir d;
|
||||
if (d.exists(ROUTES_PREFIX)) {
|
||||
QDir dr(ROUTES_PREFIX);
|
||||
return dr.entryList(QDir::Files);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
void Routing::SetToActive(const QString &name) {
|
||||
dataStore->routing->fn = ROUTES_PREFIX + name;
|
||||
dataStore->routing->Load();
|
||||
dataStore->active_routing = name;
|
||||
dataStore->Save();
|
||||
}
|
||||
|
||||
// NO default extra core
|
||||
|
||||
ExtraCore::ExtraCore() : JsonStore() {
|
||||
_add(new configItem("core_map", &this->core_map, itemType::string));
|
||||
}
|
||||
|
||||
QString ExtraCore::Get(const QString &id) const {
|
||||
auto obj = QString2QJsonObject(core_map);
|
||||
for (const auto &c: obj.keys()) {
|
||||
if (c == id) return obj[id].toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void ExtraCore::Set(const QString &id, const QString &path) {
|
||||
auto obj = QString2QJsonObject(core_map);
|
||||
obj[id] = path;
|
||||
core_map = QJsonObject2QString(obj, true);
|
||||
}
|
||||
|
||||
void ExtraCore::Delete(const QString &id) {
|
||||
auto obj = QString2QJsonObject(core_map);
|
||||
obj.remove(id);
|
||||
core_map = QJsonObject2QString(obj, true);
|
||||
}
|
||||
|
||||
InboundAuthorization::InboundAuthorization() : JsonStore() {
|
||||
_add(new configItem("user", &this->username, itemType::string));
|
||||
_add(new configItem("pass", &this->password, itemType::string));
|
||||
}
|
||||
|
||||
bool InboundAuthorization::NeedAuth() const {
|
||||
return !username.trimmed().isEmpty() && !password.trimmed().isEmpty();
|
||||
}
|
||||
namespace NekoGui_ConfigItem {
|
||||
|
||||
// 添加关联
|
||||
void JsonStore::_add(configItem *item) {
|
||||
_map.insert(item->name, QSharedPointer<configItem>(item));
|
||||
_map.insert(item->name, std::shared_ptr<configItem>(item));
|
||||
}
|
||||
|
||||
QString JsonStore::_name(void *p) {
|
||||
@@ -209,7 +28,7 @@ namespace NekoRay {
|
||||
return {};
|
||||
}
|
||||
|
||||
QSharedPointer<configItem> JsonStore::_get(const QString &name) {
|
||||
std::shared_ptr<configItem> JsonStore::_get(const QString &name) {
|
||||
// 直接 [] 会设置一个 nullptr ,所以先判断是否存在
|
||||
if (_map.contains(name)) {
|
||||
return _map[name];
|
||||
@@ -222,16 +41,16 @@ namespace NekoRay {
|
||||
if (item == nullptr) return;
|
||||
|
||||
switch (item->type) {
|
||||
case NekoRay::itemType::string:
|
||||
case itemType::string:
|
||||
*(QString *) item->ptr = *(QString *) p;
|
||||
break;
|
||||
case NekoRay::itemType::boolean:
|
||||
case itemType::boolean:
|
||||
*(bool *) item->ptr = *(bool *) p;
|
||||
break;
|
||||
case NekoRay::itemType::integer:
|
||||
case itemType::integer:
|
||||
*(int *) item->ptr = *(int *) p;
|
||||
break;
|
||||
case NekoRay::itemType::integer64:
|
||||
case itemType::integer64:
|
||||
*(long long *) item->ptr = *(long long *) p;
|
||||
break;
|
||||
// others...
|
||||
@@ -394,10 +213,192 @@ namespace NekoRay {
|
||||
return ok;
|
||||
}
|
||||
|
||||
} // namespace NekoGui_ConfigItem
|
||||
|
||||
namespace NekoGui {
|
||||
|
||||
DataStore *dataStore = new DataStore();
|
||||
|
||||
// datastore
|
||||
|
||||
DataStore::DataStore() : JsonStore() {
|
||||
_add(new configItem("extraCore", dynamic_cast<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", ¤t_group, itemType::integer));
|
||||
_add(new configItem("inbound_address", &inbound_address, itemType::string));
|
||||
_add(new configItem("inbound_socks_port", &inbound_socks_port, itemType::integer));
|
||||
_add(new configItem("inbound_http_port", &inbound_http_port, itemType::integer));
|
||||
_add(new configItem("log_level", &log_level, itemType::string));
|
||||
_add(new configItem("mux_protocol", &mux_protocol, itemType::string));
|
||||
_add(new configItem("mux_concurrency", &mux_concurrency, itemType::integer));
|
||||
_add(new configItem("mux_default_on", &mux_default_on, itemType::boolean));
|
||||
_add(new configItem("traffic_loop_interval", &traffic_loop_interval, itemType::integer));
|
||||
_add(new configItem("test_concurrent", &test_concurrent, itemType::integer));
|
||||
_add(new configItem("theme", &theme, itemType::string));
|
||||
_add(new configItem("custom_inbound", &custom_inbound, itemType::string));
|
||||
_add(new configItem("custom_route", &custom_route_global, itemType::string));
|
||||
_add(new configItem("v2ray_asset_dir", &v2ray_asset_dir, itemType::string));
|
||||
_add(new configItem("sub_use_proxy", &sub_use_proxy, itemType::boolean));
|
||||
_add(new configItem("remember_id", &remember_id, itemType::integer));
|
||||
_add(new configItem("remember_enable", &remember_enable, itemType::boolean));
|
||||
_add(new configItem("language", &language, itemType::integer));
|
||||
_add(new configItem("spmode2", &remember_spmode, itemType::stringList));
|
||||
_add(new configItem("skip_cert", &skip_cert, itemType::boolean));
|
||||
_add(new configItem("hk_mw", &hotkey_mainwindow, itemType::string));
|
||||
_add(new configItem("hk_group", &hotkey_group, itemType::string));
|
||||
_add(new configItem("hk_route", &hotkey_route, itemType::string));
|
||||
_add(new configItem("hk_spmenu", &hotkey_system_proxy_menu, itemType::string));
|
||||
_add(new configItem("fakedns", &fake_dns, itemType::boolean));
|
||||
_add(new configItem("active_routing", &active_routing, itemType::string));
|
||||
_add(new configItem("mw_size", &mw_size, itemType::string));
|
||||
_add(new configItem("conn_stat", &connection_statistics, itemType::boolean));
|
||||
_add(new configItem("vpn_impl", &vpn_implementation, itemType::integer));
|
||||
_add(new configItem("vpn_mtu", &vpn_mtu, itemType::integer));
|
||||
_add(new configItem("vpn_ipv6", &vpn_ipv6, itemType::boolean));
|
||||
_add(new configItem("vpn_hide_console", &vpn_hide_console, itemType::boolean));
|
||||
_add(new configItem("vpn_strict_route", &vpn_strict_route, itemType::boolean));
|
||||
_add(new configItem("vpn_bypass_process", &vpn_rule_process, itemType::string));
|
||||
_add(new configItem("vpn_bypass_cidr", &vpn_rule_cidr, itemType::string));
|
||||
_add(new configItem("vpn_rule_white", &vpn_rule_white, itemType::boolean));
|
||||
_add(new configItem("check_include_pre", &check_include_pre, itemType::boolean));
|
||||
_add(new configItem("sp_format", &system_proxy_format, itemType::string));
|
||||
_add(new configItem("sub_clear", &sub_clear, itemType::boolean));
|
||||
_add(new configItem("sub_insecure", &sub_insecure, itemType::boolean));
|
||||
_add(new configItem("enable_js_hook", &enable_js_hook, itemType::integer));
|
||||
_add(new configItem("log_ignore", &log_ignore, itemType::stringList));
|
||||
_add(new configItem("start_minimal", &start_minimal, itemType::boolean));
|
||||
_add(new configItem("max_log_line", &max_log_line, itemType::integer));
|
||||
_add(new configItem("splitter_state", &splitter_state, itemType::string));
|
||||
_add(new configItem("utlsFingerprint", &utlsFingerprint, itemType::string));
|
||||
_add(new configItem("core_box_clash_api", &core_box_clash_api, itemType::integer));
|
||||
_add(new configItem("core_box_clash_api_secret", &core_box_clash_api_secret, itemType::string));
|
||||
_add(new configItem("core_box_underlying_dns", &core_box_underlying_dns, itemType::string));
|
||||
_add(new configItem("core_ray_direct_dns", &core_ray_direct_dns, itemType::boolean));
|
||||
_add(new configItem("vpn_internal_tun", &vpn_internal_tun, itemType::boolean));
|
||||
#ifdef Q_OS_WIN
|
||||
_add(new configItem("core_ray_windows_disable_auto_interface", &core_ray_windows_disable_auto_interface, itemType::boolean));
|
||||
#endif
|
||||
}
|
||||
|
||||
void DataStore::UpdateStartedId(int id) {
|
||||
started_id = id;
|
||||
if (remember_enable) {
|
||||
remember_id = id;
|
||||
Save();
|
||||
} else if (remember_id >= 0) {
|
||||
remember_id = -1919;
|
||||
Save();
|
||||
}
|
||||
}
|
||||
|
||||
// preset routing
|
||||
Routing::Routing(int preset) : JsonStore() {
|
||||
if (preset == 1) {
|
||||
direct_ip =
|
||||
"geoip:cn\n"
|
||||
"geoip:private";
|
||||
direct_domain = "geosite:cn";
|
||||
proxy_ip = "";
|
||||
proxy_domain = "";
|
||||
block_ip = "";
|
||||
block_domain =
|
||||
"geosite:category-ads-all\n"
|
||||
"domain:appcenter.ms\n"
|
||||
"domain:app-measurement.com\n"
|
||||
"domain:firebase.io\n"
|
||||
"domain:crashlytics.com\n"
|
||||
"domain:google-analytics.com";
|
||||
}
|
||||
_add(new configItem("direct_ip", &this->direct_ip, itemType::string));
|
||||
_add(new configItem("direct_domain", &this->direct_domain, itemType::string));
|
||||
_add(new configItem("proxy_ip", &this->proxy_ip, itemType::string));
|
||||
_add(new configItem("proxy_domain", &this->proxy_domain, itemType::string));
|
||||
_add(new configItem("block_ip", &this->block_ip, itemType::string));
|
||||
_add(new configItem("block_domain", &this->block_domain, itemType::string));
|
||||
_add(new configItem("def_outbound", &this->def_outbound, itemType::string));
|
||||
_add(new configItem("custom", &this->custom, itemType::string));
|
||||
//
|
||||
_add(new configItem("remote_dns", &this->remote_dns, itemType::string));
|
||||
_add(new configItem("remote_dns_strategy", &this->remote_dns_strategy, itemType::string));
|
||||
_add(new configItem("direct_dns", &this->direct_dns, itemType::string));
|
||||
_add(new configItem("direct_dns_strategy", &this->direct_dns_strategy, itemType::string));
|
||||
_add(new configItem("domain_strategy", &this->domain_strategy, itemType::string));
|
||||
_add(new configItem("outbound_domain_strategy", &this->outbound_domain_strategy, itemType::string));
|
||||
_add(new configItem("dns_routing", &this->dns_routing, itemType::boolean));
|
||||
_add(new configItem("sniffing_mode", &this->sniffing_mode, itemType::integer));
|
||||
_add(new configItem("use_dns_object", &this->use_dns_object, itemType::boolean));
|
||||
_add(new configItem("dns_object", &this->dns_object, itemType::string));
|
||||
}
|
||||
|
||||
QString Routing::DisplayRouting() const {
|
||||
return QString("[Proxy] %1\n[Proxy] %2\n[Direct] %3\n[Direct] %4\n[Block] %5\n[Block] %6\n[Default Outbound] %7\n[DNS] %8")
|
||||
.arg(SplitLinesSkipSharp(proxy_domain).join(","))
|
||||
.arg(SplitLinesSkipSharp(proxy_ip).join(","))
|
||||
.arg(SplitLinesSkipSharp(direct_domain).join(","))
|
||||
.arg(SplitLinesSkipSharp(direct_ip).join(","))
|
||||
.arg(SplitLinesSkipSharp(block_domain).join(","))
|
||||
.arg(SplitLinesSkipSharp(block_ip).join(","))
|
||||
.arg(def_outbound)
|
||||
.arg(use_dns_object ? "DNS Object" : "Simple DNS");
|
||||
}
|
||||
|
||||
QStringList Routing::List() {
|
||||
QStringList l;
|
||||
QDir d;
|
||||
if (d.exists(ROUTES_PREFIX)) {
|
||||
QDir dr(ROUTES_PREFIX);
|
||||
return dr.entryList(QDir::Files);
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
void Routing::SetToActive(const QString &name) {
|
||||
NekoGui::dataStore->routing->fn = ROUTES_PREFIX + name;
|
||||
NekoGui::dataStore->routing->Load();
|
||||
NekoGui::dataStore->active_routing = name;
|
||||
NekoGui::dataStore->Save();
|
||||
}
|
||||
|
||||
// NO default extra core
|
||||
|
||||
ExtraCore::ExtraCore() : JsonStore() {
|
||||
_add(new configItem("core_map", &this->core_map, itemType::string));
|
||||
}
|
||||
|
||||
QString ExtraCore::Get(const QString &id) const {
|
||||
auto obj = QString2QJsonObject(core_map);
|
||||
for (const auto &c: obj.keys()) {
|
||||
if (c == id) return obj[id].toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
void ExtraCore::Set(const QString &id, const QString &path) {
|
||||
auto obj = QString2QJsonObject(core_map);
|
||||
obj[id] = path;
|
||||
core_map = QJsonObject2QString(obj, true);
|
||||
}
|
||||
|
||||
void ExtraCore::Delete(const QString &id) {
|
||||
auto obj = QString2QJsonObject(core_map);
|
||||
obj.remove(id);
|
||||
core_map = QJsonObject2QString(obj, true);
|
||||
}
|
||||
|
||||
InboundAuthorization::InboundAuthorization() : JsonStore() {
|
||||
_add(new configItem("user", &this->username, itemType::string));
|
||||
_add(new configItem("pass", &this->password, itemType::string));
|
||||
}
|
||||
|
||||
bool InboundAuthorization::NeedAuth() const {
|
||||
return !username.trimmed().isEmpty() && !password.trimmed().isEmpty();
|
||||
}
|
||||
|
||||
QString FindCoreAsset(const QString &name) {
|
||||
QStringList search{dataStore->v2ray_asset_dir};
|
||||
QStringList search{NekoGui::dataStore->v2ray_asset_dir};
|
||||
search << QApplication::applicationDirPath();
|
||||
search << "/usr/share/v2ray";
|
||||
search << "/usr/local/share/v2ray";
|
||||
@@ -422,7 +423,7 @@ namespace NekoRay {
|
||||
bool isAdmin() {
|
||||
if (isAdminCache >= 0) return isAdminCache;
|
||||
|
||||
auto admin = NekoRay::dataStore->flag_linux_run_core_as_admin;
|
||||
auto admin = NekoGui::dataStore->flag_linux_run_core_as_admin;
|
||||
#ifdef Q_OS_WIN
|
||||
admin = Windows_IsInAdmin();
|
||||
#else
|
||||
@@ -433,4 +434,4 @@ namespace NekoRay {
|
||||
return admin;
|
||||
};
|
||||
|
||||
} // namespace NekoRay
|
||||
} // namespace NekoGui
|
||||
21
main/NekoGui.hpp
Normal file
21
main/NekoGui.hpp
Normal 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 + "/")
|
||||
@@ -1,6 +1,6 @@
|
||||
// DO NOT INCLUDE THIS
|
||||
|
||||
namespace NekoRay {
|
||||
namespace NekoGui_ConfigItem {
|
||||
// config 工具
|
||||
enum itemType {
|
||||
string,
|
||||
@@ -28,7 +28,7 @@ namespace NekoRay {
|
||||
// 可格式化对象
|
||||
class JsonStore {
|
||||
public:
|
||||
QMap<QString, QSharedPointer<configItem>> _map;
|
||||
QMap<QString, std::shared_ptr<configItem>> _map;
|
||||
|
||||
std::function<void()> callback_after_load = nullptr;
|
||||
std::function<void()> callback_before_save = nullptr;
|
||||
@@ -49,7 +49,7 @@ namespace NekoRay {
|
||||
|
||||
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);
|
||||
|
||||
@@ -65,4 +65,6 @@ namespace NekoRay {
|
||||
|
||||
bool Load();
|
||||
};
|
||||
} // namespace NekoRay
|
||||
} // namespace NekoGui_ConfigItem
|
||||
|
||||
using namespace NekoGui_ConfigItem;
|
||||
@@ -1,6 +1,6 @@
|
||||
// DO NOT INCLUDE THIS
|
||||
|
||||
namespace NekoRay {
|
||||
namespace NekoGui {
|
||||
|
||||
class Routing : public JsonStore {
|
||||
public:
|
||||
@@ -175,4 +175,4 @@ namespace NekoRay {
|
||||
|
||||
extern DataStore *dataStore;
|
||||
|
||||
} // namespace NekoRay
|
||||
} // namespace NekoGui
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "NekoRay_Utils.hpp"
|
||||
#include "NekoGui_Utils.hpp"
|
||||
|
||||
#include "3rdparty/base64.h"
|
||||
#include "3rdparty/QThreadCreateThread.hpp"
|
||||
@@ -189,7 +189,7 @@ bool IsIpAddressV6(const QString &str) {
|
||||
|
||||
QString DisplayTime(long long time, int formatType) {
|
||||
QDateTime t;
|
||||
t.setSecsSinceEpoch(time);
|
||||
t.setMSecsSinceEpoch(time * 1000);
|
||||
return QLocale().toString(t, QLocale::FormatType(formatType));
|
||||
}
|
||||
|
||||
@@ -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 + "/")
|
||||
10
main/QJS.cpp
10
main/QJS.cpp
@@ -5,9 +5,9 @@
|
||||
#endif
|
||||
|
||||
#include "3rdparty/qjs/nekoray_qjs.h"
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
namespace NekoRay::qjs {
|
||||
namespace qjs {
|
||||
#ifndef NKR_NO_QUICKJS
|
||||
namespace exception {
|
||||
static void js_dump_obj(JSContext *ctx, QString &out, JSValueConst val) {
|
||||
@@ -80,7 +80,7 @@ namespace NekoRay::qjs {
|
||||
this->neko_ctx = malloc(sizeof(nekoray_qjs_context));
|
||||
nekoray_qjs_new_arg arg;
|
||||
arg.neko_ctx = NEKO_CTX;
|
||||
arg.enable_std = NekoRay::dataStore->enable_js_hook == 2 ? 1 : 0;
|
||||
arg.enable_std = NekoGui::dataStore->enable_js_hook == 2 ? 1 : 0;
|
||||
arg.func_log = func_log;
|
||||
nekoray_qjs_new(arg);
|
||||
#endif
|
||||
@@ -139,10 +139,10 @@ namespace NekoRay::qjs {
|
||||
|
||||
QByteArray ReadHookJS() {
|
||||
#ifndef NKR_NO_QUICKJS
|
||||
if (NekoRay::dataStore->enable_js_hook > 0) {
|
||||
if (NekoGui::dataStore->enable_js_hook > 0) {
|
||||
return ReadFile(QString("./hook.%1.js").arg(software_name.toLower()));
|
||||
}
|
||||
#endif
|
||||
return {};
|
||||
}
|
||||
} // namespace NekoRay::qjs
|
||||
} // namespace qjs
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
class QByteArray;
|
||||
class QString;
|
||||
|
||||
namespace NekoRay::qjs {
|
||||
namespace qjs {
|
||||
class QJS {
|
||||
public:
|
||||
QJS();
|
||||
@@ -20,4 +20,4 @@ namespace NekoRay::qjs {
|
||||
};
|
||||
|
||||
QByteArray ReadHookJS();
|
||||
} // namespace NekoRay::qjs
|
||||
} // namespace qjs
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
#include <QThread>
|
||||
|
||||
#include "3rdparty/RunGuard.hpp"
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
#include "ui/mainwindow_interface.h"
|
||||
#include "ui/dialog_first_setup.h"
|
||||
@@ -58,10 +58,12 @@ int main(int argc, char* argv[]) {
|
||||
#endif
|
||||
|
||||
// pre-init QApplication
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) && QT_VERSION >= QT_VERSION_CHECK(5, 10, 0)
|
||||
QApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);
|
||||
#endif
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(5, 7, 0)
|
||||
QApplication::setAttribute(Qt::AA_DontUseNativeDialogs);
|
||||
#endif
|
||||
QApplication::setQuitOnLastWindowClosed(false);
|
||||
auto preQApp = new QApplication(argc, argv);
|
||||
|
||||
@@ -77,31 +79,31 @@ int main(int argc, char* argv[]) {
|
||||
#endif
|
||||
|
||||
// Flags
|
||||
NekoRay::dataStore->argv = QApplication::arguments();
|
||||
if (NekoRay::dataStore->argv.contains("-many")) NekoRay::dataStore->flag_many = true;
|
||||
if (NekoRay::dataStore->argv.contains("-appdata")) {
|
||||
NekoRay::dataStore->flag_use_appdata = true;
|
||||
int appdataIndex = NekoRay::dataStore->argv.indexOf("-appdata");
|
||||
if (NekoRay::dataStore->argv.size() > appdataIndex + 1 && !NekoRay::dataStore->argv.at(appdataIndex + 1).startsWith("-")) {
|
||||
NekoRay::dataStore->appdataDir = NekoRay::dataStore->argv.at(appdataIndex + 1);
|
||||
NekoGui::dataStore->argv = QApplication::arguments();
|
||||
if (NekoGui::dataStore->argv.contains("-many")) NekoGui::dataStore->flag_many = true;
|
||||
if (NekoGui::dataStore->argv.contains("-appdata")) {
|
||||
NekoGui::dataStore->flag_use_appdata = true;
|
||||
int appdataIndex = NekoGui::dataStore->argv.indexOf("-appdata");
|
||||
if (NekoGui::dataStore->argv.size() > appdataIndex + 1 && !NekoGui::dataStore->argv.at(appdataIndex + 1).startsWith("-")) {
|
||||
NekoGui::dataStore->appdataDir = NekoGui::dataStore->argv.at(appdataIndex + 1);
|
||||
}
|
||||
}
|
||||
if (NekoRay::dataStore->argv.contains("-tray")) NekoRay::dataStore->flag_tray = true;
|
||||
if (NekoRay::dataStore->argv.contains("-debug")) NekoRay::dataStore->flag_debug = true;
|
||||
if (NekoRay::dataStore->argv.contains("-flag_linux_run_core_as_admin")) NekoRay::dataStore->flag_linux_run_core_as_admin = true;
|
||||
if (NekoGui::dataStore->argv.contains("-tray")) NekoGui::dataStore->flag_tray = true;
|
||||
if (NekoGui::dataStore->argv.contains("-debug")) NekoGui::dataStore->flag_debug = true;
|
||||
if (NekoGui::dataStore->argv.contains("-flag_linux_run_core_as_admin")) NekoGui::dataStore->flag_linux_run_core_as_admin = true;
|
||||
#ifdef NKR_CPP_USE_APPDATA
|
||||
NekoRay::dataStore->flag_use_appdata = true; // Example: Package & MacOS
|
||||
NekoGui::dataStore->flag_use_appdata = true; // Example: Package & MacOS
|
||||
#endif
|
||||
#ifdef NKR_CPP_DEBUG
|
||||
NekoRay::dataStore->flag_debug = true;
|
||||
NekoGui::dataStore->flag_debug = true;
|
||||
#endif
|
||||
|
||||
// dirs & clean
|
||||
auto wd = QDir(QApplication::applicationDirPath());
|
||||
if (NekoRay::dataStore->flag_use_appdata) {
|
||||
if (NekoGui::dataStore->flag_use_appdata) {
|
||||
QApplication::setApplicationName("nekoray");
|
||||
if (!NekoRay::dataStore->appdataDir.isEmpty()) {
|
||||
wd.setPath(NekoRay::dataStore->appdataDir);
|
||||
if (!NekoGui::dataStore->appdataDir.isEmpty()) {
|
||||
wd.setPath(NekoGui::dataStore->appdataDir);
|
||||
} else {
|
||||
wd.setPath(QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation));
|
||||
}
|
||||
@@ -111,13 +113,6 @@ int main(int argc, char* argv[]) {
|
||||
QDir::setCurrent(wd.absoluteFilePath("config"));
|
||||
QDir("temp").removeRecursively();
|
||||
|
||||
// HiDPI workaround
|
||||
// Mainly for Windows, not required in Qt6
|
||||
if (ReadFileText("./groups/HiDPI").toInt() == 1) {
|
||||
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
||||
}
|
||||
|
||||
// init QApplication
|
||||
delete preQApp;
|
||||
QApplication a(argc, argv);
|
||||
@@ -130,7 +125,7 @@ int main(int argc, char* argv[]) {
|
||||
RunGuard guard("nekoray" + wd.absolutePath());
|
||||
quint64 guard_data_in = GetRandomUint64();
|
||||
quint64 guard_data_out = 0;
|
||||
if (!NekoRay::dataStore->flag_many && !guard.tryToRun(&guard_data_in)) {
|
||||
if (!NekoGui::dataStore->flag_many && !guard.tryToRun(&guard_data_in)) {
|
||||
// Some Good System
|
||||
if (guard.isAnotherRunning(&guard_data_out)) {
|
||||
// Wake up a running instance
|
||||
@@ -151,10 +146,17 @@ int main(int argc, char* argv[]) {
|
||||
MF_release_runguard = [&] { guard.release(); };
|
||||
|
||||
// icons
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
||||
QIcon::setFallbackSearchPaths(QStringList{
|
||||
":/nekoray",
|
||||
":/icon",
|
||||
});
|
||||
#else
|
||||
QIcon::setThemeSearchPaths(QStringList{
|
||||
":/nekoray",
|
||||
":/icon",
|
||||
});
|
||||
#endif
|
||||
|
||||
// icon for no theme
|
||||
if (QIcon::themeName().isEmpty()) {
|
||||
@@ -164,23 +166,23 @@ int main(int argc, char* argv[]) {
|
||||
// Load coreType
|
||||
auto coreLoaded = ReadFileText("groups/coreType");
|
||||
if (coreLoaded.isEmpty()) {
|
||||
NekoRay::coreType = -1;
|
||||
NekoGui::coreType = -1;
|
||||
loadTranslate(QLocale().name());
|
||||
auto dialogFirstSetup = new DialogFirstSetup;
|
||||
dialogFirstSetup->exec();
|
||||
dialogFirstSetup->deleteLater();
|
||||
if (NekoRay::coreType < 0) {
|
||||
if (NekoGui::coreType < 0) {
|
||||
return 0;
|
||||
} else {
|
||||
QDir().mkdir("groups");
|
||||
QFile file;
|
||||
file.setFileName("groups/coreType");
|
||||
file.open(QIODevice::ReadWrite | QIODevice::Truncate);
|
||||
file.write(Int2String(NekoRay::coreType).toUtf8());
|
||||
file.write(Int2String(NekoGui::coreType).toUtf8());
|
||||
file.close();
|
||||
}
|
||||
} else {
|
||||
NekoRay::coreType = coreLoaded.toInt();
|
||||
NekoGui::coreType = coreLoaded.toInt();
|
||||
}
|
||||
|
||||
// Dir
|
||||
@@ -201,35 +203,35 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
|
||||
// Load dataStore
|
||||
switch (NekoRay::coreType) {
|
||||
case NekoRay::CoreType::V2RAY:
|
||||
NekoRay::dataStore->fn = "groups/nekoray.json";
|
||||
switch (NekoGui::coreType) {
|
||||
case NekoGui::CoreType::V2RAY:
|
||||
NekoGui::dataStore->fn = "groups/nekoray.json";
|
||||
break;
|
||||
case NekoRay::CoreType::SING_BOX:
|
||||
NekoRay::dataStore->fn = "groups/nekobox.json";
|
||||
case NekoGui::CoreType::SING_BOX:
|
||||
NekoGui::dataStore->fn = "groups/nekobox.json";
|
||||
break;
|
||||
default:
|
||||
MessageBoxWarning("Error", "Unknown coreType.");
|
||||
return 0;
|
||||
}
|
||||
auto isLoaded = NekoRay::dataStore->Load();
|
||||
auto isLoaded = NekoGui::dataStore->Load();
|
||||
if (!isLoaded) {
|
||||
NekoRay::dataStore->Save();
|
||||
NekoGui::dataStore->Save();
|
||||
}
|
||||
|
||||
// Datastore & Flags
|
||||
if (NekoRay::dataStore->start_minimal) NekoRay::dataStore->flag_tray = true;
|
||||
if (NekoGui::dataStore->start_minimal) NekoGui::dataStore->flag_tray = true;
|
||||
|
||||
// load routing
|
||||
NekoRay::dataStore->routing->fn = ROUTES_PREFIX + NekoRay::dataStore->active_routing;
|
||||
isLoaded = NekoRay::dataStore->routing->Load();
|
||||
NekoGui::dataStore->routing->fn = ROUTES_PREFIX + NekoGui::dataStore->active_routing;
|
||||
isLoaded = NekoGui::dataStore->routing->Load();
|
||||
if (!isLoaded) {
|
||||
NekoRay::dataStore->routing->Save();
|
||||
NekoGui::dataStore->routing->Save();
|
||||
}
|
||||
|
||||
// Translate
|
||||
QString locale;
|
||||
switch (NekoRay::dataStore->language) {
|
||||
switch (NekoGui::dataStore->language) {
|
||||
case 1: // English
|
||||
break;
|
||||
case 2:
|
||||
@@ -262,13 +264,13 @@ int main(int argc, char* argv[]) {
|
||||
});
|
||||
|
||||
// Do preset update
|
||||
if (NekoRay::dataStore->user_agent.isEmpty() || NekoRay::dataStore->user_agent.startsWith("Nekoray/1.0") || NekoRay::dataStore->user_agent.startsWith("ClashForAndroid")) {
|
||||
if (NekoGui::dataStore->user_agent.isEmpty() || NekoGui::dataStore->user_agent.startsWith("Nekoray/1.0") || NekoGui::dataStore->user_agent.startsWith("ClashForAndroid")) {
|
||||
if (IS_NEKO_BOX) {
|
||||
NekoRay::dataStore->user_agent = "NekoBox/PC/2.0 (Prefer ClashMeta Format)";
|
||||
NekoGui::dataStore->user_agent = "NekoBox/PC/2.0 (Prefer ClashMeta Format)";
|
||||
} else {
|
||||
NekoRay::dataStore->user_agent = "NekoRay/PC/2.0 (Prefer ClashMeta Format)";
|
||||
NekoGui::dataStore->user_agent = "NekoRay/PC/2.0 (Prefer ClashMeta Format)";
|
||||
}
|
||||
NekoRay::dataStore->Save();
|
||||
NekoGui::dataStore->Save();
|
||||
}
|
||||
|
||||
UI_InitMainWindow();
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#ifndef NKR_NO_GRPC
|
||||
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QNetworkAccessManager>
|
||||
@@ -166,7 +166,7 @@ namespace QtGrpc {
|
||||
QNetworkReply::NetworkError Call(const QString &methodName,
|
||||
const google::protobuf::Message &req, google::protobuf::Message *rsp,
|
||||
int timeout_ms = 0) {
|
||||
if (!NekoRay::dataStore->core_running) return QNetworkReply::NetworkError(-1919);
|
||||
if (!NekoGui::dataStore->core_running) return QNetworkReply::NetworkError(-1919);
|
||||
|
||||
std::string reqStr;
|
||||
req.SerializeToString(&reqStr);
|
||||
@@ -200,7 +200,7 @@ namespace QtGrpc {
|
||||
};
|
||||
} // namespace QtGrpc
|
||||
|
||||
namespace NekoRay::rpc {
|
||||
namespace NekoGui_rpc {
|
||||
|
||||
Client::Client(std::function<void(const QString &)> onError, const QString &target, const QString &token) {
|
||||
this->make_grpc_channel = [=]() { return std::make_unique<QtGrpc::Http2GrpcChannelPrivate>(target, token, "libcore.LibcoreService"); };
|
||||
@@ -299,6 +299,6 @@ namespace NekoRay::rpc {
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
} // namespace NekoRay::rpc
|
||||
} // namespace NekoGui_rpc
|
||||
|
||||
#endif
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace QtGrpc {
|
||||
class Http2GrpcChannelPrivate;
|
||||
}
|
||||
|
||||
namespace NekoRay::rpc {
|
||||
namespace NekoGui_rpc {
|
||||
class Client {
|
||||
public:
|
||||
explicit Client(std::function<void(const QString &)> onError, const QString &target, const QString &token);
|
||||
@@ -39,5 +39,5 @@ namespace NekoRay::rpc {
|
||||
};
|
||||
|
||||
inline Client *defaultClient;
|
||||
} // namespace NekoRay::rpc
|
||||
} // namespace NekoGui_rpc
|
||||
#endif
|
||||
|
||||
@@ -16,13 +16,13 @@
|
||||
|
||||
#endif
|
||||
|
||||
namespace NekoRay::sub {
|
||||
namespace NekoGui_sub {
|
||||
|
||||
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;
|
||||
auto stream = fmt::GetStreamSettings(ent->bean.get());
|
||||
auto stream = NekoGui_fmt::GetStreamSettings(ent->bean.get());
|
||||
if (stream == nullptr) return;
|
||||
// 1. "security"
|
||||
if (stream->security == "none" || stream->security == "0" || stream->security == "false") {
|
||||
@@ -58,7 +58,7 @@ namespace NekoRay::sub {
|
||||
return;
|
||||
}
|
||||
|
||||
QSharedPointer<ProxyEntity> ent;
|
||||
std::shared_ptr<NekoGui::ProxyEntity> ent;
|
||||
bool needFix = true;
|
||||
|
||||
// Nekoray format
|
||||
@@ -66,7 +66,7 @@ namespace NekoRay::sub {
|
||||
needFix = false;
|
||||
auto link = QUrl(str);
|
||||
if (!link.isValid()) return;
|
||||
ent = ProfileManager::NewProxyEntity(link.host());
|
||||
ent = NekoGui::ProfileManager::NewProxyEntity(link.host());
|
||||
if (ent->bean->version == -114514) return;
|
||||
auto j = DecodeB64IfValid(link.fragment().toUtf8(), QByteArray::Base64UrlEncoding);
|
||||
if (j.isEmpty()) return;
|
||||
@@ -77,42 +77,42 @@ namespace NekoRay::sub {
|
||||
// SOCKS
|
||||
if (str.startsWith("socks5://") || str.startsWith("socks4://") ||
|
||||
str.startsWith("socks4a://") || str.startsWith("socks://")) {
|
||||
ent = ProfileManager::NewProxyEntity("socks");
|
||||
ent = NekoGui::ProfileManager::NewProxyEntity("socks");
|
||||
auto ok = ent->SocksHTTPBean()->TryParseLink(str);
|
||||
if (!ok) return;
|
||||
}
|
||||
|
||||
// HTTP
|
||||
if (str.startsWith("http://") || str.startsWith("https://")) {
|
||||
ent = ProfileManager::NewProxyEntity("http");
|
||||
ent = NekoGui::ProfileManager::NewProxyEntity("http");
|
||||
auto ok = ent->SocksHTTPBean()->TryParseLink(str);
|
||||
if (!ok) return;
|
||||
}
|
||||
|
||||
// ShadowSocks
|
||||
if (str.startsWith("ss://")) {
|
||||
ent = ProfileManager::NewProxyEntity("shadowsocks");
|
||||
ent = NekoGui::ProfileManager::NewProxyEntity("shadowsocks");
|
||||
auto ok = ent->ShadowSocksBean()->TryParseLink(str);
|
||||
if (!ok) return;
|
||||
}
|
||||
|
||||
// VMess
|
||||
if (str.startsWith("vmess://")) {
|
||||
ent = ProfileManager::NewProxyEntity("vmess");
|
||||
ent = NekoGui::ProfileManager::NewProxyEntity("vmess");
|
||||
auto ok = ent->VMessBean()->TryParseLink(str);
|
||||
if (!ok) return;
|
||||
}
|
||||
|
||||
// VLESS
|
||||
if (str.startsWith("vless://")) {
|
||||
ent = ProfileManager::NewProxyEntity("vless");
|
||||
ent = NekoGui::ProfileManager::NewProxyEntity("vless");
|
||||
auto ok = ent->TrojanVLESSBean()->TryParseLink(str);
|
||||
if (!ok) return;
|
||||
}
|
||||
|
||||
// Trojan
|
||||
if (str.startsWith("trojan://")) {
|
||||
ent = ProfileManager::NewProxyEntity("trojan");
|
||||
ent = NekoGui::ProfileManager::NewProxyEntity("trojan");
|
||||
auto ok = ent->TrojanVLESSBean()->TryParseLink(str);
|
||||
if (!ok) return;
|
||||
}
|
||||
@@ -120,7 +120,7 @@ namespace NekoRay::sub {
|
||||
// Naive
|
||||
if (str.startsWith("naive+")) {
|
||||
needFix = false;
|
||||
ent = ProfileManager::NewProxyEntity("naive");
|
||||
ent = NekoGui::ProfileManager::NewProxyEntity("naive");
|
||||
auto ok = ent->NaiveBean()->TryParseLink(str);
|
||||
if (!ok) return;
|
||||
}
|
||||
@@ -128,7 +128,7 @@ namespace NekoRay::sub {
|
||||
// Hysteria
|
||||
if (str.startsWith("hysteria://")) {
|
||||
needFix = false;
|
||||
ent = ProfileManager::NewProxyEntity("hysteria");
|
||||
ent = NekoGui::ProfileManager::NewProxyEntity("hysteria");
|
||||
auto ok = ent->HysteriaBean()->TryParseLink(str);
|
||||
if (!ok) return;
|
||||
}
|
||||
@@ -139,7 +139,7 @@ namespace NekoRay::sub {
|
||||
if (needFix) RawUpdater_FixEnt(ent);
|
||||
|
||||
// End
|
||||
profileManager->AddProfile(ent, gid_add_to);
|
||||
NekoGui::profileManager->AddProfile(ent, gid_add_to);
|
||||
update_counter++;
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ namespace NekoRay::sub {
|
||||
if (type == "ss" || type == "ssr") type = "shadowsocks";
|
||||
if (type == "socks5") type = "socks";
|
||||
|
||||
auto ent = ProfileManager::NewProxyEntity(type);
|
||||
auto ent = NekoGui::ProfileManager::NewProxyEntity(type);
|
||||
if (ent->bean->version == -114514) continue;
|
||||
bool needFix = false;
|
||||
|
||||
@@ -372,11 +372,11 @@ namespace NekoRay::sub {
|
||||
auto auth_str = FIRST_OR_SECOND(Node2QString(proxy["auth_str"]), Node2QString(proxy["auth-str"]));
|
||||
auto auth = Node2QString(proxy["auth"]);
|
||||
if (!auth_str.isEmpty()) {
|
||||
bean->authPayloadType = fmt::HysteriaBean::hysteria_auth_string;
|
||||
bean->authPayloadType = NekoGui_fmt::HysteriaBean::hysteria_auth_string;
|
||||
bean->authPayload = auth_str;
|
||||
}
|
||||
if (!auth.isEmpty()) {
|
||||
bean->authPayloadType = fmt::HysteriaBean::hysteria_auth_base64;
|
||||
bean->authPayloadType = NekoGui_fmt::HysteriaBean::hysteria_auth_base64;
|
||||
bean->authPayload = auth;
|
||||
}
|
||||
|
||||
@@ -393,7 +393,7 @@ namespace NekoRay::sub {
|
||||
}
|
||||
|
||||
if (needFix) RawUpdater_FixEnt(ent);
|
||||
profileManager->AddProfile(ent, gid_add_to);
|
||||
NekoGui::profileManager->AddProfile(ent, gid_add_to);
|
||||
update_counter++;
|
||||
}
|
||||
} catch (const YAML::Exception &ex) {
|
||||
@@ -429,10 +429,10 @@ namespace NekoRay::sub {
|
||||
runOnNewThread([=] {
|
||||
auto gid = _sub_gid;
|
||||
if (createNewGroup) {
|
||||
auto group = ProfileManager::NewGroup();
|
||||
auto group = NekoGui::ProfileManager::NewGroup();
|
||||
group->name = QUrl(str).host();
|
||||
group->url = str;
|
||||
profileManager->AddGroup(group);
|
||||
NekoGui::profileManager->AddGroup(group);
|
||||
gid = group->id;
|
||||
MW_dialog_message("SubUpdater", "NewGroup");
|
||||
}
|
||||
@@ -444,7 +444,7 @@ namespace NekoRay::sub {
|
||||
|
||||
void GroupUpdater::Update(const QString &_str, int _sub_gid, bool _not_sub_as_url) {
|
||||
// 创建 rawUpdater
|
||||
NekoRay::dataStore->imported_count = 0;
|
||||
NekoGui::dataStore->imported_count = 0;
|
||||
auto rawUpdater = std::make_unique<RawUpdater>();
|
||||
rawUpdater->gid_add_to = _sub_gid;
|
||||
|
||||
@@ -452,7 +452,7 @@ namespace NekoRay::sub {
|
||||
QString sub_user_info;
|
||||
bool asURL = _sub_gid >= 0 || _not_sub_as_url; // 把 _str 当作 url 处理(下载内容)
|
||||
auto content = _str.trimmed();
|
||||
auto group = profileManager->GetGroup(_sub_gid);
|
||||
auto group = NekoGui::profileManager->GetGroup(_sub_gid);
|
||||
if (group != nullptr && group->archive) return;
|
||||
|
||||
// 网络请求
|
||||
@@ -472,25 +472,25 @@ namespace NekoRay::sub {
|
||||
MW_show_log("<<<<<<<< " + QObject::tr("Subscription request fininshed: %1").arg(groupName));
|
||||
}
|
||||
|
||||
QList<QSharedPointer<ProxyEntity>> in; // 更新前
|
||||
QList<QSharedPointer<ProxyEntity>> out_all; // 更新前 + 更新后
|
||||
QList<QSharedPointer<ProxyEntity>> out; // 更新后
|
||||
QList<QSharedPointer<ProxyEntity>> only_in; // 只在更新前有的
|
||||
QList<QSharedPointer<ProxyEntity>> only_out; // 只在更新后有的
|
||||
QList<QSharedPointer<ProxyEntity>> update_del; // 更新前后都有的,删除更新后多余的
|
||||
QList<std::shared_ptr<NekoGui::ProxyEntity>> in; // 更新前
|
||||
QList<std::shared_ptr<NekoGui::ProxyEntity>> out_all; // 更新前 + 更新后
|
||||
QList<std::shared_ptr<NekoGui::ProxyEntity>> out; // 更新后
|
||||
QList<std::shared_ptr<NekoGui::ProxyEntity>> only_in; // 只在更新前有的
|
||||
QList<std::shared_ptr<NekoGui::ProxyEntity>> only_out; // 只在更新后有的
|
||||
QList<std::shared_ptr<NekoGui::ProxyEntity>> update_del; // 更新前后都有的,删除更新后多余的
|
||||
|
||||
// 订阅解析前
|
||||
if (group != nullptr) {
|
||||
in = group->Profiles();
|
||||
group->last_update = QDateTime::currentSecsSinceEpoch();
|
||||
group->sub_last_update = QDateTime::currentMSecsSinceEpoch() / 1000;
|
||||
group->info = sub_user_info;
|
||||
group->order.clear();
|
||||
group->Save();
|
||||
//
|
||||
if (dataStore->sub_clear) {
|
||||
if (NekoGui::dataStore->sub_clear) {
|
||||
MW_show_log(QObject::tr("Clearing servers..."));
|
||||
for (const auto &profile: in) {
|
||||
profileManager->DeleteProfile(profile->id);
|
||||
NekoGui::profileManager->DeleteProfile(profile->id);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -512,15 +512,15 @@ namespace NekoRay::sub {
|
||||
if (group != nullptr) {
|
||||
out_all = group->Profiles();
|
||||
|
||||
ProfileFilter::OnlyInSrc_ByPointer(out_all, in, out);
|
||||
ProfileFilter::OnlyInSrc(in, out, only_in);
|
||||
ProfileFilter::OnlyInSrc(out, in, only_out);
|
||||
ProfileFilter::Common(in, out, update_del, false, true);
|
||||
NekoGui::ProfileFilter::OnlyInSrc_ByPointer(out_all, in, out);
|
||||
NekoGui::ProfileFilter::OnlyInSrc(in, out, only_in);
|
||||
NekoGui::ProfileFilter::OnlyInSrc(out, in, only_out);
|
||||
NekoGui::ProfileFilter::Common(in, out, update_del, false, true);
|
||||
update_del += only_in;
|
||||
if (dataStore->sub_clear) update_del = {};
|
||||
if (NekoGui::dataStore->sub_clear) update_del = {};
|
||||
|
||||
for (const auto &ent: update_del) {
|
||||
profileManager->DeleteProfile(ent->id);
|
||||
NekoGui::profileManager->DeleteProfile(ent->id);
|
||||
}
|
||||
|
||||
QString notice_added;
|
||||
@@ -541,8 +541,8 @@ namespace NekoRay::sub {
|
||||
MW_show_log("<<<<<<<< " + QObject::tr("Change of %1:").arg(group->name) + " " + change);
|
||||
MW_dialog_message("SubUpdater", "finish-dingyue");
|
||||
} else {
|
||||
NekoRay::dataStore->imported_count = rawUpdater->update_counter;
|
||||
NekoGui::dataStore->imported_count = rawUpdater->update_counter;
|
||||
MW_dialog_message("SubUpdater", "finish");
|
||||
}
|
||||
}
|
||||
} // namespace NekoRay::sub
|
||||
} // namespace NekoGui_sub
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace NekoRay::sub {
|
||||
namespace NekoGui_sub {
|
||||
class RawUpdater {
|
||||
public:
|
||||
void updateClash(const QString &str);
|
||||
@@ -28,4 +28,4 @@ namespace NekoRay::sub {
|
||||
};
|
||||
|
||||
extern GroupUpdater *groupUpdater;
|
||||
} // namespace NekoRay::sub
|
||||
} // namespace NekoGui_sub
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
#include <QApplication>
|
||||
#include <QDir>
|
||||
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "3rdparty/fix_old_qt.h"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
// macOS headers (possibly OBJ-c)
|
||||
#if defined(Q_OS_MACOS)
|
||||
@@ -178,7 +179,7 @@ void AutoRun_SetEnabled(bool enable) {
|
||||
|
||||
appCmdList << "-tray";
|
||||
|
||||
if (NekoRay::dataStore->flag_use_appdata) {
|
||||
if (NekoGui::dataStore->flag_use_appdata) {
|
||||
appCmdList << "-appdata";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#include "ExternalProcess.hpp"
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QDir>
|
||||
#include <QApplication>
|
||||
#include <QElapsedTimer>
|
||||
|
||||
namespace NekoRay::sys {
|
||||
namespace NekoGui_sys {
|
||||
|
||||
ExternalProcess::ExternalProcess() : QProcess() {
|
||||
// qDebug() << "[Debug] ExternalProcess()" << this << running_ext;
|
||||
@@ -24,7 +24,7 @@ namespace NekoRay::sys {
|
||||
if (managed) {
|
||||
connect(this, &QProcess::readyReadStandardOutput, this, [&]() {
|
||||
auto log = readAllStandardOutput();
|
||||
if (logCounter.fetchAndAddRelaxed(log.count("\n")) > NekoRay::dataStore->max_log_line) return;
|
||||
if (logCounter.fetchAndAddRelaxed(log.count("\n")) > NekoGui::dataStore->max_log_line) return;
|
||||
MW_show_log_ext_vt100(log);
|
||||
});
|
||||
connect(this, &QProcess::readyReadStandardError, this, [&]() {
|
||||
@@ -54,7 +54,7 @@ namespace NekoRay::sys {
|
||||
|
||||
QProcess::setEnvironment(env);
|
||||
|
||||
if (NekoRay::dataStore->flag_linux_run_core_as_admin && dynamic_cast<CoreProcess *>(this) && program != "pkexec") {
|
||||
if (NekoGui::dataStore->flag_linux_run_core_as_admin && dynamic_cast<CoreProcess *>(this) && program != "pkexec") {
|
||||
arguments.prepend(program);
|
||||
arguments.prepend("--keep-cwd");
|
||||
program = "pkexec";
|
||||
@@ -85,10 +85,10 @@ namespace NekoRay::sys {
|
||||
|
||||
connect(this, &QProcess::readyReadStandardOutput, this, [&]() {
|
||||
auto log = readAllStandardOutput();
|
||||
if (!NekoRay::dataStore->core_running) {
|
||||
if (!NekoGui::dataStore->core_running) {
|
||||
if (log.contains("grpc server listening")) {
|
||||
// The core really started
|
||||
NekoRay::dataStore->core_running = true;
|
||||
NekoGui::dataStore->core_running = true;
|
||||
if (start_profile_when_core_is_up >= 0) {
|
||||
MW_dialog_message("ExternalProcess", "CoreStarted," + Int2String(start_profile_when_core_is_up));
|
||||
start_profile_when_core_is_up = -1;
|
||||
@@ -98,7 +98,7 @@ namespace NekoRay::sys {
|
||||
QProcess::kill();
|
||||
}
|
||||
}
|
||||
if (logCounter.fetchAndAddRelaxed(log.count("\n")) > NekoRay::dataStore->max_log_line) return;
|
||||
if (logCounter.fetchAndAddRelaxed(log.count("\n")) > NekoGui::dataStore->max_log_line) return;
|
||||
MW_show_log(log);
|
||||
});
|
||||
connect(this, &QProcess::readyReadStandardError, this, [&]() {
|
||||
@@ -119,10 +119,10 @@ namespace NekoRay::sys {
|
||||
});
|
||||
connect(this, &QProcess::stateChanged, this, [&](QProcess::ProcessState state) {
|
||||
if (state == QProcess::NotRunning) {
|
||||
NekoRay::dataStore->core_running = false;
|
||||
NekoGui::dataStore->core_running = false;
|
||||
}
|
||||
|
||||
if (!dataStore->prepare_exit && state == QProcess::NotRunning) {
|
||||
if (!NekoGui::dataStore->prepare_exit && state == QProcess::NotRunning) {
|
||||
if (failed_to_start) return; // no retry
|
||||
if (restarting) return;
|
||||
|
||||
@@ -140,7 +140,7 @@ namespace NekoRay::sys {
|
||||
}
|
||||
|
||||
// Restart
|
||||
start_profile_when_core_is_up = NekoRay::dataStore->started_id;
|
||||
start_profile_when_core_is_up = NekoGui::dataStore->started_id;
|
||||
MW_show_log("[Error] " + QObject::tr("Core exited, restarting."));
|
||||
setTimeout([=] { Restart(); }, this, 1000);
|
||||
}
|
||||
@@ -150,16 +150,16 @@ namespace NekoRay::sys {
|
||||
void CoreProcess::Start() {
|
||||
show_stderr = false;
|
||||
// set extra env
|
||||
auto v2ray_asset_dir = FindCoreAsset("geoip.dat");
|
||||
auto v2ray_asset_dir = NekoGui::FindCoreAsset("geoip.dat");
|
||||
if (!v2ray_asset_dir.isEmpty()) {
|
||||
v2ray_asset_dir = QFileInfo(v2ray_asset_dir).absolutePath();
|
||||
env << "V2RAY_LOCATION_ASSET=" + v2ray_asset_dir;
|
||||
}
|
||||
if (NekoRay::dataStore->core_ray_direct_dns) env << "NKR_CORE_RAY_DIRECT_DNS=1";
|
||||
if (NekoRay::dataStore->core_ray_windows_disable_auto_interface) env << "NKR_CORE_RAY_WINDOWS_DISABLE_AUTO_INTERFACE=1";
|
||||
if (NekoGui::dataStore->core_ray_direct_dns) env << "NKR_CORE_RAY_DIRECT_DNS=1";
|
||||
if (NekoGui::dataStore->core_ray_windows_disable_auto_interface) env << "NKR_CORE_RAY_WINDOWS_DISABLE_AUTO_INTERFACE=1";
|
||||
//
|
||||
ExternalProcess::Start();
|
||||
write((dataStore->core_token + "\n").toUtf8());
|
||||
write((NekoGui::dataStore->core_token + "\n").toUtf8());
|
||||
}
|
||||
|
||||
void CoreProcess::Restart() {
|
||||
@@ -171,4 +171,4 @@ namespace NekoRay::sys {
|
||||
restarting = false;
|
||||
}
|
||||
|
||||
} // namespace NekoRay::sys
|
||||
} // namespace NekoGui_sys
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <QProcess>
|
||||
|
||||
namespace NekoRay::sys {
|
||||
namespace NekoGui_sys {
|
||||
class ExternalProcess : public QProcess {
|
||||
public:
|
||||
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;
|
||||
} // namespace NekoRay::sys
|
||||
} // namespace NekoGui_sys
|
||||
|
||||
@@ -21,7 +21,7 @@ typedef BOOL(WINAPI *MINIDUMPWRITEDUMP)(
|
||||
CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
|
||||
CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
|
||||
|
||||
LONG CreateCrashHandler(EXCEPTION_POINTERS *pException) {
|
||||
LONG __stdcall CreateCrashHandler(EXCEPTION_POINTERS *pException) {
|
||||
QDir::setCurrent(QApplication::applicationDirPath());
|
||||
|
||||
HMODULE DllHandle = NULL;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
namespace NekoRay {
|
||||
// implement in mainwindow
|
||||
namespace GroupSortMethod {
|
||||
enum GroupSortMethod {
|
||||
@@ -19,4 +18,3 @@ namespace NekoRay {
|
||||
bool descending = false; // 默认升序,开这个就是降序
|
||||
bool scroll_to_started = false;
|
||||
};
|
||||
} // namespace NekoRay
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "Icon.hpp"
|
||||
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#include "ui/ThemeManager.hpp"
|
||||
#include "ui/Icon.hpp"
|
||||
#include "main/GuiUtils.hpp"
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
#include <QStyleFactory>
|
||||
#include <QFileDialog>
|
||||
@@ -72,7 +72,7 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
|
||||
|
||||
D_LOAD_STRING(inbound_address)
|
||||
D_LOAD_COMBO_STRING(log_level)
|
||||
CACHE.custom_inbound = NekoRay::dataStore->custom_inbound;
|
||||
CACHE.custom_inbound = NekoGui::dataStore->custom_inbound;
|
||||
D_LOAD_INT(inbound_socks_port)
|
||||
D_LOAD_INT_ENABLE(inbound_http_port, http_enable)
|
||||
D_LOAD_INT(test_concurrent)
|
||||
@@ -88,9 +88,9 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
|
||||
auto str = QInputDialog::getItem(this, ui->sys_proxy_format->text() + " (Windows)",
|
||||
tr("Advanced system proxy settings. Please select a format."),
|
||||
Preset::Windows::system_proxy_format,
|
||||
Preset::Windows::system_proxy_format.indexOf(NekoRay::dataStore->system_proxy_format),
|
||||
Preset::Windows::system_proxy_format.indexOf(NekoGui::dataStore->system_proxy_format),
|
||||
false, &ok);
|
||||
if (ok) NekoRay::dataStore->system_proxy_format = str;
|
||||
if (ok) NekoGui::dataStore->system_proxy_format = str;
|
||||
});
|
||||
#else
|
||||
ui->sys_proxy_format->hide();
|
||||
@@ -106,22 +106,22 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
|
||||
D_LOAD_BOOL(start_minimal)
|
||||
D_LOAD_INT(max_log_line)
|
||||
//
|
||||
if (NekoRay::dataStore->traffic_loop_interval == 500) {
|
||||
if (NekoGui::dataStore->traffic_loop_interval == 500) {
|
||||
ui->rfsh_r->setCurrentIndex(0);
|
||||
} else if (NekoRay::dataStore->traffic_loop_interval == 1000) {
|
||||
} else if (NekoGui::dataStore->traffic_loop_interval == 1000) {
|
||||
ui->rfsh_r->setCurrentIndex(1);
|
||||
} else if (NekoRay::dataStore->traffic_loop_interval == 2000) {
|
||||
} else if (NekoGui::dataStore->traffic_loop_interval == 2000) {
|
||||
ui->rfsh_r->setCurrentIndex(2);
|
||||
} else if (NekoRay::dataStore->traffic_loop_interval == 3000) {
|
||||
} else if (NekoGui::dataStore->traffic_loop_interval == 3000) {
|
||||
ui->rfsh_r->setCurrentIndex(3);
|
||||
} else if (NekoRay::dataStore->traffic_loop_interval == 5000) {
|
||||
} else if (NekoGui::dataStore->traffic_loop_interval == 5000) {
|
||||
ui->rfsh_r->setCurrentIndex(4);
|
||||
} else {
|
||||
ui->rfsh_r->setCurrentIndex(5);
|
||||
}
|
||||
//
|
||||
ui->language->setCurrentIndex(NekoRay::dataStore->language);
|
||||
connect(ui->language, QOverload<int>::of(&QComboBox::currentIndexChanged), this, [=](int index) {
|
||||
ui->language->setCurrentIndex(NekoGui::dataStore->language);
|
||||
connect(ui->language, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), this, [=](int index) {
|
||||
CACHE.needRestart = true;
|
||||
});
|
||||
//
|
||||
@@ -129,29 +129,29 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
|
||||
ui->theme->addItems(QStyleFactory::keys());
|
||||
//
|
||||
bool ok;
|
||||
auto themeId = NekoRay::dataStore->theme.toInt(&ok);
|
||||
auto themeId = NekoGui::dataStore->theme.toInt(&ok);
|
||||
if (ok) {
|
||||
ui->theme->setCurrentIndex(themeId);
|
||||
} else {
|
||||
ui->theme->setCurrentText(NekoRay::dataStore->theme);
|
||||
ui->theme->setCurrentText(NekoGui::dataStore->theme);
|
||||
}
|
||||
//
|
||||
connect(ui->theme, QOverload<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) {
|
||||
themeManager->ApplyTheme(Int2String(index));
|
||||
NekoRay::dataStore->theme = Int2String(index);
|
||||
NekoGui::dataStore->theme = Int2String(index);
|
||||
} else {
|
||||
themeManager->ApplyTheme(ui->theme->currentText());
|
||||
NekoRay::dataStore->theme = ui->theme->currentText();
|
||||
NekoGui::dataStore->theme = ui->theme->currentText();
|
||||
}
|
||||
repaint();
|
||||
mainwindow->repaint();
|
||||
NekoRay::dataStore->Save();
|
||||
NekoGui::dataStore->Save();
|
||||
});
|
||||
|
||||
// Subscription
|
||||
|
||||
ui->user_agent->setText(NekoRay::dataStore->user_agent);
|
||||
ui->user_agent->setText(NekoGui::dataStore->user_agent);
|
||||
D_LOAD_BOOL(sub_use_proxy)
|
||||
D_LOAD_BOOL(sub_clear)
|
||||
D_LOAD_BOOL(sub_insecure)
|
||||
@@ -159,9 +159,9 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
|
||||
// Core
|
||||
|
||||
ui->groupBox_core->setTitle(software_core_name);
|
||||
ui->core_v2ray_asset->setText(NekoRay::dataStore->v2ray_asset_dir);
|
||||
ui->core_v2ray_asset->setText(NekoGui::dataStore->v2ray_asset_dir);
|
||||
//
|
||||
CACHE.extraCore = QString2QJsonObject(NekoRay::dataStore->extraCore->core_map);
|
||||
CACHE.extraCore = QString2QJsonObject(NekoGui::dataStore->extraCore->core_map);
|
||||
if (!CACHE.extraCore.contains("naive")) CACHE.extraCore.insert("naive", "");
|
||||
if (!CACHE.extraCore.contains("hysteria")) CACHE.extraCore.insert("hysteria", "");
|
||||
//
|
||||
@@ -215,10 +215,10 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
|
||||
int neko_core_new;
|
||||
if (sender() == ui->switch_core_sing_box) {
|
||||
if (IS_NEKO_BOX) return;
|
||||
neko_core_new = NekoRay::CoreType::SING_BOX;
|
||||
neko_core_new = NekoGui::CoreType::SING_BOX;
|
||||
} else {
|
||||
if (!IS_NEKO_BOX) return;
|
||||
neko_core_new = NekoRay::CoreType::V2RAY;
|
||||
neko_core_new = NekoGui::CoreType::V2RAY;
|
||||
}
|
||||
QString core_name_new = dynamic_cast<QRadioButton *>(sender())->text();
|
||||
if (QMessageBox::question(this, tr("Confirmation"),
|
||||
@@ -245,8 +245,8 @@ DialogBasicSettings::DialogBasicSettings(QWidget *parent)
|
||||
ui->utlsFingerprint->addItems(IS_NEKO_BOX ? Preset::SingBox::UtlsFingerPrint : Preset::V2Ray::UtlsFingerPrint);
|
||||
|
||||
D_LOAD_BOOL(skip_cert)
|
||||
ui->enable_js_hook->setCurrentIndex(NekoRay::dataStore->enable_js_hook);
|
||||
ui->utlsFingerprint->setCurrentText(NekoRay::dataStore->utlsFingerprint);
|
||||
ui->enable_js_hook->setCurrentIndex(NekoGui::dataStore->enable_js_hook);
|
||||
ui->utlsFingerprint->setCurrentText(NekoGui::dataStore->utlsFingerprint);
|
||||
}
|
||||
|
||||
DialogBasicSettings::~DialogBasicSettings() {
|
||||
@@ -258,7 +258,7 @@ void DialogBasicSettings::accept() {
|
||||
|
||||
D_SAVE_STRING(inbound_address)
|
||||
D_SAVE_COMBO_STRING(log_level)
|
||||
NekoRay::dataStore->custom_inbound = CACHE.custom_inbound;
|
||||
NekoGui::dataStore->custom_inbound = CACHE.custom_inbound;
|
||||
D_SAVE_INT(inbound_socks_port)
|
||||
D_SAVE_INT_ENABLE(inbound_http_port, http_enable)
|
||||
D_SAVE_INT(test_concurrent)
|
||||
@@ -266,41 +266,41 @@ void DialogBasicSettings::accept() {
|
||||
|
||||
// Style
|
||||
|
||||
NekoRay::dataStore->language = ui->language->currentIndex();
|
||||
NekoGui::dataStore->language = ui->language->currentIndex();
|
||||
D_SAVE_BOOL(connection_statistics)
|
||||
D_SAVE_BOOL(check_include_pre)
|
||||
D_SAVE_BOOL(start_minimal)
|
||||
D_SAVE_INT(max_log_line)
|
||||
|
||||
if (NekoRay::dataStore->max_log_line <= 0) {
|
||||
NekoRay::dataStore->max_log_line = 200;
|
||||
if (NekoGui::dataStore->max_log_line <= 0) {
|
||||
NekoGui::dataStore->max_log_line = 200;
|
||||
}
|
||||
|
||||
if (ui->rfsh_r->currentIndex() == 0) {
|
||||
NekoRay::dataStore->traffic_loop_interval = 500;
|
||||
NekoGui::dataStore->traffic_loop_interval = 500;
|
||||
} else if (ui->rfsh_r->currentIndex() == 1) {
|
||||
NekoRay::dataStore->traffic_loop_interval = 1000;
|
||||
NekoGui::dataStore->traffic_loop_interval = 1000;
|
||||
} else if (ui->rfsh_r->currentIndex() == 2) {
|
||||
NekoRay::dataStore->traffic_loop_interval = 2000;
|
||||
NekoGui::dataStore->traffic_loop_interval = 2000;
|
||||
} else if (ui->rfsh_r->currentIndex() == 3) {
|
||||
NekoRay::dataStore->traffic_loop_interval = 3000;
|
||||
NekoGui::dataStore->traffic_loop_interval = 3000;
|
||||
} else if (ui->rfsh_r->currentIndex() == 4) {
|
||||
NekoRay::dataStore->traffic_loop_interval = 5000;
|
||||
NekoGui::dataStore->traffic_loop_interval = 5000;
|
||||
} else {
|
||||
NekoRay::dataStore->traffic_loop_interval = 0;
|
||||
NekoGui::dataStore->traffic_loop_interval = 0;
|
||||
}
|
||||
|
||||
// Subscription
|
||||
|
||||
NekoRay::dataStore->user_agent = ui->user_agent->text();
|
||||
NekoGui::dataStore->user_agent = ui->user_agent->text();
|
||||
D_SAVE_BOOL(sub_use_proxy)
|
||||
D_SAVE_BOOL(sub_clear)
|
||||
D_SAVE_BOOL(sub_insecure)
|
||||
|
||||
// Core
|
||||
|
||||
NekoRay::dataStore->v2ray_asset_dir = ui->core_v2ray_asset->text();
|
||||
NekoRay::dataStore->extraCore->core_map = QJsonObject2QString(CACHE.extraCore, true);
|
||||
NekoGui::dataStore->v2ray_asset_dir = ui->core_v2ray_asset->text();
|
||||
NekoGui::dataStore->extraCore->core_map = QJsonObject2QString(CACHE.extraCore, true);
|
||||
|
||||
// Mux
|
||||
D_SAVE_INT(mux_concurrency)
|
||||
@@ -310,11 +310,11 @@ void DialogBasicSettings::accept() {
|
||||
// Security
|
||||
|
||||
D_SAVE_BOOL(skip_cert)
|
||||
NekoRay::dataStore->enable_js_hook = ui->enable_js_hook->currentIndex();
|
||||
NekoRay::dataStore->utlsFingerprint = ui->utlsFingerprint->currentText();
|
||||
NekoGui::dataStore->enable_js_hook = ui->enable_js_hook->currentIndex();
|
||||
NekoGui::dataStore->utlsFingerprint = ui->utlsFingerprint->currentText();
|
||||
|
||||
// 关闭连接统计,停止刷新前清空记录。
|
||||
if (NekoRay::dataStore->traffic_loop_interval == 0 || NekoRay::dataStore->connection_statistics == false) {
|
||||
if (NekoGui::dataStore->traffic_loop_interval == 0 || NekoGui::dataStore->connection_statistics == false) {
|
||||
MW_dialog_message("", "ClearConnectionList");
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ void DialogBasicSettings::accept() {
|
||||
|
||||
void DialogBasicSettings::refresh_auth() {
|
||||
ui->inbound_auth->setText({});
|
||||
if (NekoRay::dataStore->inbound_auth->NeedAuth()) {
|
||||
if (NekoGui::dataStore->inbound_auth->NeedAuth()) {
|
||||
ui->inbound_auth->setIcon(Icon::GetMaterialIcon("lock-outline"));
|
||||
} else {
|
||||
ui->inbound_auth->setIcon(Icon::GetMaterialIcon("lock-open-outline"));
|
||||
@@ -367,8 +367,8 @@ void DialogBasicSettings::on_inbound_auth_clicked() {
|
||||
auto pass_l = new QLabel(tr("Password"));
|
||||
auto user = new MyLineEdit;
|
||||
auto pass = new MyLineEdit;
|
||||
user->setText(NekoRay::dataStore->inbound_auth->username);
|
||||
pass->setText(NekoRay::dataStore->inbound_auth->password);
|
||||
user->setText(NekoGui::dataStore->inbound_auth->username);
|
||||
pass->setText(NekoGui::dataStore->inbound_auth->password);
|
||||
//
|
||||
layout->addWidget(user_l, 0, 0);
|
||||
layout->addWidget(user, 0, 1);
|
||||
@@ -378,8 +378,8 @@ void DialogBasicSettings::on_inbound_auth_clicked() {
|
||||
box->setOrientation(Qt::Horizontal);
|
||||
box->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
|
||||
connect(box, &QDialogButtonBox::accepted, w, [=] {
|
||||
NekoRay::dataStore->inbound_auth->username = user->text();
|
||||
NekoRay::dataStore->inbound_auth->password = pass->text();
|
||||
NekoGui::dataStore->inbound_auth->username = user->text();
|
||||
NekoGui::dataStore->inbound_auth->password = pass->text();
|
||||
MW_dialog_message(Dialog_DialogBasicSettings, "UpdateDataStore");
|
||||
w->accept();
|
||||
});
|
||||
@@ -411,7 +411,7 @@ void DialogBasicSettings::on_core_settings_clicked() {
|
||||
"For NekoRay, this rewrites the underlying(localhost) DNS in VPN mode.\n"
|
||||
"For NekoBox, this rewrites the underlying(localhost) DNS in VPN mode, normal mode, and also URL Test."));
|
||||
core_box_underlying_dns = new MyLineEdit;
|
||||
core_box_underlying_dns->setText(NekoRay::dataStore->core_box_underlying_dns);
|
||||
core_box_underlying_dns->setText(NekoGui::dataStore->core_box_underlying_dns);
|
||||
core_box_underlying_dns->setMinimumWidth(300);
|
||||
layout->addWidget(core_box_underlying_dns_l, ++line, 0);
|
||||
layout->addWidget(core_box_underlying_dns, line, 1);
|
||||
@@ -419,26 +419,26 @@ void DialogBasicSettings::on_core_settings_clicked() {
|
||||
if (IS_NEKO_BOX) {
|
||||
auto core_box_enable_clash_api_l = new QLabel("Enable Clash API");
|
||||
core_box_enable_clash_api = new QCheckBox;
|
||||
core_box_enable_clash_api->setChecked(NekoRay::dataStore->core_box_clash_api > 0);
|
||||
core_box_enable_clash_api->setChecked(NekoGui::dataStore->core_box_clash_api > 0);
|
||||
layout->addWidget(core_box_enable_clash_api_l, ++line, 0);
|
||||
layout->addWidget(core_box_enable_clash_api, line, 1);
|
||||
//
|
||||
auto core_box_clash_api_l = new QLabel("Clash API Listen Port");
|
||||
core_box_clash_api = new MyLineEdit;
|
||||
core_box_clash_api->setText(Int2String(std::abs(NekoRay::dataStore->core_box_clash_api)));
|
||||
core_box_clash_api->setText(Int2String(std::abs(NekoGui::dataStore->core_box_clash_api)));
|
||||
layout->addWidget(core_box_clash_api_l, ++line, 0);
|
||||
layout->addWidget(core_box_clash_api, line, 1);
|
||||
//
|
||||
auto core_box_clash_api_secret_l = new QLabel("Clash API Secret");
|
||||
core_box_clash_api_secret = new MyLineEdit;
|
||||
core_box_clash_api_secret->setText(NekoRay::dataStore->core_box_clash_api_secret);
|
||||
core_box_clash_api_secret->setText(NekoGui::dataStore->core_box_clash_api_secret);
|
||||
layout->addWidget(core_box_clash_api_secret_l, ++line, 0);
|
||||
layout->addWidget(core_box_clash_api_secret, line, 1);
|
||||
} else {
|
||||
auto core_ray_direct_dns_l = new QLabel("NKR_CORE_RAY_DIRECT_DNS");
|
||||
core_ray_direct_dns_l->setToolTip(tr("If you VPN mode is not working, try to change this option."));
|
||||
core_ray_direct_dns = new QCheckBox;
|
||||
core_ray_direct_dns->setChecked(NekoRay::dataStore->core_ray_direct_dns);
|
||||
core_ray_direct_dns->setChecked(NekoGui::dataStore->core_ray_direct_dns);
|
||||
connect(core_ray_direct_dns, &QCheckBox::clicked, this, [&] { CACHE.needRestart = true; });
|
||||
layout->addWidget(core_ray_direct_dns_l, ++line, 0);
|
||||
layout->addWidget(core_ray_direct_dns, line, 1);
|
||||
@@ -446,7 +446,7 @@ void DialogBasicSettings::on_core_settings_clicked() {
|
||||
auto core_ray_windows_disable_auto_interface_l = new QLabel("NKR_CORE_RAY_WINDOWS_DISABLE_AUTO_INTERFACE");
|
||||
core_ray_windows_disable_auto_interface_l->setToolTip(tr("If you VPN mode is not working, try to change this option."));
|
||||
core_ray_windows_disable_auto_interface = new QCheckBox;
|
||||
core_ray_windows_disable_auto_interface->setChecked(NekoRay::dataStore->core_ray_windows_disable_auto_interface);
|
||||
core_ray_windows_disable_auto_interface->setChecked(NekoGui::dataStore->core_ray_windows_disable_auto_interface);
|
||||
connect(core_ray_windows_disable_auto_interface, &QCheckBox::clicked, this, [&] { CACHE.needRestart = true; });
|
||||
layout->addWidget(core_ray_windows_disable_auto_interface_l, ++line, 0);
|
||||
layout->addWidget(core_ray_windows_disable_auto_interface, line, 1);
|
||||
@@ -457,14 +457,14 @@ void DialogBasicSettings::on_core_settings_clicked() {
|
||||
box->setOrientation(Qt::Horizontal);
|
||||
box->setStandardButtons(QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
|
||||
connect(box, &QDialogButtonBox::accepted, w, [=] {
|
||||
NekoRay::dataStore->core_box_underlying_dns = core_box_underlying_dns->text();
|
||||
NekoGui::dataStore->core_box_underlying_dns = core_box_underlying_dns->text();
|
||||
if (IS_NEKO_BOX) {
|
||||
NekoRay::dataStore->core_box_clash_api = core_box_clash_api->text().toInt() * (core_box_enable_clash_api->isChecked() ? 1 : -1);
|
||||
NekoRay::dataStore->core_box_clash_api_secret = core_box_clash_api_secret->text();
|
||||
NekoGui::dataStore->core_box_clash_api = core_box_clash_api->text().toInt() * (core_box_enable_clash_api->isChecked() ? 1 : -1);
|
||||
NekoGui::dataStore->core_box_clash_api_secret = core_box_clash_api_secret->text();
|
||||
} else {
|
||||
NekoRay::dataStore->core_ray_direct_dns = core_ray_direct_dns->isChecked();
|
||||
NekoGui::dataStore->core_ray_direct_dns = core_ray_direct_dns->isChecked();
|
||||
#ifdef Q_OS_WIN
|
||||
NekoRay::dataStore->core_ray_windows_disable_auto_interface = core_ray_windows_disable_auto_interface->isChecked();
|
||||
NekoGui::dataStore->core_ray_windows_disable_auto_interface = core_ray_windows_disable_auto_interface->isChecked();
|
||||
#endif
|
||||
}
|
||||
MW_dialog_message(Dialog_DialogBasicSettings, "UpdateDataStore");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "dialog_first_setup.h"
|
||||
#include "ui_dialog_first_setup.h"
|
||||
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
DialogFirstSetup::DialogFirstSetup(QWidget *parent) : QDialog(parent), ui(new Ui::DialogFirstSetup) {
|
||||
ui->setupUi(this);
|
||||
@@ -14,9 +14,9 @@ DialogFirstSetup::~DialogFirstSetup() {
|
||||
void DialogFirstSetup::onButtonClicked() {
|
||||
auto s = sender();
|
||||
if (s == ui->v2ray) {
|
||||
NekoRay::coreType = NekoRay::CoreType::V2RAY;
|
||||
NekoGui::coreType = NekoGui::CoreType::V2RAY;
|
||||
} else if (s == ui->singbox) {
|
||||
NekoRay::coreType = NekoRay::CoreType::SING_BOX;
|
||||
NekoGui::coreType = NekoGui::CoreType::SING_BOX;
|
||||
}
|
||||
done(0);
|
||||
}
|
||||
|
||||
@@ -5,20 +5,20 @@
|
||||
|
||||
DialogHotkey::DialogHotkey(QWidget *parent) : QDialog(parent), ui(new Ui::DialogHotkey) {
|
||||
ui->setupUi(this);
|
||||
ui->show_mainwindow->setKeySequence(NekoRay::dataStore->hotkey_mainwindow);
|
||||
ui->show_groups->setKeySequence(NekoRay::dataStore->hotkey_group);
|
||||
ui->show_routes->setKeySequence(NekoRay::dataStore->hotkey_route);
|
||||
ui->system_proxy->setKeySequence(NekoRay::dataStore->hotkey_system_proxy_menu);
|
||||
ui->show_mainwindow->setKeySequence(NekoGui::dataStore->hotkey_mainwindow);
|
||||
ui->show_groups->setKeySequence(NekoGui::dataStore->hotkey_group);
|
||||
ui->show_routes->setKeySequence(NekoGui::dataStore->hotkey_route);
|
||||
ui->system_proxy->setKeySequence(NekoGui::dataStore->hotkey_system_proxy_menu);
|
||||
GetMainWindow()->RegisterHotkey(true);
|
||||
}
|
||||
|
||||
DialogHotkey::~DialogHotkey() {
|
||||
if (result() == QDialog::Accepted) {
|
||||
NekoRay::dataStore->hotkey_mainwindow = ui->show_mainwindow->keySequence().toString();
|
||||
NekoRay::dataStore->hotkey_group = ui->show_groups->keySequence().toString();
|
||||
NekoRay::dataStore->hotkey_route = ui->show_routes->keySequence().toString();
|
||||
NekoRay::dataStore->hotkey_system_proxy_menu = ui->system_proxy->keySequence().toString();
|
||||
NekoRay::dataStore->Save();
|
||||
NekoGui::dataStore->hotkey_mainwindow = ui->show_mainwindow->keySequence().toString();
|
||||
NekoGui::dataStore->hotkey_group = ui->show_groups->keySequence().toString();
|
||||
NekoGui::dataStore->hotkey_route = ui->show_routes->keySequence().toString();
|
||||
NekoGui::dataStore->hotkey_system_proxy_menu = ui->system_proxy->keySequence().toString();
|
||||
NekoGui::dataStore->Save();
|
||||
}
|
||||
GetMainWindow()->RegisterHotkey(false);
|
||||
delete ui;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <QDialog>
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include <QMessageBox>
|
||||
|
||||
#define AddGroupToListIfExist(_id) \
|
||||
auto __ent = NekoRay::profileManager->GetGroup(_id); \
|
||||
auto __ent = NekoGui::profileManager->GetGroup(_id); \
|
||||
if (__ent != nullptr) { \
|
||||
auto wI = new QListWidgetItem(); \
|
||||
auto w = new GroupItem(this, __ent, wI); \
|
||||
@@ -24,7 +24,7 @@
|
||||
DialogManageGroups::DialogManageGroups(QWidget *parent) : QDialog(parent), ui(new Ui::DialogManageGroups) {
|
||||
ui->setupUi(this);
|
||||
|
||||
for (auto id: NekoRay::profileManager->_groups) {
|
||||
for (auto id: NekoGui::profileManager->_groups) {
|
||||
AddGroupToListIfExist(id)
|
||||
}
|
||||
|
||||
@@ -39,13 +39,13 @@ DialogManageGroups::~DialogManageGroups() {
|
||||
}
|
||||
|
||||
void DialogManageGroups::on_add_clicked() {
|
||||
auto ent = NekoRay::ProfileManager::NewGroup();
|
||||
auto ent = NekoGui::ProfileManager::NewGroup();
|
||||
auto dialog = new DialogEditGroup(ent, this);
|
||||
int ret = dialog->exec();
|
||||
dialog->deleteLater();
|
||||
|
||||
if (ret == QDialog::Accepted) {
|
||||
NekoRay::profileManager->AddGroup(ent);
|
||||
NekoGui::profileManager->AddGroup(ent);
|
||||
AddGroupToListIfExist(ent->id);
|
||||
MW_dialog_message(Dialog_DialogManageGroups, "refresh-1");
|
||||
}
|
||||
@@ -53,10 +53,10 @@ void DialogManageGroups::on_add_clicked() {
|
||||
|
||||
void DialogManageGroups::on_update_all_clicked() {
|
||||
if (QMessageBox::question(this, tr("Confirmation"), tr("Update all subscriptions?")) == QMessageBox::StandardButton::Yes) {
|
||||
for (const auto &gid: NekoRay::profileManager->_groups) {
|
||||
auto group = NekoRay::profileManager->GetGroup(gid);
|
||||
for (const auto &gid: NekoGui::profileManager->_groups) {
|
||||
auto group = NekoGui::profileManager->GetGroup(gid);
|
||||
if (group == nullptr || group->url.isEmpty()) continue;
|
||||
UI_update_one_group(NekoRay::profileManager->_groups.indexOf(gid));
|
||||
UI_update_one_group(NekoGui::profileManager->_groups.indexOf(gid));
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -65,22 +65,22 @@ void DialogManageGroups::on_update_all_clicked() {
|
||||
void UI_update_one_group(int _order) {
|
||||
// calculate next group
|
||||
int nextOrder = _order;
|
||||
QSharedPointer<NekoRay::Group> nextGroup;
|
||||
std::shared_ptr<NekoGui::Group> nextGroup;
|
||||
forever {
|
||||
nextOrder += 1;
|
||||
if (nextOrder >= NekoRay::profileManager->_groups.length()) break;
|
||||
auto nextGid = NekoRay::profileManager->_groups[nextOrder];
|
||||
nextGroup = NekoRay::profileManager->GetGroup(nextGid);
|
||||
if (nextOrder >= NekoGui::profileManager->_groups.length()) break;
|
||||
auto nextGid = NekoGui::profileManager->_groups[nextOrder];
|
||||
nextGroup = NekoGui::profileManager->GetGroup(nextGid);
|
||||
if (nextGroup == nullptr || nextGroup->url.isEmpty()) continue;
|
||||
break;
|
||||
}
|
||||
|
||||
// calculate this group
|
||||
auto group = NekoRay::profileManager->GetGroup(NekoRay::profileManager->_groups[_order]);
|
||||
auto group = NekoGui::profileManager->GetGroup(NekoGui::profileManager->_groups[_order]);
|
||||
if (group == nullptr) return;
|
||||
|
||||
// v2.2: listener is moved to GroupItem, no refresh here.
|
||||
NekoRay::sub::groupUpdater->AsyncUpdate(group->url, group->id, [=] {
|
||||
NekoGui_sub::groupUpdater->AsyncUpdate(group->url, group->id, [=] {
|
||||
if (nextGroup != nullptr) UI_update_one_group(nextOrder);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -68,8 +68,8 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
|
||||
builtInSchemesMenu->addActions(this->getBuiltInSchemes());
|
||||
ui->preset->setMenu(builtInSchemesMenu);
|
||||
|
||||
QString geoipFn = NekoRay::FindCoreAsset("geoip.dat");
|
||||
QString geositeFn = NekoRay::FindCoreAsset("geosite.dat");
|
||||
QString geoipFn = NekoGui::FindCoreAsset("geoip.dat");
|
||||
QString geositeFn = NekoGui::FindCoreAsset("geosite.dat");
|
||||
//
|
||||
const auto sourceStringsDomain = Qv2ray::components::GeositeReader::ReadGeoSiteFromFile(geoipFn);
|
||||
directDomainTxt = new AutoCompleteTextEdit("geosite", sourceStringsDomain, this);
|
||||
@@ -89,7 +89,7 @@ DialogManageRoutes::DialogManageRoutes(QWidget *parent) : QDialog(parent), ui(ne
|
||||
ui->proxyIPLayout->addWidget(proxyIPTxt, 0, 0);
|
||||
ui->blockIPLayout->addWidget(blockIPTxt, 0, 0);
|
||||
//
|
||||
REFRESH_ACTIVE_ROUTING(NekoRay::dataStore->active_routing, NekoRay::dataStore->routing)
|
||||
REFRESH_ACTIVE_ROUTING(NekoGui::dataStore->active_routing, NekoGui::dataStore->routing)
|
||||
|
||||
ADD_ASTERISK(this)
|
||||
}
|
||||
@@ -101,11 +101,11 @@ DialogManageRoutes::~DialogManageRoutes() {
|
||||
void DialogManageRoutes::accept() {
|
||||
D_C_SAVE_STRING(custom_route_global)
|
||||
bool routeChanged = false;
|
||||
if (NekoRay::dataStore->active_routing != active_routing) routeChanged = true;
|
||||
SaveDisplayRouting(NekoRay::dataStore->routing);
|
||||
NekoRay::dataStore->active_routing = active_routing;
|
||||
NekoRay::dataStore->routing->fn = ROUTES_PREFIX + NekoRay::dataStore->active_routing;
|
||||
if (NekoRay::dataStore->routing->Save()) routeChanged = true;
|
||||
if (NekoGui::dataStore->active_routing != active_routing) routeChanged = true;
|
||||
SaveDisplayRouting(NekoGui::dataStore->routing);
|
||||
NekoGui::dataStore->active_routing = active_routing;
|
||||
NekoGui::dataStore->routing->fn = ROUTES_PREFIX + NekoGui::dataStore->active_routing;
|
||||
if (NekoGui::dataStore->routing->Save()) routeChanged = true;
|
||||
//
|
||||
QString info = "UpdateDataStore";
|
||||
if (routeChanged) info += "RouteChanged";
|
||||
@@ -122,14 +122,13 @@ QList<QAction *> DialogManageRoutes::getBuiltInSchemes() {
|
||||
return list;
|
||||
}
|
||||
|
||||
QAction *DialogManageRoutes::schemeToAction(const QString &name, const NekoRay::Routing &scheme) {
|
||||
auto *action = new QAction(this);
|
||||
action->setText(name);
|
||||
connect(action, &QAction::triggered, [this, &scheme] { this->UpdateDisplayRouting((NekoRay::Routing *) &scheme, true); });
|
||||
QAction *DialogManageRoutes::schemeToAction(const QString &name, const NekoGui::Routing &scheme) {
|
||||
auto *action = new QAction(name, this);
|
||||
connect(action, &QAction::triggered, [this, &scheme] { this->UpdateDisplayRouting((NekoGui::Routing *) &scheme, true); });
|
||||
return action;
|
||||
}
|
||||
|
||||
void DialogManageRoutes::UpdateDisplayRouting(NekoRay::Routing *conf, bool qv) {
|
||||
void DialogManageRoutes::UpdateDisplayRouting(NekoGui::Routing *conf, bool qv) {
|
||||
//
|
||||
directDomainTxt->setPlainText(conf->direct_domain);
|
||||
proxyDomainTxt->setPlainText(conf->proxy_domain);
|
||||
@@ -156,7 +155,7 @@ void DialogManageRoutes::UpdateDisplayRouting(NekoRay::Routing *conf, bool qv) {
|
||||
ui->direct_dns_strategy->setCurrentText(conf->direct_dns_strategy);
|
||||
}
|
||||
|
||||
void DialogManageRoutes::SaveDisplayRouting(NekoRay::Routing *conf) {
|
||||
void DialogManageRoutes::SaveDisplayRouting(NekoGui::Routing *conf) {
|
||||
conf->direct_ip = directIPTxt->toPlainText();
|
||||
conf->direct_domain = directDomainTxt->toPlainText();
|
||||
conf->proxy_ip = proxyIPTxt->toPlainText();
|
||||
@@ -186,7 +185,7 @@ void DialogManageRoutes::on_load_save_clicked() {
|
||||
layout->addWidget(lineEdit);
|
||||
auto list = new QListWidget;
|
||||
layout->addWidget(list);
|
||||
for (const auto &name: NekoRay::Routing::List()) {
|
||||
for (const auto &name: NekoGui::Routing::List()) {
|
||||
list->addItem(name);
|
||||
}
|
||||
connect(list, &QListWidget::currentTextChanged, lineEdit, &QLineEdit::setText);
|
||||
@@ -207,7 +206,7 @@ void DialogManageRoutes::on_load_save_clicked() {
|
||||
connect(load, &QPushButton::clicked, w, [=] {
|
||||
auto fn = lineEdit->text();
|
||||
if (!fn.isEmpty()) {
|
||||
auto r = std::make_unique<NekoRay::Routing>();
|
||||
auto r = std::make_unique<NekoGui::Routing>();
|
||||
r->load_control_must = true;
|
||||
r->fn = ROUTES_PREFIX + fn;
|
||||
if (r->Load()) {
|
||||
@@ -221,7 +220,7 @@ void DialogManageRoutes::on_load_save_clicked() {
|
||||
connect(save, &QPushButton::clicked, w, [=] {
|
||||
auto fn = lineEdit->text();
|
||||
if (!fn.isEmpty()) {
|
||||
auto r = std::make_unique<NekoRay::Routing>();
|
||||
auto r = std::make_unique<NekoGui::Routing>();
|
||||
SaveDisplayRouting(r.get());
|
||||
r->fn = ROUTES_PREFIX + fn;
|
||||
if (QMessageBox::question(nullptr, software_name, tr("Save routing: %1").arg(fn) + "\n" + r->DisplayRouting()) == QMessageBox::Yes) {
|
||||
@@ -233,13 +232,13 @@ void DialogManageRoutes::on_load_save_clicked() {
|
||||
});
|
||||
connect(remove, &QPushButton::clicked, w, [=] {
|
||||
auto fn = lineEdit->text();
|
||||
if (!fn.isEmpty() && NekoRay::Routing::List().length() > 1) {
|
||||
if (!fn.isEmpty() && NekoGui::Routing::List().length() > 1) {
|
||||
if (QMessageBox::question(nullptr, software_name, tr("Remove routing: %1").arg(fn)) == QMessageBox::Yes) {
|
||||
QFile f(ROUTES_PREFIX + fn);
|
||||
f.remove();
|
||||
if (NekoRay::dataStore->active_routing == fn) {
|
||||
NekoRay::Routing::SetToActive(NekoRay::Routing::List().first());
|
||||
REFRESH_ACTIVE_ROUTING(NekoRay::dataStore->active_routing, NekoRay::dataStore->routing)
|
||||
if (NekoGui::dataStore->active_routing == fn) {
|
||||
NekoGui::Routing::SetToActive(NekoGui::Routing::List().first());
|
||||
REFRESH_ACTIVE_ROUTING(NekoGui::dataStore->active_routing, NekoGui::dataStore->routing)
|
||||
}
|
||||
w->accept();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <QMenu>
|
||||
|
||||
#include "3rdparty/qv2ray/v2/ui/QvAutoCompleteTextEdit.hpp"
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui {
|
||||
@@ -37,8 +37,8 @@ private:
|
||||
Qv2ray::ui::widgets::AutoCompleteTextEdit *blockIPTxt;
|
||||
Qv2ray::ui::widgets::AutoCompleteTextEdit *proxyIPTxt;
|
||||
//
|
||||
NekoRay::Routing routing_cn_lan = NekoRay::Routing(1);
|
||||
NekoRay::Routing routing_global = NekoRay::Routing(0);
|
||||
NekoGui::Routing routing_cn_lan = NekoGui::Routing(1);
|
||||
NekoGui::Routing routing_global = NekoGui::Routing(0);
|
||||
//
|
||||
QString title_base;
|
||||
QString active_routing;
|
||||
@@ -49,11 +49,11 @@ public slots:
|
||||
|
||||
QList<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();
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include "ui_dialog_vpn_settings.h"
|
||||
|
||||
#include "main/GuiUtils.hpp"
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
#include "ui/mainwindow_interface.h"
|
||||
|
||||
#include <QMessageBox>
|
||||
@@ -12,18 +12,18 @@ DialogVPNSettings::DialogVPNSettings(QWidget *parent) : QDialog(parent), ui(new
|
||||
ADD_ASTERISK(this);
|
||||
|
||||
ui->fake_dns->setVisible(!IS_NEKO_BOX);
|
||||
ui->fake_dns->setChecked(NekoRay::dataStore->fake_dns);
|
||||
ui->fake_dns->setChecked(NekoGui::dataStore->fake_dns);
|
||||
//
|
||||
ui->vpn_implementation->setCurrentIndex(NekoRay::dataStore->vpn_implementation);
|
||||
ui->vpn_mtu->setCurrentText(Int2String(NekoRay::dataStore->vpn_mtu));
|
||||
ui->vpn_ipv6->setChecked(NekoRay::dataStore->vpn_ipv6);
|
||||
ui->hide_console->setChecked(NekoRay::dataStore->vpn_hide_console);
|
||||
ui->vpn_implementation->setCurrentIndex(NekoGui::dataStore->vpn_implementation);
|
||||
ui->vpn_mtu->setCurrentText(Int2String(NekoGui::dataStore->vpn_mtu));
|
||||
ui->vpn_ipv6->setChecked(NekoGui::dataStore->vpn_ipv6);
|
||||
ui->hide_console->setChecked(NekoGui::dataStore->vpn_hide_console);
|
||||
#ifndef Q_OS_WIN
|
||||
ui->hide_console->setVisible(false);
|
||||
#endif
|
||||
ui->strict_route->setChecked(NekoRay::dataStore->vpn_strict_route);
|
||||
ui->strict_route->setChecked(NekoGui::dataStore->vpn_strict_route);
|
||||
ui->single_core->setVisible(IS_NEKO_BOX);
|
||||
ui->single_core->setChecked(NekoRay::dataStore->vpn_internal_tun);
|
||||
ui->single_core->setChecked(NekoGui::dataStore->vpn_internal_tun);
|
||||
//
|
||||
D_LOAD_STRING(vpn_rule_cidr)
|
||||
D_LOAD_STRING(vpn_rule_process)
|
||||
@@ -37,7 +37,7 @@ DialogVPNSettings::DialogVPNSettings(QWidget *parent) : QDialog(parent), ui(new
|
||||
ui->gb_process_name->setTitle(tr("Bypass Process Name"));
|
||||
}
|
||||
});
|
||||
ui->whitelist_mode->setChecked(NekoRay::dataStore->vpn_rule_white);
|
||||
ui->whitelist_mode->setChecked(NekoGui::dataStore->vpn_rule_white);
|
||||
}
|
||||
|
||||
DialogVPNSettings::~DialogVPNSettings() {
|
||||
@@ -48,14 +48,14 @@ void DialogVPNSettings::accept() {
|
||||
//
|
||||
auto mtu = ui->vpn_mtu->currentText().toInt();
|
||||
if (mtu > 10000 || mtu < 1000) mtu = 9000;
|
||||
NekoRay::dataStore->vpn_implementation = ui->vpn_implementation->currentIndex();
|
||||
NekoRay::dataStore->fake_dns = ui->fake_dns->isChecked();
|
||||
NekoRay::dataStore->vpn_mtu = mtu;
|
||||
NekoRay::dataStore->vpn_ipv6 = ui->vpn_ipv6->isChecked();
|
||||
NekoRay::dataStore->vpn_hide_console = ui->hide_console->isChecked();
|
||||
NekoRay::dataStore->vpn_strict_route = ui->strict_route->isChecked();
|
||||
NekoRay::dataStore->vpn_rule_white = ui->whitelist_mode->isChecked();
|
||||
NekoRay::dataStore->vpn_internal_tun = ui->single_core->isChecked();
|
||||
NekoGui::dataStore->vpn_implementation = ui->vpn_implementation->currentIndex();
|
||||
NekoGui::dataStore->fake_dns = ui->fake_dns->isChecked();
|
||||
NekoGui::dataStore->vpn_mtu = mtu;
|
||||
NekoGui::dataStore->vpn_ipv6 = ui->vpn_ipv6->isChecked();
|
||||
NekoGui::dataStore->vpn_hide_console = ui->hide_console->isChecked();
|
||||
NekoGui::dataStore->vpn_strict_route = ui->strict_route->isChecked();
|
||||
NekoGui::dataStore->vpn_rule_white = ui->whitelist_mode->isChecked();
|
||||
NekoGui::dataStore->vpn_internal_tun = ui->single_core->isChecked();
|
||||
//
|
||||
D_SAVE_STRING_QTEXTEDIT(vpn_rule_cidr)
|
||||
D_SAVE_STRING_QTEXTEDIT(vpn_rule_process)
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
|
||||
#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) {
|
||||
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);
|
||||
});
|
||||
|
||||
@@ -45,7 +45,7 @@ DialogEditGroup::DialogEditGroup(const QSharedPointer<NekoRay::Group> &ent, QWid
|
||||
|
||||
connect(ui->copy_links, &QPushButton::clicked, this, [=] {
|
||||
QStringList links;
|
||||
for (const auto &profile: NekoRay::profileManager->profiles) {
|
||||
for (const auto &profile: NekoGui::profileManager->profiles) {
|
||||
if (profile->gid != ent->id) continue;
|
||||
links += profile->bean->ToShareLink();
|
||||
}
|
||||
@@ -54,7 +54,7 @@ DialogEditGroup::DialogEditGroup(const QSharedPointer<NekoRay::Group> &ent, QWid
|
||||
});
|
||||
connect(ui->copy_links_nkr, &QPushButton::clicked, this, [=] {
|
||||
QStringList links;
|
||||
for (const auto &profile: NekoRay::profileManager->profiles) {
|
||||
for (const auto &profile: NekoGui::profileManager->profiles) {
|
||||
if (profile->gid != ent->id) continue;
|
||||
links += profile->bean->ToNekorayShareLink(profile->type);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ class DialogEditGroup : public QDialog {
|
||||
Q_OBJECT
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <QInputDialog>
|
||||
|
||||
#define ADJUST_SIZE runOnUiThread([=] { adjustSize(); adjustPosition(mainwindow); }, this);
|
||||
#define LOAD_TYPE(a) ui->type->addItem(NekoRay::ProfileManager::NewProxyEntity(a)->bean->DisplayType(), a);
|
||||
#define LOAD_TYPE(a) ui->type->addItem(NekoGui::ProfileManager::NewProxyEntity(a)->bean->DisplayType(), a);
|
||||
|
||||
DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId, QWidget *parent)
|
||||
: QDialog(parent), ui(new Ui::DialogEditProfile) {
|
||||
@@ -129,13 +129,13 @@ DialogEditProfile::DialogEditProfile(const QString &_type, int profileOrGroupId,
|
||||
LOAD_TYPE("chain");
|
||||
|
||||
// type changed
|
||||
connect(ui->type, QOverload<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());
|
||||
});
|
||||
|
||||
ui->apply_to_group->hide();
|
||||
} else {
|
||||
this->ent = NekoRay::profileManager->GetProfile(profileOrGroupId);
|
||||
this->ent = NekoGui::profileManager->GetProfile(profileOrGroupId);
|
||||
if (this->ent == nullptr) return;
|
||||
this->type = ent->type;
|
||||
ui->type->setVisible(false);
|
||||
@@ -199,7 +199,7 @@ void DialogEditProfile::typeSelected(const QString &newType) {
|
||||
}
|
||||
|
||||
if (newEnt) {
|
||||
this->ent = NekoRay::ProfileManager::NewProxyEntity(type);
|
||||
this->ent = NekoGui::ProfileManager::NewProxyEntity(type);
|
||||
this->ent->gid = groupId;
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ void DialogEditProfile::typeSelected(const QString &newType) {
|
||||
ui->port_l->setVisible(showAddressPort);
|
||||
|
||||
// 右边 stream
|
||||
auto stream = GetStreamSettings(ent->bean.data());
|
||||
auto stream = GetStreamSettings(ent->bean.get());
|
||||
if (stream != nullptr) {
|
||||
ui->right_all_w->setVisible(true);
|
||||
ui->network->setCurrentText(stream->network);
|
||||
@@ -344,7 +344,7 @@ bool DialogEditProfile::onEnd() {
|
||||
}
|
||||
|
||||
// 右边 stream
|
||||
auto stream = GetStreamSettings(ent->bean.data());
|
||||
auto stream = GetStreamSettings(ent->bean.get());
|
||||
if (stream != nullptr) {
|
||||
stream->network = ui->network->currentText();
|
||||
stream->security = ui->security->currentText();
|
||||
@@ -381,13 +381,13 @@ void DialogEditProfile::accept() {
|
||||
QStringList msg = {"accept"};
|
||||
|
||||
if (newEnt) {
|
||||
auto ok = NekoRay::profileManager->AddProfile(ent);
|
||||
auto ok = NekoGui::profileManager->AddProfile(ent);
|
||||
if (!ok) {
|
||||
MessageBoxWarning("???", "id exists");
|
||||
}
|
||||
} else {
|
||||
auto changed = ent->Save();
|
||||
if (changed && NekoRay::dataStore->started_id == ent->id) msg << "restart";
|
||||
if (changed && NekoGui::dataStore->started_id == ent->id) msg << "restart";
|
||||
}
|
||||
|
||||
MW_dialog_message(Dialog_DialogEditProfile, msg.join(","));
|
||||
@@ -456,7 +456,7 @@ void DialogEditProfile::on_apply_to_group_clicked() {
|
||||
apply_to_group_ui[ui->custom_outbound_edit] = new FloatCheckBox(ui->custom_outbound_edit, this);
|
||||
ui->apply_to_group->setText(tr("Confirm"));
|
||||
} else {
|
||||
auto group = NekoRay::profileManager->GetGroup(ent->gid);
|
||||
auto group = NekoGui::profileManager->GetGroup(ent->gid);
|
||||
if (group == nullptr) {
|
||||
MessageBoxWarning("failed", "unknown group");
|
||||
return;
|
||||
@@ -480,12 +480,12 @@ void DialogEditProfile::on_apply_to_group_clicked() {
|
||||
}
|
||||
}
|
||||
|
||||
void DialogEditProfile::do_apply_to_group(const QSharedPointer<NekoRay::Group> &group, QWidget *key) {
|
||||
auto stream = GetStreamSettings(ent->bean.data());
|
||||
void DialogEditProfile::do_apply_to_group(const std::shared_ptr<NekoGui::Group> &group, QWidget *key) {
|
||||
auto stream = GetStreamSettings(ent->bean.get());
|
||||
|
||||
auto copyStream = [=](void *p) {
|
||||
for (const auto &profile: group->Profiles()) {
|
||||
auto newStream = GetStreamSettings(profile->bean.data());
|
||||
auto newStream = GetStreamSettings(profile->bean.get());
|
||||
if (newStream == nullptr) continue;
|
||||
if (stream == newStream) continue;
|
||||
newStream->_setValue(stream->_name(p), p);
|
||||
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
QString type;
|
||||
int groupId;
|
||||
bool newEnt = false;
|
||||
QSharedPointer<NekoRay::ProxyEntity> ent;
|
||||
std::shared_ptr<NekoGui::ProxyEntity> ent;
|
||||
|
||||
QString network_title_base;
|
||||
|
||||
@@ -60,7 +60,7 @@ private:
|
||||
|
||||
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
|
||||
|
||||
@@ -15,7 +15,7 @@ EditChain::~EditChain() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EditChain::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
|
||||
void EditChain::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
|
||||
this->ent = _ent;
|
||||
auto bean = this->ent->ChainBean();
|
||||
|
||||
@@ -45,7 +45,7 @@ void EditChain::on_select_profile_clicked() {
|
||||
}
|
||||
|
||||
void EditChain::AddProfileToListIfExist(int profileId) {
|
||||
auto _ent = NekoRay::profileManager->GetProfile(profileId);
|
||||
auto _ent = NekoGui::profileManager->GetProfile(profileId);
|
||||
if (_ent != nullptr && _ent->type != "chain") {
|
||||
auto wI = new QListWidgetItem();
|
||||
wI->setData(114514, profileId);
|
||||
@@ -64,7 +64,7 @@ void EditChain::AddProfileToListIfExist(int profileId) {
|
||||
}
|
||||
|
||||
void EditChain::ReplaceProfile(ProxyItem *w, int profileId) {
|
||||
auto _ent = NekoRay::profileManager->GetProfile(profileId);
|
||||
auto _ent = NekoGui::profileManager->GetProfile(profileId);
|
||||
if (_ent != nullptr && _ent->type != "chain") {
|
||||
w->item->setData(114514, profileId);
|
||||
w->ent = _ent;
|
||||
|
||||
@@ -19,13 +19,13 @@ public:
|
||||
|
||||
~EditChain() override;
|
||||
|
||||
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override;
|
||||
void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
|
||||
|
||||
bool onEnd() override;
|
||||
|
||||
private:
|
||||
Ui::EditChain *ui;
|
||||
QSharedPointer<NekoRay::ProxyEntity> ent;
|
||||
std::shared_ptr<NekoGui::ProxyEntity> ent;
|
||||
|
||||
void AddProfileToListIfExist(int profileId);
|
||||
|
||||
|
||||
@@ -33,12 +33,12 @@ EditCustom::~EditCustom() {
|
||||
P_SAVE_INT(mapping_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;
|
||||
auto bean = this->ent->CustomBean();
|
||||
|
||||
// load known core
|
||||
auto core_map = QString2QJsonObject(NekoRay::dataStore->extraCore->core_map);
|
||||
auto core_map = QString2QJsonObject(NekoGui::dataStore->extraCore->core_map);
|
||||
for (const auto &key: core_map.keys()) {
|
||||
if (key == "naive" || key == "hysteria") continue;
|
||||
ui->core->addItem(key);
|
||||
@@ -102,7 +102,7 @@ void EditCustom::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
|
||||
th << "%server_port% => " + get_edit_text_serverPort();
|
||||
MessageBoxInfo(tr("Preview replace"), th.join("\n"));
|
||||
// EditCustom::onEnd
|
||||
auto tmpEnt = NekoRay::ProfileManager::NewProxyEntity("custom");
|
||||
auto tmpEnt = NekoGui::ProfileManager::NewProxyEntity("custom");
|
||||
auto bean = tmpEnt->CustomBean();
|
||||
SAVE_CUSTOM_BEAN
|
||||
// 补充
|
||||
@@ -110,7 +110,7 @@ void EditCustom::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
|
||||
bean->serverPort = get_edit_text_serverPort().toInt();
|
||||
if (bean->core.isEmpty()) return;
|
||||
//
|
||||
auto result = NekoRay::BuildConfig(tmpEnt, false, false);
|
||||
auto result = NekoGui::BuildConfig(tmpEnt, false, false);
|
||||
if (!result->error.isEmpty()) {
|
||||
MessageBoxInfo(software_name, result->error);
|
||||
return;
|
||||
|
||||
@@ -21,13 +21,13 @@ public:
|
||||
|
||||
~EditCustom() override;
|
||||
|
||||
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override;
|
||||
void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
|
||||
|
||||
bool onEnd() override;
|
||||
|
||||
private:
|
||||
Ui::EditCustom *ui;
|
||||
QSharedPointer<NekoRay::ProxyEntity> ent;
|
||||
std::shared_ptr<NekoGui::ProxyEntity> ent;
|
||||
|
||||
private slots:
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ EditHysteria::~EditHysteria() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EditHysteria::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
|
||||
void EditHysteria::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
|
||||
this->ent = _ent;
|
||||
auto bean = this->ent->HysteriaBean();
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
|
||||
~EditHysteria() override;
|
||||
|
||||
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override;
|
||||
void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
|
||||
|
||||
bool onEnd() override;
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
|
||||
private:
|
||||
Ui::EditHysteria *ui;
|
||||
QSharedPointer<NekoRay::ProxyEntity> ent;
|
||||
std::shared_ptr<NekoGui::ProxyEntity> ent;
|
||||
|
||||
struct {
|
||||
QString caText;
|
||||
|
||||
@@ -13,7 +13,7 @@ EditNaive::~EditNaive() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EditNaive::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
|
||||
void EditNaive::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
|
||||
this->ent = _ent;
|
||||
auto bean = this->ent->NaiveBean();
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ public:
|
||||
|
||||
~EditNaive() override;
|
||||
|
||||
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override;
|
||||
void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
|
||||
|
||||
bool onEnd() override;
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
|
||||
private:
|
||||
Ui::EditNaive *ui;
|
||||
QSharedPointer<NekoRay::ProxyEntity> ent;
|
||||
std::shared_ptr<NekoGui::ProxyEntity> ent;
|
||||
|
||||
struct {
|
||||
QString certificate;
|
||||
|
||||
@@ -17,7 +17,7 @@ EditShadowSocks::~EditShadowSocks() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EditShadowSocks::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
|
||||
void EditShadowSocks::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
|
||||
this->ent = _ent;
|
||||
auto bean = this->ent->ShadowSocksBean();
|
||||
|
||||
|
||||
@@ -16,13 +16,13 @@ public:
|
||||
|
||||
~EditShadowSocks() override;
|
||||
|
||||
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override;
|
||||
void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
|
||||
|
||||
bool onEnd() override;
|
||||
|
||||
private:
|
||||
Ui::EditShadowSocks *ui;
|
||||
QSharedPointer<NekoRay::ProxyEntity> ent;
|
||||
std::shared_ptr<NekoGui::ProxyEntity> ent;
|
||||
};
|
||||
|
||||
#endif // EDIT_SHADOWSOCKS_H
|
||||
|
||||
@@ -12,16 +12,16 @@ EditSocksHttp::~EditSocksHttp() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EditSocksHttp::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
|
||||
void EditSocksHttp::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
|
||||
this->ent = _ent;
|
||||
auto bean = this->ent->SocksHTTPBean();
|
||||
|
||||
if (bean->socks_http_type == NekoRay::fmt::SocksHttpBean::type_Socks4) {
|
||||
if (bean->socks_http_type == NekoGui_fmt::SocksHttpBean::type_Socks4) {
|
||||
ui->version->setCurrentIndex(1);
|
||||
} else {
|
||||
ui->version->setCurrentIndex(0);
|
||||
}
|
||||
if (bean->socks_http_type == NekoRay::fmt::SocksHttpBean::type_HTTP) {
|
||||
if (bean->socks_http_type == NekoGui_fmt::SocksHttpBean::type_HTTP) {
|
||||
ui->version->setVisible(false);
|
||||
ui->version_l->setVisible(false);
|
||||
}
|
||||
@@ -35,9 +35,9 @@ bool EditSocksHttp::onEnd() {
|
||||
|
||||
if (ui->version->isVisible()) {
|
||||
if (ui->version->currentIndex() == 1) {
|
||||
bean->socks_http_type = NekoRay::fmt::SocksHttpBean::type_Socks4;
|
||||
bean->socks_http_type = NekoGui_fmt::SocksHttpBean::type_Socks4;
|
||||
} else {
|
||||
bean->socks_http_type = NekoRay::fmt::SocksHttpBean::type_Socks5;
|
||||
bean->socks_http_type = NekoGui_fmt::SocksHttpBean::type_Socks5;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,11 +15,11 @@ public:
|
||||
|
||||
~EditSocksHttp() override;
|
||||
|
||||
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override;
|
||||
void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
|
||||
|
||||
bool onEnd() override;
|
||||
|
||||
private:
|
||||
Ui::EditSocksHttp *ui;
|
||||
QSharedPointer<NekoRay::ProxyEntity> ent;
|
||||
std::shared_ptr<NekoGui::ProxyEntity> ent;
|
||||
};
|
||||
|
||||
@@ -11,13 +11,13 @@ EditTrojanVLESS::~EditTrojanVLESS() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EditTrojanVLESS::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
|
||||
void EditTrojanVLESS::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
|
||||
this->ent = _ent;
|
||||
auto bean = this->ent->TrojanVLESSBean();
|
||||
if (bean->proxy_type == NekoRay::fmt::TrojanVLESSBean::proxy_VLESS) {
|
||||
if (bean->proxy_type == NekoGui_fmt::TrojanVLESSBean::proxy_VLESS) {
|
||||
ui->label->setText("UUID");
|
||||
}
|
||||
if (!IS_NEKO_BOX || bean->proxy_type != NekoRay::fmt::TrojanVLESSBean::proxy_VLESS) {
|
||||
if (!IS_NEKO_BOX || bean->proxy_type != NekoGui_fmt::TrojanVLESSBean::proxy_VLESS) {
|
||||
ui->flow->hide();
|
||||
ui->flow_l->hide();
|
||||
}
|
||||
|
||||
@@ -17,11 +17,11 @@ public:
|
||||
|
||||
~EditTrojanVLESS() override;
|
||||
|
||||
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override;
|
||||
void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
|
||||
|
||||
bool onEnd() override;
|
||||
|
||||
private:
|
||||
Ui::EditTrojanVLESS *ui;
|
||||
QSharedPointer<NekoRay::ProxyEntity> ent;
|
||||
std::shared_ptr<NekoGui::ProxyEntity> ent;
|
||||
};
|
||||
|
||||
@@ -14,7 +14,7 @@ EditVMess::~EditVMess() {
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EditVMess::onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) {
|
||||
void EditVMess::onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) {
|
||||
this->ent = _ent;
|
||||
auto bean = this->ent->VMessBean();
|
||||
|
||||
|
||||
@@ -17,11 +17,11 @@ public:
|
||||
|
||||
~EditVMess() override;
|
||||
|
||||
void onStart(QSharedPointer<NekoRay::ProxyEntity> _ent) override;
|
||||
void onStart(std::shared_ptr<NekoGui::ProxyEntity> _ent) override;
|
||||
|
||||
bool onEnd() override;
|
||||
|
||||
private:
|
||||
Ui::EditVMess *ui;
|
||||
QSharedPointer<NekoRay::ProxyEntity> ent;
|
||||
std::shared_ptr<NekoGui::ProxyEntity> ent;
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
class ProfileEditor {
|
||||
public:
|
||||
virtual void onStart(QSharedPointer<NekoRay::ProxyEntity> ent) = 0;
|
||||
virtual void onStart(std::shared_ptr<NekoGui::ProxyEntity> ent) = 0;
|
||||
|
||||
virtual bool onEnd() = 0;
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "main/NekoRay.hpp"
|
||||
#include "main/NekoGui.hpp"
|
||||
|
||||
#ifndef MW_INTERFACE
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#endif
|
||||
|
||||
namespace NekoRay::sys {
|
||||
namespace NekoGui_sys {
|
||||
class CoreProcess;
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ private:
|
||||
QShortcut *shortcut_ctrl_f = new QShortcut(QKeySequence("Ctrl+F"), this);
|
||||
QShortcut *shortcut_esc = new QShortcut(QKeySequence("Esc"), this);
|
||||
//
|
||||
NekoRay::sys::CoreProcess *core_process;
|
||||
NekoGui_sys::CoreProcess *core_process;
|
||||
qint64 vpn_pid = 0;
|
||||
//
|
||||
bool qvLogAutoScoll = true;
|
||||
@@ -149,7 +149,7 @@ private:
|
||||
//
|
||||
QString title_error;
|
||||
int icon_status = -1;
|
||||
QSharedPointer<NekoRay::ProxyEntity> running;
|
||||
std::shared_ptr<NekoGui::ProxyEntity> running;
|
||||
QString traffic_update_cache;
|
||||
QTime last_test_time;
|
||||
//
|
||||
@@ -161,15 +161,15 @@ private:
|
||||
QSemaphore sem_stopped;
|
||||
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 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);
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#include "db/Database.hpp"
|
||||
#include "db/ConfigBuilder.hpp"
|
||||
#include "db/TrafficLooper.hpp"
|
||||
#include "db/traffic/TrafficLooper.hpp"
|
||||
#include "rpc/gRPC.h"
|
||||
#include "ui/widget/MessageBoxTimer.h"
|
||||
|
||||
@@ -16,11 +16,11 @@
|
||||
|
||||
// ext core
|
||||
|
||||
std::list<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
|
||||
std::list<QSharedPointer<NekoRay::sys::ExternalProcess>> l;
|
||||
std::list<std::shared_ptr<NekoGui_sys::ExternalProcess>> l;
|
||||
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->program = extR->program;
|
||||
extC->arguments = extR->arguments;
|
||||
@@ -35,7 +35,7 @@ std::list<QSharedPointer<NekoRay::sys::ExternalProcess>> CreateExtCFromExtR(cons
|
||||
// grpc
|
||||
|
||||
#ifndef NKR_NO_GRPC
|
||||
using namespace NekoRay::rpc;
|
||||
using namespace NekoGui_rpc;
|
||||
#endif
|
||||
|
||||
void MainWindow::setup_grpc() {
|
||||
@@ -45,10 +45,10 @@ void MainWindow::setup_grpc() {
|
||||
[=](const QString &errStr) {
|
||||
MW_show_log("[Error] gRPC: " + errStr);
|
||||
},
|
||||
"127.0.0.1:" + Int2String(NekoRay::dataStore->core_port), NekoRay::dataStore->core_token);
|
||||
"127.0.0.1:" + Int2String(NekoGui::dataStore->core_port), NekoGui::dataStore->core_token);
|
||||
|
||||
// Looper
|
||||
runOnNewThread([=] { NekoRay::traffic::trafficLooper->Loop(); });
|
||||
runOnNewThread([=] { NekoGui_traffic::trafficLooper->Loop(); });
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ inline bool speedtesting = false;
|
||||
void MainWindow::speedtest_current_group(int mode) {
|
||||
auto profiles = get_selected_or_group();
|
||||
if (profiles.isEmpty()) return;
|
||||
auto group = NekoRay::profileManager->CurrentGroup();
|
||||
auto group = NekoGui::profileManager->CurrentGroup();
|
||||
if (group->archive) return;
|
||||
|
||||
#ifndef NKR_NO_GRPC
|
||||
@@ -82,7 +82,7 @@ void MainWindow::speedtest_current_group(int mode) {
|
||||
runOnNewThread([this, profiles, mode, full_test_flags]() {
|
||||
QMutex lock_write;
|
||||
QMutex lock_return;
|
||||
int threadN = NekoRay::dataStore->test_concurrent;
|
||||
int threadN = NekoGui::dataStore->test_concurrent;
|
||||
int threadN_finished = 0;
|
||||
auto profiles_test = profiles; // copy
|
||||
|
||||
@@ -106,13 +106,13 @@ void MainWindow::speedtest_current_group(int mode) {
|
||||
libcore::TestReq req;
|
||||
req.set_mode((libcore::TestMode) mode);
|
||||
req.set_timeout(3000);
|
||||
req.set_url(NekoRay::dataStore->test_url.toStdString());
|
||||
req.set_url(NekoGui::dataStore->test_url.toStdString());
|
||||
|
||||
//
|
||||
std::list<QSharedPointer<NekoRay::sys::ExternalProcess>> extCs;
|
||||
std::list<std::shared_ptr<NekoGui_sys::ExternalProcess>> extCs;
|
||||
|
||||
if (mode == libcore::TestMode::UrlTest || mode == libcore::FullTest) {
|
||||
auto c = NekoRay::BuildConfig(profile, true, false);
|
||||
auto c = BuildConfig(profile, true, false);
|
||||
// TODO refactor external test
|
||||
if (!c->extRs.empty()) {
|
||||
extCs = CreateExtCFromExtR(c->extRs, true);
|
||||
@@ -177,7 +177,7 @@ void MainWindow::speedtest_current() {
|
||||
libcore::TestReq req;
|
||||
req.set_mode(libcore::UrlTest);
|
||||
req.set_timeout(3000);
|
||||
req.set_url(NekoRay::dataStore->test_url.toStdString());
|
||||
req.set_url(NekoGui::dataStore->test_url.toStdString());
|
||||
|
||||
bool rpcOK;
|
||||
auto result = defaultClient->Test(&rpcOK, req);
|
||||
@@ -202,15 +202,15 @@ void MainWindow::speedtest_current() {
|
||||
|
||||
void MainWindow::stop_core_daemon() {
|
||||
#ifndef NKR_NO_GRPC
|
||||
NekoRay::rpc::defaultClient->Exit();
|
||||
NekoGui_rpc::defaultClient->Exit();
|
||||
#endif
|
||||
}
|
||||
|
||||
void MainWindow::neko_start(int _id) {
|
||||
if (NekoRay::dataStore->prepare_exit) return;
|
||||
if (NekoGui::dataStore->prepare_exit) return;
|
||||
|
||||
auto ents = get_now_selected();
|
||||
auto ent = (_id < 0 && !ents.isEmpty()) ? ents.first() : NekoRay::profileManager->GetProfile(_id);
|
||||
auto ent = (_id < 0 && !ents.isEmpty()) ? ents.first() : NekoGui::profileManager->GetProfile(_id);
|
||||
if (ent == nullptr) return;
|
||||
|
||||
if (select_mode) {
|
||||
@@ -220,10 +220,10 @@ void MainWindow::neko_start(int _id) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto group = NekoRay::profileManager->GetGroup(ent->gid);
|
||||
auto group = NekoGui::profileManager->GetGroup(ent->gid);
|
||||
if (group == nullptr || group->archive) return;
|
||||
|
||||
auto result = NekoRay::BuildConfig(ent, false, false);
|
||||
auto result = BuildConfig(ent, false, false);
|
||||
if (!result->error.isEmpty()) {
|
||||
MessageBoxWarning("BuildConfig return error", result->error);
|
||||
return;
|
||||
@@ -233,8 +233,8 @@ void MainWindow::neko_start(int _id) {
|
||||
#ifndef NKR_NO_GRPC
|
||||
libcore::LoadConfigReq req;
|
||||
req.set_core_config(QJsonObject2QString(result->coreConfig, true).toStdString());
|
||||
req.set_enable_nekoray_connections(NekoRay::dataStore->connection_statistics);
|
||||
if (NekoRay::dataStore->traffic_loop_interval > 0) {
|
||||
req.set_enable_nekoray_connections(NekoGui::dataStore->connection_statistics);
|
||||
if (NekoGui::dataStore->traffic_loop_interval > 0) {
|
||||
req.add_stats_outbounds("proxy");
|
||||
req.add_stats_outbounds("bypass");
|
||||
}
|
||||
@@ -248,20 +248,20 @@ void MainWindow::neko_start(int _id) {
|
||||
return false;
|
||||
}
|
||||
//
|
||||
NekoRay::traffic::trafficLooper->proxy = result->outboundStat.get();
|
||||
NekoRay::traffic::trafficLooper->items = result->outboundStats;
|
||||
NekoRay::dataStore->ignoreConnTag = result->ignoreConnTag;
|
||||
NekoRay::traffic::trafficLooper->loop_enabled = true;
|
||||
NekoGui_traffic::trafficLooper->proxy = result->outboundStat.get();
|
||||
NekoGui_traffic::trafficLooper->items = result->outboundStats;
|
||||
NekoGui::dataStore->ignoreConnTag = result->ignoreConnTag;
|
||||
NekoGui_traffic::trafficLooper->loop_enabled = true;
|
||||
#endif
|
||||
|
||||
runOnUiThread(
|
||||
[=] {
|
||||
auto extCs = CreateExtCFromExtR(result->extRs, true);
|
||||
NekoRay::sys::running_ext.splice(NekoRay::sys::running_ext.end(), extCs);
|
||||
NekoGui_sys::running_ext.splice(NekoGui_sys::running_ext.end(), extCs);
|
||||
},
|
||||
DS_cores);
|
||||
|
||||
NekoRay::dataStore->UpdateStartedId(ent->id);
|
||||
NekoGui::dataStore->UpdateStartedId(ent->id);
|
||||
running = ent;
|
||||
|
||||
runOnUiThread([=] {
|
||||
@@ -284,7 +284,7 @@ void MainWindow::neko_start(int _id) {
|
||||
mu_stopping.unlock();
|
||||
|
||||
// check core state
|
||||
if (!NekoRay::dataStore->core_running) {
|
||||
if (!NekoGui::dataStore->core_running) {
|
||||
runOnUiThread(
|
||||
[=] {
|
||||
show_log_impl("Try to start the config, but the core has not listened to the grpc port, so restart it...");
|
||||
@@ -304,7 +304,7 @@ void MainWindow::neko_start(int _id) {
|
||||
|
||||
runOnNewThread([=] {
|
||||
// stop current running
|
||||
if (NekoRay::dataStore->started_id >= 0) {
|
||||
if (NekoGui::dataStore->started_id >= 0) {
|
||||
runOnUiThread([=] { neko_stop(false, true); });
|
||||
sem_stopped.acquire();
|
||||
}
|
||||
@@ -324,7 +324,7 @@ void MainWindow::neko_start(int _id) {
|
||||
}
|
||||
|
||||
void MainWindow::neko_stop(bool crash, bool sem) {
|
||||
auto id = NekoRay::dataStore->started_id;
|
||||
auto id = NekoGui::dataStore->started_id;
|
||||
if (id < 0) {
|
||||
if (sem) sem_stopped.release();
|
||||
return;
|
||||
@@ -333,25 +333,25 @@ void MainWindow::neko_stop(bool crash, bool sem) {
|
||||
auto neko_stop_stage2 = [=] {
|
||||
runOnUiThread(
|
||||
[=] {
|
||||
while (!NekoRay::sys::running_ext.empty()) {
|
||||
auto extC = NekoRay::sys::running_ext.front();
|
||||
while (!NekoGui_sys::running_ext.empty()) {
|
||||
auto extC = NekoGui_sys::running_ext.front();
|
||||
extC->Kill();
|
||||
NekoRay::sys::running_ext.pop_front();
|
||||
NekoGui_sys::running_ext.pop_front();
|
||||
}
|
||||
},
|
||||
DS_cores);
|
||||
|
||||
#ifndef NKR_NO_GRPC
|
||||
NekoRay::traffic::trafficLooper->loop_enabled = false;
|
||||
NekoRay::traffic::trafficLooper->loop_mutex.lock();
|
||||
if (NekoRay::dataStore->traffic_loop_interval != 0) {
|
||||
NekoRay::traffic::trafficLooper->UpdateAll();
|
||||
for (const auto &item: NekoRay::traffic::trafficLooper->items) {
|
||||
NekoRay::profileManager->GetProfile(item->id)->Save();
|
||||
NekoGui_traffic::trafficLooper->loop_enabled = false;
|
||||
NekoGui_traffic::trafficLooper->loop_mutex.lock();
|
||||
if (NekoGui::dataStore->traffic_loop_interval != 0) {
|
||||
NekoGui_traffic::trafficLooper->UpdateAll();
|
||||
for (const auto &item: NekoGui_traffic::trafficLooper->items) {
|
||||
NekoGui::profileManager->GetProfile(item->id)->Save();
|
||||
runOnUiThread([=] { refresh_proxy_list(item->id); });
|
||||
}
|
||||
}
|
||||
NekoRay::traffic::trafficLooper->loop_mutex.unlock();
|
||||
NekoGui_traffic::trafficLooper->loop_mutex.unlock();
|
||||
|
||||
if (!crash) {
|
||||
bool rpcOK;
|
||||
@@ -365,8 +365,8 @@ void MainWindow::neko_stop(bool crash, bool sem) {
|
||||
}
|
||||
#endif
|
||||
|
||||
NekoRay::dataStore->UpdateStartedId(-1919);
|
||||
NekoRay::dataStore->need_keep_vpn_off = false;
|
||||
NekoGui::dataStore->UpdateStartedId(-1919);
|
||||
NekoGui::dataStore->need_keep_vpn_off = false;
|
||||
running = nullptr;
|
||||
|
||||
runOnUiThread([=] {
|
||||
@@ -411,8 +411,8 @@ void MainWindow::CheckUpdate() {
|
||||
bool ok;
|
||||
libcore::UpdateReq request;
|
||||
request.set_action(libcore::UpdateAction::Check);
|
||||
request.set_check_pre_release(NekoRay::dataStore->check_include_pre);
|
||||
auto response = NekoRay::rpc::defaultClient->Update(&ok, request);
|
||||
request.set_check_pre_release(NekoGui::dataStore->check_include_pre);
|
||||
auto response = NekoGui_rpc::defaultClient->Update(&ok, request);
|
||||
if (!ok) return;
|
||||
|
||||
auto err = response.error();
|
||||
@@ -431,7 +431,7 @@ void MainWindow::CheckUpdate() {
|
||||
}
|
||||
|
||||
runOnUiThread([=] {
|
||||
auto allow_updater = !NekoRay::dataStore->flag_use_appdata;
|
||||
auto allow_updater = !NekoGui::dataStore->flag_use_appdata;
|
||||
auto note_pre_release = response.is_pre_release() ? " (Pre-release)" : "";
|
||||
QMessageBox box(QMessageBox::Question, QObject::tr("Update") + note_pre_release,
|
||||
QObject::tr("Update found: %1\nRelease note:\n%2").arg(response.assets_name().c_str(), response.release_note().c_str()));
|
||||
@@ -450,7 +450,7 @@ void MainWindow::CheckUpdate() {
|
||||
bool ok2;
|
||||
libcore::UpdateReq request2;
|
||||
request2.set_action(libcore::UpdateAction::Download);
|
||||
auto response2 = NekoRay::rpc::defaultClient->Update(&ok2, request2);
|
||||
auto response2 = NekoGui_rpc::defaultClient->Update(&ok2, request2);
|
||||
runOnUiThread([=] {
|
||||
if (response2.error().empty()) {
|
||||
auto q = QMessageBox::question(nullptr, QObject::tr("Update"),
|
||||
|
||||
@@ -41,7 +41,7 @@ QString ParseSubInfo(const QString &info) {
|
||||
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);
|
||||
this->setLayoutDirection(Qt::LeftToRight);
|
||||
|
||||
@@ -50,7 +50,7 @@ GroupItem::GroupItem(QWidget *parent, const QSharedPointer<NekoRay::Group> &ent,
|
||||
if (ent == nullptr) return;
|
||||
|
||||
connect(this, &GroupItem::edit_clicked, this, &GroupItem::on_edit_clicked);
|
||||
connect(NekoRay::sub::groupUpdater, &NekoRay::sub::GroupUpdater::asyncUpdateCallback, this, [=](int gid) { if (gid == this->ent->id) refresh_data(); });
|
||||
connect(NekoGui_sub::groupUpdater, &NekoGui_sub::GroupUpdater::asyncUpdateCallback, this, [=](int gid) { if (gid == this->ent->id) refresh_data(); });
|
||||
|
||||
refresh_data();
|
||||
}
|
||||
@@ -74,8 +74,8 @@ void GroupItem::refresh_data() {
|
||||
} else {
|
||||
ui->url->setText(ent->url);
|
||||
QStringList info;
|
||||
if (ent->last_update != 0) {
|
||||
info << tr("Last update: %1").arg(DisplayTime(ent->last_update, QLocale::ShortFormat));
|
||||
if (ent->sub_last_update != 0) {
|
||||
info << tr("Last update: %1").arg(DisplayTime(ent->sub_last_update, QLocale::ShortFormat));
|
||||
}
|
||||
auto subinfo = ParseSubInfo(ent->info);
|
||||
if (!ent->info.isEmpty()) {
|
||||
@@ -98,7 +98,7 @@ void GroupItem::refresh_data() {
|
||||
}
|
||||
|
||||
void GroupItem::on_update_sub_clicked() {
|
||||
NekoRay::sub::groupUpdater->AsyncUpdate(ent->url, ent->id);
|
||||
NekoGui_sub::groupUpdater->AsyncUpdate(ent->url, ent->id);
|
||||
}
|
||||
|
||||
void GroupItem::on_edit_clicked() {
|
||||
@@ -114,10 +114,10 @@ void GroupItem::on_edit_clicked() {
|
||||
}
|
||||
|
||||
void GroupItem::on_remove_clicked() {
|
||||
if (NekoRay::profileManager->groups.count() == 1) return;
|
||||
if (NekoGui::profileManager->groups.count() == 1) return;
|
||||
if (QMessageBox::question(this, tr("Confirmation"), tr("Remove %1?").arg(ent->name)) ==
|
||||
QMessageBox::StandardButton::Yes) {
|
||||
NekoRay::profileManager->DeleteGroup(ent->id);
|
||||
NekoGui::profileManager->DeleteGroup(ent->id);
|
||||
MW_dialog_message(Dialog_DialogManageGroups, "refresh-1");
|
||||
delete item;
|
||||
}
|
||||
|
||||
@@ -15,13 +15,13 @@ class GroupItem : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
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;
|
||||
|
||||
void refresh_data();
|
||||
|
||||
QSharedPointer<NekoRay::Group> ent;
|
||||
std::shared_ptr<NekoGui::Group> ent;
|
||||
QListWidgetItem *item;
|
||||
|
||||
private:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
#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) {
|
||||
ui->setupUi(this);
|
||||
this->setLayoutDirection(Qt::LeftToRight);
|
||||
|
||||
@@ -17,7 +17,7 @@ class ProxyItem : public QWidget {
|
||||
Q_OBJECT
|
||||
|
||||
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;
|
||||
|
||||
@@ -25,7 +25,7 @@ public:
|
||||
|
||||
QPushButton *get_change_button();
|
||||
|
||||
QSharedPointer<NekoRay::ProxyEntity> ent;
|
||||
std::shared_ptr<NekoGui::ProxyEntity> ent;
|
||||
QListWidgetItem *item;
|
||||
bool remove_confirm = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user