Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check the model initialization before going to StateMain #3427

Merged
merged 1 commit into from
May 3, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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