diff --git a/googleplayapi.cpp b/googleplayapi.cpp index a228bf8..895a2aa 100644 --- a/googleplayapi.cpp +++ b/googleplayapi.cpp @@ -10,18 +10,18 @@ GooglePlayApi::GooglePlayApi(QObject *parent) : QObject(parent) { void GooglePlayApi::setLogin(GoogleLoginHelper *helper) { if (loginHelper != helper) { setStatus(GooglePlayApiStatus::NOT_READY); + if (loginHelper) { + disconnect(loginHelper, &GoogleLoginHelper::accountInfoChanged, this, &GooglePlayApi::updateLogin); + } loginHelper = helper; - if (helper) { - api.reset(new playapi::api(helper->getDevice())); + if (loginHelper) { + api.reset(new playapi::api(loginHelper->getDevice())); + connect(loginHelper, &GoogleLoginHelper::accountInfoChanged, this, &GooglePlayApi::updateLogin); updateLogin(); } } } -void GooglePlayApi::updateLogin() { - handleCheckinAndTos(); -} - void GooglePlayApi::requestAppInfo(const QString &packageName) { if (status == GooglePlayApiStatus::SUCCEDED) { api->details(packageName.toStdString())->call([this, packageName](playapi::proto::finsky::response::ResponseWrapper&& resp) { @@ -95,40 +95,40 @@ void GooglePlayApi::saveApiInfo() { settings.endGroup(); } -void GooglePlayApi::handleCheckinAndTos() { - if (status == GooglePlayApiStatus::NOT_READY) { - setStatus(GooglePlayApiStatus::PENDING); - QtConcurrent::run([this]() { - try { - QMutexLocker checkinMutexLocker (&checkinMutex); - loadCheckinInfo(); - if (checkinResult.android_id == 0) { - if (!loginHelper || loginHelper->account() == nullptr) { - setStatus(GooglePlayApiStatus::FAILED); - emit initError(tr("Please report this error
GooglePlayApi already in progress '!loginHelper'=%1, '!loginHelper || loginHelper->account() == nullptr'=%2").arg((bool)!loginHelper).arg((bool)(!loginHelper || loginHelper->account()))); - return; - } - playapi::checkin_api checkin(loginHelper->getDevice()); - checkin.add_auth(loginHelper->getLoginApi())->call(); - checkinResult = checkin.perform_checkin()->call(); - saveCheckinInfo(); +void GooglePlayApi::updateLogin() { + QtConcurrent::run([this]() { + try { + QMutexLocker checkinMutexLocker (&checkinMutex); + if (status == GooglePlayApiStatus::PENDING) { + emit initError(tr("Please report this error
GooglePlayApi already in progress status reporting not working status=%1").arg((int)status)); + } + setStatus(GooglePlayApiStatus::PENDING); + loadCheckinInfo(); + if (checkinResult.android_id == 0) { + if (!loginHelper) { + setStatus(GooglePlayApiStatus::FAILED); + emit initError(tr("Please report this error
GooglePlayApi needs the loginHelper")); + return; + } else if (loginHelper->account() == nullptr) { + return; } - api->set_checkin_data(checkinResult); - checkinMutexLocker.unlock(); - api->set_auth(loginHelper->getLoginApi())->call(); - - loadApiInfo(); - saveApiInfo(); - setStatus(GooglePlayApiStatus::SUCCEDED); - emit ready(); - } catch (const std::exception& ex) { - setStatus(GooglePlayApiStatus::FAILED); - emit initError(ex.what()); + playapi::checkin_api checkin(loginHelper->getDevice()); + checkin.add_auth(loginHelper->getLoginApi())->call(); + checkinResult = checkin.perform_checkin()->call(); + saveCheckinInfo(); } - }); - } else { - setStatus(GooglePlayApiStatus::FAILED); - emit initError(tr("Please report this error
GooglePlayApi already in progress status=%1").arg((int)status)); - } + api->set_checkin_data(checkinResult); + checkinMutexLocker.unlock(); + api->set_auth(loginHelper->getLoginApi())->call(); + + loadApiInfo(); + saveApiInfo(); + setStatus(GooglePlayApiStatus::SUCCEDED); + emit ready(); + } catch (const std::exception& ex) { + setStatus(GooglePlayApiStatus::FAILED); + emit initError(ex.what()); + } + }); } diff --git a/googleplayapi.h b/googleplayapi.h index aba58b8..b333979 100644 --- a/googleplayapi.h +++ b/googleplayapi.h @@ -26,7 +26,6 @@ class GooglePlayApi : public QObject { GoogleLoginHelper* loginHelper; QMutex checkinMutex; playapi::checkin_result checkinResult; - std::promise> tosApprovalPromise; GooglePlayApiStatus status = GooglePlayApiStatus::NOT_READY; void loadCheckinInfo(); @@ -42,6 +41,8 @@ class GooglePlayApi : public QObject { } } + void updateLogin(); + public: explicit GooglePlayApi(QObject *parent = nullptr); @@ -58,8 +59,6 @@ class GooglePlayApi : public QObject { void initError(QString const& text); - void tosApprovalRequired(QString const& tosText, QString const& marketingText); - void appInfoReceived(QString const& packageName, QString const& version, int versionCode, bool isBeta); void appInfoFailed(QString const& packageName, QString errorMessage); @@ -67,16 +66,8 @@ class GooglePlayApi : public QObject { void statusChanged(); public slots: - void handleCheckinAndTos(); - - void updateLogin(); - void requestAppInfo(QString const& packageName); - void setTosApproved(bool approved, bool marketing) { - tosApprovalPromise.set_value({approved, marketing}); - } - }; #endif // GOOGLEPLAYAPI_H diff --git a/qml/main.qml b/qml/main.qml index 97ce232..6ea5bf5 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -105,12 +105,6 @@ Window { playDownloadError.text = qsTr("Failed to obtain the gameversion, please check your internet connection and / or login again"); playDownloadError.open() } - - onTosApprovalRequired: function(tos, marketing) { - googleTosApprovalWindow.tosText = tos - googleTosApprovalWindow.marketingText = marketing - googleTosApprovalWindow.show() - } } GoogleVersionChannel { @@ -212,10 +206,6 @@ Window { Connections { target: googleLoginHelperInstance - onAccountInfoChanged: { - if (googleLoginHelperInstance.account !== null) - playApi.handleCheckinAndTos() - } onLoginError: function(err) { playDownloadError.text = qsTr("The Launcher failed to sign you in\nPlease login again\n%1").arg(err); playDownloadError.open() @@ -260,7 +250,6 @@ Window { Component.onCompleted: { if(launcherSettings.checkForUpdates) updateChecker.checkForUpdates() - playApi.handleCheckinAndTos() versionManagerInstance.downloadLists(googleLoginHelperInstance.getAbis(true)) if(LAUNCHER_CHANGE_LOG.length !== 0 && launcherSettings.lastVersion < LAUNCHER_VERSION_CODE) { stackView.push(panelChangelog);