mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 13:55:58 +00:00
Stores: the log goes to daily files, not a panel
The Downloads page's engine log is gone. StoresState.logLine still redacts every line and writes it to logcat, and now appends it to an app-private file per day, filesDir/stores/logs/stores-<date>.log: seven days kept (pruned as the app starts), each file rolling to .1 near 2 MB, written in order on one background thread. The session's Share logs zip carries these files under stores/, so they can be attached to a report.
This commit is contained in:
1 parent
8940b0ca32
commit
e0b0af4290
8 files changed
+86
-19
No files matched your search
@@ -30,6 +30,7 @@ class App : Application() {
|
||||
BwrapSpawner.start(this)
|
||||
com.droiddeck.launcher.frontend.GameFileSync.start(this)
|
||||
// The game stores the Stores section can talk to; the native engine loads only when one needs it.
|
||||
com.droiddeck.launcher.stores.StoresState.init(this)
|
||||
com.droiddeck.launcher.stores.StoresState.register(com.droiddeck.launcher.stores.gog.GogBackend)
|
||||
com.droiddeck.launcher.stores.StoresState.register(com.droiddeck.launcher.stores.epic.EpicBackend)
|
||||
com.droiddeck.launcher.stores.StoresState.register(com.droiddeck.launcher.stores.amazon.AmazonBackend)
|
||||
|
||||
@@ -73,7 +73,9 @@ object SessionLogShare {
|
||||
// every share kept the share sheet from appearing for ten seconds or more.
|
||||
val scrubbed = SessionArtifacts.scrubbedFiles(folder)
|
||||
val live = liveSteamLogs(context, folder)
|
||||
val total = (files + live).sumOf { it.length() }.coerceAtLeast(1L)
|
||||
// The stores' own log (last 7 days, app-private, already redacted), under stores/.
|
||||
val storeLogs = com.droiddeck.launcher.stores.StoreLogFiles.files(context)
|
||||
val total = (files + live + storeLogs).sumOf { it.length() }.coerceAtLeast(1L)
|
||||
var done = 0L
|
||||
var shown = -1
|
||||
fun advance(f: File) {
|
||||
@@ -84,6 +86,7 @@ object SessionLogShare {
|
||||
ZipOutputStream(zip.outputStream().buffered()).use { z ->
|
||||
files.forEach { f -> addEntry(z, folder.name + "/" + f.relativeTo(folder).path, f, f.relativeTo(folder).path in scrubbed); advance(f) }
|
||||
live.forEach { f -> addEntry(z, folder.name + "/steam/" + f.name, f, false); advance(f) }
|
||||
storeLogs.forEach { f -> addEntry(z, folder.name + "/stores/" + f.name, f, false); advance(f) }
|
||||
}
|
||||
return zip
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.droiddeck.launcher.stores
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import java.io.File
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.Executors
|
||||
|
||||
/**
|
||||
* The stores' log on disk, app-private: `filesDir/stores/logs/stores-<yyyy-MM-dd>.log`, one file a
|
||||
* day, the last [KEEP_DAYS] kept, each capped near [MAX_BYTES] (the full one moves to `.1`). Lines
|
||||
* arrive already redacted ([StoreLog.redactLine]). Written on one background thread, in order. The
|
||||
* session's Share logs zip carries these files, so they can be attached to a report when asked.
|
||||
*/
|
||||
object StoreLogFiles {
|
||||
private const val TAG = "StoreLogFiles"
|
||||
private const val KEEP_DAYS = 7
|
||||
private const val MAX_BYTES = 2L * 1024 * 1024
|
||||
private val DAY = SimpleDateFormat("yyyy-MM-dd", Locale.US)
|
||||
private val NAME = Regex("""stores-(\d{4}-\d{2}-\d{2})\.log(\.1)?""")
|
||||
private val writer = Executors.newSingleThreadExecutor { r -> Thread(r, "store-log").apply { isDaemon = true } }
|
||||
|
||||
fun dir(context: Context): File = File(context.applicationContext.filesDir, "stores/logs")
|
||||
|
||||
/** Appends one stamped line to today's file. Any thread. */
|
||||
fun append(context: Context, line: String) {
|
||||
val app = context.applicationContext
|
||||
val now = Date()
|
||||
writer.execute {
|
||||
try {
|
||||
val dir = dir(app).apply { mkdirs() }
|
||||
val file = File(dir, "stores-${synchronized(DAY) { DAY.format(now) }}.log")
|
||||
if (file.length() > MAX_BYTES) {
|
||||
val old = File(dir, file.name + ".1")
|
||||
old.delete()
|
||||
file.renameTo(old)
|
||||
}
|
||||
file.appendText(line + "\n")
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "could not write the stores log: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Drops the files older than [KEEP_DAYS] days. Called as the app starts. */
|
||||
fun prune(context: Context) {
|
||||
val app = context.applicationContext
|
||||
writer.execute {
|
||||
val cutoff = synchronized(DAY) { DAY.format(Date(System.currentTimeMillis() - (KEEP_DAYS - 1) * 86_400_000L)) }
|
||||
dir(app).listFiles()?.forEach { f ->
|
||||
val day = NAME.matchEntire(f.name)?.groupValues?.get(1) ?: return@forEach
|
||||
if (day < cutoff) f.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The files there are, oldest first, for a log share. */
|
||||
fun files(context: Context): List<File> =
|
||||
dir(context).listFiles { f -> f.isFile && NAME.matches(f.name) }?.sortedBy { it.name }.orEmpty()
|
||||
}
|
||||
@@ -51,8 +51,6 @@ object StoresState {
|
||||
var downloads by mutableStateOf<List<DownloadEntry>>(emptyList())
|
||||
internal set
|
||||
|
||||
/** The engine log the Downloads page shows: the last lines, newest last. */
|
||||
val log = mutableStateListOf<String>()
|
||||
|
||||
/** The native engine's version once probed, "" when the probe said it is missing, null before. */
|
||||
var engine by mutableStateOf<String?>(null)
|
||||
@@ -181,17 +179,22 @@ object StoresState {
|
||||
fun logLine(raw: String) {
|
||||
// Every store line passes here, the engines' included: no token or full URL is kept.
|
||||
val text = StoreLog.redactLine(raw)
|
||||
val stamped = "${CLOCK.format(Date())} $text"
|
||||
Log.i(TAG, text)
|
||||
main.post {
|
||||
log.add(stamped)
|
||||
while (log.size > 80) log.removeAt(0)
|
||||
}
|
||||
val app = appContext ?: return
|
||||
StoreLogFiles.append(app, "${synchronized(CLOCK) { CLOCK.format(Date()) }} $text")
|
||||
}
|
||||
|
||||
private var appContext: Context? = null
|
||||
|
||||
/** Called once as the app starts: where the log file goes, and the old days pruned. */
|
||||
fun init(context: Context) {
|
||||
appContext = context.applicationContext
|
||||
StoreLogFiles.prune(context)
|
||||
}
|
||||
|
||||
internal fun post(block: () -> Unit) = main.post(block)
|
||||
|
||||
private val CLOCK = SimpleDateFormat("HH:mm:ss", Locale.US)
|
||||
private val CLOCK = SimpleDateFormat("HH:mm:ss.SSS", Locale.US)
|
||||
}
|
||||
|
||||
/** What one store contributes: sign-in, its library, its shelves, installs and removals. */
|
||||
|
||||
@@ -193,14 +193,6 @@ private fun DownloadSettings(s: FrontEndState, a: FrontEndActions) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(8.dp), modifier = Modifier.fillMaxWidth().clip(Shape12).background(colors.surface).border(1.dp, pal.line, Shape12).padding(horizontal = 14.dp, vertical = 10.dp)) {
|
||||
DownloadControls(s, a)
|
||||
}
|
||||
SectionTitle(stringResource(R.string.stores_engine_log), null)
|
||||
Box(Modifier.fillMaxWidth().heightIn(min = 60.dp, max = 220.dp).clip(Shape12).background(Color.Black).border(1.dp, pal.line, Shape12).padding(12.dp)) {
|
||||
val lines = StoresState.log
|
||||
Text(
|
||||
if (lines.isEmpty()) stringResource(R.string.stores_log_idle) else lines.asReversed().joinToString("\n"),
|
||||
fontSize = 11.sp, lineHeight = 16.sp, fontFamily = FontFamily.Monospace, color = Color(0xFF9BE27A),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2078,8 +2078,6 @@
|
||||
<string name="stores_install_title">Install %1$s:</string>
|
||||
<string name="stores_target_internal">Internal</string>
|
||||
<string name="stores_target_free">%1$s free</string>
|
||||
<string name="stores_engine_log">Engine log</string>
|
||||
<string name="stores_log_idle">idle</string>
|
||||
<string name="stores_notification_channel">Store downloads</string>
|
||||
<string name="stores_notification_channel_hint">Shows game download progress and keeps downloads running in the background</string>
|
||||
<string name="stores_notification_one">Downloading</string>
|
||||
|
||||
Reference in new issue
Block a user