Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug in nextcloud auth #94

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading