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:
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user