commit f3cc14f405436e9e3662266d9f773caa230e196d parent 7cdfa78364bc68dd456d2a657bea56c224b16c12 Author: rhunk <101876869+rhunk@users.noreply.github.com> Date: Sat, 7 Oct 2023 11:22:48 +0200 feat: crash logs handler Diffstat:
4 files changed, 18 insertions(+), 16 deletions(-)
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/util/AndroidDialogCustom.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/util/AndroidDialogCustom.kt @@ -293,9 +293,6 @@ private class DialogWrapper( dialogLayout.setContent(parentComposition, children) } - private fun setSecurePolicy(securePolicy: SecureFlagPolicy) { - } - fun updateParameters( onDismissRequest: () -> Unit, properties: DialogProperties, @@ -303,7 +300,6 @@ private class DialogWrapper( ) { this.onDismissRequest = onDismissRequest this.properties = properties - setSecurePolicy(properties.securePolicy) setLayoutDirection(layoutDirection) if (properties.usePlatformDefaultWidth && !dialogLayout.usePlatformDefaultWidth) { // Undo fixed size in internalOnLayout, which would suppress size changes when diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/ModContext.kt b/core/src/main/kotlin/me/rhunk/snapenhance/ModContext.kt @@ -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) diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/SnapEnhance.kt b/core/src/main/kotlin/me/rhunk/snapenhance/SnapEnhance.kt @@ -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() diff --git a/core/src/main/kotlin/me/rhunk/snapenhance/core/bridge/BridgeClient.kt b/core/src/main/kotlin/me/rhunk/snapenhance/core/bridge/BridgeClient.kt @@ -73,7 +73,7 @@ class BridgeClient( } } runCatching { - onResult(future.get(10, TimeUnit.SECONDS)) + onResult(future.get(15, TimeUnit.SECONDS)) }.onFailure { timeout(it) }