mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
committed by
Benoit Marty
parent
044737a3a7
commit
33979b6574
+14
@@ -12,10 +12,12 @@ import dev.zacsweers.metro.SingleIn
|
|||||||
import io.element.android.libraries.core.log.logger.LoggerTag
|
import io.element.android.libraries.core.log.logger.LoggerTag
|
||||||
import io.element.android.libraries.di.SessionScope
|
import io.element.android.libraries.di.SessionScope
|
||||||
import io.element.android.libraries.matrix.api.MatrixClient
|
import io.element.android.libraries.matrix.api.MatrixClient
|
||||||
|
import io.element.android.libraries.matrix.api.linknewdevice.ErrorType
|
||||||
import io.element.android.libraries.matrix.api.linknewdevice.LinkDesktopHandler
|
import io.element.android.libraries.matrix.api.linknewdevice.LinkDesktopHandler
|
||||||
import io.element.android.libraries.matrix.api.linknewdevice.LinkDesktopStep
|
import io.element.android.libraries.matrix.api.linknewdevice.LinkDesktopStep
|
||||||
import io.element.android.libraries.matrix.api.logs.LoggerTags
|
import io.element.android.libraries.matrix.api.logs.LoggerTags
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.MutableStateFlow
|
import kotlinx.coroutines.flow.MutableStateFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
import kotlinx.coroutines.flow.asStateFlow
|
import kotlinx.coroutines.flow.asStateFlow
|
||||||
@@ -23,6 +25,7 @@ import kotlinx.coroutines.flow.launchIn
|
|||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
|
import kotlin.time.Duration.Companion.minutes
|
||||||
|
|
||||||
private val loggerTag = LoggerTag("LinkNewDesktopHandler", LoggerTags.linkNewDevice)
|
private val loggerTag = LoggerTag("LinkNewDesktopHandler", LoggerTags.linkNewDevice)
|
||||||
|
|
||||||
@@ -40,17 +43,26 @@ class LinkNewDesktopHandler(
|
|||||||
get() = linkDesktopStepFlow.asStateFlow()
|
get() = linkDesktopStepFlow.asStateFlow()
|
||||||
|
|
||||||
private var currentJob: Job? = null
|
private var currentJob: Job? = null
|
||||||
|
private var timerJob: Job? = null
|
||||||
private var handler: LinkDesktopHandler? = null
|
private var handler: LinkDesktopHandler? = null
|
||||||
|
|
||||||
fun createNewHandler() {
|
fun createNewHandler() {
|
||||||
currentJob?.cancel()
|
currentJob?.cancel()
|
||||||
currentJob = null
|
currentJob = null
|
||||||
|
timerJob?.cancel()
|
||||||
|
timerJob = null
|
||||||
handler = matrixClient.createLinkDesktopHandler().getOrNull()
|
handler = matrixClient.createLinkDesktopHandler().getOrNull()
|
||||||
|
timerJob = sessionScope.launch {
|
||||||
|
delay(2.minutes)
|
||||||
|
linkDesktopStepFlow.emit(LinkDesktopStep.Error(ErrorType.Expired("Scanning QrCode took too long.")))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun reset() {
|
fun reset() {
|
||||||
currentJob?.cancel()
|
currentJob?.cancel()
|
||||||
currentJob = null
|
currentJob = null
|
||||||
|
timerJob?.cancel()
|
||||||
|
timerJob = null
|
||||||
sessionScope.launch {
|
sessionScope.launch {
|
||||||
linkDesktopStepFlow.emit(LinkDesktopStep.Uninitialized)
|
linkDesktopStepFlow.emit(LinkDesktopStep.Uninitialized)
|
||||||
}
|
}
|
||||||
@@ -59,6 +71,8 @@ class LinkNewDesktopHandler(
|
|||||||
fun onScannedCode(data: ByteArray) {
|
fun onScannedCode(data: ByteArray) {
|
||||||
currentJob?.cancel()
|
currentJob?.cancel()
|
||||||
currentJob = null
|
currentJob = null
|
||||||
|
timerJob?.cancel()
|
||||||
|
timerJob = null
|
||||||
val currentHandler = handler
|
val currentHandler = handler
|
||||||
if (currentHandler == null) {
|
if (currentHandler == null) {
|
||||||
Timber.tag(loggerTag.value).e("onScannedCode: Handler is not initialized. Call createNewHandler() first.")
|
Timber.tag(loggerTag.value).e("onScannedCode: Handler is not initialized. Call createNewHandler() first.")
|
||||||
|
|||||||
Reference in New Issue
Block a user