mirror of
https://github.com/kalarina-bit/Sparkledns.git
synced 2026-11-22 07:36:09 +00:00
Add app source for F-Droid release (v1.0.6)
Adds the full Android source tree, Gradle wrapper, fastlane store metadata and the fdroiddata build recipe so F-Droid can build from source. README gains build instructions and an updated structure tree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015g6ECVSKcBG8CJPrqC3G5o
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package cc.skysparkle.sparkledns
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import java.io.File
|
||||
import java.io.PrintWriter
|
||||
import java.io.StringWriter
|
||||
|
||||
class SparkleApp : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
CrashLog.install(this)
|
||||
Thread({ runCatching { Blocklist.reload(this) } }, "blocklist-load").start()
|
||||
}
|
||||
}
|
||||
|
||||
// Saves the last crash so it can be shown and copied on the next launch
|
||||
object CrashLog {
|
||||
private const val FILE_NAME = "last_crash.txt"
|
||||
|
||||
fun install(context: Context) {
|
||||
val file = File(context.filesDir, FILE_NAME)
|
||||
val previous = Thread.getDefaultUncaughtExceptionHandler()
|
||||
Thread.setDefaultUncaughtExceptionHandler { thread, error ->
|
||||
runCatching {
|
||||
val trace = StringWriter().also { error.printStackTrace(PrintWriter(it)) }.toString()
|
||||
file.writeText(
|
||||
"Thread: ${thread.name}\n" +
|
||||
"Android ${Build.VERSION.RELEASE} (API ${Build.VERSION.SDK_INT}), " +
|
||||
"${Build.MANUFACTURER} ${Build.MODEL}\n\n$trace"
|
||||
)
|
||||
}
|
||||
previous?.uncaughtException(thread, error)
|
||||
}
|
||||
}
|
||||
|
||||
fun read(context: Context): String? =
|
||||
File(context.filesDir, FILE_NAME).takeIf { it.exists() }?.readText()
|
||||
|
||||
fun clear(context: Context) {
|
||||
File(context.filesDir, FILE_NAME).delete()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user