From b0ea8d8ef24ffb3a77d2d2b85ea043d6407f4cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Tue, 17 Oct 2023 12:59:41 +0200 Subject: [PATCH] Fix flashlight button state on errors --- .../simplemobiletools/flashlight/helpers/CameraFlash.kt | 2 +- .../simplemobiletools/flashlight/helpers/MyCameraImpl.kt | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/CameraFlash.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/CameraFlash.kt index 186b5d7..997f70b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/CameraFlash.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/CameraFlash.kt @@ -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 } } diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt index 9210b7d..0fb1b0c 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt @@ -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) }