mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 13:05:47 +00:00
fix(bottom): follow Steam's selection for any game, composite while mirroring
This commit is contained in:
1 parent
d84044a41a
commit
4ade79dc7f
7 files changed
+73
-19
No files matched your search
@@ -4650,6 +4650,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
runningGame = { gestureGame },
|
||||
quick = { drawerActions },
|
||||
copyRegion = ::copyGameRegion,
|
||||
holdComposed = ::holdComposedOutput,
|
||||
screenOff = { secondScreenPresentation?.screenOff() },
|
||||
))
|
||||
|
||||
@@ -5967,7 +5968,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
if (zeroCopyActive()) {
|
||||
WaylandCompositor.nativeSetZeroCopy(false)
|
||||
val restore = java.util.concurrent.atomic.AtomicBoolean(false)
|
||||
val back = { if (restore.compareAndSet(false, true)) WaylandCompositor.nativeSetZeroCopy(true) }
|
||||
val back = { if (restore.compareAndSet(false, true)) WaylandCompositor.nativeSetZeroCopy(composedHolds == 0) }
|
||||
uiHandler.postDelayed({ capturePausedFrame(manual = true, onDone = back) }, ZERO_COPY_SETTLE_MS)
|
||||
uiHandler.postDelayed({ back() }, ZERO_COPY_RESTORE_MS)
|
||||
} else {
|
||||
@@ -5976,6 +5977,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
|
||||
SessionService.pause(this)
|
||||
}
|
||||
|
||||
private var composedHolds = 0
|
||||
|
||||
private fun holdComposedOutput(hold: Boolean) {
|
||||
composedHolds = (composedHolds + if (hold) 1 else -1).coerceAtLeast(0)
|
||||
if (zeroCopyActive()) WaylandCompositor.nativeSetZeroCopy(composedHolds == 0)
|
||||
}
|
||||
|
||||
private fun zeroCopyActive(): Boolean =
|
||||
CompositorHost.isStarted && !SessionState.hdr && SessionPrefs.zeroCopy(this, SessionState.mode)
|
||||
|
||||
|
||||
@@ -21,17 +21,9 @@ import com.droiddeck.launcher.stores.SteamAchievements
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.isActive
|
||||
|
||||
private const val GAME_POLL_MS = 2_000L
|
||||
|
||||
@Composable
|
||||
internal fun BottomAchievementsPage(runningGame: () -> String?) {
|
||||
var appId by remember { mutableStateOf(runningGame()?.toLongOrNull()) }
|
||||
LaunchedEffect(Unit) {
|
||||
while (isActive) {
|
||||
appId = runningGame()?.toLongOrNull()
|
||||
delay(GAME_POLL_MS)
|
||||
}
|
||||
}
|
||||
val appId = rememberShownGame(runningGame)
|
||||
val game = remember(appId) { appId?.let(SteamAchievements::game) }
|
||||
val state = rememberAchievements(game)
|
||||
if (game == null || state == null) {
|
||||
|
||||
@@ -56,8 +56,6 @@ import kotlinx.coroutines.withContext
|
||||
import java.io.File
|
||||
import kotlin.coroutines.resume
|
||||
|
||||
private const val GAME_POLL_MS = 2_000L
|
||||
|
||||
private sealed class GuideList {
|
||||
object Loading : GuideList()
|
||||
object Failed : GuideList()
|
||||
@@ -67,13 +65,7 @@ private sealed class GuideList {
|
||||
@Composable
|
||||
internal fun BottomGuidesPage(runningGame: () -> String?) {
|
||||
val context = LocalContext.current
|
||||
var appId by remember { mutableStateOf(runningGame()?.toLongOrNull()) }
|
||||
LaunchedEffect(Unit) {
|
||||
while (isActive) {
|
||||
appId = runningGame()?.toLongOrNull()
|
||||
delay(GAME_POLL_MS)
|
||||
}
|
||||
}
|
||||
val appId = rememberShownGame(runningGame)
|
||||
val id = appId
|
||||
if (id == null) {
|
||||
PageNote(stringResource(R.string.bottom_guides_no_game))
|
||||
|
||||
@@ -58,7 +58,30 @@ internal object IdleHome {
|
||||
return games.filter { it.lastPlayed > 0 }.maxByOrNull { it.lastPlayed }?.let { it to false }
|
||||
}
|
||||
|
||||
class Overview(val name: String, val minutes: Long, val lastPlayed: Long)
|
||||
|
||||
fun overviewExpression(appId: Long): String = "(() => { const o = globalThis.appStore?.GetAppOverviewByAppID?.($appId); " +
|
||||
"return o ? JSON.stringify({name: o.display_name, minutes: o.minutes_playtime_forever, last: o.rt_last_time_played}) : null; })()"
|
||||
|
||||
fun parseOverview(json: String?): Overview? = runCatching {
|
||||
val o = org.json.JSONObject(json ?: return null)
|
||||
Overview(o.optString("name").ifEmpty { return null }, o.optLong("minutes"), o.optLong("last"))
|
||||
}.getOrNull()
|
||||
|
||||
private fun overview(context: Context, appId: Long): Overview? = runCatching {
|
||||
val answer = AgentGuest.steamEval(context, overviewExpression(appId), 4_000)
|
||||
if (!answer.optBoolean("ok")) null else parseOverview(answer.opt("value")?.takeIf { it != org.json.JSONObject.NULL }?.toString())
|
||||
}.getOrNull()
|
||||
|
||||
fun load(context: Context, games: List<Library.SteamGame>, selected: Long?): IdleGame? {
|
||||
if (selected != null) overview(context, selected)?.let { o ->
|
||||
val id = selected.toInt()
|
||||
val art = games.firstOrNull { it.appId == id }?.let { it.hero ?: it.art } ?: runCatching {
|
||||
Library.steamCacheImage(File(SessionPrefs.activeSteamRoot(context), "appcache/librarycache"), id,
|
||||
listOf("library_hero.jpg", "library_600x900.jpg", "header.jpg"))
|
||||
}.getOrNull()
|
||||
return IdleGame(id, o.name, art, o.minutes, o.lastPlayed, highlighted = true)
|
||||
}
|
||||
val (game, highlighted) = pick(games, selected) ?: return null
|
||||
val stats = runCatching { SteamLocalConfig.appStats(SessionPrefs.activeSteamRoot(context), game.appId) }.getOrNull()
|
||||
return IdleGame(
|
||||
@@ -72,6 +95,20 @@ internal object IdleHome {
|
||||
|
||||
private const val SELECTION_MS = 2_000L
|
||||
|
||||
@Composable
|
||||
internal fun rememberShownGame(runningGame: () -> String?): Long? {
|
||||
val context = LocalContext.current
|
||||
var appId by remember { mutableStateOf(runningGame()?.toLongOrNull()) }
|
||||
LaunchedEffect(Unit) {
|
||||
while (isActive) {
|
||||
appId = runningGame()?.toLongOrNull()
|
||||
?: withContext(Dispatchers.IO) { runCatching { AgentGuest.selectedSteamAppId(context) }.getOrNull() }
|
||||
delay(SELECTION_MS)
|
||||
}
|
||||
}
|
||||
return appId
|
||||
}
|
||||
|
||||
@Composable
|
||||
internal fun BottomIdleHome(modifier: Modifier = Modifier) {
|
||||
val context = LocalContext.current
|
||||
|
||||
@@ -18,6 +18,7 @@ import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.DisposableEffect
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
@@ -73,6 +74,7 @@ internal object MirrorRegion {
|
||||
}
|
||||
|
||||
private const val FRAME_MS = 66L
|
||||
private const val COMPOSED_SETTLE_MS = 250L
|
||||
private const val EDIT_WIDTH = 960
|
||||
private const val EDIT_HEIGHT = 540
|
||||
private const val LIVE_LONGEST = 720
|
||||
@@ -85,6 +87,10 @@ internal fun BottomMirrorPage(actions: BottomPageActions) {
|
||||
MirrorNote(stringResource(R.string.bottom_mirror_no_frame))
|
||||
return
|
||||
}
|
||||
DisposableEffect(Unit) {
|
||||
actions.holdComposed(true)
|
||||
onDispose { actions.holdComposed(false) }
|
||||
}
|
||||
val game = actions.runningGame() ?: "steam"
|
||||
var region by remember(game) { mutableStateOf(MirrorRegion.parse(SessionPrefs.mirrorRegion(context, game))) }
|
||||
var editing by remember(game) { mutableStateOf(region == null) }
|
||||
@@ -139,6 +145,7 @@ private fun MirrorEditor(
|
||||
var end by remember { mutableStateOf<Offset?>(null) }
|
||||
var picked by remember { mutableStateOf(current) }
|
||||
LaunchedEffect(Unit) {
|
||||
delay(COMPOSED_SETTLE_MS)
|
||||
val bitmap = capture(copy, null, EDIT_WIDTH, EDIT_HEIGHT)
|
||||
failed = bitmap == null
|
||||
still = bitmap?.asImageBitmap()
|
||||
|
||||
@@ -35,6 +35,7 @@ class BottomPageActions(
|
||||
val quick: () -> DrawerActions? = { null },
|
||||
val screenOff: (() -> Unit)? = null,
|
||||
val copyRegion: ((android.graphics.RectF?, Int, Int, (android.graphics.Bitmap?) -> Unit) -> Unit)? = null,
|
||||
val holdComposed: (Boolean) -> Unit = {},
|
||||
)
|
||||
|
||||
internal const val BOTTOM_PAGE_TELEMETRY = "telemetry"
|
||||
|
||||
@@ -4,7 +4,12 @@ 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),
|
||||
@@ -31,4 +36,16 @@ class BottomIdleHomeTest {
|
||||
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)"))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user