From 53ff7ebc512b89d72b1d775e3d6bb7bf9496e85a Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Tue, 3 May 2022 18:33:04 +0200 Subject: [PATCH] Check the model initialization before going to StateMain (#3427) --- src/mozillavpn.cpp | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/mozillavpn.cpp b/src/mozillavpn.cpp index 0b89558a16..8e9fa41761 100644 --- a/src/mozillavpn.cpp +++ b/src/mozillavpn.cpp @@ -348,6 +348,17 @@ void MozillaVPN::setState(State state) { void MozillaVPN::maybeStateMain() { logger.debug() << "Maybe state main"; + if (!modelsInitialized()) { + logger.warning() << "Models not initialized yet"; + SettingsHolder::instance()->clear(); + errorHandle(ErrorHandler::RemoteServiceError); + setUserState(UserNotAuthenticated); + setState(StateInitialize); + return; + } + + Q_ASSERT(m_private->m_serverData.initialized()); + if (FeatureInAppPurchase::instance()->isSupported()) { if (m_state != StateSubscriptionBlocked && m_private->m_user.subscriptionNeeded()) { @@ -644,18 +655,7 @@ void MozillaVPN::completeActivation() { TaskScheduler::scheduleTask(new TaskSurveyData()); // Finally we are able to activate the client. - TaskScheduler::scheduleTask(new TaskFunction([this]() { - if (!modelsInitialized()) { - logger.error() << "Failed to complete the authentication"; - errorHandle(ErrorHandler::RemoteServiceError); - setUserState(UserNotAuthenticated); - return; - } - - Q_ASSERT(m_private->m_serverData.initialized()); - - maybeStateMain(); - })); + TaskScheduler::scheduleTask(new TaskFunction([this]() { maybeStateMain(); })); } void MozillaVPN::deviceAdded(const QString& deviceName, @@ -745,15 +745,6 @@ void MozillaVPN::removeDeviceFromPublicKey(const QString& publicKey) { return; } - if (!modelsInitialized()) { - logger.warning() << "Models not initialized yet"; - errorHandle(ErrorHandler::RemoteServiceError); - SettingsHolder::instance()->clear(); - setUserState(UserNotAuthenticated); - setState(StateInitialize); - return; - } - maybeStateMain(); })); }