mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-22 02:01:08 +07:00
fix: fix local proxy settings and restart logic
- Added local proxy restart token management in Settings. - Implemented logic to handle local proxy state on application quit. - Updated ProxyServer to restart based on configuration changes. - Enhanced API configuration updates to bump restart token when necessary. - Improved UI components to reflect local proxy availability and state. - Added new error handling and notifications for local proxy operations.
This commit is contained in:
@@ -8,6 +8,7 @@ ProxyServer::ProxyServer(const std::shared_ptr<Settings> &settings, QObject *par
|
||||
, m_settings(settings)
|
||||
, m_service(new ProxyService(settings, this))
|
||||
{
|
||||
m_lastRestartToken = m_settings ? m_settings->localProxyRestartToken() : 0;
|
||||
}
|
||||
|
||||
ProxyServer::~ProxyServer()
|
||||
@@ -73,6 +74,7 @@ bool ProxyServer::syncSettings()
|
||||
}
|
||||
|
||||
const quint16 newProxyPort = m_settings ? m_settings->localProxyPort() : 0;
|
||||
const int restartToken = m_settings ? m_settings->localProxyRestartToken() : 0;
|
||||
const bool xrayRunning = m_service->isXrayRunning();
|
||||
|
||||
if (!xrayRunning) {
|
||||
@@ -80,15 +82,27 @@ bool ProxyServer::syncSettings()
|
||||
const bool started = startXrayProcess();
|
||||
if (started) {
|
||||
m_currentProxyPort = newProxyPort;
|
||||
m_lastRestartToken = restartToken;
|
||||
}
|
||||
return started;
|
||||
}
|
||||
|
||||
if (m_lastRestartToken != restartToken) {
|
||||
qInfo() << "Local proxy: restarting Xray due to config change token";
|
||||
const bool restarted = m_service->restartXray();
|
||||
if (restarted) {
|
||||
m_currentProxyPort = newProxyPort;
|
||||
m_lastRestartToken = restartToken;
|
||||
}
|
||||
return restarted;
|
||||
}
|
||||
|
||||
if (m_currentProxyPort != newProxyPort) {
|
||||
qInfo() << "Local proxy: proxy port changed from" << m_currentProxyPort << "to" << newProxyPort;
|
||||
const bool restarted = m_service->restartXray();
|
||||
if (restarted) {
|
||||
m_currentProxyPort = newProxyPort;
|
||||
m_lastRestartToken = restartToken;
|
||||
}
|
||||
return restarted;
|
||||
}
|
||||
|
||||
@@ -32,4 +32,5 @@ private:
|
||||
bool m_isRunning {false};
|
||||
quint16 m_currentApiPort {0};
|
||||
quint16 m_currentProxyPort {0};
|
||||
int m_lastRestartToken {0};
|
||||
};
|
||||
Reference in New Issue
Block a user