Fix initial auth handling

This (hopefully, it at least LGTM) fixes two problems:
 - OverviewPage.onCompleted: It got the wrong AuthorizationState if qml was loaded too fast because it wasn't initialized. (c++)
- The QML could have tried to open the InitializationPage "onCompleted". But the initial pageStack operation is a parent in it's call stack,  so it is neither ready nor wants to accept "completeAnimation()". A zero interval Timer was added for this case.
This commit is contained in:
John Gibbon 2020-11-27 10:25:23 +01:00
parent bf6a5535d1
commit 0ba4d9a408
2 changed files with 16 additions and 3 deletions

View file

@ -68,6 +68,14 @@ Page {
} }
} }
Timer {
id: openInitializationPageTimer
interval: 0
onTriggered: {
pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml"));
}
}
function setPageStatus() { function setPageStatus() {
switch (overviewPage.connectionState) { switch (overviewPage.connectionState) {
case TelegramAPI.WaitingForNetwork: case TelegramAPI.WaitingForNetwork:
@ -101,19 +109,23 @@ Page {
function initializePage() { function initializePage() {
overviewPage.authorizationState = tdLibWrapper.getAuthorizationState(); overviewPage.authorizationState = tdLibWrapper.getAuthorizationState();
overviewPage.handleAuthorizationState(); overviewPage.handleAuthorizationState(true);
overviewPage.connectionState = tdLibWrapper.getConnectionState(); overviewPage.connectionState = tdLibWrapper.getConnectionState();
overviewPage.setPageStatus(); overviewPage.setPageStatus();
} }
function handleAuthorizationState() { function handleAuthorizationState(isOnInitialization) {
switch (overviewPage.authorizationState) { switch (overviewPage.authorizationState) {
case TelegramAPI.WaitPhoneNumber: case TelegramAPI.WaitPhoneNumber:
case TelegramAPI.WaitCode: case TelegramAPI.WaitCode:
case TelegramAPI.WaitPassword: case TelegramAPI.WaitPassword:
case TelegramAPI.WaitRegistration: case TelegramAPI.WaitRegistration:
overviewPage.loading = false; overviewPage.loading = false;
if(isOnInitialization) { // pageStack isn't ready on Component.onCompleted
openInitializationPageTimer.start()
} else {
pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml")); pageStack.push(Qt.resolvedUrl("../pages/InitializationPage.qml"));
}
break; break;
case TelegramAPI.AuthorizationReady: case TelegramAPI.AuthorizationReady:
overviewPage.loading = false; overviewPage.loading = false;

View file

@ -49,6 +49,7 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface,
this->appSettings = appSettings; this->appSettings = appSettings;
this->mceInterface = mceInterface; this->mceInterface = mceInterface;
this->tdLibClient = td_json_client_create(); this->tdLibClient = td_json_client_create();
this->authorizationState = AuthorizationState::Closed;
this->tdLibReceiver = new TDLibReceiver(this->tdLibClient, this); this->tdLibReceiver = new TDLibReceiver(this->tdLibClient, this);
QString tdLibDatabaseDirectoryPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/tdlib"; QString tdLibDatabaseDirectoryPath = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + "/tdlib";