android, desktop: try-catch composables (#3575)

* android, desktop: try-catch composables

* test

* better catching on Android

* more try-catch'es

* Revert "test"

This reverts commit adaf92b116.

* more try-catch'es

* unneeded imports
This commit is contained in:
Stanislav Dmitrenko
2023-12-20 18:00:44 +00:00
committed by GitHub
parent 6ba3100d34
commit 4a4d470859
11 changed files with 169 additions and 36 deletions
@@ -1,6 +1,8 @@
package chat.simplex.app
import android.app.Application
import android.os.Handler
import android.os.Looper
import chat.simplex.common.platform.Log
import androidx.lifecycle.*
import androidx.work.*
@@ -35,6 +37,21 @@ class SimplexApp: Application(), LifecycleEventObserver {
return
} else {
registerGlobalErrorHandler()
Handler(Looper.getMainLooper()).post {
while (true) {
try {
Looper.loop()
} catch (e: Throwable) {
if (e.message != null && e.message!!.startsWith("Unable to start activity")) {
android.os.Process.killProcess(android.os.Process.myPid())
break
} else {
// Send it to our exception handled because it will not get the exception otherwise
Thread.getDefaultUncaughtExceptionHandler()?.uncaughtException(Looper.getMainLooper().thread, e)
}
}
}
}
}
context = this
initHaskell()