fix: "Jetzt senden" schickt immer einen Bericht (auch ohne neue Eintraege)

Nach frischer Installation ist das Diagnose-Log leer; der Knopf meldete dann nur
"Keine neuen Eintraege". Jetzt geht ein Bericht mit Vermerk "manuell gesendet" raus.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-11-12 23:01:57 +01:00
co-authored by Claude Opus 5.5
parent 3b8918d45d
commit 448b4b8edf
4 changed files with 27 additions and 5 deletions
@@ -85,17 +85,21 @@ object Diagnostics {
if (!isEnabled(context)) return
val now = System.currentTimeMillis()
if (now - prefs(context).getLong(KEY_LAST_TRY, 0) < INTERVAL_MS) return
send(context) { }
send(context, manual = false) { }
}
/** Senden; [done] bekommt (null = nichts Neues, true/false = Erfolg) auf dem Hauptthread. */
fun send(context: Context, done: (Boolean?) -> Unit) {
/**
* Senden; [done] bekommt (null = nichts Neues, true/false = Erfolg) auf dem Hauptthread.
* [manual] ("Jetzt senden"): geht auch ohne neue Logzeilen raus, dann mit dem Vermerk
* "manuell gesendet" (Version, Gerät und Kennung reichen zum Prüfen).
*/
fun send(context: Context, manual: Boolean, done: (Boolean?) -> Unit) {
val ctx = context.applicationContext
Thread {
val prefs = prefs(ctx)
val text = runCatching { logFile(ctx).readText() }.getOrDefault("")
val collected = DiagReport.collect(text, prefs.getLong(KEY_LAST_SENT, 0))
if (collected.lines.isEmpty()) {
if (collected.lines.isEmpty() && !manual) {
main.post { done(null) }
return@Thread
}
@@ -106,6 +110,7 @@ object Diagnostics {
Build.VERSION.RELEASE ?: "?",
"${Build.MANUFACTURER} ${Build.MODEL}".take(80),
collected.lines,
DiagReport.note(manual, collected.lines.isEmpty()),
)
val ok = post("${BuildConfig.JAM_SERVER}/api/diag", body.toString())
if (ok) prefs.edit().putLong(KEY_LAST_SENT, collected.latest).apply()