From a3fcd247d5fe99e44dfbff16baa4e42f6dc0ce9c Mon Sep 17 00:00:00 2001 From: konstantin <konstantin.kuharenko@demlabs.net> Date: Mon, 30 Dec 2024 18:02:47 +0300 Subject: [PATCH] [*] fix gui reset after connection --- vpn/client/DapCmdHandlers/DapCmdStates.cpp | 10 ++-------- vpn/client/DapCmdHandlers/DapCmdStates.h | 2 +- vpn/client/DapStateMachine/DapStateMachine.cpp | 10 ++++++++++ vpn/client/DapStateMachine/DapStateMachine.h | 2 ++ 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/vpn/client/DapCmdHandlers/DapCmdStates.cpp b/vpn/client/DapCmdHandlers/DapCmdStates.cpp index 38c624d07..6155ac006 100644 --- a/vpn/client/DapCmdHandlers/DapCmdStates.cpp +++ b/vpn/client/DapCmdHandlers/DapCmdStates.cpp @@ -3,16 +3,10 @@ void DapCmdStates::handle(const QJsonObject* params) { DapCmdServiceAbstract::handle(params); - QString userRequestState = getUserRequestState(); - QJsonObject result; - QJsonObject statesInfo; - for (const auto &state: _activeStateMachine->getCachedStates()) { - statesInfo.insert(state.getStringType(), state.getStringState()); - qDebug() << "[DapCmdStates] type: " << state.getStringType() << ", state: " << state.getStringState(); - } - result.insert("states", statesInfo); + + result.insert("states", _activeStateMachine->getJsonCachedStates()); if(!userRequestState.isEmpty()){ result.insert(QStringLiteral("user_request_state"), userRequestState); qDebug() << "[DapCmdStates] type: user_request_state, state: " << userRequestState; diff --git a/vpn/client/DapCmdHandlers/DapCmdStates.h b/vpn/client/DapCmdHandlers/DapCmdStates.h index eac57ea2f..20cfe5747 100644 --- a/vpn/client/DapCmdHandlers/DapCmdStates.h +++ b/vpn/client/DapCmdHandlers/DapCmdStates.h @@ -10,7 +10,7 @@ class DapCmdStates: public DapCmdServiceAbstract Q_OBJECT public: explicit DapCmdStates(QObject *parent = nullptr); - void handle(const QJsonObject* params) override; + void handle(const QJsonObject* statesInfo) override; void sendServerChanged(); private: void sendCmdStates(const QString& stateName, const QString stateVal); diff --git a/vpn/client/DapStateMachine/DapStateMachine.cpp b/vpn/client/DapStateMachine/DapStateMachine.cpp index f42978b2a..831fb1f45 100644 --- a/vpn/client/DapStateMachine/DapStateMachine.cpp +++ b/vpn/client/DapStateMachine/DapStateMachine.cpp @@ -36,6 +36,16 @@ const QVector<DapIndicator>& DapStateMachine::getCachedStates() return _statesBuffer; } +const QJsonObject DapStateMachine::getJsonCachedStates() +{ + QJsonObject statesInfo; + for (const auto &state: getCachedStates()) { + statesInfo.insert(state.getStringType(), state.getStringState()); + qDebug() << "[DapChainVpnService] [onIndicatorStateChanged] type: " << state.getStringType() << ", state: " << state.getStringState(); + } + return statesInfo; +} + void DapStateMachine::_emitStateChanged(DapIndicator::Type type, DapIndicator::State state) { m_indicatorStateCache.insert(type, new DapIndicator::State(state)); diff --git a/vpn/client/DapStateMachine/DapStateMachine.h b/vpn/client/DapStateMachine/DapStateMachine.h index 68cedd8f5..35c96790c 100644 --- a/vpn/client/DapStateMachine/DapStateMachine.h +++ b/vpn/client/DapStateMachine/DapStateMachine.h @@ -3,6 +3,7 @@ #include <QDebug> #include <QState> #include <QStateMachine> +#include <QJsonObject> #include <QCache> #include <QVector> @@ -42,6 +43,7 @@ public: DapState *initState; const QVector<DapIndicator>& getCachedStates(); + const QJsonObject getJsonCachedStates(); signals: void stateChanged(DapIndicator i); private: -- GitLab