mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
feat(components): Auto updates for FEX, DXVK and VKD3D-Proton (#2156)
* feat(components): Auto updates for FEX, DXVK and VKD3D-Proton Each component gets an Auto or Manual mode on the Default Components page. Auto installs the newest DroidDeck-Components nightly into every Proton that ships the component, matching each Proton's ARM64EC or x64 flavour, keeps the current and replaced builds, and removes older builds it downloaded. A game that ran on the previous build and exits within 30 seconds twice on the new one rolls the line back; the failed build is skipped until a newer one is published. Existing manual choices keep that component on Manual, and DXVK stays on Manual while a GPU rule pins its version. * fix(components): Auto notes per line, Original label and first-update rollback Boot history on the Original is recorded before the first update so that update can roll back, rollback notes stay with their own component, the Original shows by name, and new Protons get the current build even when no newer one is published. * fix(components): Auto owns only its own downloads and follows in-place Proton updates Auto deletes only builds it downloaded, re-swaps a Proton whose version changed under an existing choice, reports a missing nightly listing as a failed check, writes its state atomically so the page can read it without waiting on a download, and words the rollback and download messages to match what it does. * fix(components): Auto keeps a rollback and reads updated Protons' own files After a rollback only a build newer than every rejected one is taken, so an older build still listed in the nightly cannot replace the restored one. Flavour detection treats a choice saved for an older Proton version as not applied, so a Proton Steam updated in place is read from its own files and re-swapped. A failed state rename falls back to a direct write and is logged. * fix(components): Keep the last good Auto state when a save fails * fix(components): Serialise Auto state reads and writes * Install the Linux runtime by itself on first launch The runtime auto-update skipped devices with no runtime, so FEX, Proton, DXVK and VKD3D waited for the first Steam launch to install it. Claim a first install when the device never had a runtime, on a usable network, outside battery saver and with a supported GPU, and check Proton as soon as the runtime is ready. A runtime the user removed stays removed. * fix(components): Check components as soon as Proton is installed The Auto check stamped its hourly timer even when no Proton was installed yet, so a fresh device waited an hour after Proton arrived. Skip the stamp until a Proton exists and run the check right after a Proton install finishes. * fix(components): Apply stored builds on every check and retry unfinished rollbacks A held or failed download no longer skips applying the stored build or stamps the hourly timer. Stored builds are applied on every check, so a new Proton is reconciled inside the hour, and a check requested while one runs is queued. A rollback that could not restore or swap a Proton is retried and reported only once it finishes. Removing the runtime marks it as seen so it is not installed again, and the failed-save test skips where the process can still write read-only files. * fix(components): Keep rollback restores pending until applied and save state on failure * fix(components): Hold newer builds until a pending rollback is applied * fix(components): Drop pending restores for removed Protons * fix(components): Never auto-install a non-ARM64X build over a Proton's own ARM64X DXVK or VKD3D * fix(components): Read probe archives outside the lock and block auto updates while the original build is unknown * fix(components): Require ARM64X when any Proton on the line needs it, and before each swap
This commit is contained in:
1 parent
116728917f
commit
a81da1e476
48 files changed
+1410
-35
No files matched your search
@@ -5,8 +5,11 @@ import android.util.Log
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import com.droiddeck.launcher.session.ComponentUpdater
|
||||
import com.droiddeck.launcher.session.ComponentUpdates
|
||||
import com.droiddeck.launcher.session.ComponentsManager
|
||||
import com.droiddeck.launcher.session.ProtonDefault
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
|
||||
internal class ComponentsMenu(private val activity: android.app.Activity, private val ui: Handler) {
|
||||
var compSnapshot by mutableStateOf<ComponentsManager.Snapshot?>(null)
|
||||
@@ -20,6 +23,10 @@ internal class ComponentsMenu(private val activity: android.app.Activity, privat
|
||||
get() = downloads
|
||||
private set(value) { downloads = value }
|
||||
val compDownloadRevision: Long get() = downloadRevision
|
||||
var compModes by mutableStateOf<Map<String, String>>(emptyMap())
|
||||
var compAuto by mutableStateOf<Map<String, List<ComponentUpdater.Status>>>(emptyMap())
|
||||
var compAutoHeld by mutableStateOf<Set<String>>(emptySet())
|
||||
var compAutoChecking by mutableStateOf(false)
|
||||
private var shownDefault: String? = null
|
||||
|
||||
fun refreshComponents(snapshotFirst: Boolean = false) {
|
||||
@@ -29,7 +36,14 @@ internal class ComponentsMenu(private val activity: android.app.Activity, privat
|
||||
val snap = runCatching { ComponentsManager.snapshot(activity) }.onFailure { Log.w(TAG, "components", it) }.getOrNull()
|
||||
val cat = runCatching { ComponentsManager.catalog(activity, false) }.getOrNull()
|
||||
val chosen = snap?.let { s -> runCatching { ProtonDefault.selectedId(activity, s.protons.map { it.proton }) }.getOrNull() }
|
||||
runCatching { ComponentUpdater.settle(activity) }
|
||||
val modes = ComponentsManager.COMPONENTS.associateWith { SessionPrefs.componentMode(activity, it) }
|
||||
val auto = ComponentsManager.COMPONENTS.associateWith { runCatching { ComponentUpdater.status(activity, it) }.getOrDefault(emptyList()) }
|
||||
val held = if (runCatching { ComponentsManager.hardwareDxvk(activity) }.getOrDefault(false)) setOf("dxvk") else emptySet()
|
||||
ui.post {
|
||||
compModes = modes
|
||||
compAuto = auto
|
||||
compAutoHeld = held
|
||||
compSnapshot = snap ?: ComponentsManager.Snapshot(emptyList(), emptyList())
|
||||
if (cat != null && cat.fetchedAt > 0) { compCatalog = cat.items; compCatalogAt = cat.fetchedAt }
|
||||
if (chosen != null && chosen != shownDefault) {
|
||||
@@ -42,6 +56,35 @@ internal class ComponentsMenu(private val activity: android.app.Activity, privat
|
||||
}, "components").start()
|
||||
}
|
||||
|
||||
fun chooseComponentMode(comp: String, mode: String) {
|
||||
SessionPrefs.setComponentMode(activity, comp, mode)
|
||||
compModes = compModes + (comp to mode)
|
||||
if (mode != ComponentUpdates.AUTO) return
|
||||
checkComponentUpdates(force = true)
|
||||
}
|
||||
|
||||
private var checkAgain: Boolean? = null
|
||||
|
||||
fun checkComponentUpdates(force: Boolean) {
|
||||
if (compAutoChecking) {
|
||||
checkAgain = force || checkAgain == true
|
||||
return
|
||||
}
|
||||
compAutoChecking = true
|
||||
Thread({
|
||||
val notes = runCatching { ComponentUpdater.ensure(activity, force) }.onFailure { Log.w(TAG, "component updates", it) }.getOrDefault(emptyList())
|
||||
ui.post {
|
||||
compAutoChecking = false
|
||||
checkAgain?.let { again ->
|
||||
checkAgain = null
|
||||
checkComponentUpdates(again)
|
||||
}
|
||||
if (notes.isNotEmpty()) android.widget.Toast.makeText(activity, notes.joinToString("\n"), android.widget.Toast.LENGTH_LONG).show()
|
||||
refreshComponents()
|
||||
}
|
||||
}, "component-updates").start()
|
||||
}
|
||||
|
||||
fun chooseProton(id: String) {
|
||||
val proton = compSnapshot?.protons?.firstOrNull { it.proton.id == id }?.proton ?: return
|
||||
compProton = id
|
||||
|
||||
@@ -40,6 +40,8 @@ import com.droiddeck.launcher.ui.PackageRow
|
||||
import com.droiddeck.launcher.ui.exposeTestTags
|
||||
import com.droiddeck.launcher.session.OfflineMode
|
||||
import com.droiddeck.launcher.session.ProtonExtras
|
||||
import com.droiddeck.launcher.session.ComponentUpdater
|
||||
import com.droiddeck.launcher.session.ComponentUpdates
|
||||
import com.droiddeck.launcher.session.ComponentsManager
|
||||
import com.droiddeck.launcher.ui.ComponentsPage
|
||||
import com.droiddeck.launcher.session.GameSaves
|
||||
@@ -94,7 +96,11 @@ class FrontEndActivity : ComponentActivity() {
|
||||
private val components = ComponentsMenu(this, ui)
|
||||
private val decky = DeckyMenu(this, ui)
|
||||
private val updates = UpdatesMenu(this, ui)
|
||||
private val protons = ProtonMenu(this, ui) { !busy && flood == null && compatLaunch == null && pkgStage == null && components.compBusy == null }
|
||||
private val protons = ProtonMenu(
|
||||
this, ui,
|
||||
idle = { !busy && flood == null && compatLaunch == null && pkgStage == null && components.compBusy == null },
|
||||
onInstalled = { if (!OfflineMode.enabled(this)) components.checkComponentUpdates(force = false) },
|
||||
)
|
||||
|
||||
private var installed by mutableStateOf<String?>(null)
|
||||
private var flood by mutableStateOf<PendingFlood?>(null)
|
||||
@@ -1880,6 +1886,13 @@ class FrontEndActivity : ComponentActivity() {
|
||||
if (applied.isNotEmpty()) ui.post {
|
||||
android.widget.Toast.makeText(this, getString(R.string.main_applied, applied.joinToString(", ")), android.widget.Toast.LENGTH_LONG).show()
|
||||
}
|
||||
if (!OfflineMode.enabled(this)) {
|
||||
val updated = runCatching { ComponentUpdater.ensure(this, force = false) }
|
||||
.onFailure { android.util.Log.w("ComponentUpdater", "automatic component updates", it) }.getOrDefault(emptyList())
|
||||
if (updated.isNotEmpty()) ui.post {
|
||||
android.widget.Toast.makeText(this, updated.joinToString("\n"), android.widget.Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}
|
||||
ui.post {
|
||||
componentsQueueBusy = false
|
||||
if (showComponents) components.refreshComponents()
|
||||
@@ -2153,7 +2166,15 @@ class FrontEndActivity : ComponentActivity() {
|
||||
onDeletePackage = { file -> components.componentAction(getString(R.string.comp_busy_deleting)) { ComponentsManager.deletePackage(this, file) } },
|
||||
onDeleteOriginal = { version -> components.compProton?.let { pid -> components.componentAction(getString(R.string.comp_busy_deleting)) { ComponentsManager.deleteOriginal(this, pid, components.compComp, version) } } },
|
||||
onDownload = { components.downloadComponent(it) },
|
||||
onRefresh = { components.refreshComponentCatalog() },
|
||||
onRefresh = {
|
||||
components.refreshComponentCatalog()
|
||||
if (components.compModes.values.any { it == ComponentUpdates.AUTO }) components.checkComponentUpdates(force = true)
|
||||
},
|
||||
compModes = components.compModes,
|
||||
compAuto = components.compAuto,
|
||||
compAutoHeld = components.compAutoHeld,
|
||||
compAutoChecking = components.compAutoChecking,
|
||||
onCompMode = { comp, mode -> components.chooseComponentMode(comp, mode) },
|
||||
onImport = { pickComponent.launch(InAppFilePicker.buildIntent(this, WCP_EXT, getString(R.string.comp_pick_wcp))) },
|
||||
onBack = { if (!com.droiddeck.launcher.ui.Hops.back { showComponents = false }) showComponents = false },
|
||||
games = steamGames,
|
||||
@@ -2982,6 +3003,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
private fun removeRuntime() {
|
||||
if (runtimeChangesBlocked()) return
|
||||
val removal = LinuxRuntimeInstaller.beginUninstall(this) ?: return
|
||||
com.droiddeck.launcher.runtime.RuntimeAutoUpdate.seed(this)
|
||||
ready = false
|
||||
com.droiddeck.launcher.runtime.RuntimeInstallService.keepRemovalAlive(this)
|
||||
followRuntimeOperation { removal.run(it) }
|
||||
@@ -3008,6 +3030,7 @@ class FrontEndActivity : ComponentActivity() {
|
||||
android.widget.Toast.makeText(this, it, android.widget.Toast.LENGTH_LONG).show()
|
||||
}
|
||||
refresh()
|
||||
if (ok == true && LinuxRuntime.isInstalled(this)) protons.checkUpdates()
|
||||
}
|
||||
}, "runtime-operation").start()
|
||||
}
|
||||
@@ -3015,9 +3038,12 @@ class FrontEndActivity : ComponentActivity() {
|
||||
private fun autoUpdateRuntime() {
|
||||
val release = available?.takeIf { catalogFresh } ?: return
|
||||
if (!lifecycle.currentState.isAtLeast(androidx.lifecycle.Lifecycle.State.RESUMED) || runtimeChangesBlocked() || removalPending) return
|
||||
if (release.version == installed || installed == null) return
|
||||
if (installed != null) com.droiddeck.launcher.runtime.RuntimeAutoUpdate.seed(this)
|
||||
if (release.version == installed) return
|
||||
if (installed == null && (OfflineMode.enabled(this) || !com.droiddeck.launcher.core.DeviceSupport.canDraw(this) ||
|
||||
!com.droiddeck.launcher.frontend.AutoComponents.online(this) || com.droiddeck.launcher.frontend.AutoComponents.unfavourable(this))) return
|
||||
if (com.droiddeck.launcher.runtime.RuntimeAutoUpdate.claim(this, installed, release.version)) {
|
||||
Log.i(TAG, "runtime: updating $installed to ${release.version} by itself")
|
||||
Log.i(TAG, "runtime: installing ${release.version} over ${installed ?: "nothing"} by itself")
|
||||
install(release)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.droiddeck.launcher.runtime.LinuxRuntimeInstaller
|
||||
internal class ProtonMenu(
|
||||
private val activity: android.app.Activity,
|
||||
private val ui: Handler,
|
||||
private val onInstalled: () -> Unit = {},
|
||||
private val idle: () -> Boolean = { true },
|
||||
) {
|
||||
private object Operation {
|
||||
@@ -61,6 +62,7 @@ internal class ProtonMenu(
|
||||
if (automatic) Log.w("ProtonMenu", "auto-update ${tool.id}: $problem")
|
||||
else android.widget.Toast.makeText(activity, problem, android.widget.Toast.LENGTH_LONG).show()
|
||||
}
|
||||
if (problem == null) onInstalled()
|
||||
if (automatic) ensureAutoUpdates()
|
||||
}
|
||||
}, "install-proton-$id").start()
|
||||
|
||||
@@ -8,8 +8,10 @@ object RuntimeAutoUpdate {
|
||||
const val MAX_ATTEMPTS = 3
|
||||
const val RETRY_MS = 10 * 60_000L
|
||||
|
||||
fun due(installed: String?, release: String?, attempts: Int, lastAt: Long = 0L, now: Long = lastAt + RETRY_MS): Boolean =
|
||||
installed != null && !release.isNullOrEmpty() && release != installed && attempts < MAX_ATTEMPTS &&
|
||||
private const val SEEDED = "seeded"
|
||||
|
||||
fun due(installed: String?, release: String?, attempts: Int, lastAt: Long = 0L, now: Long = lastAt + RETRY_MS, first: Boolean = false): Boolean =
|
||||
(installed != null || first) && !release.isNullOrEmpty() && release != installed && attempts < MAX_ATTEMPTS &&
|
||||
(attempts == 0 || now - lastAt !in 0 until RETRY_MS)
|
||||
|
||||
fun key(appVersion: Int, release: String) = "$appVersion:$release"
|
||||
@@ -20,11 +22,17 @@ object RuntimeAutoUpdate {
|
||||
val key = key(BuildConfig.VERSION_CODE, release)
|
||||
synchronized(this) {
|
||||
val attempts = prefs.getInt(key, 0)
|
||||
if (!due(installed, release, attempts, prefs.getLong("$key@at", 0L), now)) return false
|
||||
val first = installed == null && !prefs.getBoolean(SEEDED, false)
|
||||
if (!due(installed, release, attempts, prefs.getLong("$key@at", 0L), now, first)) return false
|
||||
val edit = prefs.edit()
|
||||
prefs.all.keys.filterNot { it.startsWith("${BuildConfig.VERSION_CODE}:") }.forEach { edit.remove(it) }
|
||||
prefs.all.keys.filterNot { it.startsWith("${BuildConfig.VERSION_CODE}:") || it == SEEDED }.forEach { edit.remove(it) }
|
||||
edit.putInt(key, attempts + 1).putLong("$key@at", now).apply()
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
fun seed(context: Context) {
|
||||
val prefs = context.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
|
||||
if (!prefs.getBoolean(SEEDED, false)) prefs.edit().putBoolean(SEEDED, true).apply()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,312 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AtomicFile
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.frontend.AutoComponents
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
|
||||
object ComponentUpdater {
|
||||
private const val TAG = "ComponentUpdater"
|
||||
private const val CHECK_EVERY_MS = 3_600_000L
|
||||
private const val BOOTED_KEPT = 200
|
||||
private val lock = Any()
|
||||
private val io = Any()
|
||||
|
||||
data class Status(val line: String, val current: String, val previous: String, val protons: List<String>, val note: String)
|
||||
|
||||
private fun file(context: Context) = File(File(context.filesDir, "components").apply { mkdirs() }, "updates.json")
|
||||
|
||||
private fun load(context: Context): JSONObject = synchronized(io) {
|
||||
runCatching { JSONObject(String(AtomicFile(file(context)).readFully(), Charsets.UTF_8)) }.getOrDefault(JSONObject())
|
||||
}
|
||||
|
||||
private fun save(context: Context, state: JSONObject) {
|
||||
synchronized(io) {
|
||||
val atomic = AtomicFile(file(context))
|
||||
val output = runCatching { atomic.startWrite() }.onFailure { Log.w(TAG, "could not save", it) }.getOrNull() ?: return
|
||||
try {
|
||||
output.write(state.toString(1).toByteArray(Charsets.UTF_8))
|
||||
atomic.finishWrite(output)
|
||||
} catch (error: Exception) {
|
||||
atomic.failWrite(output)
|
||||
Log.w(TAG, "could not save", error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Map<String, Map<String, ComponentsManager.Choice>>.fileOf(p: ComponentsManager.Proton, comp: String): String? =
|
||||
this[p.id]?.get(comp)?.takeIf { it.protonVersion == p.version }?.file
|
||||
|
||||
private class Target(val comp: String, val p: ComponentsManager.Proton, val line: ComponentUpdates.Line, val ls: JSONObject) {
|
||||
val key: String get() = line.key
|
||||
}
|
||||
|
||||
private fun JSONObject.obj(key: String): JSONObject = optJSONObject(key) ?: JSONObject().also { put(key, it) }
|
||||
|
||||
private fun JSONArray?.strings(): Set<String> = this?.let { a -> (0 until a.length()).map { a.optString(it) }.toSet() } ?: emptySet()
|
||||
|
||||
private fun JSONObject.strings(key: String): Set<String> = optJSONArray(key).strings()
|
||||
|
||||
private fun JSONObject?.ints(): Map<String, Int> = this?.keys()?.asSequence()?.associateWith { optInt(it) } ?: emptyMap()
|
||||
|
||||
private fun JSONObject?.texts(): Map<String, String> = this?.keys()?.asSequence()?.associateWith { optString(it) } ?: emptyMap()
|
||||
|
||||
fun settle(context: Context) {
|
||||
val owned = load(context).optJSONObject("lines")?.let { lines -> lines.keys().asSequence().flatMap { lines.optJSONObject(it).strings("owned") }.toSet() } ?: emptySet()
|
||||
val choices = ComponentsManager.activeChoices(context).values.flatMap { it.entries }
|
||||
for (comp in ComponentsManager.COMPONENTS) {
|
||||
if (SessionPrefs.componentModeChosen(context, comp)) continue
|
||||
val manual = choices.any { (c, choice) -> c == comp && !choice.auto && choice.file !in owned && !choice.file.startsWith("original ") }
|
||||
SessionPrefs.setComponentMode(context, comp, if (manual) ComponentUpdates.MANUAL else ComponentUpdates.AUTO)
|
||||
}
|
||||
}
|
||||
|
||||
private fun managed(context: Context, comp: String): Boolean =
|
||||
SessionPrefs.componentMode(context, comp) == ComponentUpdates.AUTO && !(comp == "dxvk" && ComponentsManager.hardwareDxvk(context))
|
||||
|
||||
private fun logLines(context: Context): Sequence<String> {
|
||||
val dir = ComponentsManager.steamLogs(context)
|
||||
return sequenceOf("console_log.previous.txt", "console_log.txt").map { File(dir, it) }.filter { it.isFile }
|
||||
.flatMap { f -> runCatching { f.readLines() }.getOrDefault(emptyList()).asSequence() }
|
||||
}
|
||||
|
||||
private val STAMP = Regex("""^\[(\d{4}-\d\d-\d\d \d\d:\d\d:\d\d)]""")
|
||||
|
||||
private fun latestStamp(context: Context): String =
|
||||
logLines(context).mapNotNull { STAMP.find(it)?.groupValues?.get(1) }.maxOrNull() ?: "0"
|
||||
|
||||
private fun lineOf(context: Context, state: JSONObject, p: ComponentsManager.Proton, comp: String): ComponentUpdates.Line? {
|
||||
if (!ComponentsManager.supports(p, comp)) return null
|
||||
if (comp == "fex") return ComponentUpdates.line("fex", false)
|
||||
val key = "${p.id}|${p.version}"
|
||||
val flavors = state.obj("flavors").obj(key)
|
||||
val arm64ec = if (flavors.has(comp)) flavors.optBoolean(comp) else ComponentsManager.arm64ec(context, p, comp)?.also { flavors.put(comp, it) }
|
||||
return arm64ec?.let { ComponentUpdates.line(comp, it) }
|
||||
}
|
||||
|
||||
fun ensure(context: Context, force: Boolean): List<String> = synchronized(lock) {
|
||||
if (SessionState.running) return emptyList()
|
||||
settle(context)
|
||||
val state = load(context)
|
||||
val notes = ArrayList<String>()
|
||||
val protons = runCatching { ComponentsManager.protons(context) }.getOrDefault(emptyList())
|
||||
judge(context, state, protons, notes)
|
||||
val due = force || System.currentTimeMillis() - state.optLong("checkedAt") >= CHECK_EVERY_MS
|
||||
val wanted = ComponentsManager.COMPONENTS.filter { managed(context, it) }
|
||||
if (wanted.isEmpty() || protons.isEmpty()) {
|
||||
save(context, state)
|
||||
return notes
|
||||
}
|
||||
try {
|
||||
dropRemoved(state, protons)
|
||||
val checked = due && check(context, state, protons, wanted, force, notes)
|
||||
apply(context, state, protons, wanted, notes)
|
||||
prune(context, state)
|
||||
if (checked) state.put("checkedAt", System.currentTimeMillis())
|
||||
} finally {
|
||||
save(context, state)
|
||||
}
|
||||
notes
|
||||
}
|
||||
|
||||
private fun check(
|
||||
context: Context, state: JSONObject, protons: List<ComponentsManager.Proton>, wanted: List<String>, force: Boolean, notes: MutableList<String>,
|
||||
): Boolean {
|
||||
if (!AutoComponents.isOnline(context)) {
|
||||
state.put("note", context.getString(R.string.comp_auto_waits_network))
|
||||
return false
|
||||
}
|
||||
val catalog = runCatching { ComponentsManager.catalog(context, true).items }
|
||||
.onFailure { Log.w(TAG, "catalog", it) }.getOrDefault(emptyList())
|
||||
if (catalog.none { it.release == ComponentsManager.DD_NIGHTLY }) {
|
||||
state.put("note", context.getString(R.string.comp_auto_check_failed))
|
||||
return false
|
||||
}
|
||||
val holdBack = !force && AutoComponents.constrained(context)
|
||||
val lines = state.obj("lines")
|
||||
var complete = true
|
||||
state.remove("note")
|
||||
for (comp in wanted) for (p in protons) {
|
||||
val line = lineOf(context, state, p, comp) ?: continue
|
||||
val ls = lines.obj(line.key)
|
||||
if (rollingBack(ls)) {
|
||||
complete = false
|
||||
continue
|
||||
}
|
||||
val target = ComponentUpdates.pick(catalog, line, ls.strings("bad"))
|
||||
if (target == null || ls.optString("current") == target.file) continue
|
||||
val stored = ComponentsManager.isStored(context, target.file)
|
||||
if (!stored) {
|
||||
if (holdBack) {
|
||||
state.put("note", context.getString(R.string.comp_auto_waits_unmetered))
|
||||
complete = false
|
||||
continue
|
||||
}
|
||||
val got = runCatching { ComponentsManager.download(context, target) {} }
|
||||
if (got.isFailure) {
|
||||
Log.w(TAG, "download ${target.file}", got.exceptionOrNull())
|
||||
state.put("note", context.getString(R.string.comp_auto_check_failed))
|
||||
complete = false
|
||||
continue
|
||||
}
|
||||
}
|
||||
val stocks = protons.filter { lineOf(context, state, it, comp)?.key == line.key }.map { ComponentsManager.arm64x(context, it, comp) }
|
||||
if (ComponentUpdates.needsArm64x(line, stocks) && !ComponentsManager.packageArm64x(context, target.file, comp)) {
|
||||
Log.w(TAG, "${target.file} is not ARM64X like ${p.name}'s own ${line.key}; skipped")
|
||||
ls.put("bad", JSONArray(ls.strings("bad") + target.file))
|
||||
if (!stored) runCatching { ComponentsManager.deletePackage(context, target.file) }
|
||||
continue
|
||||
}
|
||||
ls.put("previous", ls.optString("current").ifEmpty { ComponentUpdates.ORIGINAL })
|
||||
.put("current", target.file).put("since", latestStamp(context)).put("failed", JSONObject())
|
||||
if (!stored) ls.put("owned", JSONArray(ls.strings("owned") + target.file))
|
||||
ls.remove("note")
|
||||
notes += context.getString(R.string.comp_auto_updated, ComponentsManager.LABEL[comp], target.file.removeSuffix(".wcp"))
|
||||
}
|
||||
return complete
|
||||
}
|
||||
|
||||
private fun apply(context: Context, state: JSONObject, protons: List<ComponentsManager.Proton>, wanted: List<String>, notes: MutableList<String>) {
|
||||
val lines = state.obj("lines")
|
||||
val targets = wanted.flatMap { comp ->
|
||||
protons.mapNotNull { p -> lineOf(context, state, p, comp)?.let { line -> lines.optJSONObject(line.key)?.let { Target(comp, p, line, it) } } }
|
||||
}
|
||||
val choices = ComponentsManager.activeChoices(context)
|
||||
for (t in targets) {
|
||||
val from = t.ls.optJSONObject("restore")?.optString(t.p.id).orEmpty()
|
||||
val current = t.ls.optString("current")
|
||||
if (from.isNotEmpty()) {
|
||||
if (choices.fileOf(t.p, t.comp) == from) runCatching { ComponentsManager.restore(context, t.p.id, t.comp, ComponentsManager.safeName(t.p.version)) }
|
||||
.onFailure { Log.w(TAG, "restore ${t.p.name} ${t.key}", it) }
|
||||
} else if (current.isNotEmpty() && choices.fileOf(t.p, t.comp) != current) {
|
||||
if (ComponentUpdates.needsArm64x(t.line, listOf(ComponentsManager.arm64x(context, t.p, t.comp))) &&
|
||||
!ComponentsManager.packageArm64x(context, current, t.comp)) continue
|
||||
runCatching { ComponentsManager.swap(context, t.p.id, current) }.onFailure { Log.w(TAG, "${t.p.name} ${t.key}", it) }
|
||||
}
|
||||
}
|
||||
val after = ComponentsManager.activeChoices(context)
|
||||
val unfinished = HashSet<String>()
|
||||
for (t in targets) {
|
||||
val restore = t.ls.optJSONObject("restore")
|
||||
val from = restore?.optString(t.p.id).orEmpty()
|
||||
val current = t.ls.optString("current")
|
||||
if (from.isNotEmpty()) {
|
||||
if (after.fileOf(t.p, t.comp) == from) unfinished += t.key else restore?.remove(t.p.id)
|
||||
} else if (current.isNotEmpty() && after.fileOf(t.p, t.comp) != current) {
|
||||
unfinished += t.key
|
||||
}
|
||||
}
|
||||
for (key in lines.keys().asSequence().toList()) {
|
||||
val ls = lines.optJSONObject(key) ?: continue
|
||||
val pending = ls.optString("pendingNote")
|
||||
if (pending.isEmpty() || key in unfinished || (ls.optJSONObject("restore")?.length() ?: 0) > 0) continue
|
||||
ls.remove("pendingNote")
|
||||
ls.put("note", pending)
|
||||
notes += pending
|
||||
}
|
||||
}
|
||||
|
||||
internal fun dropRemoved(state: JSONObject, protons: List<ComponentsManager.Proton>) {
|
||||
val installed = protons.mapTo(HashSet()) { it.id }
|
||||
val lines = state.optJSONObject("lines") ?: return
|
||||
for (key in lines.keys().asSequence().toList()) {
|
||||
val restore = lines.optJSONObject(key)?.optJSONObject("restore") ?: continue
|
||||
for (id in restore.keys().asSequence().toList()) if (id !in installed) restore.remove(id)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun rollingBack(ls: JSONObject): Boolean =
|
||||
(ls.optJSONObject("restore")?.length() ?: 0) > 0 || ls.optString("pendingNote").isNotEmpty()
|
||||
|
||||
private fun judge(context: Context, state: JSONObject, protons: List<ComponentsManager.Proton>, notes: MutableList<String>) {
|
||||
val mark = state.optString("logMark")
|
||||
val runs = ComponentUpdates.launches(logLines(context), mark)
|
||||
if (runs.isEmpty()) return
|
||||
state.put("logMark", runs.maxOf { it.start })
|
||||
val byTool = protons.associateBy { it.dir.name }
|
||||
val lines = state.obj("lines")
|
||||
for (comp in ComponentsManager.COMPONENTS) {
|
||||
val onLine = HashMap<String, MutableList<ComponentUpdates.Launch>>()
|
||||
for (run in runs) {
|
||||
val p = byTool[run.tool] ?: continue
|
||||
if (ComponentsManager.gameComponents(context, run.app).containsKey(comp)) continue
|
||||
val line = lineOf(context, state, p, comp) ?: continue
|
||||
onLine.getOrPut(line.key) { ArrayList() } += run
|
||||
}
|
||||
for ((key, list) in onLine) {
|
||||
val ls = lines.obj(key)
|
||||
val verdict = ComponentUpdates.judge(ComponentUpdates.Trial(
|
||||
ls.optString("current"), ls.optString("previous"), ls.optString("since"),
|
||||
ls.optJSONObject("booted").texts(), ls.optJSONObject("failed").ints(),
|
||||
), list)
|
||||
ls.put("booted", JSONObject(verdict.booted.entries.toList().takeLast(BOOTED_KEPT).associate { it.key to it.value } as Map<*, *>))
|
||||
ls.put("failed", JSONObject(verdict.failed as Map<*, *>))
|
||||
if (verdict.rollBack && managed(context, comp)) rollBack(context, state, protons, comp, key, notes)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun rollBack(context: Context, state: JSONObject, protons: List<ComponentsManager.Proton>, comp: String, key: String, notes: MutableList<String>) {
|
||||
val ls = state.obj("lines").obj(key)
|
||||
val bad = ls.optString("current")
|
||||
val back = ls.optString("previous")
|
||||
val choices = ComponentsManager.activeChoices(context)
|
||||
val targets = protons.filter { lineOf(context, state, it, comp)?.key == key && choices.fileOf(it, comp) == bad }
|
||||
for (p in targets) {
|
||||
runCatching {
|
||||
if (back == ComponentUpdates.ORIGINAL) ComponentsManager.restore(context, p.id, comp, ComponentsManager.safeName(p.version))
|
||||
else ComponentsManager.swap(context, p.id, back)
|
||||
}.onFailure { Log.w(TAG, "roll back ${p.name} $key", it) }
|
||||
}
|
||||
val after = ComponentsManager.activeChoices(context)
|
||||
val unfinished = targets.filter { after.fileOf(it, comp) == bad }
|
||||
ls.put("bad", JSONArray(ls.strings("bad") + bad)).put("current", back).put("previous", ComponentUpdates.ORIGINAL)
|
||||
.put("since", latestStamp(context)).put("failed", JSONObject())
|
||||
if (back == ComponentUpdates.ORIGINAL) ls.obj("restore").let { restore -> unfinished.forEach { restore.put(it.id, bad) } }
|
||||
val label = ComponentsManager.LABEL[comp]
|
||||
val shown = back.ifEmpty { context.getString(R.string.comp_tag_original) }.removeSuffix(".wcp")
|
||||
val note = context.getString(R.string.comp_auto_rolled_back, label, bad.removeSuffix(".wcp"), shown)
|
||||
Log.w(TAG, note)
|
||||
if (unfinished.isNotEmpty()) {
|
||||
ls.put("pendingNote", note)
|
||||
return
|
||||
}
|
||||
ls.remove("pendingNote")
|
||||
ls.put("note", note)
|
||||
notes += note
|
||||
prune(context, state)
|
||||
}
|
||||
|
||||
private fun prune(context: Context, state: JSONObject) {
|
||||
val lines = state.obj("lines")
|
||||
val selected = ComponentsManager.selectedPackages(context)
|
||||
val keep = lines.keys().asSequence().flatMap { k ->
|
||||
val ls = lines.optJSONObject(k) ?: return@flatMap emptySequence()
|
||||
ComponentUpdates.keep(ls.optString("current"), ls.optString("previous"), selected).asSequence()
|
||||
}.toSet()
|
||||
for (k in lines.keys().asSequence().toList()) {
|
||||
val ls = lines.optJSONObject(k) ?: continue
|
||||
val owned = ls.strings("owned")
|
||||
val gone = owned.filter { it !in keep && runCatching { ComponentsManager.deletePackage(context, it) }.isSuccess }
|
||||
ls.put("owned", JSONArray(owned - gone.toSet()))
|
||||
}
|
||||
}
|
||||
|
||||
fun status(context: Context, comp: String): List<Status> {
|
||||
val state = load(context)
|
||||
val lines = state.optJSONObject("lines") ?: JSONObject()
|
||||
val protons = runCatching { ComponentsManager.protons(context) }.getOrDefault(emptyList())
|
||||
val byLine = protons.groupBy { lineOf(context, state, it, comp)?.key }
|
||||
return ComponentUpdates.LINES.filter { it.comp == comp }.mapNotNull { line ->
|
||||
val on = byLine[line.key].orEmpty()
|
||||
val ls = lines.optJSONObject(line.key)
|
||||
if (on.isEmpty() && ls == null) return@mapNotNull null
|
||||
val note = ls?.optString("note").orEmpty().ifEmpty { state.optString("note") }
|
||||
Status(line.key, ls?.optString("current").orEmpty(), ls?.optString("previous").orEmpty(), on.map { it.name }, note)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.Locale
|
||||
|
||||
object ComponentUpdates {
|
||||
const val AUTO = "auto"
|
||||
const val MANUAL = "manual"
|
||||
const val ORIGINAL = ""
|
||||
const val BOOT_SECONDS = 30L
|
||||
const val BOOTED_SECONDS = 60L
|
||||
const val FAILED_BOOTS_BEFORE_ROLLBACK = 2
|
||||
|
||||
data class Line(val key: String, val comp: String, val prefix: String)
|
||||
|
||||
val LINES = listOf(
|
||||
Line("dxvk", "dxvk", "DD-dxvk-"),
|
||||
Line("dxvk-arm64ec", "dxvk", "DD-dxvk-arm64ec-"),
|
||||
Line("vkd3d", "vkd3d", "DD-vkd3d-proton-"),
|
||||
Line("vkd3d-arm64ec", "vkd3d", "DD-vkd3d-proton-arm64ec-"),
|
||||
Line("fex", "fex", "DD-FEXCore-"),
|
||||
)
|
||||
|
||||
fun line(comp: String, arm64ec: Boolean): Line = LINES.first {
|
||||
it.comp == comp && (comp == "fex" || it.key.endsWith("-arm64ec") == arm64ec)
|
||||
}
|
||||
|
||||
fun pick(items: List<ComponentsManager.CatalogItem>, line: Line, bad: Set<String>): ComponentsManager.CatalogItem? {
|
||||
val newestBad = bad.filter { belongs(it, line) }.maxWithOrNull { a, b -> ProtonExtras.compareVersions(a, b) }
|
||||
return items.filter { it.release == ComponentsManager.DD_NIGHTLY && it.comp == line.comp && belongs(it.file, line) }
|
||||
.filter { newestBad == null || ProtonExtras.compareVersions(it.file, newestBad) > 0 }
|
||||
.maxWithOrNull { a, b -> ProtonExtras.compareVersions(a.file, b.file) }
|
||||
}
|
||||
|
||||
fun belongs(file: String, line: Line): Boolean =
|
||||
file.startsWith(line.prefix) && file.removePrefix(line.prefix).firstOrNull()?.isDigit() == true
|
||||
|
||||
fun arm64ec(pe: ByteArray): Boolean? = runCatching {
|
||||
val b = ByteBuffer.wrap(pe).order(ByteOrder.LITTLE_ENDIAN)
|
||||
val header = b.getInt(0x3c)
|
||||
if (b.getInt(header) != 0x4550) return null
|
||||
val sections = b.getShort(header + 6).toInt() and 0xffff
|
||||
val optionalSize = b.getShort(header + 20).toInt() and 0xffff
|
||||
val optional = header + 24
|
||||
if ((b.getShort(optional).toInt() and 0xffff) != 0x20b) return false
|
||||
val loadConfigRva = b.getInt(optional + 112 + 10 * 8)
|
||||
if (loadConfigRva == 0) return false
|
||||
val table = optional + optionalSize
|
||||
var offset = -1
|
||||
for (i in 0 until sections) {
|
||||
val s = table + i * 40
|
||||
val size = b.getInt(s + 8)
|
||||
val va = b.getInt(s + 12)
|
||||
if (loadConfigRva >= va && loadConfigRva < va + maxOf(size, 1)) offset = b.getInt(s + 20) + loadConfigRva - va
|
||||
}
|
||||
if (offset < 0) return null
|
||||
b.getInt(offset) >= 0xC8 + 8 && b.getLong(offset + 0xC8) != 0L
|
||||
}.getOrNull()
|
||||
|
||||
fun arm64x(pe: ByteArray): Boolean = runCatching {
|
||||
val b = ByteBuffer.wrap(pe).order(ByteOrder.LITTLE_ENDIAN)
|
||||
val header = b.getInt(0x3c)
|
||||
b.getInt(header) == 0x4550 && (b.getShort(header + 4).toInt() and 0xffff) == 0xaa64 && arm64ec(pe) == true
|
||||
}.getOrDefault(false)
|
||||
|
||||
fun needsArm64x(line: Line, stocks: List<Boolean?>): Boolean =
|
||||
line.key.endsWith("-arm64ec") && stocks.any { it != false }
|
||||
|
||||
data class Launch(val app: String, val tool: String, val start: String, val seconds: Long)
|
||||
|
||||
private val PROCESS = Regex("""^\[(\d{4}-\d\d-\d\d \d\d:\d\d:\d\d)] Game process (added|removed)\s*: AppID (\d+)(?: "(.*))?""")
|
||||
private val TOOL = Regex("""compatibilitytools\.d/([^/'"]+)['"]?/|steamapps/common/([^/'"]+)['"]?/proton""")
|
||||
|
||||
fun launches(log: Sequence<String>, after: String): List<Launch> {
|
||||
val format = SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US)
|
||||
val open = HashMap<String, Pair<String, String>>()
|
||||
val out = ArrayList<Launch>()
|
||||
for (line in log) {
|
||||
val m = PROCESS.find(line) ?: continue
|
||||
val (time, what, app) = m.destructured
|
||||
if (time <= after) continue
|
||||
if (what == "added") {
|
||||
val tool = TOOL.find(m.groupValues[4])?.let { t -> t.groupValues[1].ifEmpty { t.groupValues[2] } } ?: continue
|
||||
open[app] = time to tool
|
||||
} else {
|
||||
val (start, tool) = open.remove(app) ?: continue
|
||||
val seconds = runCatching { (format.parse(time)!!.time - format.parse(start)!!.time) / 1000 }.getOrNull() ?: continue
|
||||
out += Launch(app, tool, start, seconds)
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
data class Trial(
|
||||
val current: String,
|
||||
val previous: String,
|
||||
val since: String,
|
||||
val booted: Map<String, String>,
|
||||
val failed: Map<String, Int>,
|
||||
)
|
||||
|
||||
data class Verdict(val booted: Map<String, String>, val failed: Map<String, Int>, val rollBack: Boolean)
|
||||
|
||||
fun judge(trial: Trial, runs: List<Launch>): Verdict {
|
||||
val booted = trial.booted.toMutableMap()
|
||||
val failed = trial.failed.toMutableMap()
|
||||
var rollBack = false
|
||||
for (run in runs) {
|
||||
val build = if (trial.since.isNotEmpty() && run.start > trial.since) trial.current else trial.previous
|
||||
if (run.seconds >= BOOTED_SECONDS) {
|
||||
booted[run.app] = build
|
||||
if (build == trial.current) failed.remove(run.app)
|
||||
} else if (run.seconds < BOOT_SECONDS && build == trial.current && trial.current != trial.previous &&
|
||||
booted[run.app] == trial.previous) {
|
||||
val n = (failed[run.app] ?: 0) + 1
|
||||
failed[run.app] = n
|
||||
if (n >= FAILED_BOOTS_BEFORE_ROLLBACK) rollBack = true
|
||||
}
|
||||
}
|
||||
return Verdict(booted, failed, rollBack)
|
||||
}
|
||||
|
||||
fun keep(current: String, previous: String, selected: Set<String>): Set<String> =
|
||||
(setOf(current, previous) + selected) - ORIGINAL
|
||||
}
|
||||
@@ -84,6 +84,7 @@ object ComponentsManager {
|
||||
|
||||
private fun root(context: Context) = LinuxRuntime.rootDir(context)
|
||||
private fun steam(context: Context) = File(root(context), "root/.local/share/Steam")
|
||||
fun steamLogs(context: Context) = File(steam(context), "logs")
|
||||
private fun host(context: Context, guest: String) = File(root(context), guest.removePrefix("/"))
|
||||
private fun dataDir(context: Context) = File(context.filesDir, "components").apply { mkdirs() }
|
||||
private fun packagesDir(context: Context) = File(dataDir(context), "packages").apply { mkdirs() }
|
||||
@@ -1031,6 +1032,78 @@ object ComponentsManager {
|
||||
ForcedPackage(setOf(GpuInfo.Family.A6XX), "dxvk", "dxvk-2.7.1-linux.wcp", "Dxvk-Linux"),
|
||||
)
|
||||
|
||||
private val ARM64EC_PROBE = mapOf("dxvk" to "d3d11.dll", "vkd3d" to "d3d12.dll")
|
||||
|
||||
fun arm64ec(context: Context, p: Proton, comp: String): Boolean? = stockProbe(context, p, comp)?.let(ComponentUpdates::arm64ec)
|
||||
|
||||
fun arm64x(context: Context, p: Proton, comp: String): Boolean? = stockProbe(context, p, comp)?.let(ComponentUpdates::arm64x)
|
||||
|
||||
fun packageArm64x(context: Context, file: String, comp: String): Boolean {
|
||||
val rel = "${COMP_DIR[comp] ?: return false}/aarch64-windows/${ARM64EC_PROBE.getValue(comp)}"
|
||||
val f = File(packagesDir(context), safeName(file)).takeIf { it.isFile } ?: return false
|
||||
return runCatching { readWcpEntry(f, rel) }.getOrNull()?.let(ComponentUpdates::arm64x) == true
|
||||
}
|
||||
|
||||
private fun readWcpEntry(f: File, rel: String): ByteArray? = readWcp(f) { tar ->
|
||||
var found: ByteArray? = null
|
||||
while (found == null) {
|
||||
val e = tar.nextTarEntry ?: break
|
||||
if (!e.isDirectory && normalize(e.name) == rel) found = tar.readBytes()
|
||||
}
|
||||
found
|
||||
}
|
||||
|
||||
private fun stockProbe(context: Context, p: Proton, comp: String): ByteArray? {
|
||||
val rel = "${COMP_DIR[comp] ?: return null}/aarch64-windows/${ARM64EC_PROBE.getValue(comp)}"
|
||||
val original = synchronized(lock) {
|
||||
val swapped = loadState(context).optJSONObject("active")?.optJSONObject(p.id)?.optJSONObject(comp)
|
||||
?.let { liveSelection("active", it, p) } == true
|
||||
if (!swapped) return File(p.dir, rel).takeIf { it.isFile }?.let { runCatching { it.readBytes() }.getOrNull() }
|
||||
originalFile(context, p, comp).takeIf { it.isFile } ?: return null
|
||||
}
|
||||
return runCatching { readWcpEntry(original, rel) }.getOrNull()
|
||||
}
|
||||
|
||||
fun supports(p: Proton, comp: String): Boolean =
|
||||
if (comp == "fex") File(p.dir, FEX_FILES.first()).isFile else File(p.dir, "${COMP_DIR.getValue(comp)}/aarch64-windows").isDirectory
|
||||
|
||||
fun hardwareDxvk(context: Context): Boolean =
|
||||
runtimeManaged(context, "dxvk") || FORCED_PACKAGES.any { it.comp == "dxvk" && it.matches(GpuInfo.detect()) } ||
|
||||
(com.droiddeck.launcher.core.DeviceSupport.vkBridge(context) && !SessionPrefs.bridgeProtonDxvk(context) &&
|
||||
bridgeDxvk(AppVulkan.detect(context)) != null)
|
||||
|
||||
data class Choice(val file: String, val auto: Boolean, val protonVersion: String)
|
||||
|
||||
fun activeChoices(context: Context): Map<String, Map<String, Choice>> = synchronized(lock) {
|
||||
val active = loadState(context).optJSONObject("active") ?: return emptyMap()
|
||||
active.keys().asSequence().toList().associateWith { pid ->
|
||||
val comps = active.optJSONObject(pid) ?: JSONObject()
|
||||
comps.keys().asSequence().toList().mapNotNull { c ->
|
||||
comps.optJSONObject(c)?.let { c to Choice(it.optString("file"), it.optBoolean("auto"), it.optString("protonVersion")) }
|
||||
}.toMap()
|
||||
}
|
||||
}
|
||||
|
||||
fun selectedPackages(context: Context): Set<String> = synchronized(lock) {
|
||||
val state = loadState(context)
|
||||
buildSet {
|
||||
for (key in listOf("active", "queued")) {
|
||||
val byProton = state.optJSONObject(key) ?: continue
|
||||
for (pid in byProton.keys()) {
|
||||
val comps = byProton.optJSONObject(pid) ?: continue
|
||||
for (c in comps.keys()) comps.optJSONObject(c)?.optString("file")?.takeIf(String::isNotEmpty)?.let(::add)
|
||||
}
|
||||
}
|
||||
val profiles = state.optJSONObject("profiles")
|
||||
profiles?.keys()?.forEach { scope ->
|
||||
val profile = profiles.optJSONObject(scope) ?: return@forEach
|
||||
for (c in COMPONENTS) profile.optString(c).takeIf(String::isNotEmpty)?.let(::add)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun isStored(context: Context, file: String): Boolean = File(packagesDir(context), safeName(file)).isFile
|
||||
|
||||
internal fun forcedPackageWanted(activeFile: String?, protonVersionMatches: Boolean): Boolean =
|
||||
activeFile.isNullOrEmpty() || !protonVersionMatches
|
||||
|
||||
|
||||
@@ -508,6 +508,17 @@ object SessionPrefs {
|
||||
prefs(context).edit().putString("gpuDriverMode", mode).apply()
|
||||
}
|
||||
|
||||
fun componentMode(context: Context, comp: String): String =
|
||||
prefs(context).getString("componentMode.$comp", ComponentUpdates.AUTO)
|
||||
?.takeIf { it == ComponentUpdates.AUTO || it == ComponentUpdates.MANUAL } ?: ComponentUpdates.AUTO
|
||||
|
||||
fun componentModeChosen(context: Context, comp: String): Boolean = prefs(context).contains("componentMode.$comp")
|
||||
|
||||
fun setComponentMode(context: Context, comp: String, mode: String) {
|
||||
require(mode == ComponentUpdates.AUTO || mode == ComponentUpdates.MANUAL)
|
||||
prefs(context).edit().putString("componentMode.$comp", mode).commit()
|
||||
}
|
||||
|
||||
fun settleGpuDriverMode(context: Context) {
|
||||
val p = prefs(context)
|
||||
if (p.contains("gpuDriverMode")) return
|
||||
|
||||
@@ -30,7 +30,7 @@ object SettingsReset {
|
||||
)
|
||||
|
||||
internal val SESSION_PREFIXES = listOf(
|
||||
"resolutionCap.", "displayResolution.", "customRes.", "hdr.", "fpsLimit.", "performanceMode.", "suspendPolicy.",
|
||||
"resolutionCap.", "displayResolution.", "customRes.", "hdr.", "fpsLimit.", "performanceMode.", "suspendPolicy.", "componentMode.",
|
||||
)
|
||||
|
||||
private val STEAM_TOUCH_KEYS = listOf("feedback", "autoFade", "gyro", "shake")
|
||||
|
||||
@@ -81,6 +81,8 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.session.ComponentUpdater
|
||||
import com.droiddeck.launcher.session.ComponentUpdates
|
||||
import com.droiddeck.launcher.session.ComponentsManager
|
||||
import com.droiddeck.launcher.session.ComponentsManager.CatalogItem
|
||||
import com.droiddeck.launcher.session.ComponentsManager.Snapshot
|
||||
@@ -163,6 +165,11 @@ fun ComponentsPage(
|
||||
protons: ProtonsState = ProtonsState(),
|
||||
protonActions: ProtonsActions = ProtonsActions(),
|
||||
protonOptions: @Composable () -> Unit = {},
|
||||
compModes: Map<String, String> = emptyMap(),
|
||||
compAuto: Map<String, List<ComponentUpdater.Status>> = emptyMap(),
|
||||
compAutoHeld: Set<String> = emptySet(),
|
||||
compAutoChecking: Boolean = false,
|
||||
onCompMode: (String, String) -> Unit = { _, _ -> },
|
||||
) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
@@ -521,6 +528,8 @@ fun ComponentsPage(
|
||||
else -> stringResource(R.string.comp_nightlies_count, availableRows(l, catalog, snapshot).size)
|
||||
}
|
||||
}
|
||||
val moded: (String) -> Boolean = { it in compModes && it !in compAutoHeld && !ComponentsManager.runtimeManaged(it, gpu.systemPowerVr) }
|
||||
val automatic: (String) -> Boolean = { moded(it) && compModes[it] == ComponentUpdates.AUTO }
|
||||
val installedRows: @Composable ColumnScope.(String, Boolean) -> Unit = { l, right ->
|
||||
when (l) {
|
||||
PROTON_TAB -> {
|
||||
@@ -535,7 +544,7 @@ fun ComponentsPage(
|
||||
(if (swaps > 0) stringResource(R.string.comp_swapped, v.proton.version, swaps) else stringResource(R.string.comp_all_original, v.proton.version))
|
||||
.let { if (v.inUseByGame) stringResource(R.string.comp_game_running_suffix, it) else it },
|
||||
v.proton.id == view?.proton?.id, removable = removable,
|
||||
modifier = (if (i == 0) Modifier.focusRequester(firstRow) else Modifier).trackRow(key, rowsAt),
|
||||
modifier = (if (i == 0 && !moded(l)) Modifier.focusRequester(firstRow) else Modifier).trackRow(key, rowsAt),
|
||||
onSelect = { if (v.proton.id != view?.proton?.id) { onProton(v.proton.id); flyHome(key, PROTON_TAB) } },
|
||||
onDelete = {
|
||||
if (extra != null) ask(key, right, ctx.getString(R.string.proton_remove_title, v.proton.name), ctx.getString(R.string.proton_remove_body), ctx.getString(R.string.store_remove), true, v.proton.name) {
|
||||
@@ -555,7 +564,7 @@ fun ComponentsPage(
|
||||
val key = "row:$l:${item.file ?: item.protonVersion}"
|
||||
ChoiceLine(
|
||||
item.name, item.detail, item.selected, item.removable, tag = item.tag, enabled = !managedDxvk,
|
||||
modifier = (if (i == 0 && !managedDxvk) Modifier.focusRequester(firstRow) else Modifier).trackRow(key, rowsAt),
|
||||
modifier = (if (i == 0 && !managedDxvk && !moded(l)) Modifier.focusRequester(firstRow) else Modifier).trackRow(key, rowsAt),
|
||||
onSelect = {
|
||||
if (managedDxvk || item.selected || p == null) return@ChoiceLine
|
||||
val waits = if (view.inUseByGame) ctx.getString(R.string.comp_waits_long) else ctx.getString(R.string.comp_applies_long)
|
||||
@@ -680,15 +689,31 @@ fun ComponentsPage(
|
||||
label = "layerRows",
|
||||
) { k -> body(k) }
|
||||
}
|
||||
if (single) {
|
||||
slide { k -> RowGroup(installedTitle(k)) { installedRows(k, false) } }
|
||||
Spacer(Modifier.height(12.dp))
|
||||
slide { k -> RowGroup(availableTitle(k)) { availableRows(k) } }
|
||||
} else Row(horizontalArrangement = Arrangement.spacedBy(14.dp), verticalAlignment = Alignment.Top) {
|
||||
Column(Modifier.weight(1f)) { slide { k -> RowGroup(installedTitle(k)) { installedRows(k, false) } } }
|
||||
Column(Modifier.weight(1f)) { slide { k -> RowGroup(availableTitle(k)) { availableRows(k) } } }
|
||||
if (moded(l)) slide { k ->
|
||||
if (moded(k)) Column(verticalArrangement = Arrangement.spacedBy(14.dp), modifier = Modifier.padding(bottom = 14.dp)) {
|
||||
PanelHeading(stringResource(R.string.comp_mode_title))
|
||||
ModeChoices(
|
||||
listOf(
|
||||
Triple(ComponentUpdates.AUTO, R.string.common_auto, R.string.comp_mode_auto_detail),
|
||||
Triple(ComponentUpdates.MANUAL, R.string.drivers_manual, R.string.comp_mode_manual_detail),
|
||||
),
|
||||
if (automatic(k)) ComponentUpdates.AUTO else ComponentUpdates.MANUAL, single, firstRow,
|
||||
onPick = { onCompMode(k, it) },
|
||||
)
|
||||
if (automatic(k)) AutoComponentBody(ComponentsManager.LABEL[k] ?: k, compAuto[k].orEmpty(), compAutoChecking)
|
||||
}
|
||||
}
|
||||
if (!automatic(l)) {
|
||||
if (single) {
|
||||
slide { k -> RowGroup(installedTitle(k)) { installedRows(k, false) } }
|
||||
Spacer(Modifier.height(12.dp))
|
||||
slide { k -> RowGroup(availableTitle(k)) { availableRows(k) } }
|
||||
} else Row(horizontalArrangement = Arrangement.spacedBy(14.dp), verticalAlignment = Alignment.Top) {
|
||||
Column(Modifier.weight(1f)) { slide { k -> RowGroup(installedTitle(k)) { installedRows(k, false) } } }
|
||||
Column(Modifier.weight(1f)) { slide { k -> RowGroup(availableTitle(k)) { availableRows(k) } } }
|
||||
}
|
||||
Box(Modifier.padding(top = 14.dp)) { slide { k -> actions(k) } }
|
||||
}
|
||||
Box(Modifier.padding(top = 14.dp)) { slide { k -> actions(k) } }
|
||||
if (l == "fex") {
|
||||
SettingsGroup(stringResource(R.string.fex_preset_title)) {
|
||||
SettingsRow(stringResource(R.string.fex_preset_title), null) {
|
||||
@@ -1078,6 +1103,25 @@ private fun RowGroup(title: String, content: @Composable ColumnScope.() -> Unit)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AutoComponentBody(label: String, lines: List<ComponentUpdater.Status>, checking: Boolean) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
Column(verticalArrangement = Arrangement.spacedBy(10.dp)) {
|
||||
PanelTitle(stringResource(R.string.comp_auto_title, label), stringResource(R.string.comp_auto_hint))
|
||||
if (lines.isEmpty()) EmptyLine(stringResource(R.string.comp_auto_none))
|
||||
for (line in lines) {
|
||||
val previous = line.previous.removeSuffix(".wcp").ifEmpty { stringResource(R.string.comp_tag_original) }
|
||||
val fallback = if (line.current.isEmpty()) null else stringResource(R.string.comp_auto_fallback, previous)
|
||||
PanelRow(
|
||||
line.current.removeSuffix(".wcp").ifEmpty { stringResource(if (checking) R.string.comp_auto_checking else R.string.comp_tag_original) },
|
||||
listOfNotNull(line.protons.joinToString(", ").ifEmpty { null }, fallback).joinToString(" · "),
|
||||
selected = true, onClick = null,
|
||||
)
|
||||
}
|
||||
lines.map { it.note }.filter { it.isNotEmpty() }.distinct().forEach { Text(it, fontSize = 13.sp, color = colors.onSurfaceVariant) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun EmptyLine(text: String) {
|
||||
Text(text, fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(horizontal = 14.dp, vertical = 12.dp))
|
||||
|
||||
@@ -250,18 +250,8 @@ internal fun GpuDriversBody(
|
||||
Triple(GPU_MODE_PAIR, R.string.gpu_mode_pair, R.string.gpu_mode_pair_detail),
|
||||
Triple(GPU_MODE_MIX, R.string.gpu_mode_mix, R.string.gpu_mode_mix_detail),
|
||||
)
|
||||
val choice: @Composable (Int, Modifier) -> Unit = { i, mod ->
|
||||
val (id, title, detail) = modes[i]
|
||||
PanelRow(
|
||||
stringResource(title), stringResource(detail), gpu.mode == id,
|
||||
modifier = mod.then(if (gpu.mode == id) Modifier.focusRequester(first) else Modifier)
|
||||
.then(if (i == 0) Modifier.onGloballyPositioned { placed[1] = it }.onFocusChanged { if (it.isFocused) revealCard() } else Modifier),
|
||||
onClick = { if (gpu.mode != id) actions.onMode(id) },
|
||||
)
|
||||
}
|
||||
if (single) Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { modes.indices.forEach { choice(it, Modifier) } }
|
||||
else Row(horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth().height(IntrinsicSize.Min)) {
|
||||
modes.indices.forEach { choice(it, Modifier.weight(1f).fillMaxHeight()) }
|
||||
ModeChoices(modes, gpu.mode, single, first, onPick = actions.onMode) { i ->
|
||||
if (i == 0) Modifier.onGloballyPositioned { placed[1] = it }.onFocusChanged { if (it.isFocused) revealCard() } else Modifier
|
||||
}
|
||||
when (gpu.mode) {
|
||||
GPU_MODE_AUTO -> AutoBody(gpu, actions)
|
||||
@@ -439,12 +429,35 @@ internal const val SLOT_DISPLAY = "panel"
|
||||
internal const val SLOT_RUNTIME = "rt"
|
||||
|
||||
@Composable
|
||||
private fun PanelHeading(text: String) {
|
||||
internal fun ModeChoices(
|
||||
modes: List<Triple<String, Int, Int>>,
|
||||
selected: String,
|
||||
single: Boolean,
|
||||
first: FocusRequester,
|
||||
onPick: (String) -> Unit,
|
||||
extra: (Int) -> Modifier = { Modifier },
|
||||
) {
|
||||
val choice: @Composable (Int, Modifier) -> Unit = { i, mod ->
|
||||
val (id, title, detail) = modes[i]
|
||||
PanelRow(
|
||||
stringResource(title), stringResource(detail), selected == id,
|
||||
modifier = mod.then(if (selected == id) Modifier.focusRequester(first) else Modifier).then(extra(i)),
|
||||
onClick = { if (selected != id) onPick(id) },
|
||||
)
|
||||
}
|
||||
if (single) Column(verticalArrangement = Arrangement.spacedBy(8.dp)) { modes.indices.forEach { choice(it, Modifier) } }
|
||||
else Row(horizontalArrangement = Arrangement.spacedBy(10.dp), modifier = Modifier.fillMaxWidth().height(IntrinsicSize.Min)) {
|
||||
modes.indices.forEach { choice(it, Modifier.weight(1f).fillMaxHeight()) }
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun PanelHeading(text: String) {
|
||||
Text(text.uppercase(), fontSize = 12.sp, fontWeight = FontWeight.SemiBold, letterSpacing = 1.5.sp, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PanelTitle(title: String, hint: String) {
|
||||
internal fun PanelTitle(title: String, hint: String) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(3.dp), modifier = Modifier.padding(top = 4.dp)) {
|
||||
Text(title, fontSize = 18.sp, fontWeight = FontWeight.SemiBold, color = MaterialTheme.colorScheme.onBackground)
|
||||
Text(hint, fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
@@ -461,7 +474,7 @@ private fun Pill(text: String, fill: Color, ink: Color) {
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun PanelRow(
|
||||
internal fun PanelRow(
|
||||
title: String,
|
||||
detail: String,
|
||||
selected: Boolean,
|
||||
|
||||
Reference in new issue
Block a user