feat(bottom): bottom screen research, Quick Access, game art, guides and mirror panels (#3290)

* docs: bottom screen research and proposals

* docs: expand bottom screen region mirror, guides and companion API

* feat(bottom): idle home card, per-game panel memory, Steam achievements tab and screen off

* feat(bottom): quick tiles page on the dashboard

* feat(bottom): Steam guides tab with per-game reading position

* feat(bottom): companion page with Stardew, Skyrim and Fallout 4 adapters

* docs: bottom screen implementation status

* feat(bottom): mirror a region of the game picture on the bottom screen

* fix(bottom): follow Steam's selection for any game, composite while mirroring

* docs: bottom screen hardware results and screenshots

* feat(bottom): guides wiki, fixes, maps and saved pages; hide mirrored region on top

* feat(bottom): guides, mirror and companion as their own panels in the app's settings style

* feat(bottom): Steam's Quick Access menu as a bottom screen panel

* fix(bottom): park Steam's Quick Access through its own bounds and keep it open on a lease

* feat(bottom): align Quick Access left, centre or right; keep its tab and Decky working

* fix(bottom): quieter Quick Access move handles, instant reopen, Decky tab after a cold start

* fix(bottom): lay Quick Access out at the panel's shape so every tab keeps one size

* feat(bottom): Quick Access tabs fill the bottom screen

* fix(bottom): the Quick Access button still opens the menu on the top screen

* feat(bottom): choose Quick Access layout from the bar: full width, left, center or right

* feat(bottom): brightness slider for the bottom screen with screen off at its end

* feat(bottom): game art panel, hideable bar with a pull tab, direct guide links, centred guide tabs

* fix(bottom): mirror fills the panel, options open from the bar

* docs: drop the removed dashboard row screenshot

* refactor(bottom): split the companion panel into its own change

* fix(bottom): Steam dialogs take input over the parked Quick Access menu; review fixes

* fix(bottom): extract the Quick Access relay at session start; second review round

* fix(bottom): game art refreshes details for the same game

* fix(bottom): Quick Access retries back off; art never shows another game for the running one

* fix(bottom): Quick Access keeps its lease through retry backoff

* fix(bottom): renew the Quick Access lease apart from discovery

* fix(bottom): a Quick Access panel releases only its own lease

* fix(bottom): an older Quick Access panel cannot take back a newer panel's lease

* test(bottom): an expired Quick Access lease can be taken by any panel

* fix(bottom): only the Quick Access lease owner sets the menu's shape
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-27 05:15:57 -05:00
1 parent c0506d53c9
commit 8e25301a77
101 files changed
+6595 -40

No files matched your search

@@ -99,6 +99,18 @@ class SecondScreenModeTest {
assertEquals(SecondScreenMode.MENU, SecondScreenMode.opening("dashboard", deckPad = false))
}
@Test fun steamQuickAccessOpensAgainOnlyInASteamSession() {
assertEquals(SecondScreenMode.STEAM_QAM, SecondScreenMode.opening("steam-qam", deckPad = true, dashboard = true, steam = true))
assertEquals(SecondScreenMode.MENU, SecondScreenMode.opening("steam-qam", deckPad = true, dashboard = true))
assertEquals(SecondScreenMode.MENU, SecondScreenMode.opening("steam-qam", deckPad = true, steam = true))
}
@Test fun gameArtOpensAgainOnlyInASteamSession() {
assertEquals(SecondScreenMode.ART, SecondScreenMode.opening("art", deckPad = true, dashboard = true, steam = true))
assertEquals(SecondScreenMode.MENU, SecondScreenMode.opening("art", deckPad = true, dashboard = true))
assertTrue(SecondScreenMode.ART.sessionPanel)
}
@Test fun theDesktopOpensAgainOnlyWhileItCanRun() {
assertEquals(SecondScreenMode.DESKTOP, SecondScreenMode.opening("desktop", deckPad = true, dashboard = true, bottomDesktop = true))
assertEquals(SecondScreenMode.MENU, SecondScreenMode.opening("desktop", deckPad = true, dashboard = true))
@@ -0,0 +1,129 @@
package com.droiddeck.launcher.session
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class GameLinksTest {
private fun row(vararg pairs: Pair<String, String>) =
pairs.joinToString(",", "{", "}") { (k, v) -> "\"$k\":{\"type\":\"literal\",\"value\":\"$v\"}" }
@Test
fun mapsWikidataIdsToSiteUrls() {
val json = """{"results":{"bindings":[
${row("fandom" to "it.eldenring", "pcgw" to "Elden_Ring", "gamefaqs" to "265984", "ign" to "elden-ring", "hltb" to "68151", "sw" to "Elden Ring")},
${row("fandom" to "eldenring", "pcgw" to "Elden_Ring", "gamefaqs" to "323053")}
]}}"""
val links = GameLinks.parse(json).associate { it.kind to it.url }
assertEquals("https://eldenring.fandom.com/", links[GameLinks.Kind.WIKI])
assertEquals("https://strategywiki.org/wiki/Elden_Ring", links[GameLinks.Kind.STRATEGYWIKI])
assertEquals("https://www.pcgamingwiki.com/wiki/Elden_Ring", links[GameLinks.Kind.PCGAMINGWIKI])
assertEquals("https://gamefaqs.gamespot.com/-/265984-", links[GameLinks.Kind.GAMEFAQS])
assertEquals("https://www.ign.com/games/elden-ring", links[GameLinks.Kind.IGN])
assertEquals("https://howlongtobeat.com/game/68151", links[GameLinks.Kind.HOWLONGTOBEAT])
}
@Test
fun aLanguageOnlyFandomWikiKeepsItsLanguage() {
val links = GameLinks.parse("""{"results":{"bindings":[${row("fandom" to "de.hollowknight")}]}}""")
assertEquals("https://hollowknight.fandom.com/de/", links.single().url)
}
@Test
fun noMatchIsNoLinks() {
assertTrue(GameLinks.parse("""{"results":{"bindings":[]}}""").isEmpty())
}
@Test
fun protonDbTiers() {
assertEquals("gold", GameLinks.parseTier("""{"bestReportedTier":"platinum","tier":"gold","total":2109}"""))
assertNull(GameLinks.parseTier("""{"tier":"pending"}"""))
}
@Test
fun searchesStayOnTheSitesAndSkipGameFaqsWhenItHasAPage() {
val youtube = GameLinks.searches("Arcade Paradise", emptyList()).first { it.id == "youtube" }.url
assertEquals("https://m.youtube.com/results?search_query=Arcade+Paradise+walkthrough", youtube)
assertTrue(GameLinks.searches("Bully", emptyList()).none { "duckduckgo" in it.url })
val faqs = GameLinks.Link(GameLinks.Kind.GAMEFAQS, "https://gamefaqs.gamespot.com/-/1-")
assertEquals(listOf("youtube"), GameLinks.searches("Bully", listOf(faqs)).map { it.id })
}
@Test
fun slugsTryTheFullNameThenTheShortOne() {
assertEquals(listOf("bully-scholarship-edition", "bully"), GameLinks.slugs("Bully: Scholarship Edition"))
assertEquals(listOf("sonic-mania"), GameLinks.slugs("Sonic Mania"))
assertEquals(listOf("tom-clancys-the-division-2"), GameLinks.slugs("Tom Clancy’s The Division 2"))
assertEquals(listOf("hotline-miami"), GameLinks.slugs("Hotline Miami™"))
}
@Test
fun directPagesComeFromTheSitesOwnRoutes() {
val live = setOf("https://mapgenie.io/bully", "https://www.ign.com/wikis/bully", "https://bully.fandom.com/api.php?action=query&meta=siteinfo&format=json")
val found = GameLinks.direct("Bully: Scholarship Edition",
listOf(GameLinks.Link(GameLinks.Kind.IGN, "https://www.ign.com/games/bully-scholarship-edition")),
exists = { it in live }, strategyWiki = { if (it == "Bully") "https://strategywiki.org/wiki/Bully" else null })
assertEquals(mapOf(
GameLinks.Kind.MAPGENIE to "https://mapgenie.io/bully",
GameLinks.Kind.IGN to "https://www.ign.com/wikis/bully",
GameLinks.Kind.WIKI to "https://bully.fandom.com/",
GameLinks.Kind.STRATEGYWIKI to "https://strategywiki.org/wiki/Bully",
), found.associate { it.kind to it.url })
assertTrue(found.none { "duckduckgo" in it.url })
}
@Test
fun aMissingSiteLeavesWikidataLinksAlone() {
val ign = GameLinks.Link(GameLinks.Kind.IGN, "https://www.ign.com/games/x")
assertEquals(listOf(ign), GameLinks.direct("X", listOf(ign), exists = { false }, strategyWiki = { null }))
}
@Test
fun openSearchPicksTheExactTitle() {
val json = """["Bully",["Bully's Sporting Darts","Bully"],["",""],["https://strategywiki.org/wiki/Bully%27s_Sporting_Darts","https://strategywiki.org/wiki/Bully"]]"""
assertEquals("https://strategywiki.org/wiki/Bully", GameLinks.parseOpenSearch(json, "Bully"))
assertNull(GameLinks.parseOpenSearch(json, "Canis Canem Edit"))
}
@Test
fun cachedDiscoveriesYieldToNewWikidataLinks() {
val fandom = GameLinks.Link(GameLinks.Kind.WIKI, "https://bully.fandom.com/")
val map = GameLinks.Link(GameLinks.Kind.MAPGENIE, "https://mapgenie.io/bully")
val wiki = GameLinks.Link(GameLinks.Kind.WIKI, "https://bully.wiki.gg/")
assertEquals(listOf(wiki, map), GameLinks.merge(listOf(wiki), listOf(fandom, map)))
assertEquals(listOf(fandom, map), GameLinks.merge(emptyList(), listOf(fandom, map)))
}
@Test
fun cachedLinksRoundTrip() {
val links = listOf(GameLinks.Link(GameLinks.Kind.MAPGENIE, "https://mapgenie.io/bully"))
assertEquals(links, GameLinks.readLinks(GameLinks.writeLinks(links)))
}
@Test
fun steamGuideTagFilter() {
assertEquals("https://steamcommunity.com/app/620/guides/?browsefilter=toprated&browsesort=toprated&requiredtags%5B%5D=Maps+or+Levels",
SteamGuides.listUrl(620, "Maps or Levels"))
assertEquals("https://steamcommunity.com/app/620/guides/?browsefilter=toprated&browsesort=toprated", SteamGuides.listUrl(620, null))
}
@Test
fun guideLanguageFollowsTheDevice() {
assertEquals("english", SteamGuides.language(java.util.Locale.US))
assertEquals("german", SteamGuides.language(java.util.Locale.GERMANY))
assertEquals("schinese", SteamGuides.language(java.util.Locale.SIMPLIFIED_CHINESE))
assertEquals("tchinese", SteamGuides.language(java.util.Locale.TRADITIONAL_CHINESE))
assertEquals("brazilian", SteamGuides.language(java.util.Locale("pt", "BR")))
assertEquals("latam", SteamGuides.language(java.util.Locale("es", "MX")))
assertEquals("spanish", SteamGuides.language(java.util.Locale("es", "ES")))
assertEquals("english", SteamGuides.language(java.util.Locale("eo")))
assertEquals("https://steamcommunity.com/app/620/guides/?browsefilter=toprated&browsesort=toprated&requiredtags%5B%5D=Secrets&requiredtags%5B%5D=english",
SteamGuides.listUrl(620, "Secrets", "english"))
}
}
@@ -0,0 +1,87 @@
package com.droiddeck.launcher.session
import org.junit.Assert.assertEquals
import org.junit.Assert.assertThrows
import org.junit.Test
import java.io.DataInputStream
import java.io.IOException
import java.net.ServerSocket
import kotlin.concurrent.thread
class LoopbackWebSocketTest {
@Test
fun talksToALoopbackWebSocketServer() {
val server = ServerSocket(0).apply { soTimeout = 5_000 }
var received: String? = null
val worker = thread {
server.accept().use { client ->
client.soTimeout = 5_000
val input = DataInputStream(client.getInputStream())
val out = client.getOutputStream()
out.write(upgrade(handshakeKey(input)).toByteArray())
for (text in listOf("""{"id":1}""", "x".repeat(300))) {
val bytes = text.toByteArray()
out.write(0x81)
if (bytes.size < 126) out.write(bytes.size) else { out.write(126); out.write(bytes.size shr 8); out.write(bytes.size and 0xFF) }
out.write(bytes)
}
out.flush()
val b0 = input.read()
val len = input.read() and 0x7F
val mask = ByteArray(4).also(input::readFully)
val payload = ByteArray(len).also(input::readFully)
for (i in payload.indices) payload[i] = (payload[i].toInt() xor mask[i % 4].toInt()).toByte()
if (b0 == 0x81) received = String(payload)
}
}
try {
LoopbackWebSocket(server.localPort, readTimeoutMs = 5_000).use { ws ->
assertEquals("""{"id":1}""", ws.receive())
assertEquals(300, ws.receive()!!.length)
ws.send("""{"id":2}""")
}
worker.join(5_000)
} finally {
server.close()
}
assertEquals("""{"id":2}""", received)
}
@Test
fun rejectsAnUpgradeWithoutTheRightAcceptHeader() {
for (reply in listOf(
"HTTP/1.1 101 Switching Protocols\r\n\r\n",
"HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: wrong\r\n\r\n",
"HTTP/1.1 1010 Nope\r\n\r\n",
)) {
val server = ServerSocket(0)
val worker = thread {
server.accept().use { client ->
handshakeKey(DataInputStream(client.getInputStream()))
client.getOutputStream().apply { write(reply.toByteArray()); flush() }
Thread.sleep(200)
}
}
assertThrows(IOException::class.java) { LoopbackWebSocket(server.localPort).close() }
worker.join(5_000)
server.close()
}
}
private fun upgrade(key: String) = "HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n" +
"Sec-WebSocket-Accept: ${LoopbackWebSocket.accept(key)}\r\n\r\n"
private fun handshakeKey(input: DataInputStream): String =
generateSequence { readLine(input) }.takeWhile { it.isNotEmpty() }.toList()
.first { it.startsWith("Sec-WebSocket-Key:") }.substringAfter(':').trim()
private fun readLine(input: DataInputStream): String? {
val sb = StringBuilder()
while (true) {
val c = input.read()
if (c < 0) return null
if (c == '\n'.code) return sb.toString().trimEnd('\r')
sb.append(c.toChar())
}
}
}
@@ -0,0 +1,73 @@
package com.droiddeck.launcher.session
import androidx.test.core.app.ApplicationProvider
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class SteamGuidesTest {
private val page = """
<div class="workshopBrowsePagingControls"></div>
<div data-panel="{}" role="button" id="sharedfile_1848481525_1" class="workshopItemCollectionContainer">
<a class="workshopItemCollection ugc" href="https://steamcommunity.com/sharedfiles/filedetails/?id=1848481525" data-appid="413150">
<div class="workshopItemPreviewHolder ">
<img class="workshopItemPreviewImage" src="https://images.steamusercontent.com/ugc/1/A/?imw=200&amp;imh=200">
</div>
<div class="workshopItemDetails">
<img class="fileRating" src="https://community.akamai.steamstatic.com/public/images/sharedfiles/5-star.png?v=2" />
<div class="workshopItemTitle">
Stardew &amp; You </div>
<div class="workshopItemAuthorLine">by&nbsp;<span class="workshopItemAuthorName">Farmer</span></div>
<div class="workshopItemShortDesc">Everything about
the valley...</div>
</div>
</a>
</div>
<div data-panel="{}" role="button" id="sharedfile_2_1" class="workshopItemCollectionContainer">
<a class="workshopItemCollection ugc" href="https://steamcommunity.com/sharedfiles/filedetails/?id=2">
<div class="workshopItemTitle"></div>
</a>
</div>
""".trimIndent()
@Test
fun parsesGuideCards() {
val guides = SteamGuides.parse(page)
assertEquals(1, guides.size)
val g = guides.single()
assertEquals("1848481525", g.id)
assertEquals("Stardew & You", g.title)
assertEquals("Farmer", g.author)
assertEquals("Everything about the valley...", g.summary)
assertEquals("https://images.steamusercontent.com/ugc/1/A/?imw=200&imh=200", g.preview)
assertEquals(5, g.stars)
assertEquals("https://steamcommunity.com/sharedfiles/filedetails/?id=1848481525", g.url)
}
@Test
fun remembersOnlyGuidePagesPerGame() {
val context = ApplicationProvider.getApplicationContext<android.content.Context>()
assertNull(SteamGuides.place(context, "413150"))
SteamGuides.savePlace(context, "413150", "https://example.com/", 0.5f)
assertNull(SteamGuides.place(context, "413150"))
SteamGuides.savePlace(context, "413150", "https://steamcommunity.com/sharedfiles/filedetails/?id=1#Section", 0.4f)
assertEquals(0.4f, SteamGuides.place(context, "413150")!!.scroll, 0.001f)
assertNull(SteamGuides.place(context, "620"))
SteamGuides.clear(context, "413150")
assertNull(SteamGuides.place(context, "413150"))
}
@Test
fun guideUrls() {
assertTrue(SteamGuides.isGuide("https://steamcommunity.com/sharedfiles/filedetails/?id=123"))
assertFalse(SteamGuides.isGuide("https://steamcommunity.com.evil/sharedfiles/filedetails/?id=123"))
assertFalse(SteamGuides.isGuide("http://steamcommunity.com/sharedfiles/filedetails/?id=123"))
}
}
@@ -0,0 +1,59 @@
package com.droiddeck.launcher.session
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
class SteamLocalConfigTest {
private val config = """
"UserLocalConfigStore"
{
"Software"
{
"Valve"
{
"Steam"
{
"apps"
{
"620"
{
"cloud"
{
"last_sync_state" "synchronized"
}
"LastPlayed" "1764000000"
"Playtime" "754"
}
"1145360"
{
"LastPlayed" "1764100000"
}
}
}
}
}
"1145360" { "Playtime" "9999" }
}
""".trimIndent()
@Test
fun readsPlaytimeAndLastPlayedPastNestedBlocks() {
val stats = SteamLocalConfig.appStats(config, 620)!!
assertEquals(754L, stats.playtimeMinutes)
assertEquals(1764000000L, stats.lastPlayed)
}
@Test
fun onlyReadsTheAppsBlock() {
val stats = SteamLocalConfig.appStats(config, 1145360)!!
assertEquals(0L, stats.playtimeMinutes)
assertEquals(1764100000L, stats.lastPlayed)
}
@Test
fun unknownAppIsNull() {
assertNull(SteamLocalConfig.appStats(config, 413150))
assertNull(SteamLocalConfig.appStats("not vdf", 620))
}
}
@@ -0,0 +1,154 @@
package com.droiddeck.launcher.session
import com.droiddeck.launcher.ui.QamFit
import com.droiddeck.launcher.ui.QamLayout
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class SteamQamTest {
@Test fun findsTheQuickAccessPageAndKeepsOnlyItsPath() {
val json = """[
{"title":"SP BPM_uid0","webSocketDebuggerUrl":"ws://127.0.0.1:8080/devtools/page/AAA"},
{"title":"QuickAccess_uid2","webSocketDebuggerUrl":"ws://127.0.0.1:8080/devtools/page/0F3A-b9"}
]"""
assertEquals(SteamQam.Target(4321, "/devtools/page/0F3A-b9"), SteamQam.parseTarget(4321, json))
}
@Test fun readsTheTargetListByContentLengthWithoutWaitingForClose() {
val stream = object : java.io.InputStream() {
val bytes = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 4\r\n\r\n[{}]".toByteArray()
var at = 0
override fun read(): Int = if (at < bytes.size) bytes[at++].toInt() and 0xff else error("read past the response")
}
assertEquals("[{}]", SteamQam.httpBody(stream))
}
@Test fun ignoresMissingOrForeignDebuggerUrls() {
assertNull(SteamQam.parseTarget(1, """[{"title":"SP BPM_uid0","webSocketDebuggerUrl":"ws://127.0.0.1:1/devtools/page/A"}]"""))
assertNull(SteamQam.parseTarget(1, """[{"title":"QuickAccess_uid2"}]"""))
assertNull(SteamQam.parseTarget(1, """[{"title":"QuickAccess_uid2","webSocketDebuggerUrl":"ws://x/devtools/page/A?b=1"}]"""))
}
@Test fun holdingIsALeaseAndReleasingEndsIt() {
assertTrue(SteamQam.script(true, owner = 7).contains(SteamQam.leaseScript(true, 7)))
assertTrue(SteamQam.script(false, owner = 7).contains(SteamQam.leaseScript(false, 7)))
assertTrue(SteamQam.newOwner() < SteamQam.newOwner())
}
/** Runs the lease steps in Node, in order, and returns which owner holds a live lease afterwards (0 for none). */
private fun leaseAfter(vararg steps: Pair<Boolean, Long>): Long? = runLease(steps.toList(), "g.__ddQamUntil > Date.now() ? g.__ddQamOwner : 0")?.toLongOrNull()
/** Runs lease steps (on, owner, aspect) in Node and returns [result], a JS expression over `g`. */
private fun runLease(steps: List<Any>, result: String): String? {
val node = runCatching { ProcessBuilder("node", "--version").start().waitFor() == 0 }.getOrDefault(false)
org.junit.Assume.assumeTrue("node is not installed", node)
val program = "const g = {};\n" + steps.joinToString("\n") { step ->
when (step) {
is Triple<*, *, *> -> SteamQam.leaseScript(step.first as Boolean, step.second as Long, step.third as Float)
is Pair<*, *> -> if (step.second == EXPIRE) "g.__ddQamUntil = Date.now() - 1;" else SteamQam.leaseScript(step.first as Boolean, step.second as Long)
else -> error("unknown step $step")
}
} +
"\nprocess.stdout.write(String($result));"
val p = ProcessBuilder("node", "-e", program).redirectErrorStream(true).start()
val out = p.inputStream.bufferedReader().readText().trim()
assertEquals(out, 0, p.waitFor())
return out
}
@Test fun aLateRequestFromAnOldPanelLeavesItsReplacementsLease() {
// The replacement takes the lease, then the old panel's in-flight hold lands, then its release.
assertEquals(2L, leaseAfter(true to 2L, true to 1L, false to 1L))
// The old panel's release alone does not end the replacement's lease either.
assertEquals(2L, leaseAfter(true to 1L, true to 2L, false to 1L))
// A panel releases its own lease.
assertEquals(0L, leaseAfter(true to 2L, false to 2L))
// With no live lease, any panel can take it: after a release, or once a newer panel's lease has run out.
assertEquals(1L, leaseAfter(true to 2L, false to 2L, true to 1L))
assertEquals(1L, leaseAfter(true to 2L, false to EXPIRE, true to 1L))
// A rejected hold from an older panel leaves the newer panel's layout alone.
assertEquals("1.5", runLease(listOf(Triple(true, 2L, 1.5f), Triple(true, 1L, 0.75f)), "g.__ddQamAspect"))
assertEquals("0.75", runLease(listOf(Triple(true, 2L, 1.5f), Triple(false, 2L, 0f), Triple(true, 1L, 0.75f)), "g.__ddQamAspect"))
}
@Test fun readsWhetherTheMenuIsShownOnTheTopScreen() {
assertEquals(SteamQam.Hold(2, false), SteamQam.parseHold("[2,0]"))
assertEquals(SteamQam.Hold(2, true), SteamQam.parseHold("[2,1]"))
assertNull(SteamQam.parseHold("2"))
}
@Test fun theQuickAccessButtonTogglesTheTopScreenAndTheWideLayoutFollows() {
val script = SteamQam.script(true)
assertTrue(script.contains("const ours = () => held() && m.m_eOpenSideMenu === QAM && !g.__ddQamTop;"))
assertTrue(script.contains("if (press !== g.__ddQamPress) {"))
assertTrue(QamLayout.contentScript(true).contains("max-width: none !important"))
assertFalse(QamLayout.contentScript(false).contains("max-width: none"))
}
@Test fun theMenuIsLaidOutAtThePanelsShapeOnlyWhileHeld() {
assertTrue(SteamQam.script(true, 1.5f, owner = 3).contains("g.__ddQamOwner = 3; g.__ddQamUntil = Date.now() + ${SteamQam.LEASE_MS}; g.__ddQamAspect = 1.5; }"))
assertFalse(SteamQam.script(true).contains("g.__ddQamAspect ="))
assertFalse(SteamQam.script(false, 1.5f).contains("g.__ddQamAspect ="))
}
@Test fun aSteamDialogOverTheGameGetsTheInput() {
val script = SteamQam.script(true)
assertTrue(script.contains("t.m_ID?.startsWith(\"ModalDialogOverlay\") && t.m_Root?.m_element?.isConnected"))
assertTrue(script.contains("if (dialog && !g.__ddQamTop) {"))
assertTrue(script.indexOf("if (dialog && !g.__ddQamTop)") < script.indexOf("g.__ddQamDecky = decky;"))
}
@Test fun theRelayAnswersWithItsPortAndSecret() {
assertEquals(41234 to "0123456789abcdef0123456789abcdef", SteamQam.parseRelay("41234 0123456789abcdef0123456789abcdef\n"))
assertNull(SteamQam.parseRelay("41234"))
assertNull(SteamQam.parseRelay("41234 not-a-secret"))
assertNull(SteamQam.parseRelay(null))
}
@Test fun whileHeldTheMenuStaysOffTheTopScreenAndOutOfTheGamesWay() {
val script = SteamQam.script(true)
assertTrue(script.contains("return without >= 2 ? v : 1;"))
assertTrue(script.contains("if (w > 0 && ours()) { x = popup.m_popup.innerWidth + 64; w = width(h) || w; }"))
assertTrue(script.contains("nav.m_LastActiveNavTree?.m_ID?.startsWith(\"QuickAccess\")"))
assertTrue(script.contains("if (m.m_eOpenSideMenu === QAM) m.CloseSideMenus();"))
}
@Test fun theMenuFillsTheHeightAndCentresAndTouchesMapBack() {
val (scale, left) = QamLayout.fit(1280f, 832f, 400f, 640f)
assertEquals(1.3f, scale, 0.001f)
assertEquals((1280f - 520f) / 2f, left, 0.001f)
val (x, y) = QamLayout.toCss(left + 130f, 260f, scale, left)
assertEquals(100f, x, 0.001f)
assertEquals(200f, y, 0.001f)
}
@Test fun aNarrowMenuCanSitLeftOrRight() {
assertEquals(0f, QamLayout.fit(1280f, 832f, 400f, 640f, -1).second, 0.001f)
assertEquals(1280f - 520f, QamLayout.fit(1280f, 832f, 400f, 640f, 1).second, 0.001f)
assertEquals(0f, QamLayout.fit(1280f, 832f, 1280f, 640f, 1).second, 0.001f)
}
@Test fun theLayoutButtonCyclesFullLeftCenterRight() {
assertEquals(listOf(QamFit.LEFT, QamFit.CENTER, QamFit.RIGHT, QamFit.FULL), QamFit.entries.map { it.next })
assertEquals(QamFit.FULL, QamFit.from(null))
assertEquals(QamFit.RIGHT, QamFit.from("right"))
assertEquals(QamFit.FULL, QamFit.from("sideways"))
}
@Test fun aWideMenuFitsTheWidth() {
val (scale, left) = QamLayout.fit(1280f, 832f, 1280f, 640f)
assertEquals(1f, scale, 0.001f)
assertEquals(0f, left, 0.001f)
}
private companion object {
/** A lease step that lets the current lease run out. */
const val EXPIRE = -1L
}
}
@@ -0,0 +1,41 @@
package com.droiddeck.launcher.stores
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class SteamAchievementsTest {
@Test
fun parsesTheClientsAchievementList() {
val json = """{"result":1,"data":{"rgAchievements":[
{"strID":"ACH_WIN","strName":"Winner","strDescription":"Win once","bAchieved":true,"rtUnlocked":1764000000,
"strImage":"https://cdn.example/apps/620/abc.jpg","bHidden":false},
{"strID":"ACH_SECRET","strName":"Secret","strDescription":"","bAchieved":false,"rtUnlocked":1764000000,
"strImage":"def.jpg","bHidden":true}]}}"""
val list = (SteamAchievements.parse(620, json) as StoreAchievements.Result.Found).list
assertEquals(2, list.size)
assertEquals("Winner", list[0].name)
assertTrue(list[0].unlocked)
assertEquals(1764000000L, list[0].unlockedAt)
assertEquals("https://cdn.example/apps/620/abc.jpg", list[0].icon)
assertTrue(list[1].hidden)
assertEquals(0L, list[1].unlockedAt)
assertEquals("https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/apps/620/def.jpg", list[1].icon)
}
@Test
fun gamesWithoutStatsHaveNoAchievementsAndGarbageIsUnreachable() {
assertEquals(0, (SteamAchievements.parse(12200, """{"result":2,"message":"Failed to retrieve user stats"}""") as StoreAchievements.Result.Found).list.size)
assertTrue(SteamAchievements.parse(620, "nope") is StoreAchievements.Result.Failed)
}
@Test
fun noListIsNoAchievements() {
assertEquals(0, (SteamAchievements.parse(620, """{"result":1,"data":{}}""") as StoreAchievements.Result.Found).list.size)
}
}
@@ -0,0 +1,47 @@
package com.droiddeck.launcher.ui
import androidx.test.core.app.ApplicationProvider
import android.content.Context
import com.droiddeck.launcher.session.SessionPrefs
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
@RunWith(RobolectricTestRunner::class)
class BottomBrightnessTest {
private val context = ApplicationProvider.getApplicationContext<Context>()
@Test fun followsTheSystemUntilTheUserPicksALevel() {
assertNull(BottomBrightness.level(context))
SessionPrefs.setBottomBrightness(context, 40)
assertEquals(0.4f, BottomBrightness.level(context)!!, 0.001f)
}
@Test fun theSliderNeverReachesZero() {
assertEquals(BottomBrightness.MIN, BottomBrightness.clamp(0))
assertEquals(BottomBrightness.MIN, BottomBrightness.clamp(-20))
assertEquals(100, BottomBrightness.clamp(150))
SessionPrefs.setBottomBrightness(context, 0)
assertEquals(BottomBrightness.MIN / 100f, BottomBrightness.level(context)!!, 0.001f)
}
@Test fun autoDimNeverBrightensADarkerChoice() {
assertEquals(0.05f, BottomBrightness.dimmed(context, 0.05f), 0.001f)
SessionPrefs.setBottomBrightness(context, 5)
assertEquals(0.05f, BottomBrightness.dimmed(context, 0.2f), 0.001f)
SessionPrefs.setBottomBrightness(context, 80)
assertEquals(0.05f, BottomBrightness.dimmed(context, 0.05f), 0.001f)
}
@Test fun autoDimFollowsADarkerManualSystemLevelWhenNothingIsSaved() {
val resolver = context.contentResolver
android.provider.Settings.System.putInt(resolver, android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE,
android.provider.Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL)
android.provider.Settings.System.putInt(resolver, android.provider.Settings.System.SCREEN_BRIGHTNESS, 3)
assertEquals(3 / 255f, BottomBrightness.dimmed(context, 0.05f), 0.001f)
android.provider.Settings.System.putInt(resolver, android.provider.Settings.System.SCREEN_BRIGHTNESS, 200)
assertEquals(0.05f, BottomBrightness.dimmed(context, 0.05f), 0.001f)
}
}
@@ -0,0 +1,36 @@
package com.droiddeck.launcher.ui
import org.junit.After
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
class BottomChromeTest {
@After fun clear() {
BottomChrome.reset()
}
@Test fun aFullScreenPanelHidesTheBarAndThePullTabBringsItBack() {
assertTrue(BottomChrome.barShown)
BottomChrome.request(true)
assertFalse(BottomChrome.barShown)
BottomChrome.show(true)
assertTrue(BottomChrome.barShown)
BottomChrome.request(false)
assertTrue(BottomChrome.barShown)
}
@Test fun hidingByHandLastsUntilAPanelChangesItsRequest() {
BottomChrome.show(false)
assertFalse(BottomChrome.barShown)
BottomChrome.request(true)
BottomChrome.request(false)
assertTrue(BottomChrome.barShown)
}
@Test fun moreReleasesThanRequestsNeverHideTheBarForGood() {
BottomChrome.request(false)
BottomChrome.request(false)
assertTrue(BottomChrome.barShown)
}
}
@@ -28,6 +28,11 @@ class BottomDashboardTest {
assertEquals("telemetry", pageForGameStart(listOf("telemetry", "downloads", "chat")))
assertNull(pageForGameStart(listOf("downloads", "chat")))
}
@Test fun aGameStartShowsThePageLastPickedForThatGame() {
assertEquals("chat", pageForGameStart(listOf("telemetry", "downloads", "chat"), "chat"))
assertEquals("telemetry", pageForGameStart(listOf("telemetry", "downloads"), "chat"))
}
}
class BottomDownloadsRateTest {
@@ -0,0 +1,54 @@
package com.droiddeck.launcher.ui
import android.net.Uri
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class BottomGuidesPageTest {
@Test
fun theReaderStaysOnTheSiteUnlessTheUserFollowsALink() {
val start = "https://eldenring.fandom.com/"
assertTrue(readerAllows(start, Uri.parse("https://eldenring.fandom.com/wiki/Margit"), false))
assertTrue(readerAllows(start, Uri.parse("https://community.fandom.com/"), false))
assertFalse(readerAllows(start, Uri.parse("https://ads.example.com/landing"), false))
assertTrue(readerAllows(start, Uri.parse("https://mapgenie.io/elden-ring"), true))
assertTrue(readerAllows(start, Uri.parse("https://steamcommunity.com/app/1"), false))
assertFalse(readerAllows(start, Uri.parse("intent://scan/#Intent;end"), true))
assertFalse(readerAllows(start, Uri.parse("javascript:alert(1)"), true))
}
@Test
fun adHostsAreBlockedBySuffix() {
assertTrue(ReaderAds.blocks("securepubads.g.doubleclick.net"))
assertTrue(ReaderAds.blocks("c.amazon-adsystem.com"))
assertFalse(ReaderAds.blocks("strategywiki.org"))
assertFalse(ReaderAds.blocks("static.wikia.nocookie.net"))
assertFalse(ReaderAds.blocks("net"))
assertFalse(ReaderAds.blocks(null))
}
@Test
fun bigMapsAreDecodedAtAManageableSize() {
assertEquals(1, MapMarkers.sampleSize(4000, 3000, 4096))
assertEquals(1, MapMarkers.sampleSize(4096, 2000, 4096))
assertEquals(2, MapMarkers.sampleSize(6000, 6000, 4096))
assertEquals(2, MapMarkers.sampleSize(8192, 8192, 4096))
assertEquals(4, MapMarkers.sampleSize(9000, 6000, 4096))
assertEquals(8, MapMarkers.sampleSize(20000, 12000, 4096))
}
@Test
fun mirrorHideCyclesAndDefaultsToShown() {
assertEquals(MirrorHide.OFF, MirrorHide.from(null))
assertEquals(MirrorHide.DIM, MirrorHide.from("dim"))
assertEquals(MirrorHide.BLACK, MirrorHide.OFF.next())
assertEquals(MirrorHide.OFF, MirrorHide.DIM.next())
}
}
@@ -0,0 +1,51 @@
package com.droiddeck.launcher.ui
import com.droiddeck.launcher.frontend.Library
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class BottomIdleHomeTest {
private val games = listOf(
Library.SteamGame(620, "Portal 2", null, "", lastPlayed = 100),
Library.SteamGame(1145360, "Hades", null, "", lastPlayed = 300),
Library.SteamGame(504230, "Celeste", null, ""),
)
@Test
fun prefersTheGameSelectedInSteam() {
val (game, highlighted) = IdleHome.pick(games, 504230)!!
assertEquals(504230, game.appId)
assertEquals(true, highlighted)
}
@Test
fun fallsBackToTheMostRecentGame() {
val (game, highlighted) = IdleHome.pick(games, 999)!!
assertEquals(1145360, game.appId)
assertEquals(false, highlighted)
assertEquals(1145360, IdleHome.pick(games, null)!!.first.appId)
}
@Test
fun nothingPlayedAndNothingSelected() {
assertNull(IdleHome.pick(listOf(Library.SteamGame(1, "A", null, "")), null))
}
@Test
fun readsSteamsOverviewOfTheHighlightedGame() {
val o = IdleHome.parseOverview("""{"name":"Sonic Mania","minutes":864,"last":1764000000}""")!!
assertEquals("Sonic Mania", o.name)
assertEquals(864L, o.minutes)
assertEquals(1764000000L, o.lastPlayed)
assertNull(IdleHome.parseOverview(null))
assertNull(IdleHome.parseOverview("""{"name":""}"""))
assertNull(IdleHome.parseOverview("nope"))
assertEquals(true, IdleHome.overviewExpression(584400).contains("GetAppOverviewByAppID?.(584400)"))
}
}
@@ -0,0 +1,43 @@
package com.droiddeck.launcher.ui
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class BottomMirrorPageTest {
@Test
fun regionsRoundTripAndNormalize() {
val r = MirrorRegion.normalize(0.9f, 0.3f, 0.75f, 0.05f)!!
assertEquals(0.75f, r.left, 0.0001f)
assertEquals(0.05f, r.top, 0.0001f)
assertEquals(0.9f, r.right, 0.0001f)
assertEquals(0.3f, r.bottom, 0.0001f)
val back = MirrorRegion.parse(MirrorRegion.format(r))!!
assertEquals(r.left, back.left, 0.0001f)
assertEquals(r.bottom, back.bottom, 0.0001f)
assertEquals(1f, MirrorRegion.normalize(-1f, -1f, 2f, 2f)!!.right, 0f)
}
@Test
fun tinyOrBrokenRegionsAreRejected() {
assertNull(MirrorRegion.normalize(0.5f, 0.5f, 0.505f, 0.9f))
assertNull(MirrorRegion.parse("0.1,0.2,0.3"))
assertNull(MirrorRegion.parse(null))
assertNull(MirrorRegion.parse("a,b,c,d"))
}
@Test
fun outputKeepsTheRegionsAspect() {
val minimap = MirrorRegion.normalize(0.8f, 0.0f, 1.0f, 0.3555f)!!
val (w, h) = MirrorRegion.outputSize(minimap, 16f / 9f, 720)
assertEquals(720, w)
assertEquals(720, h)
val bar = MirrorRegion.normalize(0.3f, 0.9f, 0.7f, 1.0f)!!
assertEquals(720 to 101, MirrorRegion.outputSize(bar, 16f / 9f, 720))
}
}
@@ -2,6 +2,7 @@ package com.droiddeck.launcher.ui
import android.hardware.display.DisplayManager
import android.view.Display
import android.view.MotionEvent
import android.view.View
import android.view.ViewGroup
import androidx.compose.runtime.MutableState
@@ -76,6 +77,27 @@ class SecondScreenBarTest {
return (0 until root.childCount).map { root.getChildAt(it) }
}
@Test fun theTouchThatWakesTheScreenDoesNotReachThePanel() {
SessionState.mode = SessionService.MODE_STEAM
val panel = presentation()
try {
panel.show()
panel.showMode(SecondScreenMode.KEYBOARD_TRACKPAD)
val root: ViewGroup = ReflectionHelpers.getField(panel, "root")
val seen = mutableListOf<Int>()
root.setOnTouchListener { _, e -> seen += e.actionMasked; true }
fun touch(action: Int) = MotionEvent.obtain(0, 0, action, 10f, 10f, 0).also { panel.dispatchTouchEvent(it); it.recycle() }
panel.screenOff()
touch(MotionEvent.ACTION_DOWN)
touch(MotionEvent.ACTION_UP)
assertTrue(seen.isEmpty())
assertEquals(BottomScreenLight.ON, ReflectionHelpers.getField<BottomScreenLight>(panel, "screen"))
assertEquals(false, ReflectionHelpers.getField<Boolean>(panel, "waking"))
} finally {
panel.dismiss()
}
}
@Test fun trackpadPanelHasTheBarWithTheKeyboardToggleStateAndSwap() {
SessionState.mode = SessionService.MODE_STEAM
var swaps = 0
@@ -90,13 +112,13 @@ class SecondScreenBarTest {
assertEquals(context.getString(R.string.second_mode_keyboard_trackpad), bar.title)
assertNotNull(bar.onClose); assertNotNull(bar.onMenu); assertNotNull(bar.onSteam); assertNotNull(bar.onQam)
assertNull(bar.tabs)
assertEquals(listOf("bottom-keyboard", "bottom-swap"), bar.extras.map { it.tag })
assertEquals(listOf("bottom-keyboard", "bottom-swap", "bottom-brightness-toggle", "bottom-bar-hide"), bar.extras.map { it.tag })
val keyboard = bar.extras.first()
assertEquals(context.getString(R.string.second_show_keyboard), keyboard.description)
assertFalse(keyboard.active)
bar.extras.last().onClick()
bar.extras.first { it.tag == "bottom-swap" }.onClick()
assertEquals(1, swaps)
assertEquals(listOf("bottom-keyboard", "bottom-swap"), panel.barModel(SecondScreenMode.TERMINAL)!!.extras.map { it.tag })
assertEquals(listOf("bottom-keyboard", "bottom-swap", "bottom-brightness-toggle", "bottom-bar-hide"), panel.barModel(SecondScreenMode.TERMINAL)!!.extras.map { it.tag })
ReflectionHelpers.getField<MutableState<Boolean>>(panel, "keyboardShown").value = true
val shown = panel.barModel(SecondScreenMode.KEYBOARD_TRACKPAD)!!.extras.first()
assertEquals(context.getString(R.string.second_hide_keyboard), shown.description)
@@ -115,17 +137,17 @@ class SecondScreenBarTest {
assertTrue(rootChildren(panel)[0] is ComposeView)
val bar = panel.barModel(SecondScreenMode.DECK_CONTROLS)!!
assertEquals(context.getString(R.string.second_mode_deck_controls), bar.title)
assertEquals(listOf(context.getString(R.string.swap_screens)), bar.extras.map { it.description })
bar.extras.single().onClick()
assertEquals(listOf(context.getString(R.string.swap_screens), context.getString(R.string.bottom_brightness), context.getString(R.string.bottom_bar_hide)), bar.extras.map { it.description })
bar.extras.first { it.tag == "bottom-swap" }.onClick()
assertEquals(1, swaps)
assertEquals(DeckPanel.entries.map { context.getString(it.label) }, bar.tabs!!.labels)
assertEquals(DeckPanel.BOTH.ordinal, bar.tabs!!.selected)
panel.showMode(SecondScreenMode.CUSTOM_CONTROLS)
val profile = panel.barModel(SecondScreenMode.CUSTOM_CONTROLS)!!
assertEquals(context.getString(R.string.input_profile_controls_mode), profile.title)
assertEquals(listOf(context.getString(R.string.swap_screens)), profile.extras.map { it.description })
assertEquals(listOf(context.getString(R.string.swap_screens), context.getString(R.string.bottom_brightness), context.getString(R.string.bottom_bar_hide)), profile.extras.map { it.description })
assertNotNull(profile.onClose); assertNotNull(profile.onMenu)
profile.extras.single().onClick()
profile.extras.first { it.tag == "bottom-swap" }.onClick()
assertEquals(2, swaps)
assertTrue(rootChildren(panel)[0] is ComposeView)
assertTrue(rootChildren(panel)[1] is InputSurfaceView)
@@ -134,9 +156,9 @@ class SecondScreenBarTest {
try {
noSwap.show()
noSwap.showMode(SecondScreenMode.DECK_CONTROLS)
assertTrue(noSwap.barModel(SecondScreenMode.DECK_CONTROLS)!!.extras.isEmpty())
assertEquals(listOf("bottom-keyboard"), noSwap.barModel(SecondScreenMode.TERMINAL)!!.extras.map { it.tag })
assertEquals(listOf("bottom-keyboard"), noSwap.barModel(SecondScreenMode.KEYBOARD_TRACKPAD)!!.extras.map { it.tag })
assertEquals(listOf("bottom-brightness-toggle", "bottom-bar-hide"), noSwap.barModel(SecondScreenMode.DECK_CONTROLS)!!.extras.map { it.tag })
assertEquals(listOf("bottom-keyboard", "bottom-brightness-toggle", "bottom-bar-hide"), noSwap.barModel(SecondScreenMode.TERMINAL)!!.extras.map { it.tag })
assertEquals(listOf("bottom-keyboard", "bottom-brightness-toggle", "bottom-bar-hide"), noSwap.barModel(SecondScreenMode.KEYBOARD_TRACKPAD)!!.extras.map { it.tag })
} finally { noSwap.closeControls() }
}