Skip to content

Commit b0ea8d8

Browse files
committed
Fix flashlight button state on errors
1 parent 27c3aa6 commit b0ea8d8

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/CameraFlash.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ internal class CameraFlash(
4848
manager.setTorchMode(cameraId, enable)
4949
}
5050
} catch (e: Exception) {
51-
context.showErrorToast(e)
5251
scope.launch {
5352
MyCameraImpl.cameraError.emit(Unit)
5453
}
54+
throw e
5555
}
5656
}
5757

app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,14 @@ class MyCameraImpl private constructor(private val context: Context, private var
193193
}
194194

195195
try {
196-
cameraFlash.runOrToast {
196+
cameraFlash!!.run {
197197
initialize()
198198
toggleFlashlight(true)
199199
}
200200
} catch (e: Exception) {
201201
context.showErrorToast(e)
202202
disableFlashlight()
203+
return
203204
}
204205

205206
val mainRunnable = Runnable { stateChanged(true) }
@@ -212,12 +213,9 @@ class MyCameraImpl private constructor(private val context: Context, private var
212213
}
213214

214215
try {
215-
cameraFlash.runOrToast {
216-
toggleFlashlight(false)
217-
}
216+
cameraFlash!!.toggleFlashlight(false)
218217
} catch (e: Exception) {
219218
context.showErrorToast(e)
220-
disableFlashlight()
221219
}
222220
stateChanged(false)
223221
}

0 commit comments

Comments
 (0)