mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
feat(proton): offer DroidDeck-Proton test builds in Components (#2831)
Components > Proton offers a DroidDeck-Proton pre-release that is ahead of Stable through the existing channel toggle. Automatic installs and updates stay on Stable.
This commit is contained in:
1 parent
f180d98da7
commit
c35da09d1a
40 files changed
+297
-76
No files matched your search
@@ -2431,6 +2431,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
),
|
||||
protonActions = com.droiddeck.launcher.ui.ProtonsActions(
|
||||
onInstall = { id -> protons.installProton(id) },
|
||||
onInstallTest = { id -> protons.installProton(id, test = true) },
|
||||
onCancel = { id -> ProtonExtras.tools.firstOrNull { it.id == id }?.let { ProtonExtras.unqueue(this, it) }; protons.refreshProtons() },
|
||||
onRemove = { id, dir -> protons.removeProton(id, dir) },
|
||||
onRemoveOlder = { id -> protons.removeProton(id, older = true) },
|
||||
|
||||
@@ -34,10 +34,10 @@ internal class ProtonMenu(
|
||||
var protonPercent by Operation.percent
|
||||
var protonProblem by Operation.problem
|
||||
private val checking = java.util.concurrent.atomic.AtomicBoolean(false)
|
||||
@VisibleForTesting internal var installer: (ProtonExtras.Tool, (String, Int) -> Unit) -> String? =
|
||||
{ tool, progress -> ProtonExtras.install(activity, tool, progress) }
|
||||
@VisibleForTesting internal var installer: (ProtonExtras.Tool, Boolean, (String, Int) -> Unit) -> String? =
|
||||
{ tool, test, progress -> ProtonExtras.install(activity, tool, test, progress) }
|
||||
|
||||
fun installProton(id: String, automatic: Boolean = false) {
|
||||
fun installProton(id: String, automatic: Boolean = false, test: Boolean = false) {
|
||||
val tool = ProtonExtras.tools.firstOrNull { it.id == id } ?: return
|
||||
if (protonBusyId != null || ProtonExtras.installInProgress || SessionState.running) return
|
||||
ProtonExtras.unqueue(activity, tool)
|
||||
@@ -47,7 +47,7 @@ internal class ProtonMenu(
|
||||
protonPercent = -1
|
||||
Thread({
|
||||
val problem = runCatching {
|
||||
installer(tool) { label, value ->
|
||||
installer(tool, test) { label, value ->
|
||||
ui.post { protonStage = label; protonPercent = value }
|
||||
}
|
||||
}.getOrElse { it.message ?: it.javaClass.simpleName }
|
||||
@@ -89,7 +89,7 @@ internal class ProtonMenu(
|
||||
fun refreshProtons() {
|
||||
protonRows = ProtonExtras.tools.map {
|
||||
val all = ProtonExtras.installedAll(activity, it)
|
||||
ProtonRow(it.id, it.name, all.lastOrNull(), ProtonExtras.queued(activity, it), all, ProtonExtras.update(activity, it))
|
||||
ProtonRow(it.id, it.name, all.lastOrNull(), ProtonExtras.queued(activity, it), all, ProtonExtras.update(activity, it), ProtonExtras.testBuild(activity, it))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,13 +9,15 @@ import com.droiddeck.launcher.core.Downloader
|
||||
import com.droiddeck.launcher.core.FileUtils
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import java.io.File
|
||||
import java.util.Locale
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
||||
object ProtonExtras {
|
||||
private const val TAG = "ProtonExtras"
|
||||
private const val NEED_BYTES = 4L * 1024 * 1024 * 1024
|
||||
private const val RELEASES = "https://api.github.com/repos/%s/releases?per_page=15"
|
||||
private const val RELEASES = "https://api.github.com/repos/%s/releases?per_page=15&page=%d"
|
||||
private const val RELEASE_PAGES = 5
|
||||
const val CHECK_EVERY_MS = 60L * 60 * 1000
|
||||
@Volatile
|
||||
var installInProgress = false
|
||||
@@ -104,6 +106,12 @@ object ProtonExtras {
|
||||
fun cachedLatest(context: Context, tool: Tool): String? =
|
||||
readJson(latestFile(context)).optJSONObject(tool.id)?.optString("tag")?.ifEmpty { null }
|
||||
|
||||
fun testBuild(context: Context, tool: Tool): String? =
|
||||
testFor(installedTags(context, tool), readJson(latestFile(context)).optJSONObject(tool.id)?.optString("test")?.ifEmpty { null })
|
||||
|
||||
internal fun testFor(installed: List<String>, test: String?): String? =
|
||||
test?.takeIf { it !in installed && (installed.isEmpty() || updateFor(installed, it) != null) }
|
||||
|
||||
private val checkLock = Any()
|
||||
private const val RETRY_MS = 15L * 60 * 1000
|
||||
private const val USER_SETTINGS = "user_settings.py"
|
||||
@@ -120,22 +128,27 @@ object ProtonExtras {
|
||||
if (due.isEmpty() || !force && (now - lastAttempt) in 0 until RETRY_MS) return false
|
||||
lastAttempt = now
|
||||
for (tool in due) {
|
||||
val tag = findLatestAsset(tool)?.tag ?: continue
|
||||
cache.put(tool.id, JSONObject().put("tag", tag).put("at", now))
|
||||
updateLatest(cache, tool, releases(tool), now)
|
||||
}
|
||||
runCatching { file.writeText(cache.toString()) }
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
private fun record(context: Context, tool: Tool, dir: String?, tag: String) {
|
||||
internal fun recordLatest(latest: JSONObject, tool: Tool, tag: String, test: Boolean, now: Long): Boolean {
|
||||
if (test) return false
|
||||
val entry = latest.optJSONObject(tool.id)
|
||||
val known = entry?.optString("tag")
|
||||
if (!known.isNullOrEmpty() && compareVersions(tag, known) < 0) return false
|
||||
val ahead = entry?.optString("test")?.takeIf { it.isNotEmpty() && compareVersions(it, tag) > 0 }
|
||||
latest.put(tool.id, JSONObject().put("tag", tag).put("at", now).putOpt("test", ahead))
|
||||
return true
|
||||
}
|
||||
|
||||
private fun record(context: Context, tool: Tool, dir: String?, tag: String, test: Boolean) {
|
||||
runCatching {
|
||||
val latest = readJson(latestFile(context))
|
||||
val known = latest.optJSONObject(tool.id)?.optString("tag")
|
||||
if (known.isNullOrEmpty() || compareVersions(tag, known) >= 0) {
|
||||
latest.put(tool.id, JSONObject().put("tag", tag).put("at", System.currentTimeMillis()))
|
||||
latestFile(context).writeText(latest.toString())
|
||||
}
|
||||
if (recordLatest(latest, tool, tag, test, System.currentTimeMillis())) latestFile(context).writeText(latest.toString())
|
||||
if (dir != null) {
|
||||
val releases = readJson(releasesFile(context))
|
||||
val present = toolsDir(context).list()?.toSet() ?: emptySet()
|
||||
@@ -208,17 +221,17 @@ object ProtonExtras {
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun install(context: Context, tool: Tool, onProgress: (String, Int) -> Unit): String? {
|
||||
fun install(context: Context, tool: Tool, test: Boolean = false, onProgress: (String, Int) -> Unit): String? {
|
||||
if (installInProgress) return context.getString(R.string.pextra_busy)
|
||||
installInProgress = true
|
||||
return try { installNow(context, tool, onProgress) } finally { installInProgress = false }
|
||||
return try { installNow(context, tool, test, onProgress) } finally { installInProgress = false }
|
||||
}
|
||||
|
||||
private fun installNow(context: Context, tool: Tool, onProgress: (String, Int) -> Unit): String? {
|
||||
private fun installNow(context: Context, tool: Tool, test: Boolean, onProgress: (String, Int) -> Unit): String? {
|
||||
if (SessionState.running) return context.getString(R.string.pextra_stop_session)
|
||||
if (!LinuxRuntime.isInstalled(context)) return context.getString(R.string.user_apps_runtime_required)
|
||||
|
||||
val asset = findLatestAsset(tool) ?: return context.getString(R.string.pextra_no_release, tool.name)
|
||||
val asset = releases(tool)?.let { pickAsset(tool, it, test && tool.id == OWN) } ?: return context.getString(R.string.pextra_no_release, tool.name)
|
||||
val downloads = File(context.filesDir, "proton-downloads").apply { mkdirs() }
|
||||
val archive = File(downloads, "${tool.id}-${asset.name}")
|
||||
if (asset.size > 0 && archive.length() > asset.size) archive.delete()
|
||||
@@ -313,7 +326,7 @@ object ProtonExtras {
|
||||
else {
|
||||
archive.delete()
|
||||
unqueue(context, tool)
|
||||
record(context, tool, placed, asset.tag)
|
||||
record(context, tool, placed, asset.tag, test)
|
||||
if (tool.id == OWN) replaceOlder(context, tool)
|
||||
if (EsyncPacks.enabled(context)) {
|
||||
onProgress(context.getString(R.string.esync_fetching), -1)
|
||||
@@ -331,36 +344,68 @@ object ProtonExtras {
|
||||
}
|
||||
}
|
||||
|
||||
private fun findLatestAsset(tool: Tool): Asset? {
|
||||
val releases = Downloader.downloadString(RELEASES.format(tool.repo)) ?: return null
|
||||
return try {
|
||||
pickAsset(tool, JSONArray(releases))
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "release metadata for ${tool.id}", e)
|
||||
null
|
||||
private fun releases(tool: Tool): JSONArray? = releases(tool) { page ->
|
||||
Downloader.downloadString(RELEASES.format(Locale.ROOT, tool.repo, page))?.let { body ->
|
||||
try {
|
||||
JSONArray(body)
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "release metadata for ${tool.id}", e)
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal fun pickAsset(tool: Tool, array: JSONArray): Asset? {
|
||||
for (i in 0 until array.length()) {
|
||||
val release = array.getJSONObject(i)
|
||||
if (release.optBoolean("draft", false) || release.optBoolean("prerelease", false)) continue
|
||||
val assets = release.optJSONArray("assets") ?: continue
|
||||
val entries = (0 until assets.length()).map { assets.getJSONObject(it) }
|
||||
val archive = entries.sortedBy { it.optString("name") }.firstOrNull { tool.assetPattern.containsMatchIn(it.optString("name")) } ?: continue
|
||||
internal fun releases(tool: Tool, fetch: (Int) -> JSONArray?): JSONArray? {
|
||||
val all = fetch(1) ?: return null
|
||||
var page = 1
|
||||
var last = all.length()
|
||||
while (last > 0 && page < RELEASE_PAGES && pickAsset(tool, all) == null) {
|
||||
val next = fetch(++page) ?: return null
|
||||
for (i in 0 until next.length()) all.put(next.opt(i))
|
||||
last = next.length()
|
||||
}
|
||||
return all
|
||||
}
|
||||
|
||||
internal fun pickAsset(tool: Tool, array: JSONArray, test: Boolean = false): Asset? {
|
||||
val candidates = (0 until array.length()).asSequence()
|
||||
.mapNotNull { array.optJSONObject(it) }
|
||||
.filter { !it.optBoolean("draft", false) && it.optBoolean("prerelease", false) == test }
|
||||
if (!test) return candidates.firstNotNullOfOrNull { assetOf(tool, it) }
|
||||
val stable = pickAsset(tool, array)?.tag ?: return null
|
||||
return candidates
|
||||
.filter { it.optString("tag_name").startsWith(tool.prefix) && updateFor(listOf(stable), it.optString("tag_name")) != null }
|
||||
.mapNotNull { assetOf(tool, it, requireChecksum = true) }
|
||||
.maxWithOrNull { a, b -> compareVersions(a.tag, b.tag) }
|
||||
}
|
||||
|
||||
internal fun updateLatest(cache: JSONObject, tool: Tool, array: JSONArray?, now: Long) {
|
||||
if (array == null) return
|
||||
val test = if (tool.id == OWN) pickAsset(tool, array, test = true)?.tag else null
|
||||
val tag = pickAsset(tool, array)?.tag
|
||||
if (tag == null) {
|
||||
cache.optJSONObject(tool.id)?.remove("test")
|
||||
return
|
||||
}
|
||||
cache.put(tool.id, JSONObject().put("tag", tag).put("at", now).putOpt("test", test))
|
||||
}
|
||||
|
||||
private fun assetOf(tool: Tool, release: JSONObject, requireChecksum: Boolean = false): Asset? = try {
|
||||
val assets = release.optJSONArray("assets")
|
||||
val entries = assets?.let { list -> (0 until list.length()).mapNotNull { list.optJSONObject(it) } }.orEmpty()
|
||||
entries.sortedBy { it.optString("name") }.filter { tool.assetPattern.containsMatchIn(it.optString("name")) }.mapNotNull { archive ->
|
||||
val name = archive.optString("name")
|
||||
val stem = name.substringBefore(".tar")
|
||||
val checksum = entries.firstOrNull {
|
||||
it.optString("name").startsWith(stem) && it.optString("name").contains("sha512", ignoreCase = true)
|
||||
}?.optString("browser_download_url")?.takeIf { it.startsWith("http") }
|
||||
return Asset(
|
||||
release.optString("tag_name"), name,
|
||||
archive.optString("browser_download_url").takeIf { it.startsWith("http") } ?: continue, checksum,
|
||||
archive.optLong("size", 0L),
|
||||
Hashes.githubSha256(archive.optString("digest")),
|
||||
)
|
||||
}
|
||||
return null
|
||||
archive.optString("browser_download_url").takeIf { it.startsWith("http") }?.let { url ->
|
||||
Asset(release.optString("tag_name"), name, url, checksum, archive.optLong("size", 0L), Hashes.githubSha256(archive.optString("digest")))
|
||||
}
|
||||
}.let { found -> if (requireChecksum) found.firstOrNull { it.sha256 != null || it.sha512 != null } else found.firstOrNull() }
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "release metadata for ${tool.id}", e)
|
||||
null
|
||||
}
|
||||
|
||||
private fun requestLines(context: Context): List<String> =
|
||||
|
||||
@@ -524,7 +524,7 @@ fun ComponentsPage(
|
||||
}
|
||||
val availableTitle: @Composable (String) -> String = { l ->
|
||||
when (l) {
|
||||
PROTON_TAB -> stringResource(R.string.comp_available_count, protons.rows.count { it.installed == null || it.update != null })
|
||||
PROTON_TAB -> stringResource(R.string.comp_available_count, protons.rows.count(ProtonRow::available))
|
||||
else -> stringResource(R.string.comp_nightlies_count, availableRows(l, catalog, snapshot).size)
|
||||
}
|
||||
}
|
||||
@@ -589,21 +589,29 @@ fun ComponentsPage(
|
||||
val availableRows: @Composable ColumnScope.(String) -> Unit = { l ->
|
||||
when (l) {
|
||||
PROTON_TAB -> {
|
||||
val rows = protons.rows.filter { it.installed == null || it.update != null }
|
||||
val rows = protons.rows.filter(ProtonRow::available)
|
||||
if (rows.isEmpty()) EmptyLine(stringResource(R.string.comp_nothing_new))
|
||||
for (row in rows) GetLine(
|
||||
row.name,
|
||||
when {
|
||||
row.update != null -> stringResource(R.string.proton_update_available, row.update)
|
||||
row.queued -> stringResource(R.string.proton_queued)
|
||||
else -> stringResource(R.string.proton_not_installed)
|
||||
},
|
||||
progress = if (protons.busyId == row.id) protons.percent else null,
|
||||
stage = if (protons.busyId == row.id) protons.stage else null,
|
||||
enabled = protons.busyId == null && protons.runtimeReady && !protons.sessionRunning,
|
||||
onCancel = if (row.queued && protons.busyId == null && !protons.sessionRunning) ({ protonActions.onCancel(row.id) }) else null,
|
||||
action = if (row.update != null) stringResource(R.string.common_update) else null,
|
||||
) { protonActions.onInstall(row.id) }
|
||||
for (row in rows) {
|
||||
val idle = protons.busyId == null && protons.runtimeReady && !protons.sessionRunning
|
||||
val test = row.test != null && (nightlyPicked[row.id] == true || row.installed != null && row.update == null)
|
||||
GetLine(
|
||||
row.name,
|
||||
when {
|
||||
test -> row.test!!
|
||||
row.update != null -> stringResource(R.string.proton_update_available, row.update)
|
||||
row.queued -> stringResource(R.string.proton_queued)
|
||||
else -> stringResource(R.string.proton_not_installed)
|
||||
},
|
||||
progress = if (protons.busyId == row.id) protons.percent else null,
|
||||
stage = if (protons.busyId == row.id) protons.stage else null,
|
||||
enabled = idle,
|
||||
onCancel = if (row.queued && protons.busyId == null && !protons.sessionRunning) ({ protonActions.onCancel(row.id) }) else null,
|
||||
action = if (!test && row.update != null) stringResource(R.string.common_update) else null,
|
||||
channel = if (row.test != null) ({
|
||||
ChannelToggle(test, enabled = idle && (row.installed == null || row.update != null), other = R.string.comp_channel_test) { nightlyPicked[row.id] = !test }
|
||||
}) else null,
|
||||
) { if (test) protonActions.onInstallTest(row.id) else protonActions.onInstall(row.id) }
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
val available = availableRows(l, catalog, snapshot)
|
||||
@@ -1528,12 +1536,12 @@ private fun GetLine(
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ChannelToggle(nightly: Boolean, enabled: Boolean, onFlip: () -> Unit) {
|
||||
private fun ChannelToggle(nightly: Boolean, enabled: Boolean, other: Int = R.string.comp_channel_nightly, onFlip: () -> Unit) {
|
||||
val colors = MaterialTheme.colorScheme
|
||||
val pal = LocalPalette.current
|
||||
val src = remember { MutableInteractionSource() }
|
||||
val hot = rememberHot(src) && enabled
|
||||
val state = stringResource(if (nightly) R.string.comp_channel_nightly else R.string.comp_channel_stable)
|
||||
val state = stringResource(if (nightly) other else R.string.comp_channel_stable)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(2.dp),
|
||||
modifier = Modifier.heightIn(min = 44.dp).clip(RoundedCornerShape(10.dp))
|
||||
@@ -1544,12 +1552,12 @@ private fun ChannelToggle(nightly: Boolean, enabled: Boolean, onFlip: () -> Unit
|
||||
.semantics { stateDescription = state }
|
||||
.padding(4.dp),
|
||||
) {
|
||||
for ((label, on) in listOf(R.string.comp_channel_stable to !nightly, R.string.comp_channel_nightly to nightly)) {
|
||||
for ((label, on) in listOf(R.string.comp_channel_stable to !nightly, other to nightly)) {
|
||||
Text(
|
||||
stringResource(label), fontSize = 13.sp, fontWeight = FontWeight.SemiBold, maxLines = 1,
|
||||
color = if (!enabled) colors.onSurfaceVariant else if (on) (if (hot) pal.onSignal else pal.signal) else colors.onSurfaceVariant,
|
||||
color = if (on) (if (hot) pal.onSignal else pal.signal) else colors.onSurfaceVariant,
|
||||
modifier = Modifier.clip(RoundedCornerShape(7.dp))
|
||||
.background(if (on && enabled) (if (hot) pal.signal else pal.signal.copy(alpha = 0.16f)) else Color.Transparent)
|
||||
.background(if (on) (if (hot) pal.signal else pal.signal.copy(alpha = 0.16f)) else Color.Transparent)
|
||||
.padding(horizontal = 10.dp, vertical = 6.dp),
|
||||
)
|
||||
}
|
||||
@@ -1634,6 +1642,7 @@ class ProtonsState(
|
||||
|
||||
class ProtonsActions(
|
||||
val onInstall: (String) -> Unit = {},
|
||||
val onInstallTest: (String) -> Unit = {},
|
||||
val onCancel: (String) -> Unit = {},
|
||||
val onRemove: (String, String) -> Unit = { _, _ -> },
|
||||
val onRemoveOlder: (String) -> Unit = {},
|
||||
@@ -1641,8 +1650,10 @@ class ProtonsActions(
|
||||
|
||||
class ProtonRow(
|
||||
val id: String, val name: String, val installed: String?, val queued: Boolean,
|
||||
val installedAll: List<String> = listOfNotNull(installed), val update: String? = null,
|
||||
)
|
||||
val installedAll: List<String> = listOfNotNull(installed), val update: String? = null, val test: String? = null,
|
||||
) {
|
||||
val available: Boolean get() = installed == null || update != null || test != null
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun gpuCardValue(gpu: GpuDriversState, auto: String): String {
|
||||
|
||||
Reference in new issue
Block a user