Prevent crashes in case of exception

This commit is contained in:
Sylvain Berfini 2024-07-31 09:29:21 +02:00
parent e14a142fb7
commit 5cc491335c
2 changed files with 23 additions and 7 deletions

View file

@ -499,8 +499,12 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
fun postOnCoreThread(
@WorkerThread lambda: (core: Core) -> Unit
) {
coreThread.post {
lambda.invoke(core)
if (::coreThread.isInitialized) {
coreThread.post {
lambda.invoke(core)
}
} else {
Log.e("$TAG Core's thread not initialized yet!")
}
}
@ -509,9 +513,13 @@ class CoreContext @UiThread constructor(val context: Context) : HandlerThread("C
@WorkerThread lambda: (core: Core) -> Unit,
delay: Long
) {
coreThread.postDelayed({
lambda.invoke(core)
}, delay)
if (::coreThread.isInitialized) {
coreThread.postDelayed({
lambda.invoke(core)
}, delay)
} else {
Log.e("$TAG Core's thread not initialized yet!")
}
}
@AnyThread

View file

@ -148,12 +148,20 @@ class PermissionsFragment : GenericFragment() {
if (core.accountList.isNotEmpty()) {
coreContext.postOnMainThread {
Log.w("$TAG At least one account was found, leaving assistant")
requireActivity().finish()
try {
requireActivity().finish()
} catch (ise: IllegalStateException) {
Log.e("$TAG Failed to finish activity: $ise")
}
}
} else {
coreContext.postOnMainThread {
Log.w("$TAG No account was found, going to landing fragment")
goToLoginFragment()
try {
goToLoginFragment()
} catch (ise: IllegalStateException) {
Log.e("$TAG Failed to navigate to login fragment: $ise")
}
}
}
}