Skip to content

Commit

Permalink
Remove tos completly, fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherHX committed Oct 25, 2020
1 parent 40d22b1 commit 68d9248
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 61 deletions.
78 changes: 39 additions & 39 deletions googleplayapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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("<b>Please report this error</b><br>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("<b>Please report this error</b><br>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("<b>Please report this error</b><br>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("<b>Please report this error</b><br>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());
}
});
}

13 changes: 2 additions & 11 deletions googleplayapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class GooglePlayApi : public QObject {
GoogleLoginHelper* loginHelper;
QMutex checkinMutex;
playapi::checkin_result checkinResult;
std::promise<std::pair<bool, bool>> tosApprovalPromise;
GooglePlayApiStatus status = GooglePlayApiStatus::NOT_READY;

void loadCheckinInfo();
Expand All @@ -42,6 +41,8 @@ class GooglePlayApi : public QObject {
}
}

void updateLogin();

public:
explicit GooglePlayApi(QObject *parent = nullptr);

Expand All @@ -58,25 +59,15 @@ 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);

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
11 changes: 0 additions & 11 deletions qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 68d9248

Please sign in to comment.