mirror of
https://github.com/Qv2ray/Qv2ray.git
synced 2025-05-20 02:40:20 +08:00
code refactors
This commit is contained in:
parent
4992a6a020
commit
58b0d4d3b5
@ -1 +1 @@
|
||||
3157
|
||||
3166
|
||||
|
16
Qv2ray.pro
16
Qv2ray.pro
@ -60,12 +60,13 @@ SOURCES += \
|
||||
src/QvCoreConfigOperations_Convertion.cpp \
|
||||
src/QvCoreConfigOperations_Generation.cpp \
|
||||
src/QvUtils.cpp \
|
||||
src/ui/routeNodeModels/QvInboundNodeModel.cpp \
|
||||
src/ui/routeNodeModels/QvOutboundNodeModel.cpp \
|
||||
src/ui/routeNodeModels/QvRuleNodeModel.cpp \
|
||||
src/ui/RouteNodeModels/QvInboundNodeModel.cpp \
|
||||
src/ui/RouteNodeModels/QvOutboundNodeModel.cpp \
|
||||
src/ui/RouteNodeModels/QvRuleNodeModel.cpp \
|
||||
src/ui/w_MainWindow_extra.cpp \
|
||||
src/ui/w_PreferencesWindow.cpp \
|
||||
src/ui/w_RoutesEditor_extra.cpp \
|
||||
src/utils/QvGlobalVarsInstantiation.cpp \
|
||||
src/utils/QvHelpers.cpp \
|
||||
src/utils/QJsonModel.cpp \
|
||||
src/ui/w_ExportConfig.cpp \
|
||||
@ -103,10 +104,10 @@ HEADERS += \
|
||||
src/components/QvPACHandler.hpp \
|
||||
src/components/QvSystemProxyConfigurator.hpp \
|
||||
src/components/QvTCPing.hpp \
|
||||
src/ui/routeNodeModels/QvInboundNodeModel.hpp \
|
||||
src/ui/routeNodeModels/QvNodeModelsBase.hpp \
|
||||
src/ui/routeNodeModels/QvOutboundNodeModel.hpp \
|
||||
src/ui/routeNodeModels/QvRuleNodeModel.hpp \
|
||||
src/ui/RouteNodeModels/QvInboundNodeModel.hpp \
|
||||
src/ui/RouteNodeModels/QvNodeModelsBase.hpp \
|
||||
src/ui/RouteNodeModels/QvOutboundNodeModel.hpp \
|
||||
src/ui/RouteNodeModels/QvRuleNodeModel.hpp \
|
||||
src/ui/w_ExportConfig.hpp \
|
||||
src/ui/w_ImportConfig.hpp \
|
||||
src/ui/w_InboundEditor.hpp \
|
||||
@ -118,6 +119,7 @@ HEADERS += \
|
||||
src/ui/w_SubscriptionEditor.hpp \
|
||||
src/ui/w_ScreenShot_Core.hpp \
|
||||
src/utils/QvHelpers.hpp \
|
||||
src/utils/QvRuntimeConfig.hpp \
|
||||
src/utils/QvTinyLog.hpp \
|
||||
src/utils/QJsonModel.hpp \
|
||||
src/utils/QJsonObjectInsertMacros.h
|
||||
|
@ -18,7 +18,7 @@ const int QV2RAY_CONFIG_VERSION = 8;
|
||||
# endif
|
||||
#endif
|
||||
|
||||
extern bool isDebug;
|
||||
extern const bool isDebugBuild;
|
||||
// Base folder suffix.
|
||||
#ifdef QT_DEBUG
|
||||
# define QV2RAY_CONFIG_DIR_SUFFIX "_debug/"
|
||||
|
@ -5,9 +5,6 @@ namespace Qv2ray
|
||||
{
|
||||
namespace Utils
|
||||
{
|
||||
static bool _isQv2rayExiting = false;
|
||||
Qv2rayConfig GlobalConfig = Qv2rayConfig();
|
||||
QString Qv2rayConfigPath = "";
|
||||
void SaveGlobalConfig(Qv2rayConfig conf)
|
||||
{
|
||||
GlobalConfig = conf;
|
||||
@ -31,21 +28,17 @@ namespace Qv2ray
|
||||
file.open(QFile::ReadOnly);
|
||||
QTextStream stream(&file);
|
||||
auto str = stream.readAll();
|
||||
auto config = StructFromJsonString<Qv2rayConfig>(str);
|
||||
auto config = StructFromJsonString<Qv2rayConfig>(str);
|
||||
SaveGlobalConfig(config);
|
||||
file.close();
|
||||
}
|
||||
|
||||
void ExitQv2ray()
|
||||
{
|
||||
_isQv2rayExiting = true;
|
||||
isExiting = true;
|
||||
QApplication::quit();
|
||||
}
|
||||
|
||||
bool isExiting()
|
||||
{
|
||||
return _isQv2rayExiting;
|
||||
}
|
||||
tuple<QString, int, QString> GetConnectionInfo(const CONFIGROOT &root)
|
||||
{
|
||||
bool validOutboundFound = false;
|
||||
|
@ -11,6 +11,7 @@ namespace Qv2ray
|
||||
{
|
||||
extern QString Qv2rayConfigPath;
|
||||
extern Qv2rayConfig GlobalConfig;
|
||||
extern bool isExiting;
|
||||
//
|
||||
void SaveGlobalConfig(Qv2rayConfig conf);
|
||||
void LoadGlobalConfig();
|
||||
@ -27,7 +28,6 @@ namespace Qv2ray
|
||||
}
|
||||
|
||||
void ExitQv2ray();
|
||||
bool isExiting();
|
||||
tuple<QString, int, QString> GetConnectionInfo(const CONFIGROOT &alias);
|
||||
bool GetOutboundData(const OUTBOUND &out, QString *host, int *port, QString *protocol);
|
||||
}
|
||||
|
@ -7,9 +7,6 @@ namespace Qv2ray
|
||||
{
|
||||
namespace CommandArgOperations
|
||||
{
|
||||
// Instantiation
|
||||
QvStartupOptions StartupOption = QvStartupOptions{};
|
||||
|
||||
QvCommandArgParser::QvCommandArgParser() : QObject(),
|
||||
noAPIOption("noAPI", QObject::tr("Disable gRPC API subsystems.")),
|
||||
runAsRootOption("I-just-wanna-run-with-root", QObject::tr("Explicitly run Qv2ray as root.")),
|
||||
|
@ -242,6 +242,9 @@ namespace Qv2ray
|
||||
{
|
||||
KernelStarted = false;
|
||||
vProcess->close();
|
||||
// Block until V2ray core exits
|
||||
// Should we use -1 instead of waiting for 30secs?
|
||||
vProcess->waitForFinished();
|
||||
killTimer(apiTimerId);
|
||||
apiFailedCounter = 0;
|
||||
transferData.clear();
|
||||
|
@ -42,7 +42,7 @@ namespace Qv2ray
|
||||
|
||||
QvTCPingData QvTCPingModel::startTestLatency(QvTCPingData data, const int count)
|
||||
{
|
||||
if (isExiting()) return QvTCPingData();
|
||||
if (isExiting) return QvTCPingData();
|
||||
|
||||
double successCount = 0, errorCount = 0;
|
||||
addrinfo *resolved;
|
||||
@ -61,7 +61,7 @@ namespace Qv2ray
|
||||
int currentCount = 0;
|
||||
|
||||
while (currentCount < count) {
|
||||
if (isExiting()) return QvTCPingData();
|
||||
if (isExiting) return QvTCPingData();
|
||||
|
||||
timeval rtt;
|
||||
|
||||
@ -102,7 +102,7 @@ namespace Qv2ray
|
||||
|
||||
int QvTCPingModel::resolveHost(const string &host, int port, addrinfo **res)
|
||||
{
|
||||
if (isExiting()) return 0;
|
||||
if (isExiting) return 0;
|
||||
|
||||
addrinfo hints;
|
||||
#ifdef _WIN32
|
||||
@ -120,7 +120,7 @@ namespace Qv2ray
|
||||
|
||||
int QvTCPingModel::testLatency(struct addrinfo *addr, struct timeval *rtt)
|
||||
{
|
||||
if (isExiting()) return 0;
|
||||
if (isExiting) return 0;
|
||||
|
||||
int fd;
|
||||
struct timeval start;
|
||||
@ -131,7 +131,7 @@ namespace Qv2ray
|
||||
|
||||
/* try to connect for each of the entries: */
|
||||
while (addr != nullptr) {
|
||||
if (isExiting()) return 0;
|
||||
if (isExiting) return 0;
|
||||
|
||||
/* create socket */
|
||||
if ((fd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol)) == -1)
|
||||
|
@ -16,9 +16,6 @@
|
||||
#include "unistd.h"
|
||||
#endif
|
||||
|
||||
bool isDebug = false;
|
||||
|
||||
|
||||
void signalHandler(int signum)
|
||||
{
|
||||
cout << "Interrupt signal (" << signum << ") received." << endl;
|
||||
@ -269,12 +266,10 @@ int main(int argc, char *argv[])
|
||||
//
|
||||
#ifdef QT_DEBUG
|
||||
// ----------------------------> For debug build...
|
||||
isDebug = true;
|
||||
SingleApplication::setApplicationName("Qv2ray - DEBUG");
|
||||
#endif
|
||||
|
||||
//
|
||||
if (StartupOption.debugLog) {
|
||||
if (isDebugBuild || StartupOption.debugLog) {
|
||||
DEBUG(MODULE_INIT, "Debug log enabled")
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "w_SubscriptionEditor.hpp"
|
||||
#include "w_RoutesEditor.hpp"
|
||||
|
||||
#include "QvRuntimeConfig.hpp"
|
||||
|
||||
ImportConfigWindow::ImportConfigWindow(QWidget *parent)
|
||||
: QDialog(parent)
|
||||
@ -25,6 +26,7 @@ ImportConfigWindow::ImportConfigWindow(QWidget *parent)
|
||||
setupUi(this);
|
||||
nameTxt->setText(QDateTime::currentDateTime().toString("MMdd_hhmm"));
|
||||
REGISTER_WINDOW
|
||||
RESTORE_RUNTIME_CONFIG(screenShotHideQv2ray, hideQv2rayCB->setChecked)
|
||||
}
|
||||
|
||||
ImportConfigWindow::~ImportConfigWindow()
|
||||
@ -280,3 +282,9 @@ void ImportConfigWindow::on_routeEditBtn_clicked()
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ImportConfigWindow::on_hideQv2rayCB_stateChanged(int arg1)
|
||||
{
|
||||
Q_UNUSED(arg1)
|
||||
SET_RUNTIME_CONFIG(screenShotHideQv2ray, hideQv2rayCB->isChecked)
|
||||
}
|
||||
|
@ -34,6 +34,8 @@ class ImportConfigWindow : public QDialog, private Ui::ImportConfigWindow
|
||||
|
||||
void on_routeEditBtn_clicked();
|
||||
|
||||
void on_hideQv2rayCB_stateChanged(int arg1);
|
||||
|
||||
private:
|
||||
QMap<QString, CONFIGROOT> connections;
|
||||
QMap<QString, QString> vmessErrors;
|
||||
|
@ -10,9 +10,17 @@
|
||||
#include "w_InboundEditor.hpp"
|
||||
#include "w_ImportConfig.hpp"
|
||||
|
||||
#include "RouteNodeModels/QvRuleNodeModel.hpp"
|
||||
#include "RouteNodeModels/QvInboundNodeModel.hpp"
|
||||
#include "RouteNodeModels/QvOutboundNodeModel.hpp"
|
||||
|
||||
#include "NodeStyle.hpp"
|
||||
#include "FlowView.hpp"
|
||||
#include "FlowViewStyle.hpp"
|
||||
|
||||
using QtNodes::FlowView;
|
||||
using namespace Qv2ray::Components::Nodes;
|
||||
|
||||
static bool isLoading = false;
|
||||
#define CurrentRule this->rules[this->currentRuleTag]
|
||||
#define LOADINGCHECK if(isLoading) return;
|
||||
@ -115,7 +123,7 @@ void RouteEditor::onNodeClicked(Node &n)
|
||||
{
|
||||
LOADINGCHECK
|
||||
|
||||
if (isExiting()) return;
|
||||
if (isExiting) return;
|
||||
|
||||
auto isOut = outboundNodes.values().contains(&n);
|
||||
auto isIn = inboundNodes.values().contains(&n);
|
||||
@ -160,7 +168,7 @@ void RouteEditor::onConnectionCreated(QtNodes::Connection const &c)
|
||||
{
|
||||
LOADINGCHECK
|
||||
|
||||
if (isExiting()) return;
|
||||
if (isExiting) return;
|
||||
|
||||
// Connection Established
|
||||
auto const sourceNode = c.getNode(PortType::Out);
|
||||
@ -211,7 +219,7 @@ void RouteEditor::onConnectionDeleted(QtNodes::Connection const &c)
|
||||
{
|
||||
LOADINGCHECK
|
||||
|
||||
if (isExiting()) return;
|
||||
if (isExiting) return;
|
||||
|
||||
// Connection Deleted
|
||||
auto const source = c.getNode(PortType::Out);
|
||||
|
@ -7,30 +7,14 @@
|
||||
#include <QListWidgetItem>
|
||||
#include "QvUtils.hpp"
|
||||
|
||||
#include "Node.hpp"
|
||||
#include "FlowScene.hpp"
|
||||
#include "FlowView.hpp"
|
||||
#include "ConnectionStyle.hpp"
|
||||
|
||||
#include "Node.hpp"
|
||||
#include "NodeData.hpp"
|
||||
#include "ConnectionStyle.hpp"
|
||||
#include "FlowScene.hpp"
|
||||
#include "FlowView.hpp"
|
||||
#include "DataModelRegistry.hpp"
|
||||
|
||||
#include "routeNodeModels/QvRuleNodeModel.hpp"
|
||||
#include "routeNodeModels/QvInboundNodeModel.hpp"
|
||||
#include "routeNodeModels/QvOutboundNodeModel.hpp"
|
||||
|
||||
using QtNodes::DataModelRegistry;
|
||||
using QtNodes::FlowScene;
|
||||
using QtNodes::FlowView;
|
||||
using QtNodes::Node;
|
||||
using QtNodes::FlowScene;
|
||||
using QtNodes::ConnectionStyle;
|
||||
using QtNodes::TypeConverter;
|
||||
using QtNodes::TypeConverterId;
|
||||
|
||||
using namespace Qv2ray::Components::Nodes;
|
||||
|
||||
#include "ui_w_RoutesEditor.h"
|
||||
|
||||
|
@ -63,7 +63,6 @@ QImage ScreenShotWindow::DoScreenShot()
|
||||
setWindowFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint);
|
||||
this->showFullScreen();
|
||||
this->exec();
|
||||
this->close();
|
||||
return resultImage;
|
||||
}
|
||||
|
||||
|
30
src/utils/QvGlobalVarsInstantiation.cpp
Normal file
30
src/utils/QvGlobalVarsInstantiation.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
// Instantiation for Qv2ray global objects.
|
||||
|
||||
#include "Qv2rayBase.hpp"
|
||||
#include "QvUtils.hpp"
|
||||
#include "QvRuntimeConfig.hpp"
|
||||
#include "QvCore/QvCommandLineArgs.hpp"
|
||||
|
||||
// Global scope variable.
|
||||
#ifdef QT_DEBUG
|
||||
const bool isDebugBuild = true;
|
||||
#else
|
||||
const bool isDebugBuild = false;
|
||||
#endif
|
||||
|
||||
namespace Qv2ray
|
||||
{
|
||||
namespace Utils
|
||||
{
|
||||
// Qv2ray runtime config
|
||||
Qv2rayRuntimeConfig RuntimeConfig = Qv2rayRuntimeConfig();
|
||||
bool isExiting = false;
|
||||
Qv2rayConfig GlobalConfig = Qv2rayConfig();
|
||||
QString Qv2rayConfigPath = "";
|
||||
}
|
||||
|
||||
namespace CommandArgOperations
|
||||
{
|
||||
QvStartupOptions StartupOption = QvStartupOptions{};
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ void __QV2RAY_LOG_FUNC__(int type, const std::string &func, int line, const QStr
|
||||
{
|
||||
auto logString = "[" + module + "]: " + log;
|
||||
|
||||
if (StartupOption.debugLog || (isDebug && type == QV2RAY_LOG_DEBUG)) {
|
||||
if (StartupOption.debugLog || (isDebugBuild && type == QV2RAY_LOG_DEBUG)) {
|
||||
logString.prepend(QString::fromStdString(func + ":" + to_string(line) + " "));
|
||||
}
|
||||
|
||||
|
17
src/utils/QvRuntimeConfig.hpp
Normal file
17
src/utils/QvRuntimeConfig.hpp
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef QVRUNTIMECONFIG_HPP
|
||||
#define QVRUNTIMECONFIG_HPP
|
||||
|
||||
#define SET_RUNTIME_CONFIG(conf, val) RuntimeConfig.conf = val();
|
||||
#define RESTORE_RUNTIME_CONFIG(conf, func) func(RuntimeConfig.conf);
|
||||
|
||||
namespace Qv2ray
|
||||
{
|
||||
namespace Utils
|
||||
{
|
||||
struct Qv2rayRuntimeConfig {
|
||||
bool screenShotHideQv2ray;
|
||||
};
|
||||
extern Qv2rayRuntimeConfig RuntimeConfig;
|
||||
}
|
||||
}
|
||||
#endif // QVRUNTIMECONFIG_HPP
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user