mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-08-14 03:22:52 +03:00
Compare commits
2 Commits
dev
...
fix/window
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
738d8f4db1 | ||
|
|
8c4288023c |
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user