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:
@@ -72,6 +72,13 @@ object DiagReport {
|
||||
return listOf("absturz", "exception", "error", "fehler", "fehlgeschlagen", "failed").any { it in lower }
|
||||
}
|
||||
|
||||
/** Vermerk zum Bericht: manuell gesendet (ggf. ohne neue Einträge) oder leer. */
|
||||
fun note(manual: Boolean, noNewLines: Boolean): String = when {
|
||||
manual && noNewLines -> "manuell gesendet (keine neuen Einträge)"
|
||||
manual -> "manuell gesendet"
|
||||
else -> ""
|
||||
}
|
||||
|
||||
fun build(installId: String, version: String, androidVersion: String, device: String, lines: List<String>, note: String = ""): JSONObject =
|
||||
JSONObject()
|
||||
.put("app", "android")
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -276,7 +276,7 @@ class MainActivity : AppCompatActivity() {
|
||||
.setView(content)
|
||||
.setPositiveButton(R.string.diag_done, null)
|
||||
.setNeutralButton(R.string.diag_send_now) { _, _ ->
|
||||
Diagnostics.send(this) { ok ->
|
||||
Diagnostics.send(this, manual = true) { ok ->
|
||||
val text = when (ok) {
|
||||
null -> R.string.diag_nothing
|
||||
true -> R.string.diag_sent
|
||||
|
||||
Reference in New Issue
Block a user