Merge pull request #94 from Dacid99/main

Fixed bug in nextcloud auth
This commit is contained in:
Xilin Jia 2024-09-24 23:37:58 +01:00 committed by GitHub
commit d84dbeba7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -22,6 +22,7 @@ class NextcloudLoginFlow(private val httpClient: OkHttpClient, private val rawHo
private val hostname = HostnameParser(rawHostUrl)
private var token: String? = null
private var endpoint: String? = null
private var isWaitingForBrowser:Boolean = false
fun saveInstanceState(): ArrayList<String?> {
val state = ArrayList<String?>()
@ -51,7 +52,7 @@ class NextcloudLoginFlow(private val httpClient: OkHttpClient, private val rawHo
withContext(Dispatchers.Main) {
val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(result))
context.startActivity(browserIntent)
poll()
isWaitingForBrowser = true
}
} catch (e: Throwable) {
Log.e(TAG, Log.getStackTraceString(e))
@ -79,6 +80,13 @@ class NextcloudLoginFlow(private val httpClient: OkHttpClient, private val rawHo
throw RuntimeException("Maximum retries exceeded")
}
fun onResume(){ //trigger poll only when returning from the browser
if (token != null && isWaitingForBrowser){
poll()
isWaitingForBrowser = false
}
}
private fun poll() {
CoroutineScope(Dispatchers.IO).launch {
try {

View File

@ -285,6 +285,8 @@ class SynchronizationPreferencesFragment : PreferenceFragmentCompat() {
}
override fun onResume() {
super.onResume()
nextcloudLoginFlow?.onResume()
if (shouldDismiss) dismiss()
}
override fun onNextcloudAuthenticated(server: String, username: String, password: String) {