From e0b0af4290e1966ade626d658dca9b86cd792408 Mon Sep 17 00:00:00 2001 From: The412Banner Date: Thu, 8 Oct 2026 21:13:39 -0400 Subject: [PATCH] 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-.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. --- .../main/java/com/droiddeck/launcher/App.kt | 1 + .../launcher/session/SessionLogShare.kt | 5 +- .../launcher/stores/StoreLogFiles.kt | 62 +++++++++++++++++++ .../droiddeck/launcher/stores/StoresState.kt | 19 +++--- .../droiddeck/launcher/ui/StoresDownloads.kt | 8 --- app/src/main/res/values/strings.xml | 2 - docs/development/stores.md | 5 ++ docs/progress-log.md | 3 + 8 files changed, 86 insertions(+), 19 deletions(-) create mode 100644 app/src/main/java/com/droiddeck/launcher/stores/StoreLogFiles.kt diff --git a/app/src/main/java/com/droiddeck/launcher/App.kt b/app/src/main/java/com/droiddeck/launcher/App.kt index 9c291f2bc..d1287bedd 100644 --- a/app/src/main/java/com/droiddeck/launcher/App.kt +++ b/app/src/main/java/com/droiddeck/launcher/App.kt @@ -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) diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt index 10bfd3b04..c12a69f39 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionLogShare.kt @@ -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 } diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoreLogFiles.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoreLogFiles.kt new file mode 100644 index 000000000..f74188ebe --- /dev/null +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoreLogFiles.kt @@ -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-.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 = + dir(context).listFiles { f -> f.isFile && NAME.matches(f.name) }?.sortedBy { it.name }.orEmpty() +} diff --git a/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt b/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt index 50b4310b6..89861188f 100644 --- a/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt +++ b/app/src/main/java/com/droiddeck/launcher/stores/StoresState.kt @@ -51,8 +51,6 @@ object StoresState { var downloads by mutableStateOf>(emptyList()) internal set - /** The engine log the Downloads page shows: the last lines, newest last. */ - val log = mutableStateListOf() /** The native engine's version once probed, "" when the probe said it is missing, null before. */ var engine by mutableStateOf(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. */ diff --git a/app/src/main/java/com/droiddeck/launcher/ui/StoresDownloads.kt b/app/src/main/java/com/droiddeck/launcher/ui/StoresDownloads.kt index 520b15605..c217c8090 100644 --- a/app/src/main/java/com/droiddeck/launcher/ui/StoresDownloads.kt +++ b/app/src/main/java/com/droiddeck/launcher/ui/StoresDownloads.kt @@ -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), - ) - } } /** diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 975f08870..eba85c7d5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2078,8 +2078,6 @@ Install %1$s: Internal %1$s free - Engine log - idle Store downloads Shows game download progress and keeps downloads running in the background Downloading diff --git a/docs/development/stores.md b/docs/development/stores.md index 045192ead..f3053bd8c 100644 --- a/docs/development/stores.md +++ b/docs/development/stores.md @@ -113,5 +113,10 @@ each manager runs its Java fetch loop. | Downloads at a time | `SessionPrefs.gameStoresParallel` (1) | Downloads | | Install to (last pick, dialog default only) | `SessionPrefs.storesInstallTarget` | the Install dialog | +Store log lines (the engines' included) go through `StoresState.logLine`, which redacts them +(`StoreLog.redactLine`) and writes them to logcat and to `filesDir/stores/logs/stores-.log` +(`StoreLogFiles`: one file a day, seven days kept, ~2 MB each before it rolls to `.1`). Nothing +shows them in the app; the session's Share logs zip carries them under `stores/`. + Credentials live in `filesDir/stores//credentials.json` only (`StoreAccounts`); store URLs are logged through `StoreLog.redactUrl`, which drops the query string where the signed tokens live. diff --git a/docs/progress-log.md b/docs/progress-log.md index c554239c0..ca26ffea2 100644 --- a/docs/progress-log.md +++ b/docs/progress-log.md @@ -135,6 +135,9 @@ without it and Setup says "Stores engine not built"). when installed, Resume, the download percentage, the install size, or Free / price / discount. A thin bar over the art while downloading. Install, Resume, Uninstall, Get and Buy live on the game page; A on a card opens it. +- **No log panel:** the Downloads page's engine log is gone. Store lines go to logcat and to + app-private daily files (`filesDir/stores/logs/stores-.log`, seven days, ~2 MB rolling to + `.1`), pruned as the app starts; the session's Share logs zip includes them under `stores/`. - **Store log lines are redacted at the one choke point** (`StoresState.logLine`, which the engines' lines reach too): every URL is cut to scheme, host and a plain first path segment (a GOG secure link's token sits in the path, so it goes), no query, fragment or userinfo; token-like values