diff --git a/sys/ExternalProcess.cpp b/sys/ExternalProcess.cpp index 07f7a38..03aaaf4 100644 --- a/sys/ExternalProcess.cpp +++ b/sys/ExternalProcess.cpp @@ -4,7 +4,7 @@ #include #include #include -#include +#include namespace NekoRay::sys { @@ -74,6 +74,10 @@ namespace NekoRay::sys { } } + // + + QElapsedTimer coreRestartTimer; + CoreProcess::CoreProcess(const QString &core_path, const QStringList &args) : ExternalProcess() { ExternalProcess::managed = false; ExternalProcess::program = core_path; @@ -106,18 +110,24 @@ namespace NekoRay::sys { if (!dataStore->prepare_exit && state == QProcess::NotRunning) { if (failed_to_start) return; // no retry - restart_id = NekoRay::dataStore->started_id; MW_dialog_message("ExternalProcess", "CoreCrashed"); - MW_show_log("[Error] " + QObject::tr("Core exited, restarting.")); + + // Retry rate limit + if (coreRestartTimer.isValid()) { + if (coreRestartTimer.restart() < 10 * 1000) { + coreRestartTimer = QElapsedTimer(); + MW_show_log("[Error] " + QObject::tr("Core exits too frequently, stop automatic restart this profile.")); + return; + } + } else { + coreRestartTimer.start(); + } // Restart - setTimeout( - [=] { - Kill(); - ExternalProcess::started = false; - Start(); - }, - this, 1000); + restart_id = NekoRay::dataStore->started_id; + MW_show_log("[Error] " + QObject::tr("Core exited, restarting.")); + + setTimeout([=] { Restart(); }, this, 1000); } else if (state == QProcess::Running && restart_id >= 0) { // Restart profile setTimeout( @@ -145,4 +155,10 @@ namespace NekoRay::sys { write((dataStore->core_token + "\n").toUtf8()); } + void CoreProcess::Restart() { + Kill(); + ExternalProcess::started = false; + Start(); + } + } // namespace NekoRay::sys diff --git a/sys/ExternalProcess.hpp b/sys/ExternalProcess.hpp index 225709b..440fd4a 100644 --- a/sys/ExternalProcess.hpp +++ b/sys/ExternalProcess.hpp @@ -33,6 +33,8 @@ namespace NekoRay::sys { void Start() override; + void Restart(); + private: bool show_stderr = false; bool failed_to_start = false; diff --git a/translations/fa_IR.ts b/translations/fa_IR.ts index 61a68c7..699e1d9 100644 --- a/translations/fa_IR.ts +++ b/translations/fa_IR.ts @@ -1462,10 +1462,6 @@ End: %2 Failed to stop, please restart the program. - - Core exits too frequently, stop automatic restart this profile. - - ProxyItem @@ -1602,6 +1598,10 @@ Direct: %2 Core exited, restarting. + + Core exits too frequently, stop automatic restart this profile. + + Qv2ray::ui::widgets::AutoCompleteTextEdit diff --git a/translations/zh_CN.ts b/translations/zh_CN.ts index 1e6b861..d5759a3 100644 --- a/translations/zh_CN.ts +++ b/translations/zh_CN.ts @@ -1469,10 +1469,6 @@ Split by line. If there is no response for a long time, it is recommended to restart the software. 如果长时间没有反应,建议重启软件。 - - Core exits too frequently, stop automatic restart this profile. - Core 退出太频繁,停止自动重启。 - ProxyItem @@ -1608,6 +1604,10 @@ Release note: Core exited, restarting. Core 退出,正在重新启动。 + + Core exits too frequently, stop automatic restart this profile. + Core 退出太频繁,停止自动重启。 + Qv2ray::ui::widgets::AutoCompleteTextEdit diff --git a/ui/mainwindow.cpp b/ui/mainwindow.cpp index 63fdad8..cd07026 100644 --- a/ui/mainwindow.cpp +++ b/ui/mainwindow.cpp @@ -44,9 +44,6 @@ #include #include #include -#include - -QElapsedTimer coreRestartTimer; void UI_InitMainWindow() { mainwindow = new MainWindow; @@ -579,15 +576,6 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info) } else if (info == "CoreCrashed") { neko_stop(true); } else if (info.startsWith("CoreRestarted")) { - if (coreRestartTimer.isValid()) { - if (coreRestartTimer.restart() < 10 * 1000) { - coreRestartTimer = QElapsedTimer(); - show_log_impl("[Error] " + tr("Core exits too frequently, stop automatic restart this profile.")); - return; - } - } else { - coreRestartTimer.start(); - } neko_start(info.split(",")[1].toInt()); } } diff --git a/ui/mainwindow_grpc.cpp b/ui/mainwindow_grpc.cpp index 928c045..b46533f 100644 --- a/ui/mainwindow_grpc.cpp +++ b/ui/mainwindow_grpc.cpp @@ -230,6 +230,15 @@ void MainWindow::neko_start(int _id) { } auto neko_start_stage2 = [=] { + if (!NekoRay::dataStore->core_running) { + runOnUiThread( + [=] { + core_process->Restart(); + }, + DS_cores); + QThread::sleep(1); + } + #ifndef NKR_NO_GRPC libcore::LoadConfigReq req; req.set_core_config(QJsonObject2QString(result->coreConfig, true).toStdString()); @@ -244,6 +253,8 @@ void MainWindow::neko_start(int _id) { if (rpcOK && !error.isEmpty()) { runOnUiThread([=] { MessageBoxWarning("LoadConfig return error", error); }); return false; + } else if (!rpcOK) { + return false; } // NekoRay::traffic::trafficLooper->proxy = result->outboundStat.get(); @@ -338,6 +349,8 @@ void MainWindow::neko_stop(bool crash, bool sem) { if (rpcOK && !error.isEmpty()) { runOnUiThread([=] { MessageBoxWarning("Stop return error", error); }); return false; + } else if (!rpcOK) { + return false; } } #endif