mirror of
https://github.com/Mahdi-zarei/nekoray.git
synced 2025-12-23 01:50:17 +08:00
fix profile stop
This commit is contained in:
parent
0af30d53a2
commit
f6bf4eeed0
@ -66,7 +66,7 @@ public:
|
|||||||
|
|
||||||
void profile_start(int _id = -1);
|
void profile_start(int _id = -1);
|
||||||
|
|
||||||
void profile_stop(bool crash = false, bool sem = false, bool manual = false);
|
void profile_stop(bool crash = false, bool block = false, bool manual = false);
|
||||||
|
|
||||||
void set_spmode_system_proxy(bool enable, bool save = true);
|
void set_spmode_system_proxy(bool enable, bool save = true);
|
||||||
|
|
||||||
@ -193,7 +193,6 @@ private:
|
|||||||
QMutex mu_starting;
|
QMutex mu_starting;
|
||||||
QMutex mu_stopping;
|
QMutex mu_stopping;
|
||||||
QMutex mu_exit;
|
QMutex mu_exit;
|
||||||
QSemaphore sem_stopped;
|
|
||||||
int exit_reason = 0;
|
int exit_reason = 0;
|
||||||
//
|
//
|
||||||
QMutex mu_download_assets;
|
QMutex mu_download_assets;
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
|
#include "include/ui/mainwindow.h"
|
||||||
|
|
||||||
namespace Configs_sys {
|
namespace Configs_sys {
|
||||||
CoreProcess::~CoreProcess() {
|
CoreProcess::~CoreProcess() {
|
||||||
}
|
}
|
||||||
@ -59,7 +61,8 @@ namespace Configs_sys {
|
|||||||
if (failed_to_start) return; // no retry
|
if (failed_to_start) return; // no retry
|
||||||
if (restarting) return;
|
if (restarting) return;
|
||||||
|
|
||||||
MW_dialog_message("ExternalProcess", "CoreCrashed");
|
MW_show_log("[Fatal] " + QObject::tr("Core exited, cleaning up..."));
|
||||||
|
GetMainWindow()->profile_stop(true, true);
|
||||||
|
|
||||||
// Retry rate limit
|
// Retry rate limit
|
||||||
if (coreRestartTimer.isValid()) {
|
if (coreRestartTimer.isValid()) {
|
||||||
@ -74,7 +77,7 @@ namespace Configs_sys {
|
|||||||
|
|
||||||
// Restart
|
// Restart
|
||||||
start_profile_when_core_is_up = Configs::dataStore->started_id;
|
start_profile_when_core_is_up = Configs::dataStore->started_id;
|
||||||
MW_show_log("[Fatal] " + QObject::tr("Core exited, restarting."));
|
MW_show_log("[Warn] " + QObject::tr("Restarting the core ..."));
|
||||||
setTimeout([=,this] { Restart(); }, this, 200);
|
setTimeout([=,this] { Restart(); }, this, 200);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@ -772,8 +772,6 @@ 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") {
|
||||||
profile_stop();
|
profile_stop();
|
||||||
} else if (info == "CoreCrashed") {
|
|
||||||
profile_stop(true);
|
|
||||||
} else if (info.startsWith("CoreStarted")) {
|
} else if (info.startsWith("CoreStarted")) {
|
||||||
Configs::IsAdmin(true);
|
Configs::IsAdmin(true);
|
||||||
if (Configs::dataStore->remember_enable || Configs::dataStore->flag_restart_tun_on) {
|
if (Configs::dataStore->remember_enable || Configs::dataStore->flag_restart_tun_on) {
|
||||||
@ -879,7 +877,6 @@ void MainWindow::prepare_exit()
|
|||||||
//
|
//
|
||||||
Configs::dataStore->save_control_no_save = true; // don't change datastore after this line
|
Configs::dataStore->save_control_no_save = true; // don't change datastore after this line
|
||||||
profile_stop(false, true);
|
profile_stop(false, true);
|
||||||
sem_stopped.acquire();
|
|
||||||
|
|
||||||
QMutex coreKillMu;
|
QMutex coreKillMu;
|
||||||
coreKillMu.lock();
|
coreKillMu.lock();
|
||||||
|
|||||||
@ -524,8 +524,7 @@ void MainWindow::profile_start(int _id) {
|
|||||||
runOnNewThread([=, this] {
|
runOnNewThread([=, this] {
|
||||||
// stop current running
|
// stop current running
|
||||||
if (running != nullptr) {
|
if (running != nullptr) {
|
||||||
runOnUiThread([=,this] { profile_stop(false, true, true); });
|
profile_stop(false, true, true);
|
||||||
sem_stopped.acquire();
|
|
||||||
}
|
}
|
||||||
// do start
|
// do start
|
||||||
MW_show_log(">>>>>>>> " + tr("Starting profile %1").arg(ent->bean->DisplayTypeAndName()));
|
MW_show_log(">>>>>>>> " + tr("Starting profile %1").arg(ent->bean->DisplayTypeAndName()));
|
||||||
@ -564,12 +563,11 @@ void MainWindow::set_spmode_system_proxy(bool enable, bool save) {
|
|||||||
refresh_status();
|
refresh_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::profile_stop(bool crash, bool sem, bool manual) {
|
void MainWindow::profile_stop(bool crash, bool block, bool manual) {
|
||||||
auto id = Configs::dataStore->started_id;
|
if (running == nullptr) {
|
||||||
if (id < 0) {
|
|
||||||
if (sem) sem_stopped.release();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
auto id = running->id;
|
||||||
|
|
||||||
auto profile_stop_stage2 = [=,this] {
|
auto profile_stop_stage2 = [=,this] {
|
||||||
if (!crash) {
|
if (!crash) {
|
||||||
@ -586,9 +584,10 @@ void MainWindow::profile_stop(bool crash, bool sem, bool manual) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (!mu_stopping.tryLock()) {
|
if (!mu_stopping.tryLock()) {
|
||||||
if (sem) sem_stopped.release();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
QMutex blocker;
|
||||||
|
if (block) blocker.lock();
|
||||||
|
|
||||||
// timeout message
|
// timeout message
|
||||||
auto restartMsgbox = new QMessageBox(QMessageBox::Question, software_name, tr("If there is no response for a long time, it is recommended to restart the software."),
|
auto restartMsgbox = new QMessageBox(QMessageBox::Question, software_name, tr("If there is no response for a long time, it is recommended to restart the software."),
|
||||||
@ -612,7 +611,7 @@ void MainWindow::profile_stop(bool crash, bool sem, bool manual) {
|
|||||||
restartMsgboxTimer->deleteLater();
|
restartMsgboxTimer->deleteLater();
|
||||||
restartMsgbox->deleteLater();
|
restartMsgbox->deleteLater();
|
||||||
|
|
||||||
runOnNewThread([=, this] {
|
runOnNewThread([=, this, &blocker] {
|
||||||
// do stop
|
// do stop
|
||||||
MW_show_log(">>>>>>>> " + tr("Stopping profile %1").arg(running->bean->DisplayTypeAndName()));
|
MW_show_log(">>>>>>>> " + tr("Stopping profile %1").arg(running->bean->DisplayTypeAndName()));
|
||||||
if (!profile_stop_stage2()) {
|
if (!profile_stop_stage2()) {
|
||||||
@ -623,13 +622,19 @@ void MainWindow::profile_stop(bool crash, bool sem, bool manual) {
|
|||||||
Configs::dataStore->need_keep_vpn_off = false;
|
Configs::dataStore->need_keep_vpn_off = false;
|
||||||
running = nullptr;
|
running = nullptr;
|
||||||
|
|
||||||
if (sem) sem_stopped.release();
|
if (block) blocker.unlock();
|
||||||
|
|
||||||
runOnUiThread([=, this] {
|
runOnUiThread([=, this, &blocker] {
|
||||||
refresh_status();
|
refresh_status();
|
||||||
refresh_proxy_list_impl_refresh_data(id, true);
|
refresh_proxy_list_impl_refresh_data(id, true);
|
||||||
|
|
||||||
mu_stopping.unlock();
|
mu_stopping.unlock();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (block)
|
||||||
|
{
|
||||||
|
blocker.lock();
|
||||||
|
blocker.unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user