Skip to content

Commit

Permalink
Check the model initialization before going to StateMain (#3427)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakulf authored May 3, 2022
1 parent 1526971 commit 53ff7eb
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions src/mozillavpn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}));
}
Expand Down

0 comments on commit 53ff7eb

Please sign in to comment.