minor refactor

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

View File

@@ -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