Compare commits

...

2 Commits

Author SHA1 Message Date
NickVs2015
738d8f4db1 fix: correct ControlService call and ANSI error message decoding on Windows 2026-08-13 01:30:07 +03:00
NickVs2015
8c4288023c fix: debounce VPN reconnect triggers 2026-08-13 01:23:31 +03:00
4 changed files with 24 additions and 8 deletions

View File

@@ -130,7 +130,8 @@ bool WindowsServiceManager::stopService() {
logger.warning() << ("Service stop not possible, as its not running");
}
bool ok = ControlService(m_service, SERVICE_CONTROL_STOP, NULL);
SERVICE_STATUS status;
bool ok = ControlService(m_service, SERVICE_CONTROL_STOP, &status);
if (ok) {
logger.debug() << ("Service stop requested");
startPolling(SERVICE_STOPPED, 10);

View File

@@ -27,8 +27,7 @@ QString WindowsUtils::getErrorMessage(quint32 code) {
nullptr, code, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPSTR)&messageBuffer, 0, nullptr);
std::string message(messageBuffer, size);
QString result(message.c_str());
QString result = QString::fromLocal8Bit(messageBuffer, static_cast<int>(size)).trimmed();
LocalFree(messageBuffer);
return result;
}
@@ -39,8 +38,9 @@ QString WindowsUtils::getErrorMessage() {
// A simple function to log windows error messages.
void WindowsUtils::windowsLog(const QString& msg) {
QString errmsg = getErrorMessage();
logger.error() << msg << "-" << errmsg;
quint32 code = GetLastError();
QString errmsg = getErrorMessage(code);
logger.error() << msg << "-" << errmsg << QString("(code %1)").arg(code);
}
// Static

View File

@@ -36,14 +36,21 @@
using namespace ProtocolUtils;
namespace {
constexpr int RECONNECT_DEBOUNCE_MSEC = 1500;
}
VpnConnection::VpnConnection(SecureServersRepository* serversRepository, SecureAppSettingsRepository* appSettingsRepository, QObject *parent)
: QObject(parent), m_serversRepository(serversRepository), m_appSettingsRepository(appSettingsRepository), m_checkTimer(this)
: QObject(parent), m_serversRepository(serversRepository), m_appSettingsRepository(appSettingsRepository), m_checkTimer(this), m_reconnectDebounceTimer(this)
{
#if defined(Q_OS_IOS) || defined(MACOS_NE)
m_checkTimer.setInterval(1000);
connect(IosController::Instance(), &IosController::connectionStateChanged, this, &VpnConnection::setConnectionState);
connect(IosController::Instance(), &IosController::bytesChanged, this, &VpnConnection::onBytesChanged);
#endif
m_reconnectDebounceTimer.setSingleShot(true);
connect(&m_reconnectDebounceTimer, &QTimer::timeout, this, &VpnConnection::reconnectToVpn);
}
VpnConnection::~VpnConnection()
@@ -381,8 +388,8 @@ void VpnConnection::createProtocolConnections()
#ifdef AMNEZIA_DESKTOP
IpcClient::withInterface([this](QSharedPointer<IpcInterfaceReplica> rep) {
connect(rep.data(), &IpcInterfaceReplica::networkChanged, this, &VpnConnection::reconnectToVpn, Qt::QueuedConnection);
connect(rep.data(), &IpcInterfaceReplica::wakeup, this, &VpnConnection::reconnectToVpn, Qt::QueuedConnection);
connect(rep.data(), &IpcInterfaceReplica::networkChanged, this, &VpnConnection::requestReconnect, Qt::QueuedConnection);
connect(rep.data(), &IpcInterfaceReplica::wakeup, this, &VpnConnection::requestReconnect, Qt::QueuedConnection);
});
#endif
}
@@ -549,6 +556,11 @@ QString VpnConnection::bytesPerSecToText(quint64 bytes)
return QString("%1 %2").arg(QString::number(mbps, 'f', 2)).arg(tr("Mbps")); // Mbit/s
}
void VpnConnection::requestReconnect() {
qDebug() << "Reconnect requested; debouncing for" << RECONNECT_DEBOUNCE_MSEC << "ms";
m_reconnectDebounceTimer.start(RECONNECT_DEBOUNCE_MSEC);
}
void VpnConnection::reconnectToVpn() {
if (m_vpnProtocol.isNull())
return;

View File

@@ -51,6 +51,7 @@ public slots:
void setRepositories(SecureServersRepository* serversRepository, SecureAppSettingsRepository* appSettingsRepository);
void connectToVpn(const QString &serverId, DockerContainer container, const QJsonObject &vpnConfiguration);
void reconnectToVpn();
void requestReconnect();
void disconnectFromVpn();
void onKillSwitchModeChanged(bool enabled);
@@ -83,6 +84,8 @@ private:
// Only for iOS for now, check counters
QTimer m_checkTimer;
QTimer m_reconnectDebounceTimer;
#ifdef Q_OS_ANDROID
AndroidVpnProtocol* androidVpnProtocol = nullptr;