mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-06-22 02:01:08 +07:00
feat: enhance local proxy error handling and configuration management
- Added signal for local proxy start failure to Settings. - Updated CoreController to emit failure signals with descriptive messages when local proxy fails to start. - Refactored XrayController to accept JSON configuration directly, improving configuration handling. - Removed unused config file loading logic to streamline the XrayController's functionality.
This commit is contained in:
@@ -44,24 +44,14 @@ bool ProxyService::startXray()
|
||||
|
||||
QString error;
|
||||
const auto configData = m_configManager->buildConfig(error);
|
||||
qDebug() << "configData:" << configData.value().serializedConfig;
|
||||
qDebug() << "configData:" << configData.value().parsedConfig;
|
||||
if (!configData) {
|
||||
logConfigError(error);
|
||||
return false;
|
||||
}
|
||||
|
||||
QString configPath;
|
||||
if (!m_configManager->writeTempConfig(configData->serializedConfig, configPath, error)) {
|
||||
qDebug() << "configPath:" << configPath;
|
||||
logConfigError(error);
|
||||
return false;
|
||||
}
|
||||
qDebug() << "configPath:" << configPath;
|
||||
|
||||
m_cachedConfig = configData->parsedConfig;
|
||||
|
||||
const bool success = m_xrayController->start(configPath);
|
||||
const bool success = m_xrayController->start(configData->serializedConfig);
|
||||
if (success) {
|
||||
ProxyLogger::getInstance().info("Xray started successfully");
|
||||
emit xrayStatusChanged(true);
|
||||
@@ -78,7 +68,6 @@ bool ProxyService::stopXray()
|
||||
const bool stopped = m_xrayController->stop();
|
||||
if (stopped) {
|
||||
ProxyLogger::getInstance().info("Xray stopped");
|
||||
m_configManager->removeTempConfig();
|
||||
emit xrayStatusChanged(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
#include "proxylogger.h"
|
||||
#include "core/ipcclient.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
namespace {
|
||||
const QString kIpcUnavailableError = QStringLiteral("Failed to communicate with IPC service");
|
||||
}
|
||||
@@ -20,25 +18,25 @@ XrayController::~XrayController()
|
||||
stop();
|
||||
}
|
||||
|
||||
bool XrayController::start(const QString &configPath)
|
||||
bool XrayController::start(const QString &configJson)
|
||||
{
|
||||
|
||||
if (m_isRunning) {
|
||||
ProxyLogger::getInstance().info("Xray is already running");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
ProxyLogger::getInstance().info("Request to start Xray via IPC");
|
||||
|
||||
m_lastError.clear();
|
||||
|
||||
QString configContent;
|
||||
if (!loadConfigFile(configPath, configContent)) {
|
||||
if (configJson.trimmed().isEmpty()) {
|
||||
m_lastError = QStringLiteral("Config content is empty");
|
||||
ProxyLogger::getInstance().error(m_lastError);
|
||||
return false;
|
||||
}
|
||||
|
||||
const bool ipcResult = IpcClient::withInterface([&](QSharedPointer<IpcInterfaceReplica> iface) {
|
||||
iface->xrayStart(configContent);
|
||||
iface->xrayStart(configJson);
|
||||
return true;
|
||||
}, []() {
|
||||
return false;
|
||||
@@ -89,39 +87,4 @@ qint64 XrayController::getProcessId() const
|
||||
QString XrayController::getError() const
|
||||
{
|
||||
return m_lastError;
|
||||
}
|
||||
|
||||
bool XrayController::loadConfigFile(const QString &configPath, QString &configContent)
|
||||
{
|
||||
if (configPath.isEmpty()) {
|
||||
m_lastError = "Config path is empty";
|
||||
ProxyLogger::getInstance().error(m_lastError);
|
||||
return false;
|
||||
}
|
||||
|
||||
QFile configFile(configPath);
|
||||
if (!configFile.exists()) {
|
||||
m_lastError = QString("Config file not found at: %1").arg(configPath);
|
||||
ProxyLogger::getInstance().error(m_lastError);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!configFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
m_lastError = QString("Failed to open config file: %1").arg(configFile.errorString());
|
||||
ProxyLogger::getInstance().error(m_lastError);
|
||||
return false;
|
||||
}
|
||||
|
||||
QByteArray data = configFile.readAll();
|
||||
configFile.close();
|
||||
|
||||
if (data.isEmpty()) {
|
||||
m_lastError = QString("Config file is empty: %1").arg(configPath);
|
||||
ProxyLogger::getInstance().error(m_lastError);
|
||||
return false;
|
||||
}
|
||||
|
||||
configContent = QString::fromUtf8(data);
|
||||
ProxyLogger::getInstance().debug(QString("Loaded Xray config from %1").arg(configPath));
|
||||
return true;
|
||||
}
|
||||
@@ -10,15 +10,13 @@ public:
|
||||
explicit XrayController(QObject* parent = nullptr);
|
||||
~XrayController();
|
||||
|
||||
bool start(const QString& configPath);
|
||||
bool start(const QString& configJson);
|
||||
bool stop();
|
||||
bool isXrayRunning() const;
|
||||
qint64 getProcessId() const;
|
||||
QString getError() const;
|
||||
|
||||
private:
|
||||
bool loadConfigFile(const QString& configPath, QString& configContent);
|
||||
|
||||
bool m_isRunning {false};
|
||||
QString m_lastError;
|
||||
};
|
||||
Reference in New Issue
Block a user