Android: login window now only opens when login is actually pressed

This commit is contained in:
Pieter Vander Vennet 2025-06-26 03:13:12 +02:00
parent da6f95863c
commit f4c0541bb1
3 changed files with 21 additions and 6 deletions

@ -1 +1 @@
Subproject commit 1d442585b5202fcb4424d41fa2597cc23f0a9b65
Subproject commit 24a5122a96e9bdaa72c889b081832794fcee9e38

View file

@ -80,6 +80,13 @@ npx capacitor-assets generate
npx cap sync
npm run clean
# Monkey patch version numbers to make everything work
cd android
sed "s/\.\.\/node_modules//" -i capacitor.settings.gradle
cd capacitor
sed "s/'com.android.tools.build:gradle:8.2.1'/'com.android.tools.build:gradle:8.10'/" -i build.gradle
tput bel
tput bel # Note: tput doesn't work in the runners and may not be the last command, otherwise, it'll fail.
echo "All done! Don't forget to click 'gradle sync files' in Android Studio"

View file

@ -286,8 +286,9 @@ export class OsmConnection {
public async AttemptLogin() {
this.updateCapabilities()
if (this.loadingStatus.data !== "logged-in") {
// Stay 'logged-in' if we are already logged in; this simply means we are checking for messages
this.loadingStatus.setData("loading")
}else{
// Stay 'logged-in' if we are already logged in; this simply means we are checking for messages
}
if (this.fakeUser) {
this.loadingStatus.setData("logged-in")
@ -628,15 +629,18 @@ export class OsmConnection {
return this._oauth_config.url + "oauth2_access_token"
}
private async loginAndroidPolyfill() {
/**
* Sets up a callback to the Android App, in order to receive the
* token when it arrives.
* Note that this promise might never resolve and should thus not be awaited
*/
private async androidPolyfillCaptureLogincode() {
const key = this.getLoginCookieName()
if (localStorage.getItem(key)) {
// We are probably already logged in
return
}
const tokenPromise = AndroidPolyfill.requestLoginCodes()
console.trace("Opening login page for android")
await AndroidPolyfill.openLoginPage()
const token = await tokenPromise
console.log("Got login token!", token)
localStorage.setItem(key, token)
@ -666,7 +670,11 @@ export class OsmConnection {
apiUrl: this._oauth_config.api_url ?? this._oauth_config.url,
})
if (AndroidPolyfill.inAndroid.data) {
this.loginAndroidPolyfill() // NO AWAIT!
this.androidPolyfillCaptureLogincode().then(() => {}) // NO AWAIT!
if(autoLogin){
console.trace("Opening login page for android")
AndroidPolyfill.openLoginPage()
}
}
}