Skip to content

Commit

Permalink
Check the model initialization before going to StateMain (mozilla-mob…
Browse files Browse the repository at this point in the history
  • Loading branch information
bakulf authored and aaronkollasch committed May 31, 2022
1 parent 5ea1a21 commit fd1eef7
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 @@ -349,6 +349,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 @@ -645,18 +656,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 @@ -746,15 +746,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 fd1eef7

Please sign in to comment.