From 2e3196788e4f12e0c7c62b17ce43c24450a0b254 Mon Sep 17 00:00:00 2001 From: The412Banner Date: Sun, 20 Sep 2026 03:16:09 -0400 Subject: [PATCH] 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. --- .../com/steamdeck/launcher/MainActivity.kt | 56 +++++++++ .../com/steamdeck/launcher/SessionActivity.kt | 2 +- .../launcher/runtime/DesktopCatalog.kt | 109 ++++++++++++++++++ .../runtime/LinuxRuntimeInstaller.java | 4 +- .../launcher/session/SessionService.kt | 11 +- .../launcher/session/SessionState.kt | 4 + .../launcher/ui/DesktopAppsDialog.kt | 90 +++++++++++++++ .../com/steamdeck/launcher/ui/MainScreen.kt | 11 ++ .../overlay/usr/local/bin/bannerlator-session | 8 ++ 9 files changed, 289 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/com/steamdeck/launcher/runtime/DesktopCatalog.kt create mode 100644 app/src/main/java/com/steamdeck/launcher/ui/DesktopAppsDialog.kt diff --git a/app/src/main/java/com/steamdeck/launcher/MainActivity.kt b/app/src/main/java/com/steamdeck/launcher/MainActivity.kt index 77e4f56110..2283dcc096 100644 --- a/app/src/main/java/com/steamdeck/launcher/MainActivity.kt +++ b/app/src/main/java/com/steamdeck/launcher/MainActivity.kt @@ -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?>(emptyList()) + private var packageRows by mutableStateOf?>(emptyList()) + private var pkgStage by mutableStateOf(null) + private var pkgPercent by mutableIntStateOf(-1) + private var desktopInstalled by mutableStateOf(false) private var protonRows by mutableStateOf>(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) diff --git a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt index cb993e18ff..8ed35ef994 100644 --- a/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt +++ b/app/src/main/java/com/steamdeck/launcher/SessionActivity.kt @@ -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() } diff --git a/app/src/main/java/com/steamdeck/launcher/runtime/DesktopCatalog.kt b/app/src/main/java/com/steamdeck/launcher/runtime/DesktopCatalog.kt new file mode 100644 index 0000000000..351f5b4115 --- /dev/null +++ b/app/src/main/java/com/steamdeck/launcher/runtime/DesktopCatalog.kt @@ -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? { + 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() + } +} diff --git a/app/src/main/java/com/steamdeck/launcher/runtime/LinuxRuntimeInstaller.java b/app/src/main/java/com/steamdeck/launcher/runtime/LinuxRuntimeInstaller.java index e72f9e32cb..9ab20d170b 100644 --- a/app/src/main/java/com/steamdeck/launcher/runtime/LinuxRuntimeInstaller.java +++ b/app/src/main/java/com/steamdeck/launcher/runtime/LinuxRuntimeInstaller.java @@ -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]; diff --git a/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt b/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt index ca2f2676be..2eef3fb2bc 100644 --- a/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt +++ b/app/src/main/java/com/steamdeck/launcher/session/SessionService.kt @@ -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) } diff --git a/app/src/main/java/com/steamdeck/launcher/session/SessionState.kt b/app/src/main/java/com/steamdeck/launcher/session/SessionState.kt index b838ccbcf4..1ca21c5d02 100644 --- a/app/src/main/java/com/steamdeck/launcher/session/SessionState.kt +++ b/app/src/main/java/com/steamdeck/launcher/session/SessionState.kt @@ -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 = Pair(1920, 1080) diff --git a/app/src/main/java/com/steamdeck/launcher/ui/DesktopAppsDialog.kt b/app/src/main/java/com/steamdeck/launcher/ui/DesktopAppsDialog.kt new file mode 100644 index 0000000000..891e0d4861 --- /dev/null +++ b/app/src/main/java/com/steamdeck/launcher/ui/DesktopAppsDialog.kt @@ -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?, + 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") } }, + ) +} diff --git a/app/src/main/java/com/steamdeck/launcher/ui/MainScreen.kt b/app/src/main/java/com/steamdeck/launcher/ui/MainScreen.kt index d20597ea47..6e1e2f5269 100644 --- a/app/src/main/java/com/steamdeck/launcher/ui/MainScreen.kt +++ b/app/src/main/java/com/steamdeck/launcher/ui/MainScreen.kt @@ -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), diff --git a/tools/linuxfs/overlay/usr/local/bin/bannerlator-session b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session index 78b75704f2..9dbd0292c7 100755 --- a/tools/linuxfs/overlay/usr/local/bin/bannerlator-session +++ b/tools/linuxfs/overlay/usr/local/bin/bannerlator-session @@ -4,6 +4,7 @@ # bannerlator-session desktop the file manager # bannerlator-session run a Linux program (AppImage, script or ELF) # bannerlator-session steam [steam-url] the native Steam client +# bannerlator-session lxqt the LXQt/labwc desktop (SteamDeck's desktop package) # BL_WIDTH / BL_HEIGHT size the output, BL_FPS limits it, BL_LOG collects everything said here. set -u export HOME=${HOME:-/root} @@ -48,6 +49,13 @@ if [ -z "${BL_INSIDE:-}" ]; then wayland-info >/dev/null 2>&1 && break sleep 0.1 done + # The desktop (SteamDeck's hosted package) is its own nested compositor, labwc, drawing straight + # into the app's: no gamescope in between. + if [ "$mode" = lxqt ]; then + step "starting the desktop" + [ -x /usr/local/bin/steamdeck-desktop ] || { echo "== the desktop package is not installed"; exit 66; } + exec /usr/local/bin/steamdeck-desktop + fi width=${BL_WIDTH:-1280} height=${BL_HEIGHT:-720} args=(--backend wayland --expose-wayland -f -W "$width" -H "$height" -w "$width" -h "$height")