From d0388c9ad086ff377c0cebafadd1558e06cb7c18 Mon Sep 17 00:00:00 2001 From: Sebastian Streich Date: Wed, 7 Aug 2024 18:13:52 +0200 Subject: [PATCH] [webExt] Let the client communicate the connectionTime --- src/controller.cpp | 24 ++++++++++++++++++++++++ src/controller.h | 1 + src/webextensionadapter.cpp | 3 ++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/controller.cpp b/src/controller.cpp index 31f1d70b28..580640b6a4 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -325,6 +325,30 @@ void Controller::handshakeTimeout() { serverUnavailable(); } +qint64 Controller::connectionTimestamp() const { + switch (m_state) { + case Controller::State::StateConfirming: + [[fallthrough]]; + case Controller::State::StateConnecting: + [[fallthrough]]; + case Controller::State::StateDisconnecting: + [[fallthrough]]; + case Controller::State::StateInitializing: + [[fallthrough]]; + case Controller::State::StateOff: + return 0; + case Controller::State::StateOn: + [[fallthrough]]; + case Controller::State::StateOnPartial: + [[fallthrough]]; + case Controller::State::StateSilentSwitching: + [[fallthrough]]; + case Controller::State::StateSwitching: + return m_connectedTimeInUTC.toMSecsSinceEpoch(); + } + Q_UNREACHABLE(); +} + void Controller::serverUnavailable() { logger.info() << "Server Unavailable - Ping succeeded: " << m_pingReceived; diff --git a/src/controller.h b/src/controller.h index e2bfe8bbc0..be89ce7685 100644 --- a/src/controller.h +++ b/src/controller.h @@ -60,6 +60,7 @@ class Controller : public QObject, public LogSerializer { public: qint64 time() const; + qint64 connectionTimestamp() const; void serverUnavailable(); void captivePortalPresent(); void captivePortalGone(); diff --git a/src/webextensionadapter.cpp b/src/webextensionadapter.cpp index 19555b9db0..1ebae3f2e2 100644 --- a/src/webextensionadapter.cpp +++ b/src/webextensionadapter.cpp @@ -132,7 +132,8 @@ QJsonObject WebExtensionAdapter::serializeStatus() { QJsonObject obj; obj["authenticated"] = App::isUserAuthenticated(); obj["location"] = locationObj; - + obj["connectedSince"] = + QString::number(vpn->controller()->connectionTimestamp()); { int stateValue = vpn->state(); if (stateValue > App::StateCustom) {