feat(app): crash notification

This commit is contained in:
rhunk
2024-05-29 14:04:55 +02:00
parent 9973da1021
commit 420c02af64
2 changed files with 24 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ import me.rhunk.snapenhance.common.bridge.wrapper.LocaleWrapper
import me.rhunk.snapenhance.common.bridge.wrapper.LoggerWrapper
import me.rhunk.snapenhance.common.bridge.wrapper.MappingsWrapper
import me.rhunk.snapenhance.common.config.ModConfig
import me.rhunk.snapenhance.common.logger.fatalCrash
import me.rhunk.snapenhance.common.util.getPurgeTime
import me.rhunk.snapenhance.e2ee.E2EEImplementation
import me.rhunk.snapenhance.scripting.RemoteScriptManager
@@ -129,6 +130,7 @@ class RemoteSideContext(
}
}.onFailure {
log.error("Failed to load RemoteSideContext", it)
androidContext.fatalCrash(it)
}
scriptManager.runtime.eachModule {

View File

@@ -1,6 +1,11 @@
package me.rhunk.snapenhance.common.logger
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.content.Context
import android.util.Log
import kotlin.system.exitProcess
abstract class AbstractLogger(
logChannel: LogChannel,
@@ -35,4 +40,21 @@ abstract class AbstractLogger(
open fun warn(message: Any?, tag: String = TAG) {}
open fun assert(message: Any?, tag: String = TAG) {}
}
fun Context.fatalCrash(throwable: Throwable) {
getSystemService(NotificationManager::class.java).apply {
createNotificationChannel(
NotificationChannel("default", "Default", NotificationManager.IMPORTANCE_HIGH)
)
notify(
0,
Notification.Builder(this@fatalCrash, "default")
.setContentTitle("Failed to load SnapEnhance")
.setStyle(Notification.BigTextStyle().bigText(throwable.message + "\n" + throwable.stackTraceToString()))
.setSmallIcon(android.R.drawable.stat_notify_error)
.build()
)
}
exitProcess(1)
}