mirror of
https://github.com/MatsuriDayo/nekoray.git
synced 2025-12-17 12:34:37 +03:00
feat: restart profile after core crash
This commit is contained in:
@@ -55,6 +55,15 @@
|
|||||||
"ff00::/8"
|
"ff00::/8"
|
||||||
],
|
],
|
||||||
"outbound": "block"
|
"outbound": "block"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"process_name": [
|
||||||
|
"nekoray_core",
|
||||||
|
"nekoray_core.exe",
|
||||||
|
"nekobox_core",
|
||||||
|
"nekobox_core.exe"
|
||||||
|
],
|
||||||
|
"outbound": "direct"
|
||||||
}
|
}
|
||||||
%PROCESS_NAME_RULE%
|
%PROCESS_NAME_RULE%
|
||||||
%CIDR_RULE%
|
%CIDR_RULE%
|
||||||
|
|||||||
@@ -107,3 +107,14 @@ void runOnUiThread(const std::function<void()> &callback, QObject *parent) {
|
|||||||
void runOnNewThread(const std::function<void()> &callback) {
|
void runOnNewThread(const std::function<void()> &callback) {
|
||||||
createQThread(callback)->start();
|
createQThread(callback)->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setTimeout(const std::function<void()> &callback, QObject *obj, int timeout) {
|
||||||
|
auto t = new QTimer;
|
||||||
|
QObject::connect(t, &QTimer::timeout, obj, [=] {
|
||||||
|
callback();
|
||||||
|
t->deleteLater();
|
||||||
|
});
|
||||||
|
t->setSingleShot(true);
|
||||||
|
t->setInterval(timeout);
|
||||||
|
t->start();
|
||||||
|
}
|
||||||
|
|||||||
@@ -198,3 +198,5 @@ inline void connectOnce(EMITTER *emitter, SIGNAL signal, RECEIVER *receiver, Rec
|
|||||||
|
|
||||||
*connection = QObject::connect(emitter, signal, receiver, onTriggered, connectionType);
|
*connection = QObject::connect(emitter, signal, receiver, onTriggered, connectionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setTimeout(const std::function<void()> &callback, QObject *obj, int timeout = 0);
|
||||||
|
|||||||
@@ -90,19 +90,22 @@ namespace NekoRay::sys {
|
|||||||
if (!dataStore->core_prepare_exit && state == QProcess::NotRunning) {
|
if (!dataStore->core_prepare_exit && state == QProcess::NotRunning) {
|
||||||
if (failed_to_start) return; // no retry
|
if (failed_to_start) return; // no retry
|
||||||
|
|
||||||
|
restart_id = NekoRay::dataStore->started_id;
|
||||||
|
dialog_message("ExternalProcess", "Crashed");
|
||||||
showLog("[Error] core exited, restarting.\n");
|
showLog("[Error] core exited, restarting.\n");
|
||||||
|
|
||||||
// Restart
|
// Restart
|
||||||
auto t = new QTimer;
|
setTimeout([=] {
|
||||||
connect(t, &QTimer::timeout, this, [=] {
|
|
||||||
Kill();
|
Kill();
|
||||||
ExternalProcess::started = false;
|
ExternalProcess::started = false;
|
||||||
Start();
|
Start();
|
||||||
t->deleteLater();
|
}, this, 1000);
|
||||||
});
|
} else if (state == QProcess::Running && restart_id >= 0) {
|
||||||
t->setSingleShot(true);
|
// Restart profile
|
||||||
t->setInterval(1000);
|
setTimeout([=] {
|
||||||
t->start();
|
dialog_message("ExternalProcess", "CoreRestarted," + Int2String(restart_id));
|
||||||
|
restart_id = -1;
|
||||||
|
}, this, 1000);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ namespace NekoRay::sys {
|
|||||||
private:
|
private:
|
||||||
bool show_stderr = false;
|
bool show_stderr = false;
|
||||||
bool failed_to_start = false;
|
bool failed_to_start = false;
|
||||||
|
int restart_id = -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
// start & kill change this list
|
// start & kill change this list
|
||||||
|
|||||||
@@ -481,6 +481,8 @@ void MainWindow::dialog_message_impl(const QString &sender, const QString &info)
|
|||||||
} else if (sender == "ExternalProcess") {
|
} else if (sender == "ExternalProcess") {
|
||||||
if (info == "Crashed") {
|
if (info == "Crashed") {
|
||||||
neko_stop();
|
neko_stop();
|
||||||
|
} else if (info.startsWith("CoreRestarted")) {
|
||||||
|
neko_start(info.split(",")[1].toInt());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user