mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
feat(bottom): align Quick Access left, centre or right; keep its tab and Decky working
This commit is contained in:
1 parent
bd5f2d26cf
commit
911a9b1eab
42 files changed
+236
-33
No files matched your search
@@ -172,6 +172,13 @@ object SessionPrefs {
|
||||
prefs(context).edit().putString("mirrorHide.app.$game", mode).apply()
|
||||
}
|
||||
|
||||
/** Where Steam's Quick Access menu sits on the bottom screen when it is narrower than the panel: -1, 0 or 1. */
|
||||
fun quickAccessAlign(context: Context): Int = prefs(context).getInt("bottomQamAlign", 0).coerceIn(-1, 1)
|
||||
|
||||
fun setQuickAccessAlign(context: Context, align: Int) {
|
||||
prefs(context).edit().putInt("bottomQamAlign", align.coerceIn(-1, 1)).apply()
|
||||
}
|
||||
|
||||
fun clearGameBottomScreen(context: Context, game: String) {
|
||||
prefs(context).edit().remove("secondScreenPanel.app.$game").remove("bottomPage.app.$game").remove("mirrorRegion.app.$game")
|
||||
.remove("mirrorHide.app.$game").apply()
|
||||
|
||||
@@ -67,8 +67,9 @@ object SteamQam {
|
||||
c.EnsureCorrectComposition?.();
|
||||
return;
|
||||
}
|
||||
if (m.m_eOpenSideMenu === 0) { m.OpenQuickAccessMenu(); c.EnsureCorrectComposition?.(); }
|
||||
if (m.m_eOpenSideMenu === 0) { m.OpenQuickAccessMenu(g.__ddQamTab ?? undefined); c.EnsureCorrectComposition?.(); }
|
||||
if (m.m_eOpenSideMenu !== QAM) return;
|
||||
if (m.m_eQuickAccessTab != null) g.__ddQamTab = m.m_eQuickAccessTab;
|
||||
if (!g.__ddQamOn) { g.__ddQamOn = true; c.EnsureCorrectComposition?.(); }
|
||||
for (const v of views()) {
|
||||
if (!v.__ddAsked) {
|
||||
@@ -94,16 +95,16 @@ object SteamQam {
|
||||
|
||||
fun hold(context: Context): Int? = eval(context, script(true))?.toIntOrNull()
|
||||
|
||||
fun release(context: Context) {
|
||||
fun release(context: Context, relayPort: Int) {
|
||||
eval(context, script(false))
|
||||
helper(context, "stop")
|
||||
if (relayPort > 0) helper(context, "stop", relayPort.toString())
|
||||
}
|
||||
|
||||
fun target(context: Context): Target? = runCatching {
|
||||
val devtools = File(AgentGuest.dir(context), "cdp-port").readText().trim().toInt()
|
||||
val relay = helper(context, "start", devtools.toString())?.trim()?.toIntOrNull() ?: return null
|
||||
parseTarget(relay, get(relay, "/json"))
|
||||
}.onFailure { android.util.Log.w(TAG, "no quick access target: $it") }.getOrNull()
|
||||
}.onFailure { android.util.Log.e(TAG, "no quick access target: $it") }.getOrNull()
|
||||
|
||||
private fun helper(context: Context, vararg args: String): String? = runCatching {
|
||||
val request = JSONObject().put("kind", "exec").put("argv", JSONArray(listOf("droiddeck-qam-relay") + args)).put("timeout", 5.0)
|
||||
@@ -118,10 +119,28 @@ object SteamQam {
|
||||
write("GET $path HTTP/1.1\r\nHost: 127.0.0.1:$port\r\nAccept: */*\r\nConnection: close\r\n\r\n".toByteArray())
|
||||
flush()
|
||||
}
|
||||
val response = s.getInputStream().readBytes().toString(Charsets.UTF_8)
|
||||
val split = response.indexOf("\r\n\r\n")
|
||||
check(response.startsWith("HTTP/1.1 200") && split > 0) { "devtools answered ${response.take(80)}" }
|
||||
response.substring(split + 4)
|
||||
httpBody(s.getInputStream())
|
||||
}
|
||||
|
||||
/** Reads one response, by its Content-Length when it has one: DevTools does not always close the connection. */
|
||||
internal fun httpBody(input: java.io.InputStream): String {
|
||||
val head = StringBuilder()
|
||||
while (!head.endsWith("\r\n\r\n")) {
|
||||
val b = input.read()
|
||||
check(b >= 0 && head.length < 16_384) { "devtools answered ${head.take(80)}" }
|
||||
head.append(b.toChar())
|
||||
}
|
||||
check(head.startsWith("HTTP/1.1 200")) { "devtools answered ${head.take(80)}" }
|
||||
val length = Regex("(?im)^content-length:\\s*(\\d+)").find(head)?.groupValues?.get(1)?.toInt()
|
||||
val body = if (length == null) input.readBytes() else ByteArray(length).also { buf ->
|
||||
var read = 0
|
||||
while (read < length) {
|
||||
val n = input.read(buf, read, length - read)
|
||||
check(n > 0) { "devtools closed after $read of $length bytes" }
|
||||
read += n
|
||||
}
|
||||
}
|
||||
return body.toString(Charsets.UTF_8)
|
||||
}
|
||||
|
||||
internal fun parseTarget(port: Int, json: String): Target? {
|
||||
|
||||
@@ -4,16 +4,25 @@ import android.graphics.BitmapFactory
|
||||
import android.util.Base64
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.AlignHorizontalCenter
|
||||
import androidx.compose.material.icons.outlined.AlignHorizontalLeft
|
||||
import androidx.compose.material.icons.outlined.AlignHorizontalRight
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableIntStateOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.FilterQuality
|
||||
@@ -24,12 +33,15 @@ import androidx.compose.ui.input.pointer.PointerEventType
|
||||
import androidx.compose.ui.input.pointer.pointerInput
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.compose.ui.unit.IntSize
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.droiddeck.launcher.R
|
||||
import com.droiddeck.launcher.companion.CdpPage
|
||||
import com.droiddeck.launcher.session.SessionPhase
|
||||
import com.droiddeck.launcher.session.SessionPrefs
|
||||
import com.droiddeck.launcher.session.SessionState
|
||||
import com.droiddeck.launcher.session.SteamQam
|
||||
import kotlin.concurrent.thread
|
||||
@@ -53,9 +65,10 @@ internal class QamFrame(val image: ImageBitmap, val cssWidth: Float, val cssHeig
|
||||
}
|
||||
|
||||
internal object QamLayout {
|
||||
fun fit(boxWidth: Float, boxHeight: Float, contentRight: Float, cssHeight: Float): Pair<Float, Float> {
|
||||
/** Scale and left edge of the menu in a box; [align] -1, 0 or 1 places a narrower menu left, centred or right. */
|
||||
fun fit(boxWidth: Float, boxHeight: Float, contentRight: Float, cssHeight: Float, align: Int = 0): Pair<Float, Float> {
|
||||
val scale = min(boxWidth / contentRight, boxHeight / cssHeight)
|
||||
return scale to (boxWidth - contentRight * scale) / 2f
|
||||
return scale to (boxWidth - contentRight * scale) * (align.coerceIn(-1, 1) + 1) / 2f
|
||||
}
|
||||
|
||||
fun toCss(x: Float, y: Float, scale: Float, left: Float): Pair<Float, Float> = (x - left) / scale to y / scale
|
||||
@@ -73,15 +86,18 @@ internal fun SteamQamPanel() {
|
||||
var image by remember { mutableStateOf<ImageBitmap?>(null) }
|
||||
var shape by remember { mutableStateOf<FloatArray?>(null) }
|
||||
var failed by remember { mutableStateOf(false) }
|
||||
var align by remember { mutableIntStateOf(SessionPrefs.quickAccessAlign(context)) }
|
||||
val holder = remember { arrayOfNulls<CdpPage>(1) }
|
||||
val relay = remember { intArrayOf(0) }
|
||||
DisposableEffect(Unit) {
|
||||
onDispose {
|
||||
val page = holder[0]
|
||||
val port = relay[0]
|
||||
holder[0] = null
|
||||
thread(name = "qam-release", isDaemon = true) {
|
||||
runCatching { page?.send("Page.stopScreencast") }
|
||||
page?.close()
|
||||
SteamQam.release(context)
|
||||
SteamQam.release(context, port)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -100,12 +116,12 @@ internal fun SteamQamPanel() {
|
||||
if (page == null || page.closed) {
|
||||
page?.close()
|
||||
page = SteamQam.target(context)?.let { t ->
|
||||
relay[0] = t.port
|
||||
runCatching {
|
||||
CdpPage(t.port, t.path) { method, params ->
|
||||
if (method == "Page.screencastFrame") {
|
||||
holder[0]?.send("Page.screencastFrameAck", JSONObject().put("sessionId", params.optInt("sessionId")))
|
||||
val bytes = Base64.decode(params.optString("data"), Base64.DEFAULT)
|
||||
BitmapFactory.decodeByteArray(bytes, 0, bytes.size)?.let { image = it.asImageBitmap() }
|
||||
decodeFrame(params.optString("data"))?.let { image = it }
|
||||
}
|
||||
}
|
||||
}.onFailure { android.util.Log.w("SteamQam", "devtools connect: $it") }.getOrNull()
|
||||
@@ -115,6 +131,11 @@ internal fun SteamQamPanel() {
|
||||
page?.send("Page.startScreencast", JSONObject().put("format", "jpeg").put("quality", 85)
|
||||
.put("maxWidth", 1920).put("maxHeight", 1440))
|
||||
}
|
||||
// The screencast sends frames only when the menu repaints, so a still menu needs one screenshot.
|
||||
if (image == null) {
|
||||
page?.call("Page.captureScreenshot", JSONObject().put("format", "jpeg").put("quality", 85))
|
||||
?.optJSONObject("result")?.optString("data")?.let(::decodeFrame)?.let { image = it }
|
||||
}
|
||||
(page?.evaluate(QamLayout.CONTENT_SCRIPT) as? String)?.let { text ->
|
||||
runCatching {
|
||||
val a = JSONArray(text)
|
||||
@@ -140,20 +161,22 @@ internal fun SteamQamPanel() {
|
||||
val density = LocalDensity.current
|
||||
val boxW = with(density) { maxWidth.toPx() }
|
||||
val boxH = with(density) { maxHeight.toPx() }
|
||||
val (scale, left) = QamLayout.fit(boxW, boxH, f.contentRight, f.cssHeight)
|
||||
val (scale, left) = QamLayout.fit(boxW, boxH, f.contentRight, f.cssHeight, align)
|
||||
Canvas(
|
||||
Modifier.fillMaxSize().pointerInput(f.cssWidth, f.contentRight, boxW, boxH) {
|
||||
Modifier.fillMaxSize().pointerInput(f.cssWidth, f.contentRight, boxW, boxH, align) {
|
||||
var touching = false
|
||||
awaitPointerEventScope {
|
||||
while (true) {
|
||||
val event = awaitPointerEvent()
|
||||
val change = event.changes.firstOrNull() ?: continue
|
||||
val (x, y) = QamLayout.toCss(change.position.x, change.position.y, scale, left)
|
||||
val type = when (event.type) {
|
||||
PointerEventType.Press -> "touchStart"
|
||||
PointerEventType.Press -> if (x in 0f..f.contentRight && y in 0f..f.cssHeight) "touchStart" else null
|
||||
PointerEventType.Move -> "touchMove"
|
||||
PointerEventType.Release -> "touchEnd"
|
||||
else -> null
|
||||
} ?: continue
|
||||
val (x, y) = QamLayout.toCss(change.position.x, change.position.y, scale, left)
|
||||
}?.takeIf { it == "touchStart" || touching } ?: continue
|
||||
touching = type != "touchEnd"
|
||||
val points = if (type == "touchEnd") JSONArray()
|
||||
else JSONArray().put(JSONObject().put("x", x.toDouble()).put("y", y.toDouble()))
|
||||
holder[0]?.send("Input.dispatchTouchEvent", JSONObject().put("type", type).put("touchPoints", points))
|
||||
@@ -172,5 +195,33 @@ internal fun SteamQamPanel() {
|
||||
filterQuality = FilterQuality.Medium,
|
||||
)
|
||||
}
|
||||
val width = f.contentRight * scale
|
||||
val gap = with(density) { 64.dp.toPx() }
|
||||
val choose = { a: Int -> align = a; SessionPrefs.setQuickAccessAlign(context, a) }
|
||||
if (left >= gap) {
|
||||
AlignButtons((-1 until align).toList(), choose, Modifier.align(Alignment.CenterStart).width(with(density) { left.toDp() }))
|
||||
}
|
||||
if (boxW - left - width >= gap) {
|
||||
AlignButtons((align + 1..1).toList(), choose, Modifier.align(Alignment.CenterEnd).width(with(density) { (boxW - left - width).toDp() }))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun AlignButtons(targets: List<Int>, choose: (Int) -> Unit, modifier: Modifier) {
|
||||
Column(modifier, horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.spacedBy(12.dp)) {
|
||||
for (a in targets) {
|
||||
val (label, icon) = when (a) {
|
||||
-1 -> R.string.bottom_qam_align_left to Icons.Outlined.AlignHorizontalLeft
|
||||
0 -> R.string.bottom_qam_align_center to Icons.Outlined.AlignHorizontalCenter
|
||||
else -> R.string.bottom_qam_align_right to Icons.Outlined.AlignHorizontalRight
|
||||
}
|
||||
BarButton(stringResource(label), Modifier.testTag("qam-align-$a"), vector = icon) { choose(a) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun decodeFrame(data: String): ImageBitmap? = runCatching {
|
||||
val bytes = Base64.decode(data, Base64.DEFAULT)
|
||||
BitmapFactory.decodeByteArray(bytes, 0, bytes.size)?.asImageBitmap()
|
||||
}.getOrNull()
|
||||
@@ -2244,6 +2244,9 @@
|
||||
<string name="bottom_companion_weight">الحمولة</string>
|
||||
<string name="bottom_companion_radio">الراديو</string>
|
||||
<string name="bottom_qam_title">الوصول السريع</string>
|
||||
<string name="bottom_qam_align_left">نقل إلى اليسار</string>
|
||||
<string name="bottom_qam_align_center">نقل إلى الوسط</string>
|
||||
<string name="bottom_qam_align_right">نقل إلى اليمين</string>
|
||||
<string name="bottom_qam_unavailable">قائمة الوصول السريع في Steam غير متاحة بعد.</string>
|
||||
<string name="bottom_page_telemetry">إحصاءات داخل اللعبة</string>
|
||||
<string name="bottom_hud_group">مؤشرات الشاشة السفلية</string>
|
||||
|
||||
@@ -2239,6 +2239,9 @@
|
||||
<string name="bottom_companion_weight">Peso cargado</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Acceso rápido</string>
|
||||
<string name="bottom_qam_align_left">Mover a la izquierda</string>
|
||||
<string name="bottom_qam_align_center">Mover al centro</string>
|
||||
<string name="bottom_qam_align_right">Mover a la derecha</string>
|
||||
<string name="bottom_qam_unavailable">El menú de acceso rápido de Steam aún no está disponible.</string>
|
||||
<string name="bottom_page_telemetry">Estadísticas del juego</string>
|
||||
<string name="bottom_hud_group">HUD de la pantalla inferior</string>
|
||||
|
||||
@@ -2144,6 +2144,9 @@
|
||||
<string name="bottom_companion_weight">Товар</string>
|
||||
<string name="bottom_companion_radio">Радио</string>
|
||||
<string name="bottom_qam_title">Бърз достъп</string>
|
||||
<string name="bottom_qam_align_left">Премести вляво</string>
|
||||
<string name="bottom_qam_align_center">Премести в центъра</string>
|
||||
<string name="bottom_qam_align_right">Премести вдясно</string>
|
||||
<string name="bottom_qam_unavailable">Менюто за бърз достъп на Steam още не е налично.</string>
|
||||
<string name="bottom_page_telemetry">Статистика в играта</string>
|
||||
<string name="bottom_hud_group">HUD на долния екран</string>
|
||||
|
||||
@@ -2194,6 +2194,9 @@
|
||||
<string name="bottom_companion_weight">Nosnost</string>
|
||||
<string name="bottom_companion_radio">Rádio</string>
|
||||
<string name="bottom_qam_title">Rychlý přístup</string>
|
||||
<string name="bottom_qam_align_left">Přesunout doleva</string>
|
||||
<string name="bottom_qam_align_center">Přesunout na střed</string>
|
||||
<string name="bottom_qam_align_right">Přesunout doprava</string>
|
||||
<string name="bottom_qam_unavailable">Nabídka rychlého přístupu Steamu zatím není k dispozici.</string>
|
||||
<string name="bottom_page_telemetry">Statistiky ve hře</string>
|
||||
<string name="bottom_hud_group">HUD na spodní obrazovce</string>
|
||||
|
||||
@@ -2144,6 +2144,9 @@
|
||||
<string name="bottom_companion_weight">Bæreevne</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Hurtig adgang</string>
|
||||
<string name="bottom_qam_align_left">Flyt til venstre</string>
|
||||
<string name="bottom_qam_align_center">Flyt til midten</string>
|
||||
<string name="bottom_qam_align_right">Flyt til højre</string>
|
||||
<string name="bottom_qam_unavailable">Steams menu til hurtig adgang er ikke tilgængelig endnu.</string>
|
||||
<string name="bottom_page_telemetry">Statistik i spillet</string>
|
||||
<string name="bottom_hud_group">HUD på nederste skærm</string>
|
||||
|
||||
@@ -2136,6 +2136,9 @@
|
||||
<string name="bottom_companion_weight">Traglast</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Schnellzugriff</string>
|
||||
<string name="bottom_qam_align_left">Nach links verschieben</string>
|
||||
<string name="bottom_qam_align_center">In die Mitte verschieben</string>
|
||||
<string name="bottom_qam_align_right">Nach rechts verschieben</string>
|
||||
<string name="bottom_qam_unavailable">Das Schnellzugriffsmenü von Steam ist noch nicht verfügbar.</string>
|
||||
<string name="bottom_page_telemetry">Spielstatistiken</string>
|
||||
<string name="bottom_hud_group">HUD für den unteren Bildschirm</string>
|
||||
|
||||
@@ -2144,6 +2144,9 @@
|
||||
<string name="bottom_companion_weight">Φορτίο</string>
|
||||
<string name="bottom_companion_radio">Ραδιόφωνο</string>
|
||||
<string name="bottom_qam_title">Γρήγορη πρόσβαση</string>
|
||||
<string name="bottom_qam_align_left">Μετακίνηση αριστερά</string>
|
||||
<string name="bottom_qam_align_center">Μετακίνηση στο κέντρο</string>
|
||||
<string name="bottom_qam_align_right">Μετακίνηση δεξιά</string>
|
||||
<string name="bottom_qam_unavailable">Το μενού γρήγορης πρόσβασης του Steam δεν είναι ακόμη διαθέσιμο.</string>
|
||||
<string name="bottom_page_telemetry">Στατιστικά παιχνιδιού</string>
|
||||
<string name="bottom_hud_group">HUD κάτω οθόνης</string>
|
||||
|
||||
@@ -2169,6 +2169,9 @@
|
||||
<string name="bottom_companion_weight">Peso cargado</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Acceso rápido</string>
|
||||
<string name="bottom_qam_align_left">Mover a la izquierda</string>
|
||||
<string name="bottom_qam_align_center">Mover al centro</string>
|
||||
<string name="bottom_qam_align_right">Mover a la derecha</string>
|
||||
<string name="bottom_qam_unavailable">El menú de acceso rápido de Steam aún no está disponible.</string>
|
||||
<string name="bottom_page_telemetry">Estadísticas del juego</string>
|
||||
<string name="bottom_hud_group">HUD de la pantalla inferior</string>
|
||||
|
||||
@@ -2144,6 +2144,9 @@
|
||||
<string name="bottom_companion_weight">Kantokyky</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Pikavalikko</string>
|
||||
<string name="bottom_qam_align_left">Siirrä vasemmalle</string>
|
||||
<string name="bottom_qam_align_center">Siirrä keskelle</string>
|
||||
<string name="bottom_qam_align_right">Siirrä oikealle</string>
|
||||
<string name="bottom_qam_unavailable">Steamin pikavalikko ei ole vielä käytettävissä.</string>
|
||||
<string name="bottom_page_telemetry">Pelinsisäiset tilastot</string>
|
||||
<string name="bottom_hud_group">Alanäytön HUD</string>
|
||||
|
||||
@@ -2168,6 +2168,9 @@
|
||||
<string name="bottom_companion_weight">Charge</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Accès rapide</string>
|
||||
<string name="bottom_qam_align_left">Déplacer à gauche</string>
|
||||
<string name="bottom_qam_align_center">Déplacer au centre</string>
|
||||
<string name="bottom_qam_align_right">Déplacer à droite</string>
|
||||
<string name="bottom_qam_unavailable">Le menu d’accès rapide de Steam n’est pas encore disponible.</string>
|
||||
<string name="bottom_page_telemetry">Statistiques en jeu</string>
|
||||
<string name="bottom_hud_group">HUD de l\'écran du bas</string>
|
||||
|
||||
@@ -2144,6 +2144,9 @@
|
||||
<string name="bottom_companion_weight">वज़न क्षमता</string>
|
||||
<string name="bottom_companion_radio">रेडियो</string>
|
||||
<string name="bottom_qam_title">क्विक एक्सेस</string>
|
||||
<string name="bottom_qam_align_left">बाईं ओर ले जाएँ</string>
|
||||
<string name="bottom_qam_align_center">बीच में ले जाएँ</string>
|
||||
<string name="bottom_qam_align_right">दाईं ओर ले जाएँ</string>
|
||||
<string name="bottom_qam_unavailable">Steam का क्विक एक्सेस मेनू अभी उपलब्ध नहीं है।</string>
|
||||
<string name="bottom_page_telemetry">इन-गेम आंकड़े</string>
|
||||
<string name="bottom_hud_group">निचली स्क्रीन HUD</string>
|
||||
|
||||
@@ -2144,6 +2144,9 @@
|
||||
<string name="bottom_companion_weight">Teherbírás</string>
|
||||
<string name="bottom_companion_radio">Rádió</string>
|
||||
<string name="bottom_qam_title">Gyorselérés</string>
|
||||
<string name="bottom_qam_align_left">Áthelyezés balra</string>
|
||||
<string name="bottom_qam_align_center">Áthelyezés középre</string>
|
||||
<string name="bottom_qam_align_right">Áthelyezés jobbra</string>
|
||||
<string name="bottom_qam_unavailable">A Steam gyorselérési menüje még nem érhető el.</string>
|
||||
<string name="bottom_page_telemetry">Játékon belüli statisztikák</string>
|
||||
<string name="bottom_hud_group">HUD az alsó képernyőn</string>
|
||||
|
||||
@@ -2120,6 +2120,9 @@
|
||||
<string name="bottom_companion_weight">Beban</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Akses Cepat</string>
|
||||
<string name="bottom_qam_align_left">Pindahkan ke kiri</string>
|
||||
<string name="bottom_qam_align_center">Pindahkan ke tengah</string>
|
||||
<string name="bottom_qam_align_right">Pindahkan ke kanan</string>
|
||||
<string name="bottom_qam_unavailable">Menu Akses Cepat Steam belum tersedia.</string>
|
||||
<string name="bottom_page_telemetry">Statistik dalam gim</string>
|
||||
<string name="bottom_hud_group">HUD layar bawah</string>
|
||||
|
||||
@@ -2160,6 +2160,9 @@
|
||||
<string name="bottom_companion_weight">Peso trasportato</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Accesso rapido</string>
|
||||
<string name="bottom_qam_align_left">Sposta a sinistra</string>
|
||||
<string name="bottom_qam_align_center">Sposta al centro</string>
|
||||
<string name="bottom_qam_align_right">Sposta a destra</string>
|
||||
<string name="bottom_qam_unavailable">Il menu di accesso rapido di Steam non è ancora disponibile.</string>
|
||||
<string name="bottom_page_telemetry">Statistiche di gioco</string>
|
||||
<string name="bottom_hud_group">HUD dello schermo inferiore</string>
|
||||
|
||||
@@ -2120,6 +2120,9 @@
|
||||
<string name="bottom_companion_weight">所持重量</string>
|
||||
<string name="bottom_companion_radio">ラジオ</string>
|
||||
<string name="bottom_qam_title">クイックアクセス</string>
|
||||
<string name="bottom_qam_align_left">左へ移動</string>
|
||||
<string name="bottom_qam_align_center">中央へ移動</string>
|
||||
<string name="bottom_qam_align_right">右へ移動</string>
|
||||
<string name="bottom_qam_unavailable">Steam のクイックアクセスメニューはまだ使えません。</string>
|
||||
<string name="bottom_page_telemetry">ゲーム内統計</string>
|
||||
<string name="bottom_hud_group">下部画面の HUD</string>
|
||||
|
||||
@@ -2120,6 +2120,9 @@
|
||||
<string name="bottom_companion_weight">소지 무게</string>
|
||||
<string name="bottom_companion_radio">라디오</string>
|
||||
<string name="bottom_qam_title">빠른 메뉴</string>
|
||||
<string name="bottom_qam_align_left">왼쪽으로 이동</string>
|
||||
<string name="bottom_qam_align_center">가운데로 이동</string>
|
||||
<string name="bottom_qam_align_right">오른쪽으로 이동</string>
|
||||
<string name="bottom_qam_unavailable">Steam 빠른 메뉴를 아직 사용할 수 없습니다.</string>
|
||||
<string name="bottom_page_telemetry">게임 내 통계</string>
|
||||
<string name="bottom_hud_group">하단 화면 HUD</string>
|
||||
|
||||
@@ -2120,6 +2120,9 @@
|
||||
<string name="bottom_companion_weight">Beban</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Akses Pantas</string>
|
||||
<string name="bottom_qam_align_left">Alih ke kiri</string>
|
||||
<string name="bottom_qam_align_center">Alih ke tengah</string>
|
||||
<string name="bottom_qam_align_right">Alih ke kanan</string>
|
||||
<string name="bottom_qam_unavailable">Menu Akses Pantas Steam belum tersedia.</string>
|
||||
<string name="bottom_page_telemetry">Statistik dalam permainan</string>
|
||||
<string name="bottom_hud_group">HUD skrin bawah</string>
|
||||
|
||||
@@ -2144,6 +2144,9 @@
|
||||
<string name="bottom_companion_weight">Bæreevne</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Hurtigtilgang</string>
|
||||
<string name="bottom_qam_align_left">Flytt til venstre</string>
|
||||
<string name="bottom_qam_align_center">Flytt til midten</string>
|
||||
<string name="bottom_qam_align_right">Flytt til høyre</string>
|
||||
<string name="bottom_qam_unavailable">Steams hurtigtilgangsmeny er ikke tilgjengelig ennå.</string>
|
||||
<string name="bottom_page_telemetry">Statistikk i spillet</string>
|
||||
<string name="bottom_hud_group">HUD på bunnskjermen</string>
|
||||
|
||||
@@ -2144,6 +2144,9 @@
|
||||
<string name="bottom_companion_weight">Draaggewicht</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Snelle toegang</string>
|
||||
<string name="bottom_qam_align_left">Naar links verplaatsen</string>
|
||||
<string name="bottom_qam_align_center">Naar het midden verplaatsen</string>
|
||||
<string name="bottom_qam_align_right">Naar rechts verplaatsen</string>
|
||||
<string name="bottom_qam_unavailable">Het menu Snelle toegang van Steam is nog niet beschikbaar.</string>
|
||||
<string name="bottom_page_telemetry">In-game statistieken</string>
|
||||
<string name="bottom_hud_group">HUD op het onderste scherm</string>
|
||||
|
||||
@@ -2194,6 +2194,9 @@
|
||||
<string name="bottom_companion_weight">Udźwig</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Szybki dostęp</string>
|
||||
<string name="bottom_qam_align_left">Przesuń w lewo</string>
|
||||
<string name="bottom_qam_align_center">Przesuń na środek</string>
|
||||
<string name="bottom_qam_align_right">Przesuń w prawo</string>
|
||||
<string name="bottom_qam_unavailable">Menu szybkiego dostępu Steam nie jest jeszcze dostępne.</string>
|
||||
<string name="bottom_page_telemetry">Statystyki w grze</string>
|
||||
<string name="bottom_hud_group">HUD dolnego ekranu</string>
|
||||
|
||||
@@ -2174,6 +2174,9 @@
|
||||
<string name="bottom_companion_weight">Peso transportado</string>
|
||||
<string name="bottom_companion_radio">Rádio</string>
|
||||
<string name="bottom_qam_title">Acesso rápido</string>
|
||||
<string name="bottom_qam_align_left">Mover para a esquerda</string>
|
||||
<string name="bottom_qam_align_center">Mover para o centro</string>
|
||||
<string name="bottom_qam_align_right">Mover para a direita</string>
|
||||
<string name="bottom_qam_unavailable">O menu de acesso rápido do Steam ainda não está disponível.</string>
|
||||
<string name="bottom_page_telemetry">Estatísticas no jogo</string>
|
||||
<string name="bottom_hud_group">HUD do ecrã inferior</string>
|
||||
|
||||
@@ -2182,6 +2182,9 @@
|
||||
<string name="bottom_companion_weight">Peso carregado</string>
|
||||
<string name="bottom_companion_radio">Rádio</string>
|
||||
<string name="bottom_qam_title">Acesso rápido</string>
|
||||
<string name="bottom_qam_align_left">Mover para a esquerda</string>
|
||||
<string name="bottom_qam_align_center">Mover para o centro</string>
|
||||
<string name="bottom_qam_align_right">Mover para a direita</string>
|
||||
<string name="bottom_qam_unavailable">O menu de acesso rápido do Steam ainda não está disponível.</string>
|
||||
<string name="bottom_page_telemetry">Estatísticas no jogo</string>
|
||||
<string name="bottom_hud_group">HUD da tela inferior</string>
|
||||
|
||||
@@ -2169,6 +2169,9 @@
|
||||
<string name="bottom_companion_weight">Greutate purtată</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Acces rapid</string>
|
||||
<string name="bottom_qam_align_left">Mută la stânga</string>
|
||||
<string name="bottom_qam_align_center">Mută în centru</string>
|
||||
<string name="bottom_qam_align_right">Mută la dreapta</string>
|
||||
<string name="bottom_qam_unavailable">Meniul de acces rapid Steam nu este încă disponibil.</string>
|
||||
<string name="bottom_page_telemetry">Statistici în joc</string>
|
||||
<string name="bottom_hud_group">HUD pe ecranul de jos</string>
|
||||
|
||||
@@ -2195,6 +2195,9 @@
|
||||
<string name="bottom_companion_weight">Переносимый вес</string>
|
||||
<string name="bottom_companion_radio">Радио</string>
|
||||
<string name="bottom_qam_title">Быстрый доступ</string>
|
||||
<string name="bottom_qam_align_left">Сдвинуть влево</string>
|
||||
<string name="bottom_qam_align_center">Сдвинуть в центр</string>
|
||||
<string name="bottom_qam_align_right">Сдвинуть вправо</string>
|
||||
<string name="bottom_qam_unavailable">Меню быстрого доступа Steam пока недоступно.</string>
|
||||
<string name="bottom_page_telemetry">Игровая статистика</string>
|
||||
<string name="bottom_hud_group">HUD нижнего экрана</string>
|
||||
|
||||
@@ -2144,6 +2144,9 @@
|
||||
<string name="bottom_companion_weight">Bärvikt</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Snabbåtkomst</string>
|
||||
<string name="bottom_qam_align_left">Flytta till vänster</string>
|
||||
<string name="bottom_qam_align_center">Flytta till mitten</string>
|
||||
<string name="bottom_qam_align_right">Flytta till höger</string>
|
||||
<string name="bottom_qam_unavailable">Steams snabbåtkomstmeny är inte tillgänglig än.</string>
|
||||
<string name="bottom_page_telemetry">Statistik i spelet</string>
|
||||
<string name="bottom_hud_group">HUD på nedre skärmen</string>
|
||||
|
||||
@@ -2120,6 +2120,9 @@
|
||||
<string name="bottom_companion_weight">น้ำหนักที่แบก</string>
|
||||
<string name="bottom_companion_radio">วิทยุ</string>
|
||||
<string name="bottom_qam_title">เข้าถึงด่วน</string>
|
||||
<string name="bottom_qam_align_left">ย้ายไปทางซ้าย</string>
|
||||
<string name="bottom_qam_align_center">ย้ายไปตรงกลาง</string>
|
||||
<string name="bottom_qam_align_right">ย้ายไปทางขวา</string>
|
||||
<string name="bottom_qam_unavailable">เมนูเข้าถึงด่วนของ Steam ยังไม่พร้อมใช้งาน</string>
|
||||
<string name="bottom_page_telemetry">สถิติในเกม</string>
|
||||
<string name="bottom_hud_group">HUD หน้าจอล่าง</string>
|
||||
|
||||
@@ -2136,6 +2136,9 @@
|
||||
<string name="bottom_companion_weight">Taşıma ağırlığı</string>
|
||||
<string name="bottom_companion_radio">Radyo</string>
|
||||
<string name="bottom_qam_title">Hızlı Erişim</string>
|
||||
<string name="bottom_qam_align_left">Sola taşı</string>
|
||||
<string name="bottom_qam_align_center">Ortaya taşı</string>
|
||||
<string name="bottom_qam_align_right">Sağa taşı</string>
|
||||
<string name="bottom_qam_unavailable">Steam Hızlı Erişim menüsü henüz kullanılamıyor.</string>
|
||||
<string name="bottom_page_telemetry">Oyun içi istatistikler</string>
|
||||
<string name="bottom_hud_group">Alt ekrandaki HUD</string>
|
||||
|
||||
@@ -2194,6 +2194,9 @@
|
||||
<string name="bottom_companion_weight">Вага ноші</string>
|
||||
<string name="bottom_companion_radio">Радіо</string>
|
||||
<string name="bottom_qam_title">Швидкий доступ</string>
|
||||
<string name="bottom_qam_align_left">Перемістити ліворуч</string>
|
||||
<string name="bottom_qam_align_center">Перемістити в центр</string>
|
||||
<string name="bottom_qam_align_right">Перемістити праворуч</string>
|
||||
<string name="bottom_qam_unavailable">Меню швидкого доступу Steam ще недоступне.</string>
|
||||
<string name="bottom_page_telemetry">Ігрова статистика</string>
|
||||
<string name="bottom_hud_group">HUD на нижньому екрані</string>
|
||||
|
||||
@@ -2120,6 +2120,9 @@
|
||||
<string name="bottom_companion_weight">Trọng lượng mang</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Truy cập nhanh</string>
|
||||
<string name="bottom_qam_align_left">Chuyển sang trái</string>
|
||||
<string name="bottom_qam_align_center">Chuyển vào giữa</string>
|
||||
<string name="bottom_qam_align_right">Chuyển sang phải</string>
|
||||
<string name="bottom_qam_unavailable">Menu Truy cập nhanh của Steam chưa sẵn sàng.</string>
|
||||
<string name="bottom_page_telemetry">Thông số trong game</string>
|
||||
<string name="bottom_hud_group">HUD màn hình dưới</string>
|
||||
|
||||
@@ -2197,6 +2197,9 @@
|
||||
<string name="bottom_companion_weight">负重</string>
|
||||
<string name="bottom_companion_radio">收音机</string>
|
||||
<string name="bottom_qam_title">快速访问</string>
|
||||
<string name="bottom_qam_align_left">移到左侧</string>
|
||||
<string name="bottom_qam_align_center">移到中间</string>
|
||||
<string name="bottom_qam_align_right">移到右侧</string>
|
||||
<string name="bottom_qam_unavailable">Steam 快速访问菜单暂不可用。</string>
|
||||
<string name="bottom_page_telemetry">游戏内数据</string>
|
||||
<string name="bottom_hud_group">下屏 HUD</string>
|
||||
|
||||
@@ -2119,6 +2119,9 @@
|
||||
<string name="bottom_companion_weight">負重</string>
|
||||
<string name="bottom_companion_radio">收音機</string>
|
||||
<string name="bottom_qam_title">快速存取</string>
|
||||
<string name="bottom_qam_align_left">移到左側</string>
|
||||
<string name="bottom_qam_align_center">移到中間</string>
|
||||
<string name="bottom_qam_align_right">移到右側</string>
|
||||
<string name="bottom_qam_unavailable">Steam 快速存取選單暫時無法使用。</string>
|
||||
<string name="bottom_page_telemetry">遊戲內數據</string>
|
||||
<string name="bottom_hud_group">下方螢幕 HUD</string>
|
||||
|
||||
@@ -2119,6 +2119,9 @@
|
||||
<string name="bottom_companion_weight">負重</string>
|
||||
<string name="bottom_companion_radio">收音機</string>
|
||||
<string name="bottom_qam_title">快速存取</string>
|
||||
<string name="bottom_qam_align_left">移到左側</string>
|
||||
<string name="bottom_qam_align_center">移到中間</string>
|
||||
<string name="bottom_qam_align_right">移到右側</string>
|
||||
<string name="bottom_qam_unavailable">Steam 快速存取選單暫時無法使用。</string>
|
||||
<string name="bottom_page_telemetry">遊戲內數據</string>
|
||||
<string name="bottom_hud_group">下螢幕 HUD</string>
|
||||
|
||||
@@ -2427,6 +2427,9 @@
|
||||
<string name="bottom_companion_weight">Carry weight</string>
|
||||
<string name="bottom_companion_radio">Radio</string>
|
||||
<string name="bottom_qam_title">Quick Access</string>
|
||||
<string name="bottom_qam_align_left">Move to the left</string>
|
||||
<string name="bottom_qam_align_center">Move to the center</string>
|
||||
<string name="bottom_qam_align_right">Move to the right</string>
|
||||
<string name="bottom_qam_unavailable">Steam\'s Quick Access menu is not available yet.</string>
|
||||
<string name="bottom_page_telemetry">In-game stats</string>
|
||||
<string name="bottom_hud_group">Bottom screen HUD</string>
|
||||
|
||||
@@ -18,6 +18,15 @@ class SteamQamTest {
|
||||
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"}]"""))
|
||||
@@ -46,6 +55,12 @@ class SteamQamTest {
|
||||
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 aWideMenuFitsTheWidth() {
|
||||
val (scale, left) = QamLayout.fit(1280f, 832f, 1280f, 640f)
|
||||
assertEquals(1f, scale, 0.001f)
|
||||
|
||||
@@ -165,23 +165,29 @@ Details: [bottom-screen-companion-api.md](bottom-screen-companion-api.md).
|
||||
|
||||
### 9. Steam's Quick Access menu on the bottom screen
|
||||
|
||||
**Status:** built as its own panel (Quick Access in the panel picker, Steam sessions only) and checked on a Retroid Pocket Duo Lite Plus in Big Picture and in a game. The bottom screen shows Steam's real Quick Access menu: notifications, friends and chat, quick settings, performance, soundtracks and help, plus any tab a plugin loader adds. Taps, drags and scrolling go to it; the controller stays on the top screen, so the d-pad drives the library or the game while the menu stays open. Code: [`session/SteamQam.kt`](../../app/src/main/java/com/droiddeck/launcher/session/SteamQam.kt), [`ui/BottomSteamQamPanel.kt`](../../app/src/main/java/com/droiddeck/launcher/ui/BottomSteamQamPanel.kt), [`droiddeck-qam-relay`](../../tools/linuxfs/overlay/usr/local/bin/droiddeck-qam-relay).
|
||||
**Status:** built as its own panel (Quick Access in the panel picker, Steam sessions only) and checked on a Retroid Pocket Duo Lite Plus in Big Picture and in a game. The bottom screen shows Steam's real Quick Access menu: notifications, friends and chat, quick settings, performance, soundtracks and help, plus Decky Loader's tab and its plugins when Decky is enabled. Taps, drags and scrolling go to it; the controller stays on the top screen, so the d-pad drives the library or the game while the menu stays open. Code: [`session/SteamQam.kt`](../../app/src/main/java/com/droiddeck/launcher/session/SteamQam.kt), [`ui/BottomSteamQamPanel.kt`](../../app/src/main/java/com/droiddeck/launcher/ui/BottomSteamQamPanel.kt), [`droiddeck-qam-relay`](../../tools/linuxfs/overlay/usr/local/bin/droiddeck-qam-relay).
|
||||
|
||||
Plugin loaders expose Steam's CEF DevTools so the menu can be viewed in a desktop browser, but it renders only while it is open on the main screen. The panel keeps it open without covering the top screen:
|
||||
|
||||
- Steam's UI is told to open the menu and keep it open: its composition request is capped at "notification" while the menu is ours, so gamescope keeps focus on the game, and losing focus no longer closes it. Gamepad focus moves from the menu back to the main UI only when the menu took it, so Steam's own popups keep the controller. The blurred backdrop is hidden.
|
||||
- The menu's browser view is placed just outside the Big Picture window through its own `SetBounds`, so it keeps rendering but never shows on top, including while Steam slides it wider for Friends and chat.
|
||||
- A timer inside Steam keeps this state every 250 ms, so the menu comes back as soon as Steam's main menu closes. It runs on a 5 s lease that the panel renews each second: if the app stops, Steam returns to normal by itself.
|
||||
- A timer inside Steam keeps this state every 250 ms, so the menu comes back, on the tab it was showing, as soon as Steam's main menu or a full-screen page such as Decky's store closes. It runs on a 5 s lease that the panel renews each second: if the app stops, Steam returns to normal by itself.
|
||||
- The hold starts only once the session is ready: holding the menu before Steam's first frame kept gamescope from presenting anything.
|
||||
- `droiddeck-qam-relay` relays the app to the DevTools port, which only answers clients inside the guest. The panel streams the menu with `Page.startScreencast`, scales its content to the panel and fills the rest with the menu's own background, and forwards touches with `Input.dispatchTouchEvent`.
|
||||
- `droiddeck-qam-relay` relays the app to the DevTools port, which only answers clients inside the guest. The panel streams the menu with `Page.startScreencast`, scales its content to the panel and fills the rest with the menu's own background, and forwards touches on the menu with `Input.dispatchTouchEvent`. When the menu is narrower than the panel, buttons in the free space move it left, centre or right; the choice is kept.
|
||||
- Leaving the panel closes the menu and turns the patches off; the Steam button and the normal Quick Access button then work as before. Opening Steam's main menu replaces the Quick Access menu for as long as it is open, as on a Deck.
|
||||
|
||||
Limits: it relies on Steam's minified UI stores and method names, so a client update can break it; the panel then shows that the menu is not available. Plugin tabs appear only if a loader is installed in the session.
|
||||
Checked with Decky Loader 3.3.1 enabled: its tab renders and takes touch, and its store opens full screen on top with the controller, then returns to the Decky tab below.
|
||||
|
||||
Limits: it relies on Steam's minified UI stores and method names, so a client update can break it; the panel then shows that the menu is not available.
|
||||
|
||||
| Big Picture, friends | In game, performance | In game, quick settings |
|
||||
| --- | --- | --- |
|
||||
|  |  |  |
|
||||
|
||||
| Decky, centred | Decky, aligned right |
|
||||
| --- | --- |
|
||||
|  |  |
|
||||
|
||||
The top screen during that game, with the menu open on the bottom: 
|
||||
|
||||
## Related fixes
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 75 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 73 KiB |
@@ -2,7 +2,7 @@
|
||||
# Relays the app to Steam's DevTools port, which only answers clients inside the guest, while the bottom screen
|
||||
# shows Steam's quick access menu.
|
||||
# droiddeck-qam-relay start <devtools port> prints the relay port
|
||||
# droiddeck-qam-relay stop
|
||||
# droiddeck-qam-relay stop [<relay port>] stops the relay, or only the one on that port
|
||||
|
||||
import os
|
||||
import socket
|
||||
@@ -18,9 +18,9 @@ MAX_SECONDS = 6 * 3600
|
||||
def owner():
|
||||
try:
|
||||
with open(FLAG) as f:
|
||||
return f.read().strip()
|
||||
return f.read().split()
|
||||
except OSError:
|
||||
return None
|
||||
return []
|
||||
|
||||
|
||||
def pipe(src, dst):
|
||||
@@ -57,21 +57,23 @@ def relay(server, devtools_port):
|
||||
def serve(server, devtools_port, me):
|
||||
threading.Thread(target=relay, args=(server, devtools_port), daemon=True).start()
|
||||
started = time.monotonic()
|
||||
while owner() == me and time.monotonic() - started < MAX_SECONDS:
|
||||
while owner()[:1] == [me] and time.monotonic() - started < MAX_SECONDS:
|
||||
time.sleep(INTERVAL)
|
||||
server.close()
|
||||
|
||||
|
||||
def main():
|
||||
command = sys.argv[1] if len(sys.argv) > 1 else ""
|
||||
if command == "stop" and len(sys.argv) == 2:
|
||||
if command == "stop" and len(sys.argv) in (2, 3):
|
||||
if len(sys.argv) == 3 and owner()[1:] != [sys.argv[2]]:
|
||||
return 0
|
||||
try:
|
||||
os.unlink(FLAG)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
return 0
|
||||
if command != "start" or len(sys.argv) != 3:
|
||||
print("usage: droiddeck-qam-relay start <devtools port> | stop", file=sys.stderr)
|
||||
print("usage: droiddeck-qam-relay start <devtools port> | stop [<relay port>]", file=sys.stderr)
|
||||
return 2
|
||||
devtools_port = int(sys.argv[2])
|
||||
server = socket.socket()
|
||||
@@ -84,7 +86,7 @@ def main():
|
||||
os.setsid()
|
||||
me = str(os.getpid())
|
||||
with open(FLAG, "w") as f:
|
||||
f.write(me)
|
||||
f.write("%s %d" % (me, server.getsockname()[1]))
|
||||
devnull = os.open(os.devnull, os.O_RDWR)
|
||||
for fd in (0, 1, 2):
|
||||
os.dup2(devnull, fd)
|
||||
|
||||
@@ -27,7 +27,7 @@ class QamRelayTest(unittest.TestCase):
|
||||
self.relay.FLAG = str(self.tmp / "flag")
|
||||
self.relay.INTERVAL = 0.05
|
||||
|
||||
def test_pipes_bytes_both_ways_until_stopped(self):
|
||||
def test_pipes_bytes_both_ways_until_its_own_port_is_stopped(self):
|
||||
upstream = socket.socket()
|
||||
upstream.bind(("127.0.0.1", 0))
|
||||
upstream.listen(1)
|
||||
@@ -43,20 +43,24 @@ class QamRelayTest(unittest.TestCase):
|
||||
server.bind(("127.0.0.1", 0))
|
||||
server.listen(1)
|
||||
port = server.getsockname()[1]
|
||||
Path(self.relay.FLAG).write_text("me")
|
||||
Path(self.relay.FLAG).write_text("me %d" % port)
|
||||
serving = threading.Thread(target=self.relay.serve, args=(server, upstream.getsockname()[1], "me"), daemon=True)
|
||||
serving.start()
|
||||
with socket.create_connection(("127.0.0.1", port), 2) as client:
|
||||
client.sendall(b"GET /json")
|
||||
client.settimeout(2)
|
||||
self.assertEqual(b"answer:GET /json", client.recv(100))
|
||||
with mock.patch.object(self.relay.sys, "argv", ["x", "stop"]):
|
||||
with mock.patch.object(self.relay.sys, "argv", ["x", "stop", str(port + 1)]):
|
||||
self.assertEqual(0, self.relay.main())
|
||||
serving.join(0.3)
|
||||
self.assertTrue(serving.is_alive())
|
||||
with mock.patch.object(self.relay.sys, "argv", ["x", "stop", str(port)]):
|
||||
self.assertEqual(0, self.relay.main())
|
||||
serving.join(2)
|
||||
self.assertFalse(serving.is_alive())
|
||||
|
||||
def test_rejects_unknown_commands(self):
|
||||
for argv in (["x"], ["x", "start"], ["x", "size", "1", "2"]):
|
||||
for argv in (["x"], ["x", "start"], ["x", "stop", "1", "2"]):
|
||||
with mock.patch.object(self.relay.sys, "argv", argv), mock.patch.object(self.relay.sys, "stderr"):
|
||||
self.assertEqual(2, self.relay.main())
|
||||
|
||||
|
||||
Reference in new issue
Block a user