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) manager.setTorchMode(cameraId, enable)
} }
} catch (e: Exception) { } catch (e: Exception) {
context.showErrorToast(e)
scope.launch { scope.launch {
MyCameraImpl.cameraError.emit(Unit) MyCameraImpl.cameraError.emit(Unit)
} }
throw e
} }
} }

View File

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