mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-18 20:36:04 +00:00
Desktop: an lxqt session mode, the hosted-package catalog and the Desktop & apps screen
A second thing to launch beside Steam: the LXQt/labwc desktop, a hosted package the app installs into the runtime like the runtime itself, with the emulators and apps as further packages from the same catalog (desktop.json in winlator-contents). A tar package extracts over the rootfs with the runtime's own extractor; an AppImage lands in /opt/appimages with a .desktop entry and runs extracted, since proot has no FUSE. The session script's lxqt mode runs the desktop's labwc in place of gamescope.
This commit is contained in:
1 parent
7f154b933d
commit
2e3196788e
9 files changed
+289
-6
No files matched your search
@@ -17,7 +17,11 @@ import com.steamdeck.launcher.core.FileUtils
|
||||
import com.steamdeck.launcher.gpu.FrameGen
|
||||
import com.steamdeck.launcher.gpu.LsfgNative
|
||||
import com.steamdeck.launcher.runtime.LinuxRuntime
|
||||
import com.steamdeck.launcher.runtime.DesktopCatalog
|
||||
import com.steamdeck.launcher.runtime.LinuxRuntimeInstaller
|
||||
import com.steamdeck.launcher.session.SessionService
|
||||
import com.steamdeck.launcher.ui.DesktopAppsDialog
|
||||
import com.steamdeck.launcher.ui.PackageRow
|
||||
import com.steamdeck.launcher.session.ProtonExtras
|
||||
import com.steamdeck.launcher.ui.ProtonDialog
|
||||
import com.steamdeck.launcher.ui.ProtonRow
|
||||
@@ -49,6 +53,12 @@ class MainActivity : ComponentActivity() {
|
||||
private var showFrameGen by mutableStateOf(false)
|
||||
private var showCredits by mutableStateOf(false)
|
||||
private var showProtons by mutableStateOf(false)
|
||||
private var showApps by mutableStateOf(false)
|
||||
private var catalog by mutableStateOf<List<DesktopCatalog.Entry>?>(emptyList())
|
||||
private var packageRows by mutableStateOf<List<PackageRow>?>(emptyList())
|
||||
private var pkgStage by mutableStateOf<String?>(null)
|
||||
private var pkgPercent by mutableIntStateOf(-1)
|
||||
private var desktopInstalled by mutableStateOf(false)
|
||||
private var protonRows by mutableStateOf<List<ProtonRow>>(emptyList())
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -62,13 +72,25 @@ class MainActivity : ComponentActivity() {
|
||||
availableSize = available?.let { FileUtils.sizeToString(it.size) },
|
||||
busy = busy, stage = stage, percent = percent, failed = failed,
|
||||
frameGenLabel = frameGenLabel,
|
||||
desktopInstalled = desktopInstalled,
|
||||
),
|
||||
onPlay = { startActivity(Intent(this, SessionActivity::class.java)) },
|
||||
onDesktop = {
|
||||
startActivity(Intent(this, SessionActivity::class.java)
|
||||
.putExtra(SessionService.EXTRA_MODE, SessionService.MODE_DESKTOP))
|
||||
},
|
||||
onApps = { openApps() },
|
||||
onRuntime = { onRuntimeButton() },
|
||||
onFrameGen = { showFrameGen = true },
|
||||
onProtons = { refreshProtons(); showProtons = true },
|
||||
onCredits = { showCredits = true },
|
||||
)
|
||||
if (showApps) DesktopAppsDialog(
|
||||
rows = packageRows, busyStage = pkgStage, busyPercent = pkgPercent,
|
||||
onInstall = { id -> installPackage(id) },
|
||||
onRemove = { id -> catalog?.firstOrNull { it.id == id }?.let { DesktopCatalog.remove(this, it) }; refreshPackages() },
|
||||
onDismiss = { showApps = false },
|
||||
)
|
||||
if (showProtons) ProtonDialog(
|
||||
rows = protonRows,
|
||||
onInstall = { id -> ProtonExtras.tools.first { it.id == id }.let { ProtonExtras.queue(this, it) }; refreshProtons() },
|
||||
@@ -111,11 +133,45 @@ class MainActivity : ComponentActivity() {
|
||||
if (!busy) Thread({ checkCatalog() }, "catalog").start()
|
||||
}
|
||||
|
||||
private fun openApps() {
|
||||
showApps = true
|
||||
if (catalog.isNullOrEmpty()) Thread({
|
||||
val fetched = DesktopCatalog.fetch()
|
||||
ui.post { catalog = fetched; refreshPackages() }
|
||||
}, "catalog-desktop").start()
|
||||
else refreshPackages()
|
||||
}
|
||||
|
||||
private fun refreshPackages() {
|
||||
packageRows = catalog?.sortedBy { it.tier }?.map {
|
||||
PackageRow(it.id, it.name, it.tier, it.version, FileUtils.sizeToString(it.size), it.notes,
|
||||
DesktopCatalog.installed(this, it.id))
|
||||
}
|
||||
desktopInstalled = DesktopCatalog.desktopInstalled(this)
|
||||
}
|
||||
|
||||
private fun installPackage(id: String) {
|
||||
val entry = catalog?.firstOrNull { it.id == id } ?: return
|
||||
if (pkgStage != null) return
|
||||
pkgStage = "Starting…"; pkgPercent = -1
|
||||
Thread({
|
||||
val problem = DesktopCatalog.install(this, entry) { stage, percent ->
|
||||
ui.post { pkgStage = stage; pkgPercent = percent }
|
||||
}
|
||||
ui.post {
|
||||
pkgStage = null
|
||||
if (problem != null) android.widget.Toast.makeText(this, "${entry.name}: $problem", android.widget.Toast.LENGTH_LONG).show()
|
||||
refreshPackages()
|
||||
}
|
||||
}, "install-pkg").start()
|
||||
}
|
||||
|
||||
private fun refreshProtons() {
|
||||
protonRows = ProtonExtras.tools.map { ProtonRow(it.id, it.name, ProtonExtras.installed(this, it), ProtonExtras.queued(this, it)) }
|
||||
}
|
||||
|
||||
private fun refresh() {
|
||||
desktopInstalled = DesktopCatalog.desktopInstalled(this)
|
||||
installed = LinuxRuntimeInstaller.installedVersion(this)
|
||||
ready = LinuxRuntime.isInstalled(this)
|
||||
frameGenLabel = FrameGen.label(this)
|
||||
|
||||
@@ -251,7 +251,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback {
|
||||
// start nothing, and leave the loading panel counting up over a dead session.
|
||||
if (!SessionState.running) {
|
||||
CompositorHost.newSession()
|
||||
SessionService.start(this)
|
||||
SessionService.start(this, intent.getStringExtra(SessionService.EXTRA_MODE) ?: SessionService.MODE_STEAM)
|
||||
}
|
||||
applyFrameGen()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package com.steamdeck.launcher.runtime
|
||||
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.steamdeck.launcher.core.Downloader
|
||||
import com.steamdeck.launcher.core.FileUtils
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* The hosted packages that go into the runtime on request — the desktop, the emulators, and the
|
||||
* builds we mirror or make ourselves — described by desktop.json beside the runtime's own catalog.
|
||||
*
|
||||
* Two kinds. A `tar` extracts over the rootfs like the runtime itself (the same extractor, links
|
||||
* and modes preserved). An `appimage` is one file dropped in /opt/appimages with a .desktop entry
|
||||
* written for it; proot has no FUSE, so it runs extracted (APPIMAGE_EXTRACT_AND_RUN).
|
||||
*/
|
||||
object DesktopCatalog {
|
||||
private const val TAG = "DesktopCatalog"
|
||||
const val CATALOG_URL = "https://raw.githubusercontent.com/The412Banner/winlator-contents/main/desktop.json"
|
||||
|
||||
class Entry(
|
||||
val id: String, val name: String, val tier: Int, val version: String, val kind: String,
|
||||
val url: String, val sha256: String, val size: Long, val notes: String,
|
||||
/** For an appimage: the icon name and menu category of its .desktop entry. */
|
||||
val icon: String, val category: String,
|
||||
)
|
||||
|
||||
fun fetch(): List<Entry>? {
|
||||
val body = Downloader.downloadString(CATALOG_URL) ?: return null
|
||||
return try {
|
||||
val json = JSONObject(body)
|
||||
val arr = json.getJSONArray("packages")
|
||||
(0 until arr.length()).map { i ->
|
||||
val o = arr.getJSONObject(i)
|
||||
Entry(
|
||||
o.getString("id"), o.getString("name"), o.optInt("tier", 1), o.optString("version", ""),
|
||||
o.optString("kind", "tar"), o.getString("url"), o.optString("sha256", ""),
|
||||
o.optLong("size", 0L), o.optString("notes", ""),
|
||||
o.optString("icon", "applications-games"), o.optString("category", "Game"),
|
||||
)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "catalog: $e"); null
|
||||
}
|
||||
}
|
||||
|
||||
private fun marker(context: Context, id: String) = File(LinuxRuntime.rootDir(context), ".steamdeck-pkg-$id")
|
||||
|
||||
/** The installed version of a package, or null. */
|
||||
fun installed(context: Context, id: String): String? =
|
||||
FileUtils.readString(marker(context, id))?.trim()?.takeIf { it.isNotEmpty() }
|
||||
|
||||
fun desktopInstalled(context: Context): Boolean =
|
||||
File(LinuxRuntime.rootDir(context), "usr/local/bin/steamdeck-desktop").isFile
|
||||
|
||||
/** Downloads, verifies and installs one package. Returns null on success, else a message. */
|
||||
fun install(context: Context, entry: Entry, listener: LinuxRuntimeInstaller.ProgressListener?): String? {
|
||||
val root = LinuxRuntime.rootDir(context)
|
||||
if (!root.isDirectory) return "The Linux runtime is not installed"
|
||||
val download = File(context.cacheDir, "pkg-${entry.id}.download")
|
||||
try {
|
||||
listener?.onProgress("Downloading ${entry.name}", 0)
|
||||
val ok = Downloader.downloadFile(entry.url, download, true) { f ->
|
||||
listener?.onProgress("Downloading ${entry.name}", if (f < 0) -1 else Math.round(f * 100f))
|
||||
}
|
||||
if (!ok) return "Download failed"
|
||||
if (entry.sha256.isNotEmpty()) {
|
||||
listener?.onProgress("Verifying", -1)
|
||||
val actual = LinuxRuntimeInstaller.sha256(download)
|
||||
if (!entry.sha256.equals(actual, ignoreCase = true)) return "Checksum mismatch — nothing was changed"
|
||||
}
|
||||
listener?.onProgress("Installing ${entry.name}", -1)
|
||||
when (entry.kind) {
|
||||
"appimage" -> {
|
||||
val dir = File(root, "opt/appimages").apply { mkdirs() }
|
||||
val target = File(dir, "${entry.id}.AppImage")
|
||||
if (!download.renameTo(target)) return "Could not place the AppImage"
|
||||
target.setExecutable(true, false)
|
||||
FileUtils.writeString(File(root, "usr/share/applications/steamdeck-${entry.id}.desktop"),
|
||||
"[Desktop Entry]\nType=Application\nName=${entry.name}\n" +
|
||||
"Exec=env APPIMAGE_EXTRACT_AND_RUN=1 /opt/appimages/${entry.id}.AppImage\n" +
|
||||
"Icon=${entry.icon}\nTerminal=false\nCategories=${entry.category};\n")
|
||||
}
|
||||
else -> if (!LinuxRuntimeInstaller.extract(download, root, listener)) return "Extraction failed"
|
||||
}
|
||||
FileUtils.writeString(marker(context, entry.id), entry.version)
|
||||
return null
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "install ${entry.id}", e)
|
||||
return e.message ?: "Install failed"
|
||||
} finally {
|
||||
download.delete()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an appimage package outright. A tar package is spread through the rootfs and is
|
||||
* not tracked file by file; only its marker is dropped, which offers it again.
|
||||
*/
|
||||
fun remove(context: Context, entry: Entry) {
|
||||
val root = LinuxRuntime.rootDir(context)
|
||||
if (entry.kind == "appimage") {
|
||||
File(root, "opt/appimages/${entry.id}.AppImage").delete()
|
||||
File(root, "usr/share/applications/steamdeck-${entry.id}.desktop").delete()
|
||||
}
|
||||
marker(context, entry.id).delete()
|
||||
}
|
||||
}
|
||||
@@ -187,7 +187,7 @@ public final class LinuxRuntimeInstaller {
|
||||
* empty file instead of its link target is a rootfs that boots to nothing. Symlinks, hard
|
||||
* links and the executable bit are all carried over here.
|
||||
*/
|
||||
private static boolean extract(File archive, File destination, ProgressListener listener) {
|
||||
public static boolean extract(File archive, File destination, ProgressListener listener) {
|
||||
long entries = 0;
|
||||
try (InputStream in = new ZstdCompressorInputStream(
|
||||
new BufferedInputStream(new FileInputStream(archive), 1 << 16));
|
||||
@@ -245,7 +245,7 @@ public final class LinuxRuntimeInstaller {
|
||||
}
|
||||
}
|
||||
|
||||
private static String sha256(File file) throws Exception {
|
||||
public static String sha256(File file) throws Exception {
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
try (InputStream in = new BufferedInputStream(new FileInputStream(file), 1 << 16)) {
|
||||
byte[] buffer = new byte[1 << 16];
|
||||
|
||||
@@ -56,6 +56,7 @@ class SessionService : Service() {
|
||||
}
|
||||
startForeground(NOTIFICATION_ID, buildNotification())
|
||||
if (SessionState.running) return START_NOT_STICKY
|
||||
SessionState.mode = intent?.getStringExtra(EXTRA_MODE) ?: MODE_STEAM
|
||||
SessionState.running = true
|
||||
SessionState.firstFrameSeen = false
|
||||
acquireLocks()
|
||||
@@ -139,7 +140,7 @@ class SessionService : Service() {
|
||||
SessionState.fakeInputDir = fakeInputDir
|
||||
}
|
||||
guest.add(LinuxRuntime.SESSION_SCRIPT)
|
||||
guest.add(LinuxRuntime.MODE_STEAM)
|
||||
guest.add(SessionState.mode)
|
||||
|
||||
// Android has no /dev/shm; the cache stands in for it and, unlike the real thing, keeps
|
||||
// whatever a session leaves behind. The client abandons tens of megabytes of streams a run.
|
||||
@@ -402,8 +403,12 @@ class SessionService : Service() {
|
||||
private const val NO_PAD_SWITCH = "Download/steamdeck-no-pad"
|
||||
private const val PAD_LOG_SWITCH = "Download/steamdeck-pad-log"
|
||||
|
||||
fun start(context: Context) {
|
||||
val intent = Intent(context, SessionService::class.java)
|
||||
const val EXTRA_MODE = "mode"
|
||||
const val MODE_STEAM = "steam"
|
||||
const val MODE_DESKTOP = "lxqt"
|
||||
|
||||
fun start(context: Context, mode: String = MODE_STEAM) {
|
||||
val intent = Intent(context, SessionService::class.java).putExtra(EXTRA_MODE, mode)
|
||||
if (Build.VERSION.SDK_INT >= 26) context.startForegroundService(intent)
|
||||
else context.startService(intent)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,10 @@ object SessionState {
|
||||
@Volatile
|
||||
var running = false
|
||||
|
||||
/** Which session this is: SessionService.MODE_STEAM or MODE_DESKTOP. */
|
||||
@Volatile
|
||||
var mode = "steam"
|
||||
|
||||
/** The size gamescope was told to render at; set by the activity before the service starts. */
|
||||
@Volatile
|
||||
var outputSize: Pair<Int, Int> = Pair(1920, 1080)
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.steamdeck.launcher.ui
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.LinearProgressIndicator
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
/** One hosted package as the dialog shows it. */
|
||||
class PackageRow(
|
||||
val id: String, val name: String, val tier: Int, val version: String, val size: String,
|
||||
val notes: String, val installed: String?,
|
||||
)
|
||||
|
||||
/**
|
||||
* The desktop and everything that goes on it, installed into the runtime on request. Tier 1 is
|
||||
* packaged natively for this hardware; tier 2 is an upstream ARM64 build we mirror and expect
|
||||
* little of on a phone; tier 3 is built by us from source.
|
||||
*/
|
||||
@Composable
|
||||
fun DesktopAppsDialog(
|
||||
rows: List<PackageRow>?,
|
||||
busyStage: String?,
|
||||
busyPercent: Int,
|
||||
onInstall: (String) -> Unit,
|
||||
onRemove: (String) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
AlertDialog(
|
||||
onDismissRequest = { if (busyStage == null) onDismiss() },
|
||||
title = { Text("Desktop & apps") },
|
||||
text = {
|
||||
Column(modifier = Modifier.heightIn(max = 420.dp).verticalScroll(rememberScrollState())) {
|
||||
if (busyStage != null) {
|
||||
Text(if (busyPercent >= 0) "$busyStage $busyPercent%" else busyStage, style = MaterialTheme.typography.bodySmall)
|
||||
if (busyPercent >= 0) LinearProgressIndicator(progress = { busyPercent / 100f }, modifier = Modifier.fillMaxWidth().padding(vertical = 6.dp))
|
||||
else LinearProgressIndicator(modifier = Modifier.fillMaxWidth().padding(vertical = 6.dp))
|
||||
Spacer(Modifier.height(8.dp))
|
||||
}
|
||||
when {
|
||||
rows == null -> Text("Could not reach the package catalog", color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
rows.isEmpty() -> Text("Loading the catalog…", color = MaterialTheme.colorScheme.onSurfaceVariant)
|
||||
}
|
||||
var lastTier = 0
|
||||
for (row in rows ?: emptyList()) {
|
||||
if (row.tier != lastTier) {
|
||||
lastTier = row.tier
|
||||
Text(
|
||||
when (row.tier) {
|
||||
1 -> "Native for this hardware"
|
||||
2 -> "Upstream ARM64 builds — experimental on a phone"
|
||||
else -> "Built from source — experimental"
|
||||
},
|
||||
style = MaterialTheme.typography.labelSmall,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(top = 8.dp, bottom = 2.dp),
|
||||
)
|
||||
}
|
||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth().padding(vertical = 3.dp)) {
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(row.name, style = MaterialTheme.typography.bodyMedium)
|
||||
Text(
|
||||
(if (row.installed != null) "installed ${row.installed}" else "${row.version} · ${row.size}") +
|
||||
(if (row.notes.isNotEmpty()) " — ${row.notes}" else ""),
|
||||
style = MaterialTheme.typography.bodySmall,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
if (row.installed != null) TextButton(enabled = busyStage == null, onClick = { onRemove(row.id) }) { Text("Remove") }
|
||||
else TextButton(enabled = busyStage == null, onClick = { onInstall(row.id) }) { Text("Install") }
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = { TextButton(enabled = busyStage == null, onClick = onDismiss) { Text("Close") } },
|
||||
)
|
||||
}
|
||||
@@ -42,6 +42,7 @@ class MainUiState(
|
||||
val percent: Int,
|
||||
val failed: Boolean,
|
||||
val frameGenLabel: String,
|
||||
val desktopInstalled: Boolean,
|
||||
)
|
||||
|
||||
/**
|
||||
@@ -57,6 +58,8 @@ class MainUiState(
|
||||
fun MainScreen(
|
||||
state: MainUiState,
|
||||
onPlay: () -> Unit,
|
||||
onDesktop: () -> Unit,
|
||||
onApps: () -> Unit,
|
||||
onRuntime: () -> Unit,
|
||||
onFrameGen: () -> Unit,
|
||||
onProtons: () -> Unit,
|
||||
@@ -129,6 +132,10 @@ fun MainScreen(
|
||||
onClick = onPlay, enabled = state.ready && !state.busy,
|
||||
modifier = Modifier.fillMaxWidth().height(buttonHeight),
|
||||
) { Text("Play", fontSize = 14.sp * k) }
|
||||
OutlinedButton(
|
||||
onClick = onDesktop, enabled = state.ready && !state.busy && state.desktopInstalled,
|
||||
modifier = Modifier.fillMaxWidth().padding(top = 5.dp * k).height(buttonHeight + 5.dp * k),
|
||||
) { Text(if (state.desktopInstalled) "Desktop" else "Desktop — install it under Desktop & apps", fontSize = 13.sp * k) }
|
||||
val runtimeLabel = when {
|
||||
state.busy -> "Working…"
|
||||
!state.ready -> "Install Linux runtime"
|
||||
@@ -143,6 +150,10 @@ fun MainScreen(
|
||||
onClick = onFrameGen,
|
||||
modifier = Modifier.fillMaxWidth().padding(top = 5.dp * k).height(buttonHeight + 5.dp * k),
|
||||
) { Text("Frame generation: ${state.frameGenLabel}", fontSize = 13.sp * k) }
|
||||
OutlinedButton(
|
||||
onClick = onApps, enabled = state.ready && !state.busy,
|
||||
modifier = Modifier.fillMaxWidth().padding(top = 5.dp * k).height(buttonHeight + 5.dp * k),
|
||||
) { Text("Desktop & apps", fontSize = 13.sp * k) }
|
||||
OutlinedButton(
|
||||
onClick = onProtons,
|
||||
modifier = Modifier.fillMaxWidth().padding(top = 5.dp * k).height(buttonHeight + 5.dp * k),
|
||||
|
||||
Reference in new issue
Block a user