mirror of
https://github.com/rhunk/SnapEnhance.git
synced 2025-06-12 13:17:42 +02:00
feat: crash logs handler
This commit is contained in:
@ -86,15 +86,11 @@ class ModContext {
|
||||
}
|
||||
|
||||
fun shortToast(message: Any?) {
|
||||
runOnUiThread {
|
||||
Toast.makeText(androidContext, message.toString(), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
Toast.makeText(androidContext, message.toString(), Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
fun longToast(message: Any?) {
|
||||
runOnUiThread {
|
||||
Toast.makeText(androidContext, message.toString(), Toast.LENGTH_LONG).show()
|
||||
}
|
||||
Toast.makeText(androidContext, message.toString(), Toast.LENGTH_LONG).show()
|
||||
}
|
||||
|
||||
fun softRestartApp(saveSettings: Boolean = false) {
|
||||
@ -112,11 +108,15 @@ class ModContext {
|
||||
}
|
||||
|
||||
fun crash(message: String, throwable: Throwable? = null) {
|
||||
Logger.xposedLog(message, throwable ?: Exception())
|
||||
longToast(message)
|
||||
logCritical(message, throwable ?: Throwable())
|
||||
delayForceCloseApp(100)
|
||||
}
|
||||
|
||||
fun logCritical(message: Any?, throwable: Throwable = Throwable()) {
|
||||
log.error(message ?: "Snapchat crash", throwable)
|
||||
longToast(message ?: "Snapchat has crashed! Please check logs for more details.")
|
||||
}
|
||||
|
||||
private fun delayForceCloseApp(delay: Long) = Handler(Looper.getMainLooper()).postDelayed({
|
||||
forceCloseApp()
|
||||
}, delay)
|
||||
|
@ -10,7 +10,6 @@ import kotlinx.coroutines.runBlocking
|
||||
import me.rhunk.snapenhance.action.EnumAction
|
||||
import me.rhunk.snapenhance.bridge.ConfigStateListener
|
||||
import me.rhunk.snapenhance.bridge.SyncCallback
|
||||
import me.rhunk.snapenhance.core.Logger
|
||||
import me.rhunk.snapenhance.core.bridge.BridgeClient
|
||||
import me.rhunk.snapenhance.core.event.events.impl.SnapWidgetBroadcastReceiveEvent
|
||||
import me.rhunk.snapenhance.core.event.events.impl.UnaryCallEvent
|
||||
@ -56,7 +55,7 @@ class SnapEnhance {
|
||||
}
|
||||
) { bridgeResult ->
|
||||
if (!bridgeResult) {
|
||||
Logger.xposedLog("Cannot connect to bridge service")
|
||||
logCritical("Cannot connect to bridge service")
|
||||
softRestartApp()
|
||||
return@connect
|
||||
}
|
||||
@ -71,7 +70,7 @@ class SnapEnhance {
|
||||
}.onSuccess {
|
||||
isBridgeInitialized = true
|
||||
}.onFailure {
|
||||
Logger.xposedLog("Failed to initialize", it)
|
||||
logCritical("Failed to initialize bridge", it)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -108,6 +107,13 @@ class SnapEnhance {
|
||||
|
||||
private fun init(scope: CoroutineScope) {
|
||||
with(appContext) {
|
||||
Thread::class.java.hook("dispatchUncaughtException", HookStage.BEFORE) { param ->
|
||||
runCatching {
|
||||
val throwable = param.argNullable(0) ?: Throwable()
|
||||
logCritical(null, throwable)
|
||||
}
|
||||
}
|
||||
|
||||
reloadConfig()
|
||||
actionManager.init()
|
||||
initConfigListener()
|
||||
|
@ -73,7 +73,7 @@ class BridgeClient(
|
||||
}
|
||||
}
|
||||
runCatching {
|
||||
onResult(future.get(10, TimeUnit.SECONDS))
|
||||
onResult(future.get(15, TimeUnit.SECONDS))
|
||||
}.onFailure {
|
||||
timeout(it)
|
||||
}
|
||||
|
Reference in New Issue
Block a user