catch and show exceptions thrown at showing timer notifications

This commit is contained in:
tibbi 2022-07-03 15:37:27 +02:00
parent 1ed261e534
commit db8a9f8e44

View File

@ -21,6 +21,8 @@ import com.simplemobiletools.clock.services.TimerStopService
import com.simplemobiletools.clock.services.startStopwatchService import com.simplemobiletools.clock.services.startStopwatchService
import com.simplemobiletools.clock.services.startTimerService import com.simplemobiletools.clock.services.startTimerService
import com.simplemobiletools.commons.extensions.checkUseEnglish import com.simplemobiletools.commons.extensions.checkUseEnglish
import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.commons.extensions.toast
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode import org.greenrobot.eventbus.ThreadMode
@ -109,7 +111,13 @@ class App : Application(), LifecycleObserver {
val pendingIntent = getOpenTimerTabIntent(event.timerId) val pendingIntent = getOpenTimerTabIntent(event.timerId)
val notification = getTimerNotification(timer, pendingIntent, false) val notification = getTimerNotification(timer, pendingIntent, false)
val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager val notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
try {
notificationManager.notify(event.timerId, notification) notificationManager.notify(event.timerId, notification)
} catch (e: Exception) {
showErrorToast(e)
}
updateTimerState(event.timerId, TimerState.Finished) updateTimerState(event.timerId, TimerState.Finished)
Handler(Looper.getMainLooper()).postDelayed({ Handler(Looper.getMainLooper()).postDelayed({
hideNotification(event.timerId) hideNotification(event.timerId)