mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
fix(storage): let launcher prefixes and Linux system caches be removed (#2867)
This commit is contained in:
1 parent
2ea857a07c
commit
d852b1a4e5
43 files changed
+757
-74
No files matched your search
@@ -71,7 +71,10 @@ class StorageReport(
|
||||
val kept: List<KeptPrefix>,
|
||||
val leftoversChecked: Boolean,
|
||||
val storeGames: List<StoreGameUsage> = emptyList(),
|
||||
val systemCaches: List<SystemCacheUsage> = emptyList(),
|
||||
val checkouts: List<CheckoutUsage> = emptyList(),
|
||||
) {
|
||||
val systemCacheBytes: Long get() = systemCaches.sumOf { it.bytes }
|
||||
val otherPrefixes: Long get() = kept.sumOf { it.bytes }
|
||||
val droiddeck: Long get() = buckets.values.sum()
|
||||
val installedShaders: Long get() = games.sumOf { it.shaders }
|
||||
@@ -358,6 +361,9 @@ object StorageScan {
|
||||
val stores = m(File(rootfs, "root/Games"))
|
||||
val flatpak = m(File(rootfs, "root/.local/share/flatpak"))
|
||||
val rootfsBytes = m(rootfs)
|
||||
val systemCaches = SystemCaches.find(rootfs, clientRoots, System.currentTimeMillis())
|
||||
.map { (kind, found) -> SystemCacheUsage(kind, found, found.sumOf { walker.measure(it) }) }.filter { it.bytes > 0 }
|
||||
val checkouts = SystemCaches.checkouts(rootfs).map { CheckoutUsage(it, walker.measure(it)) }.sortedByDescending { it.bytes }
|
||||
val privateBytes = privateRoots.sumOf { m(it) }
|
||||
val system = rootfsBytes - installs - inApps("compatdata") - inApps("shadercache") - workshop -
|
||||
compatTools - stores - flatpak
|
||||
@@ -381,7 +387,7 @@ object StorageScan {
|
||||
),
|
||||
prefixes, shaders, workshop, flatpak,
|
||||
games.sortedByDescending { it.total }, tools.values.toList(), leftovers, logs, logBytes,
|
||||
components, flatpakApps, flatpakRuntimes, kept, everyLibraryRead, storeGames,
|
||||
components, flatpakApps, flatpakRuntimes, kept, everyLibraryRead, storeGames, systemCaches, checkouts,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ import com.droiddeck.launcher.session.ComponentsManager
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import com.droiddeck.launcher.stores.StoreGameSidecar
|
||||
|
||||
enum class CleanItem { OLD_TOOLS, LEFTOVERS, LEFTOVERS_UNSURE, LOGS, UNUSED_CUSTOM, UNUSED_COMPONENTS, SHADERS }
|
||||
enum class CleanItem { OLD_TOOLS, LEFTOVERS, LEFTOVERS_UNSURE, LOGS, SYSTEM_CACHES, UNUSED_CUSTOM, UNUSED_COMPONENTS, SHADERS }
|
||||
|
||||
object StorageState {
|
||||
private const val TAG = "StorageState"
|
||||
@@ -61,8 +61,17 @@ object StorageState {
|
||||
}, "storage-store-sizes").start()
|
||||
}
|
||||
|
||||
/** The last scan's overview from disk, shown until this run's first scan lands. */
|
||||
var saved by mutableStateOf<StorageSummary?>(null)
|
||||
private set
|
||||
|
||||
private fun publish(app: Context, result: StorageReport) {
|
||||
report = result
|
||||
val summary = StorageSummary.of(result)
|
||||
saved = summary
|
||||
Thread({
|
||||
runCatching { StorageSummary.file(app.filesDir).writeText(summary.toJson()) }.onFailure { Log.w(TAG, "could not keep the storage summary", it) }
|
||||
}, "storage-summary").start()
|
||||
val live = result.storeGames.mapTo(HashSet()) { sizeKey(it) }
|
||||
storeSizes.keys.retainAll(live)
|
||||
measureStoreGames(app)
|
||||
@@ -88,6 +97,9 @@ object StorageState {
|
||||
|
||||
fun refresh(context: Context, force: Boolean = false) {
|
||||
val current = report
|
||||
if (current == null && saved == null) {
|
||||
saved = runCatching { StorageSummary.fromJson(StorageSummary.file(context.applicationContext.filesDir).readText()) }.getOrNull()
|
||||
}
|
||||
if (scanning || cleaning) {
|
||||
if (force) refreshAgain = true
|
||||
return
|
||||
@@ -122,9 +134,10 @@ object StorageState {
|
||||
CleanItem.UNUSED_CUSTOM -> report.unusedTools.filter { it.reason == ToolReason.CUSTOM }.sumOf { it.bytes }
|
||||
CleanItem.UNUSED_COMPONENTS -> report.unusedComponents.sumOf { it.bytes }
|
||||
CleanItem.SHADERS -> report.installedShaders
|
||||
CleanItem.SYSTEM_CACHES -> report.systemCacheBytes
|
||||
}
|
||||
|
||||
val SAFE = setOf(CleanItem.OLD_TOOLS, CleanItem.LEFTOVERS, CleanItem.LOGS)
|
||||
val SAFE = setOf(CleanItem.OLD_TOOLS, CleanItem.LEFTOVERS, CleanItem.LOGS, CleanItem.SYSTEM_CACHES)
|
||||
|
||||
fun safeBytes(report: StorageReport): Long = SAFE.sumOf { bytes(report, it) }
|
||||
|
||||
@@ -200,10 +213,19 @@ object StorageState {
|
||||
true
|
||||
})
|
||||
|
||||
/**
|
||||
* Whether a kept prefix may be removed. A store app's prefix can go, as Wine makes a new one and the app can be set up
|
||||
* again, but not while a store game is installed inside it, as Battle.net does on drive C, or while a download may write to it.
|
||||
*/
|
||||
internal fun keptRemovable(report: StorageReport, prefix: KeptPrefix): Boolean =
|
||||
prefix.owner != PrefixOwner.LAUNCHER || (report.storeGames.none { it.game.folder.path.startsWith(prefix.dir.path + "/") } &&
|
||||
!com.droiddeck.launcher.stores.download.DownloadQueue.anyActive())
|
||||
|
||||
fun resetKept(context: Context, prefix: KeptPrefix) = act(context, "kept-${prefix.dir.name}", { _, fresh ->
|
||||
val dir = fresh.kept.firstOrNull { it.dir.path == prefix.dir.path && it.owner == prefix.owner }
|
||||
?.takeIf { it.owner == PrefixOwner.SHARED || it.owner == PrefixOwner.GAME }?.dir ?: return@act false
|
||||
check(FileOps.delete(dir)) { "cannot delete $dir" }
|
||||
val kept = fresh.kept.firstOrNull { it.dir.path == prefix.dir.path && it.owner == prefix.owner }
|
||||
?.takeIf { keptRemovable(fresh, it) } ?: return@act false
|
||||
val reset = kept.owner == PrefixOwner.SHARED || kept.owner == PrefixOwner.GAME
|
||||
(listOf(kept.dir) + listOfNotNull(kept.shaders?.takeUnless { reset })).forEach { check(FileOps.delete(it)) { "cannot delete $it" } }
|
||||
true
|
||||
})
|
||||
|
||||
@@ -225,9 +247,25 @@ object StorageState {
|
||||
com.droiddeck.launcher.stores.StoresState.uninstall(app, next.game) { uninstallNext(app, rest.drop(1)) }
|
||||
}
|
||||
|
||||
/** Clears one cache, as found by a fresh scan, so a file that became busy since stays. */
|
||||
fun clearSystemCache(context: Context, kind: SystemCache) = act(context, "cache-$kind", { _, fresh ->
|
||||
val files = fresh.systemCaches.firstOrNull { it.kind == kind }?.files.orEmpty()
|
||||
files.forEach { FileOps.delete(it) }
|
||||
files.isNotEmpty()
|
||||
})
|
||||
|
||||
/** Deletes a checkout the fresh scan still lists, and the main repository's record of it if it was a worktree. */
|
||||
fun removeCheckout(context: Context, dir: java.io.File) = act(context, "checkout-${dir.name}", { app, fresh ->
|
||||
val checkout = fresh.checkouts.firstOrNull { it.dir.path == dir.path } ?: return@act false
|
||||
val record = SystemCaches.worktreeRecord(com.droiddeck.launcher.runtime.LinuxRuntime.rootDir(app), checkout.dir)
|
||||
check(FileOps.delete(checkout.dir)) { "cannot delete ${checkout.dir}" }
|
||||
record?.let { FileOps.delete(it) }
|
||||
true
|
||||
})
|
||||
|
||||
fun removeDirs(context: Context, dirs: List<java.io.File>) = act(context, "remove-${dirs.size}", { _, fresh ->
|
||||
val allowed = (fresh.games.flatMap { it.shaderDirs + listOfNotNull(it.prefixDir) } + fresh.leftovers.flatMap { listOfNotNull(it.prefix, it.shaders) } +
|
||||
fresh.kept.filter { it.owner == PrefixOwner.SHARED || it.owner == PrefixOwner.GAME }.flatMap { listOfNotNull(it.dir, it.shaders) }).mapTo(HashSet()) { it.path }
|
||||
fresh.kept.filter { keptRemovable(fresh, it) }.flatMap { listOfNotNull(it.dir, it.shaders) }).mapTo(HashSet()) { it.path }
|
||||
val wanted = dirs.distinctBy { it.path }
|
||||
val targets = wanted.filter { it.path in allowed }
|
||||
if (targets.size < wanted.size) Log.w(TAG, "kept ${wanted.size - targets.size} folders that are no longer safe to remove")
|
||||
@@ -283,6 +321,7 @@ object StorageState {
|
||||
CleanItem.LEFTOVERS_UNSURE -> report.leftovers.filter { !it.safe }.forEach(::deleteLeftover)
|
||||
CleanItem.LOGS -> report.logs.forEach { FileOps.delete(it) }
|
||||
CleanItem.SHADERS -> report.games.flatMap { it.shaderDirs }.forEach { FileOps.delete(it) }
|
||||
CleanItem.SYSTEM_CACHES -> report.systemCaches.flatMap { it.files }.forEach { FileOps.delete(it) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
package com.droiddeck.launcher.storage
|
||||
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* What the Storage overview shows, kept on disk so the page opens at once after DroidDeck restarts, as it does on
|
||||
* every update, while a fresh scan of the whole userland runs behind it.
|
||||
*/
|
||||
class StorageSummary(
|
||||
val at: Long, val total: Long, val free: Long, val buckets: Map<Bucket, Long>, val safe: Long,
|
||||
val games: Int, val gamesOnSd: Int, val prefixes: Long, val workshop: Long, val shaders: Long,
|
||||
val tools: Int, val unusedTools: Long, val components: Int, val unusedComponents: Long,
|
||||
val storeGames: Int, val flatpakApps: Int, val flatpakShared: Long, val logBytes: Long, val systemClearable: Long,
|
||||
) {
|
||||
val droiddeck: Long get() = buckets.values.sum()
|
||||
|
||||
fun toJson(): String = JSONObject().apply {
|
||||
put("v", VERSION)
|
||||
put("at", at); put("total", total); put("free", free); put("safe", safe)
|
||||
put("buckets", JSONObject().apply { buckets.forEach { (b, v) -> put(b.name, v) } })
|
||||
put("games", games); put("gamesOnSd", gamesOnSd); put("prefixes", prefixes); put("workshop", workshop); put("shaders", shaders)
|
||||
put("tools", tools); put("unusedTools", unusedTools); put("components", components); put("unusedComponents", unusedComponents)
|
||||
put("storeGames", storeGames); put("flatpakApps", flatpakApps); put("flatpakShared", flatpakShared)
|
||||
put("logBytes", logBytes); put("systemClearable", systemClearable)
|
||||
}.toString()
|
||||
|
||||
companion object {
|
||||
private const val VERSION = 1
|
||||
|
||||
fun of(r: StorageReport) = StorageSummary(
|
||||
r.at, r.total, r.free, r.buckets, StorageState.safeBytes(r),
|
||||
r.games.size, r.gamesOnSd, r.prefixes, r.workshop, r.shaders,
|
||||
r.tools.size, r.unusedTools.sumOf { it.bytes }, r.components.size, r.unusedComponents.sumOf { it.bytes },
|
||||
r.storeGames.size, r.flatpakApps.size, r.flatpakRuntimes + r.flatpakCache, r.logBytes,
|
||||
r.systemCacheBytes + r.checkouts.sumOf { it.bytes },
|
||||
)
|
||||
|
||||
/** A summary another version wrote, or a damaged file, reads as none, so the page measures as before. */
|
||||
fun fromJson(text: String): StorageSummary? = runCatching {
|
||||
val o = JSONObject(text)
|
||||
if (o.optInt("v") != VERSION) return null
|
||||
val b = o.getJSONObject("buckets")
|
||||
StorageSummary(
|
||||
o.getLong("at"), o.getLong("total"), o.getLong("free"), Bucket.entries.associateWith { b.optLong(it.name) }, o.getLong("safe"),
|
||||
o.getInt("games"), o.getInt("gamesOnSd"), o.getLong("prefixes"), o.getLong("workshop"), o.getLong("shaders"),
|
||||
o.getInt("tools"), o.getLong("unusedTools"), o.getInt("components"), o.getLong("unusedComponents"),
|
||||
o.getInt("storeGames"), o.getInt("flatpakApps"), o.getLong("flatpakShared"), o.getLong("logBytes"), o.getLong("systemClearable"),
|
||||
)
|
||||
}.getOrNull()
|
||||
|
||||
fun file(filesDir: File) = File(filesDir, "storage-summary.json")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.droiddeck.launcher.storage
|
||||
|
||||
import java.io.File
|
||||
import java.nio.file.Files
|
||||
import java.nio.file.LinkOption
|
||||
import java.nio.file.attribute.BasicFileAttributes
|
||||
|
||||
/** Parts of the Linux userland that the system and Steam make again when needed, so clearing them loses nothing. */
|
||||
enum class SystemCache { TEMP, PACKAGES, STEAM_WEB, STEAM_CORRUPT }
|
||||
|
||||
class SystemCacheUsage(val kind: SystemCache, val files: List<File>, val bytes: Long)
|
||||
|
||||
/** A git checkout in the home folder, such as one the agent made with `git worktree add`. */
|
||||
class CheckoutUsage(val dir: File, val bytes: Long)
|
||||
|
||||
object SystemCaches {
|
||||
/** Temporary files nothing has touched for a day belong to no program still running. */
|
||||
const val TEMP_IDLE_MS = 24L * 60 * 60 * 1000
|
||||
|
||||
/**
|
||||
* What each cache would delete. In /tmp, hidden entries (X11, ICE and other sockets' folders) stay, as does
|
||||
* anything changed within [TEMP_IDLE_MS] or holding a socket or pipe. apt keeps only its downloaded packages
|
||||
* here, and Steam's web cache and the download chunks it set aside as corrupt come back or are not needed.
|
||||
*/
|
||||
fun find(rootfs: File, steamRoots: List<File>, now: Long): Map<SystemCache, List<File>> = linkedMapOf(
|
||||
SystemCache.TEMP to File(rootfs, "tmp").listFiles().orEmpty().filter { !it.name.startsWith(".") && idle(it, now) },
|
||||
SystemCache.PACKAGES to File(rootfs, "var/cache/apt/archives").let { dir ->
|
||||
dir.listFiles().orEmpty().filter { it.isFile && it.name.endsWith(".deb") } + File(dir, "partial").listFiles().orEmpty()
|
||||
},
|
||||
SystemCache.STEAM_WEB to steamRoots.map { File(it, "config/htmlcache") }.filter { it.isDirectory },
|
||||
SystemCache.STEAM_CORRUPT to steamRoots.map { File(it, "steamapps/corrupt") }.filter { it.isDirectory },
|
||||
)
|
||||
|
||||
/** The home folder's git checkouts but the DroidDeck source, which the Agent tab's own entry covers. */
|
||||
fun checkouts(rootfs: File): List<File> = File(rootfs, "root").listFiles().orEmpty()
|
||||
.filter { it.isDirectory && it.name != "DroidDeck" && File(it, ".git").exists() }
|
||||
|
||||
/**
|
||||
* The main repository's record of a worktree, which `git worktree prune` would drop once the folder is gone.
|
||||
* Only a path inside some `.git/worktrees/` under [rootfs] counts.
|
||||
*/
|
||||
fun worktreeRecord(rootfs: File, checkout: File): File? {
|
||||
val link = File(checkout, ".git").takeIf { it.isFile } ?: return null
|
||||
val path = runCatching { link.readText() }.getOrNull()?.lineSequence()?.firstOrNull { it.startsWith("gitdir:") }
|
||||
?.removePrefix("gitdir:")?.trim()?.takeIf { it.startsWith("/") && "/.git/worktrees/" in it && "/../" !in it } ?: return null
|
||||
return File(rootfs, path.removePrefix("/")).takeIf { it.isDirectory }
|
||||
}
|
||||
|
||||
/** Nothing inside changed for [TEMP_IDLE_MS] and nothing is a socket or pipe; links are not followed. */
|
||||
internal fun idle(file: File, now: Long): Boolean = runCatching {
|
||||
Files.walk(file.toPath()).use { paths ->
|
||||
paths.allMatch { p ->
|
||||
val a = Files.readAttributes(p, BasicFileAttributes::class.java, LinkOption.NOFOLLOW_LINKS)
|
||||
!a.isOther && now - a.lastModifiedTime().toMillis() >= TEMP_IDLE_MS
|
||||
}
|
||||
}
|
||||
}.getOrDefault(false)
|
||||
}
|
||||
@@ -178,6 +178,8 @@ object DownloadQueue {
|
||||
|
||||
fun isActive(key: String): Boolean = entry(key)?.isActive == true
|
||||
|
||||
fun anyActive(): Boolean = synchronized(lock) { items.values.any { it.entry.isActive } }
|
||||
|
||||
fun enqueue(context: Context, entry: DownloadEntry, factory: () -> DownloadJob) {
|
||||
val app = context.applicationContext
|
||||
synchronized(lock) {
|
||||
|
||||
@@ -220,9 +220,9 @@ private fun StorageCard() {
|
||||
modifier = Modifier.fillMaxWidth().heightIn(min = 60.dp).padding(horizontal = 14.dp, vertical = 10.dp),
|
||||
) {
|
||||
Column(Modifier.weight(1f)) {
|
||||
Text(stringResource(storageTitle(item)), fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground)
|
||||
Text(stringResource(agentStorageTitle(item)), fontSize = 15.sp, fontWeight = FontWeight.SemiBold, color = colors.onBackground)
|
||||
Text(
|
||||
if (armed) stringResource(storageWarning(item)) else Formatter.formatShortFileSize(context, AgentStorage.sizes[item] ?: 0L),
|
||||
if (armed) stringResource(agentStorageWarning(item)) else Formatter.formatShortFileSize(context, AgentStorage.sizes[item] ?: 0L),
|
||||
fontSize = 13.sp, color = if (armed) AttentionAmber else pal.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
@@ -241,7 +241,7 @@ private fun StorageCard() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun storageTitle(item: AgentStorage.Item) = when (item) {
|
||||
internal fun agentStorageTitle(item: AgentStorage.Item) = when (item) {
|
||||
AgentStorage.Item.CLAUDE_CODE -> R.string.agent_storage_claude
|
||||
AgentStorage.Item.CODEX -> R.string.agent_storage_codex
|
||||
AgentStorage.Item.OPENCODE -> R.string.agent_storage_opencode
|
||||
@@ -250,7 +250,7 @@ private fun storageTitle(item: AgentStorage.Item) = when (item) {
|
||||
AgentStorage.Item.CACHES -> R.string.agent_storage_caches
|
||||
}
|
||||
|
||||
private fun storageWarning(item: AgentStorage.Item) = when (item) {
|
||||
internal fun agentStorageWarning(item: AgentStorage.Item) = when (item) {
|
||||
AgentStorage.Item.SOURCE -> R.string.agent_storage_source_warning
|
||||
AgentStorage.Item.CACHES -> R.string.agent_storage_caches_warning
|
||||
else -> R.string.agent_storage_reinstall_warning
|
||||
|
||||
@@ -91,8 +91,12 @@ import com.droiddeck.launcher.storage.GameUsage
|
||||
import com.droiddeck.launcher.storage.KeptPrefix
|
||||
import com.droiddeck.launcher.storage.PrefixOwner
|
||||
import com.droiddeck.launcher.storage.StoreGameUsage
|
||||
import com.droiddeck.launcher.storage.SystemCache
|
||||
import com.droiddeck.launcher.agent.AgentHost
|
||||
import com.droiddeck.launcher.agent.AgentStorage
|
||||
import com.droiddeck.launcher.storage.StorageReport
|
||||
import com.droiddeck.launcher.storage.StorageState
|
||||
import com.droiddeck.launcher.storage.StorageSummary
|
||||
import com.droiddeck.launcher.storage.ToolReason
|
||||
import com.droiddeck.launcher.storage.ToolState
|
||||
import com.droiddeck.launcher.storage.ToolUsage
|
||||
@@ -124,9 +128,10 @@ internal fun StoragePanel(s: FrontEndState, a: FrontEndActions) {
|
||||
var view by remember { mutableStateOf("overview") }
|
||||
var cleanup by remember { mutableStateOf(false) }
|
||||
val report = StorageState.report
|
||||
LaunchedEffect(Unit) { StorageState.refresh(ctx) }
|
||||
val summary = report?.let { remember(it) { StorageSummary.of(it) } } ?: StorageState.saved
|
||||
LaunchedEffect(Unit) { StorageState.refresh(ctx); AgentStorage.measure(ctx) }
|
||||
LaunchedEffect(s.sessionRunning) { if (!s.sessionRunning) StorageState.refresh(ctx, force = report != null) }
|
||||
if (report == null) {
|
||||
if (summary == null) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(14.dp),
|
||||
modifier = Modifier.fillMaxWidth().padding(top = 8.dp).clip(Shape14).background(MaterialTheme.colorScheme.surface)
|
||||
@@ -140,7 +145,7 @@ internal fun StoragePanel(s: FrontEndState, a: FrontEndActions) {
|
||||
}
|
||||
return
|
||||
}
|
||||
if (cleanup) CleanUpDialog(report, s.sessionRunning) { cleanup = false }
|
||||
if (cleanup && report != null) CleanUpDialog(report, s.sessionRunning) { cleanup = false }
|
||||
val top = remember { androidx.compose.foundation.relocation.BringIntoViewRequester() }
|
||||
LaunchedEffect(view) {
|
||||
StorageState.lastFreed = null
|
||||
@@ -148,14 +153,17 @@ internal fun StoragePanel(s: FrontEndState, a: FrontEndActions) {
|
||||
runCatching { top.bringIntoView() }
|
||||
}
|
||||
Box(Modifier.fillMaxWidth().height(1.dp).bringIntoViewRequester(top))
|
||||
when (view) {
|
||||
// Until this run's scan lands, the saved overview shows; a section opened meanwhile appears once it does.
|
||||
if (report == null) Overview(summary, s.sessionRunning, onCleanUp = { cleanup = true }, onOpen = { view = it })
|
||||
else when (view) {
|
||||
"games" -> GamesView(report, s.sessionRunning, a) { view = "overview" }
|
||||
"data" -> GameDataView(report, s.sessionRunning) { view = "overview" }
|
||||
"components" -> ComponentsView(report, s.sessionRunning) { view = "overview" }
|
||||
"desktop" -> DesktopView(report, s.sessionRunning) { view = "overview" }
|
||||
"stores" -> StoreGamesView(report, s.sessionRunning) { view = "overview" }
|
||||
"tools" -> ToolsView(report, s.sessionRunning) { view = "overview" }
|
||||
else -> Overview(report, s.sessionRunning, onCleanUp = { cleanup = true }, onOpen = { view = it })
|
||||
"system" -> SystemView(report, s.sessionRunning) { view = "overview" }
|
||||
else -> Overview(summary, s.sessionRunning, onCleanUp = { cleanup = true }, onOpen = { view = it })
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,7 +275,7 @@ private fun DefaultStorageGroup() {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun Overview(report: StorageReport, sessionRunning: Boolean, onCleanUp: () -> Unit, onOpen: (String) -> Unit) {
|
||||
private fun Overview(report: StorageSummary, sessionRunning: Boolean, onCleanUp: () -> Unit, onOpen: (String) -> Unit) {
|
||||
val narrowPane = LocalNarrowPane.current
|
||||
BoxWithConstraints(Modifier.fillMaxWidth()) {
|
||||
val wide = !narrowPane && maxWidth >= WIDE_OVERVIEW
|
||||
@@ -280,11 +288,11 @@ private val NARROW_ROW = 640.dp
|
||||
|
||||
@OptIn(ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
private fun OverviewContent(report: StorageReport, sessionRunning: Boolean, wide: Boolean, onCleanUp: () -> Unit, onOpen: (String) -> Unit) {
|
||||
private fun OverviewContent(report: StorageSummary, sessionRunning: Boolean, wide: Boolean, onCleanUp: () -> Unit, onOpen: (String) -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val used = report.total - report.free
|
||||
val safe = StorageState.safeBytes(report)
|
||||
val safe = report.safe
|
||||
val low = report.free < StorageState.LOW_SPACE_BYTES
|
||||
ActionStatus()
|
||||
val summary = Modifier.fillMaxWidth().padding(top = 8.dp).clip(Shape14).background(colors.surface).border(1.dp, pal.line, Shape14)
|
||||
@@ -311,7 +319,7 @@ private fun OverviewContent(report: StorageReport, sessionRunning: Boolean, wide
|
||||
Text(stringResource(R.string.storage_safe_now), fontSize = 13.sp, color = colors.onSurfaceVariant)
|
||||
Text(gb(safe), fontSize = 26.sp, fontWeight = FontWeight.Bold, color = if (safe > 0) pal.good else colors.onBackground)
|
||||
Text(stringResource(R.string.storage_safe_hint), fontSize = 12.sp, color = colors.onSurfaceVariant, modifier = Modifier.padding(bottom = 10.dp))
|
||||
PrimaryButton(stringResource(R.string.storage_clean_up), enabled = !sessionRunning && !StorageState.busy, compact = true, onClick = onCleanUp)
|
||||
PrimaryButton(stringResource(R.string.storage_clean_up), enabled = !sessionRunning && !StorageState.busy && StorageState.report != null, compact = true, onClick = onCleanUp)
|
||||
} }
|
||||
if (wide) Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(18.dp), modifier = summary) {
|
||||
usage(Modifier.weight(1f))
|
||||
@@ -328,11 +336,11 @@ private fun OverviewContent(report: StorageReport, sessionRunning: Boolean, wide
|
||||
}
|
||||
DefaultStorageGroup()
|
||||
SectionTitle(stringResource(R.string.storage_where), null)
|
||||
val unused = report.unusedTools.sumOf { it.bytes }
|
||||
val unused = report.unusedTools
|
||||
val tiles = listOf<@Composable (Modifier) -> Unit>(
|
||||
{ m ->
|
||||
BucketCard(Bucket.GAMES, Icons.Outlined.VideogameAsset, stringResource(R.string.storage_games),
|
||||
pluralStringResource(R.plurals.storage_games_installed, report.games.size, report.games.size) +
|
||||
pluralStringResource(R.plurals.storage_games_installed, report.games, report.games) +
|
||||
if (report.gamesOnSd > 0) " · " + pluralStringResource(R.plurals.storage_games_on_sd, report.gamesOnSd, report.gamesOnSd) else "",
|
||||
report.buckets.getValue(Bucket.GAMES), m) { onOpen("games") }
|
||||
},
|
||||
@@ -343,30 +351,32 @@ private fun OverviewContent(report: StorageReport, sessionRunning: Boolean, wide
|
||||
},
|
||||
{ m ->
|
||||
BucketCard(Bucket.TOOLS, Icons.Outlined.Layers, stringResource(R.string.storage_tools),
|
||||
if (unused > 0) stringResource(R.string.storage_tools_unused, gb(unused)) else pluralStringResource(R.plurals.storage_tools_count, report.tools.size, report.tools.size),
|
||||
if (unused > 0) stringResource(R.string.storage_tools_unused, gb(unused)) else pluralStringResource(R.plurals.storage_tools_count, report.tools, report.tools),
|
||||
report.buckets.getValue(Bucket.TOOLS), m, attention = unused > 0) { onOpen("tools") }
|
||||
},
|
||||
{ m ->
|
||||
val unusedComponents = report.unusedComponents.sumOf { it.bytes }
|
||||
val unusedComponents = report.unusedComponents
|
||||
BucketCard(Bucket.COMPONENTS, Icons.Outlined.Extension, stringResource(R.string.storage_components),
|
||||
if (unusedComponents > 0) stringResource(R.string.storage_tools_unused, gb(unusedComponents))
|
||||
else pluralStringResource(R.plurals.storage_components_count, report.components.size, report.components.size),
|
||||
else pluralStringResource(R.plurals.storage_components_count, report.components, report.components),
|
||||
report.buckets.getValue(Bucket.COMPONENTS), m, attention = unusedComponents > 0) { onOpen("components") }
|
||||
},
|
||||
{ m ->
|
||||
BucketCard(Bucket.STORES, Icons.Outlined.ShoppingBag, stringResource(R.string.storage_stores),
|
||||
pluralStringResource(R.plurals.storage_games_installed, report.storeGames.size, report.storeGames.size),
|
||||
pluralStringResource(R.plurals.storage_games_installed, report.storeGames, report.storeGames),
|
||||
report.buckets.getValue(Bucket.STORES), m) { onOpen("stores") }
|
||||
},
|
||||
{ m ->
|
||||
BucketCard(Bucket.DESKTOP, Icons.Outlined.Monitor, stringResource(R.string.storage_desktop),
|
||||
pluralStringResource(R.plurals.storage_desktop_apps, report.flatpakApps.size, report.flatpakApps.size) +
|
||||
" · " + stringResource(R.string.storage_desktop_shared, gb(report.flatpakRuntimes + report.flatpakCache)),
|
||||
pluralStringResource(R.plurals.storage_desktop_apps, report.flatpakApps, report.flatpakApps) +
|
||||
" · " + stringResource(R.string.storage_desktop_shared, gb(report.flatpakShared)),
|
||||
report.buckets.getValue(Bucket.DESKTOP), m) { onOpen("desktop") }
|
||||
},
|
||||
{ m ->
|
||||
val clearable = report.systemClearable + agentBytes().sumOf { it.second }
|
||||
BucketCard(Bucket.SYSTEM, Icons.Outlined.Storage, stringResource(R.string.storage_system),
|
||||
stringResource(R.string.storage_system_hint), report.buckets.getValue(Bucket.SYSTEM), m, locked = true)
|
||||
if (clearable >= ONE_MB) stringResource(R.string.storage_system_clearable, gb(clearable)) else stringResource(R.string.storage_system_hint),
|
||||
report.buckets.getValue(Bucket.SYSTEM), m) { onOpen("system") }
|
||||
},
|
||||
{ m ->
|
||||
BucketCard(Bucket.DROIDDECK, Icons.Outlined.Folder, stringResource(R.string.storage_app_data),
|
||||
@@ -397,7 +407,7 @@ private fun bucketLabel(bucket: Bucket) = stringResource(when (bucket) {
|
||||
})
|
||||
|
||||
@Composable
|
||||
private fun UsageBar(report: StorageReport, modifier: Modifier) {
|
||||
private fun UsageBar(report: StorageSummary, modifier: Modifier) {
|
||||
val total = report.total.coerceAtLeast(1).toFloat()
|
||||
val other = (report.total - report.free - report.droiddeck).coerceAtLeast(0)
|
||||
Row(modifier.fillMaxWidth().height(14.dp).clip(RoundedCornerShape(7.dp)).background(Color(0xFF0A0C0F))) {
|
||||
@@ -532,6 +542,7 @@ private fun CleanRow(item: CleanItem, report: StorageReport, on: Boolean, modifi
|
||||
CleanItem.UNUSED_CUSTOM -> Triple(custom.joinToString(", ") { it.name }, stringResource(R.string.storage_item_custom_detail), 1)
|
||||
CleanItem.UNUSED_COMPONENTS -> Triple(stringResource(R.string.storage_item_components), unusedLabels.joinToString(", "), 1)
|
||||
CleanItem.SHADERS -> Triple(stringResource(R.string.storage_item_shaders), stringResource(R.string.storage_item_shaders_detail), 2)
|
||||
CleanItem.SYSTEM_CACHES -> Triple(stringResource(R.string.storage_item_system_caches), stringResource(R.string.storage_item_system_caches_detail), 0)
|
||||
}
|
||||
ToggleRow(
|
||||
title, detail, StorageState.bytes(report, item), on, modifier,
|
||||
@@ -962,7 +973,7 @@ private fun GameDataView(report: StorageReport, sessionRunning: Boolean, onBack:
|
||||
}
|
||||
if (safe.isNotEmpty()) add(DataTarget("safe", safeLabel, safe.mapNotNull { l -> l.prefix?.let { it to l.prefixBytes } }, safe.mapNotNull { l -> l.shaders?.let { it to l.bytes - l.prefixBytes } }))
|
||||
unsure.forEach { l -> add(DataTarget("left:${leftoverKey(l)}", unsureNames[leftoverKey(l)].orEmpty(), listOfNotNull(l.prefix?.let { it to l.prefixBytes }), listOfNotNull(l.shaders?.let { it to l.bytes - l.prefixBytes }))) }
|
||||
kept.filter { it.owner == PrefixOwner.SHARED || it.owner == PrefixOwner.GAME }
|
||||
kept.filter { StorageState.keptRemovable(report, it) }
|
||||
.forEach { k -> add(DataTarget("kept:${k.dir.path}", keptNames[k.dir.path].orEmpty(), listOf(k.dir to k.bytes), listOfNotNull(k.shaders?.let { it to k.shaderBytes }))) }
|
||||
}.associateBy { it.key }
|
||||
val chosen = picked.mapNotNull { targets[it] }
|
||||
@@ -1019,7 +1030,8 @@ private fun GameDataView(report: StorageReport, sessionRunning: Boolean, onBack:
|
||||
SectionTitle(stringResource(R.string.storage_data_other), gb(kept.sumOf { it.bytes + it.shaderBytes }))
|
||||
ListCard {
|
||||
kept.forEachIndexed { i, k ->
|
||||
val resettable = k.owner == PrefixOwner.SHARED || k.owner == PrefixOwner.GAME
|
||||
val removable = StorageState.keptRemovable(report, k)
|
||||
val reset = k.owner == PrefixOwner.SHARED || k.owner == PrefixOwner.GAME
|
||||
val key = "kept:${k.dir.path}"
|
||||
ItemRow(
|
||||
keptName(k),
|
||||
@@ -1028,13 +1040,14 @@ private fun GameDataView(report: StorageReport, sessionRunning: Boolean, onBack:
|
||||
PrefixOwner.LAUNCHER -> if (k.users.isEmpty()) stringResource(R.string.storage_launcher_prefix)
|
||||
else stringResource(R.string.storage_launcher_used_by, k.users.distinct().joinToString(", "))
|
||||
PrefixOwner.GAME -> stringResource(R.string.storage_prefix_shaders, gb(k.bytes), gb(k.shaderBytes))
|
||||
PrefixOwner.UNKNOWN -> stringResource(R.string.storage_unknown_prefix_detail)
|
||||
PrefixOwner.UNKNOWN -> stringResource(R.string.storage_leftover_unsure_detail)
|
||||
}, k.shaderBytes.takeIf { it >= ONE_MB && k.owner != PrefixOwner.GAME }?.let { stringResource(R.string.storage_bulk_shaders) + " " + gb(it).replace(' ', ' ') }).joinToString(" · "),
|
||||
k.bytes + k.shaderBytes, i == kept.lastIndex,
|
||||
pill = if (k.owner == PrefixOwner.LAUNCHER) { { Pill(stringResource(R.string.storage_tag_required), MaterialTheme.colorScheme.onSurfaceVariant) } } else null,
|
||||
selected = if (resettable) key in picked else null, slot = true, selectable = !busy, onSelect = { toggle(key) },
|
||||
action = if (resettable) {
|
||||
{ SecondaryButton(stringResource(R.string.storage_reset_prefix), compact = true, enabled = !busy) { confirmKept = k } }
|
||||
pill = if (!removable) { { Pill(stringResource(R.string.storage_tag_required), MaterialTheme.colorScheme.onSurfaceVariant) } }
|
||||
else if (k.owner == PrefixOwner.UNKNOWN) { { Pill(stringResource(R.string.storage_tag_saves), AttentionAmber) } } else null,
|
||||
selected = if (removable) key in picked else null, slot = true, selectable = !busy, onSelect = { toggle(key) },
|
||||
action = if (removable) {
|
||||
{ SecondaryButton(stringResource(if (reset) R.string.storage_reset_prefix else R.string.storage_remove), compact = true, enabled = !busy) { confirmKept = k } }
|
||||
} else null,
|
||||
)
|
||||
}
|
||||
@@ -1051,11 +1064,16 @@ private fun GameDataView(report: StorageReport, sessionRunning: Boolean, onBack:
|
||||
onDismiss = { confirmBulk = false },
|
||||
)
|
||||
confirmKept?.let { k ->
|
||||
val reset = k.owner == PrefixOwner.SHARED || k.owner == PrefixOwner.GAME
|
||||
ConfirmDialog(
|
||||
stringResource(R.string.storage_reset_prefix_title, keptName(k)),
|
||||
if (k.owner == PrefixOwner.SHARED) stringResource(R.string.storage_reset_shared_confirm, gb(k.bytes))
|
||||
else stringResource(R.string.storage_reset_prefix_confirm, gb(k.bytes), k.library),
|
||||
stringResource(R.string.storage_reset_prefix),
|
||||
stringResource(if (reset) R.string.storage_reset_prefix_title else R.string.storage_remove_title, keptName(k)),
|
||||
when (k.owner) {
|
||||
PrefixOwner.SHARED -> stringResource(R.string.storage_reset_shared_confirm, gb(k.bytes))
|
||||
PrefixOwner.GAME -> stringResource(R.string.storage_reset_prefix_confirm, gb(k.bytes), k.library)
|
||||
PrefixOwner.LAUNCHER -> stringResource(R.string.storage_remove_launcher_confirm, gb(k.bytes + k.shaderBytes))
|
||||
PrefixOwner.UNKNOWN -> stringResource(R.string.storage_leftover_confirm, gb(k.bytes + k.shaderBytes))
|
||||
},
|
||||
stringResource(if (reset) R.string.storage_reset_prefix else R.string.storage_remove),
|
||||
onConfirm = { StorageState.resetKept(ctx, k) }, onDismiss = { confirmKept = null },
|
||||
)
|
||||
}
|
||||
@@ -1181,6 +1199,93 @@ private fun StoreGamesView(report: StorageReport, sessionRunning: Boolean, onBac
|
||||
}
|
||||
}
|
||||
|
||||
/** What the Agent tab added to the Linux userland, with sizes once measured. */
|
||||
private fun agentBytes(): List<Pair<AgentStorage.Item, Long>> =
|
||||
AgentStorage.Item.entries.mapNotNull { item -> AgentStorage.sizes[item]?.takeIf { it >= ONE_MB }?.let { item to it } }
|
||||
|
||||
private fun cacheName(kind: SystemCache) = when (kind) {
|
||||
SystemCache.TEMP -> R.string.storage_cache_temp
|
||||
SystemCache.PACKAGES -> R.string.storage_cache_packages
|
||||
SystemCache.STEAM_WEB -> R.string.storage_cache_steam_web
|
||||
SystemCache.STEAM_CORRUPT -> R.string.storage_cache_steam_corrupt
|
||||
}
|
||||
|
||||
/**
|
||||
* The Linux system bucket opened up: caches that come back on their own, what the Agent tab installed, and the rest,
|
||||
* which runs everything and stays.
|
||||
*/
|
||||
@Composable
|
||||
private fun SystemView(report: StorageReport, sessionRunning: Boolean, onBack: () -> Unit) {
|
||||
val ctx = LocalContext.current
|
||||
val busy = sessionRunning || StorageState.busy
|
||||
var confirmAgent by remember { mutableStateOf<AgentStorage.Item?>(null) }
|
||||
var confirmCheckout by remember { mutableStateOf<com.droiddeck.launcher.storage.CheckoutUsage?>(null) }
|
||||
val removing = AgentStorage.removing.size
|
||||
var wasRemoving by remember { mutableStateOf(false) }
|
||||
LaunchedEffect(removing) {
|
||||
if (wasRemoving && removing == 0) StorageState.refresh(ctx, force = true)
|
||||
wasRemoving = removing > 0
|
||||
}
|
||||
val caches = report.systemCaches.sortedByDescending { it.bytes }
|
||||
val agent = agentBytes().sortedByDescending { it.second }
|
||||
val checkouts = report.checkouts.filter { it.bytes >= ONE_MB }
|
||||
val agentTotal = agent.sumOf { it.second } + checkouts.sumOf { it.bytes }
|
||||
val rest = (report.buckets.getValue(Bucket.SYSTEM) - report.systemCacheBytes - agentTotal).coerceAtLeast(0)
|
||||
SubHeader(stringResource(R.string.storage_system), stringResource(R.string.storage_system_clearable, gb(report.systemCacheBytes + agentTotal)), onBack) {
|
||||
if (caches.isNotEmpty()) PrimaryButton(stringResource(R.string.storage_free_button, gb(report.systemCacheBytes)), compact = true, enabled = !busy) {
|
||||
StorageState.clean(ctx, setOf(CleanItem.SYSTEM_CACHES)) { }
|
||||
}
|
||||
}
|
||||
ActionStatus()
|
||||
if (sessionRunning) { Note(stringResource(R.string.storage_session_running)); Spacer(Modifier.height(4.dp)) }
|
||||
if (caches.isNotEmpty()) {
|
||||
SectionTitle(stringResource(R.string.storage_item_system_caches), gb(report.systemCacheBytes))
|
||||
ListCard {
|
||||
caches.forEachIndexed { i, c ->
|
||||
ItemRow(stringResource(cacheName(c.kind)), stringResource(R.string.storage_cache_detail), c.bytes, i == caches.lastIndex,
|
||||
pill = { Pill(stringResource(R.string.storage_tag_safe), LocalPalette.current.good) },
|
||||
action = { SecondaryButton(stringResource(R.string.storage_clear), compact = true, enabled = !busy) { StorageState.clearSystemCache(ctx, c.kind) } })
|
||||
}
|
||||
}
|
||||
}
|
||||
if (agent.isNotEmpty() || checkouts.isNotEmpty()) {
|
||||
SectionTitle(stringResource(R.string.rail_agent), gb(agentTotal))
|
||||
ListCard {
|
||||
agent.forEachIndexed { i, (item, bytes) ->
|
||||
ItemRow(stringResource(agentStorageTitle(item)), stringResource(agentStorageWarning(item)), bytes, i == agent.lastIndex && checkouts.isEmpty(),
|
||||
action = {
|
||||
SecondaryButton(stringResource(R.string.storage_remove), compact = true,
|
||||
enabled = AgentStorage.removing[item] != true && AgentHost.state != AgentHost.State.WORKING) { confirmAgent = item }
|
||||
})
|
||||
}
|
||||
checkouts.forEachIndexed { i, c ->
|
||||
ItemRow(c.dir.name, stringResource(R.string.agent_storage_source_warning), c.bytes, i == checkouts.lastIndex,
|
||||
action = {
|
||||
SecondaryButton(stringResource(R.string.storage_remove), compact = true,
|
||||
enabled = !busy && AgentHost.state != AgentHost.State.WORKING) { confirmCheckout = c }
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
SectionTitle(stringResource(R.string.storage_in_use), gb(rest))
|
||||
ListCard {
|
||||
ItemRow(stringResource(R.string.storage_system), stringResource(R.string.storage_system_hint), rest, true,
|
||||
action = { Icon(Icons.Outlined.Lock, contentDescription = null, tint = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.size(16.dp)) })
|
||||
}
|
||||
confirmAgent?.let { item ->
|
||||
ConfirmDialog(
|
||||
stringResource(R.string.storage_remove_title, stringResource(agentStorageTitle(item))), stringResource(agentStorageWarning(item)),
|
||||
stringResource(R.string.storage_remove), onConfirm = { AgentStorage.remove(ctx, item) }, onDismiss = { confirmAgent = null },
|
||||
)
|
||||
}
|
||||
confirmCheckout?.let { c ->
|
||||
ConfirmDialog(
|
||||
stringResource(R.string.storage_remove_title, c.dir.name), stringResource(R.string.agent_storage_source_warning),
|
||||
stringResource(R.string.storage_remove), onConfirm = { StorageState.removeCheckout(ctx, c.dir) }, onDismiss = { confirmCheckout = null },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun ComponentsView(report: StorageReport, sessionRunning: Boolean, onBack: () -> Unit) {
|
||||
val ctx = LocalContext.current
|
||||
|
||||
Reference in new issue
Block a user