Fix flashlight button state on errors

This commit is contained in:
Ensar Sarajčić 2023-10-17 12:59:41 +02:00
parent 27c3aa60d0
commit b0ea8d8ef2
2 changed files with 4 additions and 6 deletions

View File

@ -48,10 +48,10 @@ internal class CameraFlash(
manager.setTorchMode(cameraId, enable)
}
} catch (e: Exception) {
context.showErrorToast(e)
scope.launch {
MyCameraImpl.cameraError.emit(Unit)
}
throw e
}
}

View File

@ -193,13 +193,14 @@ class MyCameraImpl private constructor(private val context: Context, private var
}
try {
cameraFlash.runOrToast {
cameraFlash!!.run {
initialize()
toggleFlashlight(true)
}
} catch (e: Exception) {
context.showErrorToast(e)
disableFlashlight()
return
}
val mainRunnable = Runnable { stateChanged(true) }
@ -212,12 +213,9 @@ class MyCameraImpl private constructor(private val context: Context, private var
}
try {
cameraFlash.runOrToast {
toggleFlashlight(false)
}
cameraFlash!!.toggleFlashlight(false)
} catch (e: Exception) {
context.showErrorToast(e)
disableFlashlight()
}
stateChanged(false)
}