Skip to content

Commit

Permalink
fixed bug in nextcloud auth
Browse files Browse the repository at this point in the history
  • Loading branch information
david committed Sep 23, 2024
1 parent 8ae7365 commit 1b0d101
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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?>()
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1b0d101

Please sign in to comment.