Skip to content

Commit

Permalink
feat: add a crash handler to write logs in Download folder
Browse files Browse the repository at this point in the history
  • Loading branch information
plateaukao committed Sep 30, 2024
1 parent dbd3191 commit e688d75
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import info.plateaukao.einkbro.pocket.PocketNetwork
import info.plateaukao.einkbro.preference.ConfigManager
import info.plateaukao.einkbro.service.TtsManager
import info.plateaukao.einkbro.unit.LocaleManager
import info.plateaukao.einkbro.util.CustomExceptionHandler
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.GlobalContext.startKoin
import org.koin.dsl.module
Expand Down Expand Up @@ -59,6 +60,10 @@ class EinkBroApplication : Application() {
}

instance = this

Thread.setDefaultUncaughtExceptionHandler(
CustomExceptionHandler(Thread.getDefaultUncaughtExceptionHandler())
)
}

override fun onTerminate() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package info.plateaukao.einkbro.util

import android.os.Environment
import java.io.File

class CustomExceptionHandler(private val defaultHandler: Thread.UncaughtExceptionHandler) :
Thread.UncaughtExceptionHandler {
override fun uncaughtException(thread: Thread, throwable: Throwable) {
val tempFile = File(
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString() + "/crash_log.txt"
)
if (tempFile.exists()) {
tempFile.delete()
}
tempFile.createNewFile()
tempFile.appendText(throwable.stackTraceToString())

defaultHandler.uncaughtException(thread, throwable)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ fun BookmarkList(
interactionSource = interactionSource,
indication = null,
onClick = { onBookmarkClick(bookmark) },
onLongClick = { onBookmarkLongClick?.invoke(bookmark) },
onLongClick = { onBookmarkLongClick(bookmark) },
)
}
),
Expand All @@ -350,7 +350,7 @@ fun BookmarkItem(
dragModifier: Modifier = Modifier,
iconClick: () -> Unit,
) {
val borderWidth = if (isPressed) 1.dp else -1.dp
val borderWidth = if (isPressed) 1.dp else (-1).dp

Row(
modifier = modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private fun ToolbarList(
state,
key = info.hashCode(),
) { isDragging ->
val borderWidth = if (isDragging) 1.5.dp else -1.dp
val borderWidth = if (isDragging) 1.5.dp else (-1).dp
Column(
modifier = Modifier
.border(
Expand Down

0 comments on commit e688d75

Please sign in to comment.