mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
feat(proton): install experimental Proton builds from a .zip (#2864)
Components > Proton gains an Experimental builds card that installs a Proton build from a .zip, lists it as Experimental-<name> and removes it with its stored and unpacked originals and selections. Replacing a build keeps its user settings and is safe to interrupt. Co-authored-by: maxjivi05 <maxjividen@gmail.com>
This commit is contained in:
1 parent
c35da09d1a
commit
44ade5eeee
43 files changed
+1059
-36
No files matched your search
@@ -275,6 +275,11 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
private val pickAnyDriver = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { r ->
|
||||
if (r.resultCode == RESULT_OK) InAppFilePicker.pickedUri(r.data)?.let { drivers.importDriver(it, linux = null) }
|
||||
}
|
||||
private val pickExperimentalProton = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { r ->
|
||||
if (r.resultCode == RESULT_OK) InAppFilePicker.pickedFile(r.data)?.let { zip ->
|
||||
protons.installExperimental { progress -> com.droiddeck.launcher.session.ExperimentalProtons.installFromFile(this, zip, progress) }
|
||||
}
|
||||
}
|
||||
private val pickLossless = registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { r ->
|
||||
if (r.resultCode == RESULT_OK) InAppFilePicker.pickedFile(r.data)?.let { importLossless(it) }
|
||||
}
|
||||
@@ -2427,7 +2432,7 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
),
|
||||
protons = com.droiddeck.launcher.ui.ProtonsState(
|
||||
rows = protons.protonRows, busyId = protons.protonBusyId, stage = protons.protonStage, percent = protons.protonPercent,
|
||||
runtimeReady = ready && !busy, sessionRunning = SessionState.running,
|
||||
runtimeReady = ready && !busy, sessionRunning = SessionState.running, experimental = protons.experimentalDirs,
|
||||
),
|
||||
protonActions = com.droiddeck.launcher.ui.ProtonsActions(
|
||||
onInstall = { id -> protons.installProton(id) },
|
||||
@@ -2435,6 +2440,11 @@ class FrontEndActivity : ComponentActivity(), com.droiddeck.launcher.ui.AgentPet
|
||||
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) },
|
||||
onExperimentalFile = {
|
||||
pickExperimentalProton.launch(InAppFilePicker.buildIntent(this, ZIP_EXT, getString(R.string.xproton_pick),
|
||||
android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DOWNLOADS).path))
|
||||
},
|
||||
onRemoveExperimental = { dir -> protons.removeExperimental(dir) },
|
||||
),
|
||||
protonOptions = {
|
||||
com.droiddeck.launcher.ui.ProtonOptions(
|
||||
|
||||
@@ -7,6 +7,7 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.setValue
|
||||
import com.droiddeck.launcher.session.ExperimentalProtons
|
||||
import com.droiddeck.launcher.session.ProtonExtras
|
||||
import com.droiddeck.launcher.ui.ProtonRow
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
@@ -27,12 +28,17 @@ internal class ProtonMenu(
|
||||
val stage = mutableStateOf<String?>(null)
|
||||
val percent = mutableIntStateOf(-1)
|
||||
val problem = mutableStateOf<String?>(null)
|
||||
val experimental = mutableStateOf<List<String>>(emptyList())
|
||||
}
|
||||
var protonRows by Operation.rows
|
||||
var protonBusyId by Operation.busyId
|
||||
var protonStage by Operation.stage
|
||||
var protonPercent by Operation.percent
|
||||
var protonProblem by Operation.problem
|
||||
var experimentalDirs by Operation.experimental
|
||||
companion object {
|
||||
const val EXPERIMENTAL = "experimental"
|
||||
}
|
||||
private val checking = java.util.concurrent.atomic.AtomicBoolean(false)
|
||||
@VisibleForTesting internal var installer: (ProtonExtras.Tool, Boolean, (String, Int) -> Unit) -> String? =
|
||||
{ tool, test, progress -> ProtonExtras.install(activity, tool, test, progress) }
|
||||
@@ -86,7 +92,47 @@ internal class ProtonMenu(
|
||||
}, "remove-proton-$id").start()
|
||||
}
|
||||
|
||||
fun installExperimental(work: ((String, Int) -> Unit) -> String?) {
|
||||
if (protonBusyId != null || ProtonExtras.installInProgress || SessionState.running) return
|
||||
protonBusyId = EXPERIMENTAL
|
||||
protonProblem = null
|
||||
protonStage = activity.getString(R.string.store_starting)
|
||||
protonPercent = -1
|
||||
Thread({
|
||||
val problem = runCatching {
|
||||
work { label, value -> ui.post { protonStage = label; protonPercent = value } }
|
||||
}.getOrElse { it.message ?: it.javaClass.simpleName }
|
||||
ui.post {
|
||||
protonProblem = problem
|
||||
protonBusyId = null
|
||||
protonStage = null
|
||||
protonPercent = -1
|
||||
refreshProtons()
|
||||
android.widget.Toast.makeText(activity, problem ?: activity.getString(R.string.xproton_installed), android.widget.Toast.LENGTH_LONG).show()
|
||||
if (problem == null) onInstalled()
|
||||
}
|
||||
}, "install-proton-experimental").start()
|
||||
}
|
||||
|
||||
fun removeExperimental(dir: String) {
|
||||
if (protonBusyId != null || SessionState.running) return
|
||||
protonBusyId = EXPERIMENTAL
|
||||
protonProblem = null
|
||||
protonStage = activity.getString(R.string.main_removing_named, dir)
|
||||
protonPercent = -1
|
||||
Thread({
|
||||
val removed = runCatching { ExperimentalProtons.remove(activity, dir) }.getOrDefault(false)
|
||||
ui.post {
|
||||
protonBusyId = null
|
||||
protonStage = null
|
||||
refreshProtons()
|
||||
if (!removed) android.widget.Toast.makeText(activity, activity.getString(R.string.xproton_remove_failed, dir), android.widget.Toast.LENGTH_LONG).show()
|
||||
}
|
||||
}, "remove-proton-experimental").start()
|
||||
}
|
||||
|
||||
fun refreshProtons() {
|
||||
experimentalDirs = ExperimentalProtons.installed(activity).map { it.dir }
|
||||
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), ProtonExtras.testBuild(activity, it))
|
||||
|
||||
@@ -282,6 +282,8 @@ object ComponentsManager {
|
||||
if (parts.size > 1) parts[1] else parts.firstOrNull()?.ifEmpty { null } ?: "unknown"
|
||||
}.getOrDefault("unknown")
|
||||
|
||||
internal fun isProtonTree(dir: File): Boolean = File(dir, WINE).isDirectory && File(dir, "proton").isFile
|
||||
|
||||
fun protons(context: Context): List<Proton> {
|
||||
val found = LinkedHashMap<String, Proton>()
|
||||
val bases = listOf(File(steam(context), "compatibilitytools.d") to false) +
|
||||
@@ -290,7 +292,7 @@ object ComponentsManager {
|
||||
for ((base, valve) in bases) {
|
||||
val entries = base.listFiles()?.sortedBy { it.name } ?: continue
|
||||
for (dir in entries) {
|
||||
if (!File(dir, WINE).isDirectory || !File(dir, "proton").isFile) continue
|
||||
if (!isProtonTree(dir)) continue
|
||||
val real = runCatching { dir.canonicalPath }.getOrDefault(dir.path)
|
||||
if (found.containsKey(real)) continue
|
||||
val guest = if (dir.absolutePath.startsWith(rootPath)) dir.absolutePath.removePrefix(rootPath) else dir.absolutePath
|
||||
@@ -900,15 +902,26 @@ object ComponentsManager {
|
||||
}
|
||||
}
|
||||
|
||||
fun forgetProton(context: Context, dirName: String) {
|
||||
synchronized(lock) {
|
||||
val id = safeName(dirName)
|
||||
if (protons(context).any { it.id == id }) return
|
||||
val state = loadState(context)
|
||||
val selected = listOf("active", "queued").map { state.sub(it).remove(id) != null }.any { it }
|
||||
if (selected && runCatching { saveState(context, state) }.onFailure { Log.w(TAG, "forget $id", it) }.isFailure) return
|
||||
File(originalsDir(context), id).deleteRecursively()
|
||||
}
|
||||
fun forgetProton(context: Context, dirName: String): Boolean = synchronized(lock) {
|
||||
val id = safeName(dirName)
|
||||
if (protons(context).any { it.id == id }) return true
|
||||
val state = loadState(context)
|
||||
val selected = listOf("active", "queued").map { state.sub(it).remove(id) != null }.any { it }
|
||||
val published = File(launchDir(context), "desired.tsv")
|
||||
val listed = published.takeIf { it.isFile }
|
||||
?.useLines { rows -> rows.any { it.split('\t').getOrNull(1) == dirName } } == true
|
||||
if ((selected || listed) && runCatching { saveState(context, state) }.onFailure { Log.w(TAG, "forget $id", it) }.isFailure) return false
|
||||
val originals = File(originalsDir(context), id)
|
||||
val store = File(launchDir(context), "store")
|
||||
val used = published.takeIf { it.isFile }?.useLines { rows ->
|
||||
rows.mapNotNull { it.substringAfterLast('\t').substringAfter("/store/", "").substringBefore('/').ifEmpty { null } }.toSet()
|
||||
}.orEmpty()
|
||||
val unpacked = originals.listFiles().orEmpty().flatMap { version ->
|
||||
version.listFiles().orEmpty().map { File(store, "original-$id-${version.name}-${it.name.removeSuffix(".wcp")}") }
|
||||
}.filter { it.name !in used }
|
||||
if (unpacked.any { File(it, ".complete").delete(); !it.deleteRecursively() && it.exists() }) return false
|
||||
originals.deleteRecursively()
|
||||
true
|
||||
}
|
||||
|
||||
private fun storePackage(context: Context, part: File, dest: File) {
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
package com.droiddeck.launcher.session
|
||||
|
||||
import android.content.Context
|
||||
import android.os.StatFs
|
||||
import android.util.Log
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.runtime.LinuxRuntime
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
import java.nio.file.Files
|
||||
import java.security.DigestOutputStream
|
||||
import java.security.MessageDigest
|
||||
import java.util.zip.ZipFile
|
||||
import kotlin.io.path.ExperimentalPathApi
|
||||
import kotlin.io.path.deleteRecursively
|
||||
import org.json.JSONObject
|
||||
|
||||
object ExperimentalProtons {
|
||||
private const val TAG = "ExperimentalProtons"
|
||||
const val PREFIX = "Experimental-"
|
||||
private const val MARKER = ".droiddeck-experimental.json"
|
||||
private const val STAGING = ".droiddeck-experimental"
|
||||
private const val BACKUPS = ".droiddeck-experimental-old"
|
||||
private const val INCOMING = ".droiddeck-experimental-new"
|
||||
private const val GUEST_TOOLS = "/root/.local/share/Steam/compatibilitytools.d"
|
||||
private const val NEED_BYTES = 4L * 1024 * 1024 * 1024
|
||||
private const val USER_SETTINGS = "user_settings.py"
|
||||
private val TARBALL = Regex("(?i)\\.tar(\\.(gz|xz|zst|bz2))?$")
|
||||
|
||||
data class Installed(val dir: String, val label: String, val source: String)
|
||||
|
||||
private fun toolsDir(context: Context) = File(LinuxRuntime.rootDir(context), GUEST_TOOLS.removePrefix("/"))
|
||||
|
||||
fun installed(context: Context): List<Installed> =
|
||||
toolsDir(context).listFiles()
|
||||
?.filter { it.isDirectory && File(it, MARKER).isFile }
|
||||
?.map { dir ->
|
||||
val info = runCatching { JSONObject(File(dir, MARKER).readText()) }.getOrDefault(JSONObject())
|
||||
Installed(dir.name, info.optString("label").ifEmpty { dir.name }, info.optString("source"))
|
||||
}
|
||||
?.sortedBy { it.dir }
|
||||
?: emptyList()
|
||||
|
||||
fun remove(context: Context, dir: String): Boolean {
|
||||
val tools = toolsDir(context)
|
||||
val target = File(tools, dir)
|
||||
if (!File(target, MARKER).isFile) return false
|
||||
val gone = deleteTree(target) && deleteTree(File(File(tools, BACKUPS), dir)) && deleteTree(File(File(tools, INCOMING), dir))
|
||||
if (gone) ComponentsManager.forgetProton(context, dir)
|
||||
return gone
|
||||
}
|
||||
|
||||
internal fun dirName(tree: String, label: String?): String {
|
||||
val base = ComponentsManager.safeName(tree)
|
||||
val tag = label?.let(ComponentsManager::safeName)?.takeIf { it != "unnamed" && !base.contains(it, ignoreCase = true) }
|
||||
return PREFIX + base + (tag?.let { "-$it" } ?: "")
|
||||
}
|
||||
|
||||
internal fun compatVdf(name: String): String = """"compatibilitytools"
|
||||
{
|
||||
"compat_tools"
|
||||
{
|
||||
"$name"
|
||||
{
|
||||
"install_path" "."
|
||||
"display_name" "$name"
|
||||
"from_oslist" "windows"
|
||||
"to_oslist" "linux"
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
fun installFromFile(context: Context, zip: File, onProgress: (String, Int) -> Unit): String? {
|
||||
preflight(context)?.let { return it }
|
||||
if (StatFs(LinuxRuntime.rootDir(context).path).availableBytes < NEED_BYTES + zip.length()) {
|
||||
return context.getString(R.string.xproton_no_space)
|
||||
}
|
||||
return install(context, zip, zip.name.substringBeforeLast('.'), zip.name, onProgress)
|
||||
}
|
||||
|
||||
private fun preflight(context: Context): String? = when {
|
||||
SessionState.running -> context.getString(R.string.pextra_stop_session)
|
||||
!LinuxRuntime.isInstalled(context) -> context.getString(R.string.user_apps_runtime_required)
|
||||
else -> null
|
||||
}
|
||||
|
||||
private fun install(context: Context, zip: File, label: String, source: String, onProgress: (String, Int) -> Unit): String? {
|
||||
val tools = toolsDir(context).apply { mkdirs() }
|
||||
val staging = File(tools, STAGING)
|
||||
val forget = { name: String -> ComponentsManager.forgetProton(context, name) }
|
||||
restoreInterrupted(tools, forget)
|
||||
deleteTree(staging)
|
||||
staging.mkdirs()
|
||||
try {
|
||||
LinuxRuntime.writeAccounts(context)
|
||||
SessionFiles.stage(context, LinuxRuntime.rootDir(context))
|
||||
onProgress(context.getString(R.string.xproton_unzipping), -1)
|
||||
val tarball = runCatching { extractTarball(zip, staging) }
|
||||
.getOrElse { return it.message ?: context.getString(R.string.xproton_bad_zip) }
|
||||
?: return context.getString(R.string.xproton_bad_zip)
|
||||
if (SessionState.running) return context.getString(R.string.pextra_session_started)
|
||||
|
||||
onProgress(context.getString(R.string.xproton_unpacking), -1)
|
||||
val unpacked = File(staging, "unpacked").apply { mkdirs() }
|
||||
val status = runGuest(context, listOf("tar", "-xf", "$GUEST_TOOLS/$STAGING/${tarball.name}", "-C", "$GUEST_TOOLS/$STAGING/unpacked"))
|
||||
tarball.delete()
|
||||
if (status != 0) return context.getString(R.string.xproton_untar_failed, status)
|
||||
|
||||
val tree = buildTree(unpacked) ?: return context.getString(R.string.xproton_no_tree)
|
||||
val name = dirName(tree.name, label)
|
||||
ownFile(tree, "compatibilitytool.vdf").writeText(compatVdf(name))
|
||||
ownFile(tree, MARKER).writeText(
|
||||
JSONObject().put("label", name).put("source", source).put("at", System.currentTimeMillis() / 1000).toString(),
|
||||
)
|
||||
val final = File(tools, name)
|
||||
val settings = File(final, USER_SETTINGS)
|
||||
if (Files.isRegularFile(settings.toPath(), java.nio.file.LinkOption.NOFOLLOW_LINKS)) {
|
||||
settings.copyTo(ownFile(tree, USER_SETTINGS))
|
||||
}
|
||||
if (!placeTree(tree, tools, name, forget)) return context.getString(R.string.xproton_place_failed)
|
||||
|
||||
onProgress(context.getString(R.string.pextra_installing, name), -1)
|
||||
runGuest(context, listOf("steam-compatibility", "/root/.local/share/Steam"))
|
||||
return null
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "install $source", e)
|
||||
return e.message ?: context.getString(R.string.xproton_bad_zip)
|
||||
} finally {
|
||||
deleteTree(staging)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun buildTree(unpacked: File): File? {
|
||||
val root = unpacked.canonicalFile
|
||||
return unpacked.listFiles()?.sortedBy { it.name }?.firstOrNull {
|
||||
!Files.isSymbolicLink(it.toPath()) && it.isDirectory && it.canonicalFile.parentFile == root &&
|
||||
Files.isRegularFile(File(it, "toolmanifest.vdf").toPath(), java.nio.file.LinkOption.NOFOLLOW_LINKS) &&
|
||||
ComponentsManager.isProtonTree(it)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalPathApi::class)
|
||||
internal fun deleteTree(dir: File): Boolean =
|
||||
runCatching { dir.toPath().deleteRecursively() }.onFailure { Log.w(TAG, "delete $dir", it) }.isSuccess && !Files.exists(dir.toPath(), java.nio.file.LinkOption.NOFOLLOW_LINKS)
|
||||
|
||||
internal fun ownFile(tree: File, name: String): File {
|
||||
val file = File(tree, name)
|
||||
Files.deleteIfExists(file.toPath())
|
||||
return file
|
||||
}
|
||||
|
||||
internal fun placeTree(tree: File, tools: File, name: String, forget: (String) -> Boolean): Boolean {
|
||||
val incoming = File(File(tools, INCOMING).apply { mkdirs() }, name)
|
||||
if (!deleteTree(incoming) || !tree.renameTo(incoming)) return false
|
||||
return finishPlacing(tools, name, forget)
|
||||
}
|
||||
|
||||
private fun finishPlacing(tools: File, name: String, forget: (String) -> Boolean): Boolean {
|
||||
val incoming = File(File(tools, INCOMING), name)
|
||||
val final = File(tools, name)
|
||||
val backup = File(File(tools, BACKUPS).apply { mkdirs() }, name)
|
||||
val moved = !final.exists() || (deleteTree(backup) && final.renameTo(backup))
|
||||
val placed = moved && (!backup.exists() || forget(name)) && incoming.renameTo(final)
|
||||
if (!placed) {
|
||||
if (!final.exists()) backup.renameTo(final)
|
||||
deleteTree(incoming)
|
||||
}
|
||||
if (final.exists()) deleteTree(backup)
|
||||
return placed
|
||||
}
|
||||
|
||||
internal fun restoreInterrupted(tools: File, forget: (String) -> Boolean) {
|
||||
File(tools, INCOMING).listFiles()?.forEach { finishPlacing(tools, it.name, forget) }
|
||||
File(tools, BACKUPS).listFiles()?.forEach { if (File(tools, it.name).exists()) deleteTree(it) else it.renameTo(File(tools, it.name)) }
|
||||
}
|
||||
|
||||
private fun extractTarball(zip: File, into: File): File? = ZipFile(zip).use { z ->
|
||||
val entries = z.entries().toList().filter { !it.isDirectory }
|
||||
val entry = entries.filter { TARBALL.containsMatchIn(it.name) }.maxByOrNull { it.size } ?: return null
|
||||
val name = File(entry.name).name
|
||||
val sums = checksumEntry(entries.map { it.name }, name)?.let { checksumName -> entries.first { it.name == checksumName } }
|
||||
val expected = sums?.let { e ->
|
||||
z.getInputStream(e).use { checksumIn(it.readBytes().decodeToString()) }
|
||||
?: throw IllegalStateException("${File(e.name).name} holds no SHA-512 checksum")
|
||||
}
|
||||
val out = File(into, name)
|
||||
val digest = MessageDigest.getInstance("SHA-512")
|
||||
z.getInputStream(entry).use { input -> DigestOutputStream(FileOutputStream(out), digest).use { input.copyTo(it, 1 shl 16) } }
|
||||
if (expected != null && !expected.equals(digest.digest().joinToString("") { "%02x".format(it) }, ignoreCase = true)) {
|
||||
out.delete()
|
||||
throw IllegalStateException("Checksum mismatch in $name")
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
internal fun checksumIn(text: String): String? = Regex("(?i)\\b[0-9a-f]{128}\\b").find(text)?.value
|
||||
|
||||
internal fun checksumEntry(entries: List<String>, tarball: String): String? {
|
||||
val stem = tarball.substringBefore(".tar")
|
||||
return entries.firstOrNull {
|
||||
val name = File(it).name
|
||||
!TARBALL.containsMatchIn(name) && (name.startsWith("$tarball.") || name.startsWith("$stem.")) && name.contains("sha512", true)
|
||||
}
|
||||
}
|
||||
|
||||
private fun runGuest(context: Context, command: List<String>): Int {
|
||||
val guest = listOf(
|
||||
"/usr/bin/env", "-i", "HOME=/root", "USER=root", "PATH=/usr/local/bin:/usr/bin:/bin",
|
||||
"LANG=C.UTF-8", "XDG_DATA_HOME=/root/.local/share",
|
||||
) + command
|
||||
val child = ProtonExtras.guestProcess(context, guest).start()
|
||||
child.inputStream.bufferedReader().useLines { lines -> lines.forEach { Log.i(TAG, it) } }
|
||||
return child.waitFor()
|
||||
}
|
||||
}
|
||||
@@ -290,26 +290,12 @@ object ProtonExtras {
|
||||
val root = LinuxRuntime.rootDir(context)
|
||||
LinuxRuntime.writeAccounts(context)
|
||||
com.droiddeck.launcher.session.SessionFiles.stage(context, root)
|
||||
val runtimeDir = File(context.filesDir, ".proton-install-rt").apply { mkdirs() }
|
||||
val guest = listOf(
|
||||
"/usr/bin/env", "-i", "HOME=/root", "USER=root", "PATH=/usr/local/bin:/usr/bin:/bin",
|
||||
"LANG=C.UTF-8", "XDG_DATA_HOME=/root/.local/share",
|
||||
"/usr/local/bin/droiddeck-proton-extra", "/root/.local/share/Steam", archive.absolutePath,
|
||||
)
|
||||
val process = if (com.droiddeck.launcher.runtime.NativeGuest.enabled(context)) {
|
||||
com.droiddeck.launcher.runtime.NativeGuest.processBuilder(context, root,
|
||||
LinuxRuntime.binds(context, null, runtimeDir, null, null), guest).redirectErrorStream(true)
|
||||
} else {
|
||||
ProcessBuilder(LinuxRuntime.command(context, null, runtimeDir, null, guest))
|
||||
.directory(root)
|
||||
.redirectErrorStream(true)
|
||||
.also { builder ->
|
||||
val hostEnv = builder.environment()
|
||||
hostEnv["PROOT_LOADER"] = LinuxRuntime.prootLoader(context).path
|
||||
hostEnv["PROOT_TMP_DIR"] = LinuxRuntime.prootTempDir(context).path
|
||||
LinuxRuntime.prootLibraryPath(context).takeIf { it.isNotEmpty() }?.let { hostEnv["LD_LIBRARY_PATH"] = it }
|
||||
}
|
||||
}
|
||||
val process = guestProcess(context, guest)
|
||||
val child = process.start()
|
||||
var placed: String? = null
|
||||
child.inputStream.bufferedReader().useLines { lines ->
|
||||
@@ -344,6 +330,25 @@ object ProtonExtras {
|
||||
}
|
||||
}
|
||||
|
||||
internal fun guestProcess(context: Context, guest: List<String>): ProcessBuilder {
|
||||
val root = LinuxRuntime.rootDir(context)
|
||||
val runtimeDir = File(context.filesDir, ".proton-install-rt").apply { mkdirs() }
|
||||
return if (com.droiddeck.launcher.runtime.NativeGuest.enabled(context)) {
|
||||
com.droiddeck.launcher.runtime.NativeGuest.processBuilder(context, root,
|
||||
LinuxRuntime.binds(context, null, runtimeDir, null, null), guest).redirectErrorStream(true)
|
||||
} else {
|
||||
ProcessBuilder(LinuxRuntime.command(context, null, runtimeDir, null, guest))
|
||||
.directory(root)
|
||||
.redirectErrorStream(true)
|
||||
.also { builder ->
|
||||
val hostEnv = builder.environment()
|
||||
hostEnv["PROOT_LOADER"] = LinuxRuntime.prootLoader(context).path
|
||||
hostEnv["PROOT_TMP_DIR"] = LinuxRuntime.prootTempDir(context).path
|
||||
LinuxRuntime.prootLibraryPath(context).takeIf { it.isNotEmpty() }?.let { hostEnv["LD_LIBRARY_PATH"] = it }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun releases(tool: Tool): JSONArray? = releases(tool) { page ->
|
||||
Downloader.downloadString(RELEASES.format(Locale.ROOT, tool.repo, page))?.let { body ->
|
||||
try {
|
||||
|
||||
@@ -539,7 +539,8 @@ fun ComponentsPage(
|
||||
val key = "proton:${v.proton.id}"
|
||||
val swaps = v.components.values.count { it.activeFile != null }
|
||||
val extra = protons.rows.firstOrNull { v.proton.dir.name in it.installedAll }
|
||||
val removable = extra != null && protons.busyId == null && protons.runtimeReady && !protons.sessionRunning
|
||||
val experimental = v.proton.dir.name in protons.experimental
|
||||
val removable = (extra != null || experimental) && protons.busyId == null && protons.runtimeReady && !protons.sessionRunning
|
||||
ChoiceLine(
|
||||
v.proton.name,
|
||||
(if (swaps > 0) stringResource(R.string.comp_swapped, v.proton.version, swaps) else stringResource(R.string.comp_all_original, v.proton.version))
|
||||
@@ -548,7 +549,10 @@ fun ComponentsPage(
|
||||
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) {
|
||||
if (experimental) 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) {
|
||||
protonActions.onRemoveExperimental(v.proton.dir.name)
|
||||
}
|
||||
else 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) {
|
||||
protonActions.onRemove(extra.id, v.proton.dir.name)
|
||||
}
|
||||
},
|
||||
@@ -738,6 +742,10 @@ fun ComponentsPage(
|
||||
}
|
||||
}
|
||||
}
|
||||
if (l == PROTON_TAB && DeveloperTools.on) {
|
||||
Spacer(Modifier.height(12.dp))
|
||||
ExperimentalProtonGroup(protons, protonActions)
|
||||
}
|
||||
if (l == PROTON_TAB) {
|
||||
Spacer(Modifier.height(12.dp))
|
||||
Note(stringResource(R.string.comp_about_text))
|
||||
@@ -1631,6 +1639,18 @@ private fun DeviceChip(s: GpuDriversState) {
|
||||
) { face() }
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ExperimentalProtonGroup(protons: ProtonsState, actions: ProtonsActions) {
|
||||
val busy = protons.busyId == com.droiddeck.launcher.ProtonMenu.EXPERIMENTAL
|
||||
val idle = protons.busyId == null && protons.runtimeReady && !protons.sessionRunning
|
||||
RowGroup(stringResource(R.string.xproton_title)) {
|
||||
if (busy) GetLine(stringResource(R.string.xproton_title), "", progress = protons.percent, enabled = false, stage = protons.stage) {}
|
||||
else Row(horizontalArrangement = Arrangement.spacedBy(14.dp), modifier = Modifier.padding(start = 14.dp, top = 4.dp, bottom = 8.dp)) {
|
||||
SmallButton(stringResource(R.string.xproton_pick_zip), enabled = idle, onClick = actions.onExperimentalFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ProtonsState(
|
||||
val rows: List<ProtonRow> = emptyList(),
|
||||
val busyId: String? = null,
|
||||
@@ -1638,6 +1658,7 @@ class ProtonsState(
|
||||
val percent: Int = -1,
|
||||
val runtimeReady: Boolean = true,
|
||||
val sessionRunning: Boolean = false,
|
||||
val experimental: List<String> = emptyList(),
|
||||
)
|
||||
|
||||
class ProtonsActions(
|
||||
@@ -1646,6 +1667,8 @@ class ProtonsActions(
|
||||
val onCancel: (String) -> Unit = {},
|
||||
val onRemove: (String, String) -> Unit = { _, _ -> },
|
||||
val onRemoveOlder: (String) -> Unit = {},
|
||||
val onExperimentalFile: () -> Unit = {},
|
||||
val onRemoveExperimental: (String) -> Unit = {},
|
||||
)
|
||||
|
||||
class ProtonRow(
|
||||
|
||||
Reference in new issue
Block a user