mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 12:28:40 +00:00
feat: DroidDeck-Proton is downloaded, kept up to date and used by default (#1540)
This commit is contained in:
1 parent
2a69505199
commit
3fdc74051c
12 files changed
+389
-16
No files matched your search
@@ -41,6 +41,7 @@ internal class ProtonMenu(
|
||||
ui.post { protonStage = label; protonPercent = value }
|
||||
}
|
||||
}.getOrElse { it.message ?: it.javaClass.simpleName }
|
||||
if (problem == null && !automatic && tool.id == ProtonExtras.OWN) ProtonExtras.setDeclined(activity, false)
|
||||
ui.post {
|
||||
protonBusyId = null
|
||||
protonStage = null
|
||||
@@ -63,6 +64,7 @@ internal class ProtonMenu(
|
||||
protonPercent = -1
|
||||
Thread({
|
||||
if (older) ProtonExtras.removeOlder(activity, tool) else ProtonExtras.remove(activity, tool, dir)
|
||||
if (tool.id == ProtonExtras.OWN && ProtonExtras.installedAll(activity, tool).isEmpty()) ProtonExtras.setDeclined(activity, true)
|
||||
ui.post {
|
||||
protonBusyId = null
|
||||
protonStage = null
|
||||
@@ -94,9 +96,22 @@ internal class ProtonMenu(
|
||||
ProtonExtras.installInProgress || SessionState.running || LinuxRuntimeInstaller.isBusy() ||
|
||||
SessionState.phase !in setOf(SessionPhase.IDLE, SessionPhase.FAILED) ||
|
||||
!LinuxRuntime.isInstalled(activity) || !AutoComponents.online(activity) || AutoComponents.unfavourable(activity)) return
|
||||
if (ProtonExtras.installedAll(activity, ProtonExtras.tools.first { it.id == ProtonExtras.OWN }).size > 1) {
|
||||
protonBusyId = ProtonExtras.OWN
|
||||
Thread({
|
||||
ProtonExtras.tidy(activity)
|
||||
val tidied = ProtonExtras.installedAll(activity, ProtonExtras.tools.first { it.id == ProtonExtras.OWN }).size <= 1
|
||||
ui.post {
|
||||
protonBusyId = null
|
||||
refreshProtons()
|
||||
if (tidied) ensureAutoUpdates()
|
||||
}
|
||||
}, "proton-tidy").start()
|
||||
return
|
||||
}
|
||||
val attempts = activity.getSharedPreferences("proton-auto-updates", android.content.Context.MODE_PRIVATE)
|
||||
val (tool, update) = ProtonExtras.tools.firstNotNullOfOrNull { tool ->
|
||||
val update = ProtonExtras.update(activity, tool) ?: return@firstNotNullOfOrNull null
|
||||
val update = ProtonExtras.update(activity, tool) ?: ProtonExtras.missing(activity, tool) ?: return@firstNotNullOfOrNull null
|
||||
val previous = attempts.getLong("${tool.id}.at", 0L)
|
||||
if (attempts.getString("${tool.id}.tag", null) != update || now - previous !in 0 until 15L * 60 * 1000) tool to update else null
|
||||
} ?: return
|
||||
|
||||
@@ -780,6 +780,43 @@ object ComponentsManager {
|
||||
true
|
||||
}
|
||||
|
||||
fun carryOver(context: Context, fromDir: String, toDir: String) {
|
||||
synchronized(lock) {
|
||||
val target = protons(context).firstOrNull { it.id == safeName(toDir) } ?: return
|
||||
val state = loadState(context)
|
||||
val wanted = carried(state, safeName(fromDir)) { File(packagesDir(context), it).isFile }
|
||||
val active = state.sub("active").optJSONObject(target.id)
|
||||
val queued = state.sub("queued").sub(target.id)
|
||||
var changed = false
|
||||
wanted.forEach { (comp, entry) ->
|
||||
if (active?.has(comp) != true && !queued.has(comp)) {
|
||||
queued.put(comp, entry)
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
if (queued.length() == 0) state.sub("queued").remove(target.id)
|
||||
if (changed) saveState(context, state)
|
||||
}
|
||||
}
|
||||
|
||||
internal fun carried(state: JSONObject, from: String, present: (String) -> Boolean): Map<String, JSONObject> = buildMap {
|
||||
state.optJSONObject("active")?.optJSONObject(from)?.let { active ->
|
||||
active.keys().forEach { comp ->
|
||||
val entry = active.optJSONObject(comp) ?: return@forEach
|
||||
val file = entry.optString("file")
|
||||
if (comp in COMPONENTS && file.endsWith(".wcp") && present(file)) {
|
||||
put(comp, JSONObject().put("kind", "package").put("file", file).put("label", entry.optString("label")))
|
||||
}
|
||||
}
|
||||
}
|
||||
state.optJSONObject("queued")?.optJSONObject(from)?.let { queued ->
|
||||
queued.keys().forEach { comp ->
|
||||
val entry = queued.optJSONObject(comp) ?: return@forEach
|
||||
if (comp in COMPONENTS && entry.optString("kind") == "package" && present(entry.optString("file"))) put(comp, entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun forgetProton(context: Context, dirName: String) {
|
||||
synchronized(lock) {
|
||||
val id = safeName(dirName)
|
||||
|
||||
@@ -114,12 +114,19 @@ object ProtonDefault {
|
||||
return if (SessionState.running && state.live && (tool == null || state.pending != tool.name)) Outcome.LIVE else Outcome.NEXT_START
|
||||
}
|
||||
|
||||
internal fun movedGames(choices: Map<String, GameChoice?>, from: Set<String>, to: String): Map<String, GameChoice?>? {
|
||||
if (choices.values.none { it != null && !it.valve && it.dir in from }) return null
|
||||
return choices.mapValues { (_, choice) -> if (choice != null && !choice.valve && choice.dir in from) GameChoice(false, to) else choice }
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun requestGame(context: Context, scope: String, proton: ComponentsManager.Proton?): Outcome {
|
||||
require(GameEnvironment.validScope(scope))
|
||||
fun moveGames(context: Context, from: Set<String>, to: String) {
|
||||
val d = dir(context)
|
||||
val choices = parseGames(read(File(d, GAMES))).toMutableMap()
|
||||
choices[scope] = proton?.let { GameChoice(it.valve, it.dir.name) }
|
||||
val moved = movedGames(parseGames(read(File(d, GAMES))), from, to) ?: return
|
||||
writeGames(d, moved)
|
||||
}
|
||||
|
||||
private fun writeGames(d: File, choices: Map<String, GameChoice?>) {
|
||||
val games = JSONObject()
|
||||
choices.forEach { (id, choice) ->
|
||||
games.put(id, choice?.let { JSONObject().put("valve", it.valve).put("dir", it.dir) } ?: JSONObject.NULL)
|
||||
@@ -134,6 +141,15 @@ object ProtonDefault {
|
||||
Log.w(TAG, "could not write the per-game Proton request", e)
|
||||
throw e
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun requestGame(context: Context, scope: String, proton: ComponentsManager.Proton?): Outcome {
|
||||
require(GameEnvironment.validScope(scope))
|
||||
val d = dir(context)
|
||||
val choices = parseGames(read(File(d, GAMES))).toMutableMap()
|
||||
choices[scope] = proton?.let { GameChoice(it.valve, it.dir.name) }
|
||||
writeGames(d, choices)
|
||||
val state = state(context)
|
||||
val tool = proton?.let { selected -> state.tools.firstOrNull { it.valve == selected.valve && it.dir == selected.dir.name } }
|
||||
return if (SessionState.running && state.live && (proton == null || tool != null && state.pending != tool.name)) {
|
||||
|
||||
@@ -16,16 +16,20 @@ 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"
|
||||
const val CHECK_EVERY_MS = 6L * 60 * 60 * 1000
|
||||
const val CHECK_EVERY_MS = 60L * 60 * 1000
|
||||
@Volatile
|
||||
var installInProgress = false
|
||||
private set
|
||||
@Volatile
|
||||
private var replacing = false
|
||||
|
||||
class Tool(val id: String, val name: String, val prefix: String, val repo: String, val assetPattern: Regex)
|
||||
|
||||
internal data class Asset(val tag: String, val name: String, val url: String, val sha512: String?, val size: Long,
|
||||
val sha256: String? = null)
|
||||
|
||||
const val OWN = "droiddeck"
|
||||
|
||||
val tools = listOf(
|
||||
Tool("ge", "GE-Proton", "GE-Proton", "GloriousEggroll/proton-ge-custom", Regex("aarch64\\.tar\\.(gz|xz)$")),
|
||||
Tool("cachyos", "proton-cachyos", "proton-cachyos", "CachyOS/proton-cachyos", Regex("arm64\\.tar\\.(gz|xz)$")),
|
||||
@@ -78,11 +82,23 @@ object ProtonExtras {
|
||||
|
||||
fun update(context: Context, tool: Tool): String? = updateFor(installedTags(context, tool), cachedLatest(context, tool))
|
||||
|
||||
fun missing(context: Context, tool: Tool): String? =
|
||||
if (tool.id == OWN && !declined(context) && installedAll(context, tool).isEmpty()) cachedLatest(context, tool) else null
|
||||
|
||||
private fun choices(context: Context) = context.getSharedPreferences("proton-auto-updates", Context.MODE_PRIVATE)
|
||||
|
||||
fun declined(context: Context): Boolean = choices(context).getBoolean("$OWN.declined", false)
|
||||
|
||||
fun setDeclined(context: Context, declined: Boolean) {
|
||||
choices(context).edit().putBoolean("$OWN.declined", declined).apply()
|
||||
}
|
||||
|
||||
fun cachedLatest(context: Context, tool: Tool): String? =
|
||||
readJson(latestFile(context)).optJSONObject(tool.id)?.optString("tag")?.ifEmpty { null }
|
||||
|
||||
private val checkLock = Any()
|
||||
private const val RETRY_MS = 15L * 60 * 1000
|
||||
private const val USER_SETTINGS = "user_settings.py"
|
||||
private var lastAttempt = 0L
|
||||
|
||||
fun checkLatest(context: Context, force: Boolean = false, now: Long = System.currentTimeMillis()): Boolean {
|
||||
@@ -145,6 +161,44 @@ object ProtonExtras {
|
||||
}
|
||||
}
|
||||
|
||||
private fun replaceOlder(context: Context, tool: Tool) {
|
||||
val all = installedAll(context, tool)
|
||||
val newest = all.lastOrNull() ?: return
|
||||
val older = all.dropLast(1)
|
||||
if (older.isEmpty()) return
|
||||
replacing = true
|
||||
try {
|
||||
for (old in older.asReversed()) {
|
||||
if (SessionState.running) break
|
||||
if (runCatching { ComponentsManager.carryOver(context, old, newest) }.onFailure { Log.w(TAG, "components of $old", it) }.isFailure) continue
|
||||
if (runCatching { keepUserSettings(context, old, newest) }.onFailure { Log.w(TAG, "user settings of $old", it) }.isFailure) continue
|
||||
if (runCatching { ProtonDefault.moveGames(context, setOf(old), newest) }.onFailure { Log.w(TAG, "per-game picks of $old", it) }.isFailure) continue
|
||||
if (File(toolsDir(context), old).deleteRecursively()) ComponentsManager.forgetProton(context, old)
|
||||
else Log.w(TAG, "could not remove $old")
|
||||
}
|
||||
} finally {
|
||||
replacing = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun keepUserSettings(context: Context, old: String, newest: String) {
|
||||
val from = File(File(toolsDir(context), old), USER_SETTINGS)
|
||||
val to = File(File(toolsDir(context), newest), USER_SETTINGS)
|
||||
if (from.isFile && !to.exists()) from.copyTo(to)
|
||||
}
|
||||
|
||||
fun tidy(context: Context) {
|
||||
val tool = tools.firstOrNull { it.id == OWN } ?: return
|
||||
if (installedAll(context, tool).size > 1) replaceOlder(context, tool)
|
||||
}
|
||||
|
||||
fun awaitReplacement(timeoutMs: Long) {
|
||||
val until = System.currentTimeMillis() + timeoutMs
|
||||
while (replacing && System.currentTimeMillis() < until) {
|
||||
try { Thread.sleep(50) } catch (_: InterruptedException) { Thread.currentThread().interrupt(); return }
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
fun install(context: Context, tool: Tool, onProgress: (String, Int) -> Unit): String? {
|
||||
if (installInProgress) return context.getString(R.string.pextra_busy)
|
||||
@@ -246,6 +300,7 @@ object ProtonExtras {
|
||||
archive.delete()
|
||||
unqueue(context, tool)
|
||||
record(context, tool, placed, asset.tag)
|
||||
if (tool.id == OWN) replaceOlder(context, tool)
|
||||
if (EsyncPacks.enabled(context)) {
|
||||
onProgress(context.getString(R.string.esync_fetching), -1)
|
||||
try {
|
||||
|
||||
@@ -372,6 +372,7 @@ class SessionService : Service() {
|
||||
acquireLocks()
|
||||
Thread({
|
||||
OrphanReaper.reap("session starting")
|
||||
ProtonExtras.awaitReplacement(120_000)
|
||||
runSession(gen)
|
||||
}, "session-start").start()
|
||||
return START_NOT_STICKY
|
||||
|
||||
@@ -30,7 +30,7 @@ object SteamLiveShortcuts {
|
||||
let added = 0;
|
||||
for (const w of want) {
|
||||
if (await ${KNOWN}(w.appid, w.name, w.exe)) continue;
|
||||
if (await ${ADD}(w.name, w.exe, w.dir, true)) added++;
|
||||
if (await ${ADD}(w.name, w.exe, w.dir, true, ${JSONObject.quote(compatTool(context))})) added++;
|
||||
}
|
||||
return added;
|
||||
})()
|
||||
@@ -46,7 +46,7 @@ object SteamLiveShortcuts {
|
||||
(async () => {
|
||||
const known = await ${KNOWN}(${appId?.and(0xFFFFFFFFL) ?: 0}, ${JSONObject.quote(name)}, ${JSONObject.quote(exe)});
|
||||
if (known) return known;
|
||||
return await ${ADD}(${JSONObject.quote(name)}, ${JSONObject.quote(exe)}, ${JSONObject.quote(dir)}, $compat);
|
||||
return await ${ADD}(${JSONObject.quote(name)}, ${JSONObject.quote(exe)}, ${JSONObject.quote(dir)}, $compat, ${JSONObject.quote(compatTool(context))});
|
||||
})()
|
||||
""".trimIndent()
|
||||
val id = evaluate(context, js)?.toLongOrNull()?.and(0xFFFFFFFFL)?.takeIf { it != 0L } ?: return null
|
||||
@@ -161,12 +161,15 @@ object SteamLiveShortcuts {
|
||||
return 0;
|
||||
})"""
|
||||
|
||||
private val ADD = """(async (name, exe, dir, compat) => {
|
||||
private fun compatTool(context: Context): String =
|
||||
com.droiddeck.launcher.session.ProtonDefault.state(context).default ?: COMPAT_TOOL
|
||||
|
||||
private val ADD = """(async (name, exe, dir, compat, tool) => {
|
||||
const id = await SteamClient.Apps.AddShortcut(name, exe, dir, "");
|
||||
if (!id) return 0;
|
||||
try { SteamClient.Apps.SetShortcutName(id, name); } catch (e) {}
|
||||
try { SteamClient.Apps.AddUserTagToApps([id], ${JSONObject.quote(TAG_NAME)}); } catch (e) {}
|
||||
if (compat) { try { SteamClient.Apps.SpecifyCompatTool(id, ${JSONObject.quote(COMPAT_TOOL)}); } catch (e) {} }
|
||||
if (compat) { try { SteamClient.Apps.SpecifyCompatTool(id, tool); } catch (e) {} }
|
||||
for (let i = 0; i < 40; i++) {
|
||||
try { if (globalThis.appStore.GetAppOverviewByAppID(id)) break; } catch (e) {}
|
||||
await new Promise(r => setTimeout(r, 250));
|
||||
|
||||
Reference in new issue
Block a user