feat(running_apps): media_dag_running_apps enrichment — TTL-capped last_known_state/last_known_title for apps without a live session (P3-3b)

This commit is contained in:
James Mackay committed 2026-10-08 10:42:41 +01:00
1 parent aa4ee7ed62
commit 1f0a4b2021
3 files changed
+41

No files matched your search

@@ -12,6 +12,7 @@ def running_apps_from_tasks(
recent_tasks: list[dict],
media_sessions: list[MediaSessionInfo] | None = None,
foreground_package: str | None = None,
last_known: dict[str, MediaSessionInfo] | None = None,
) -> list[dict] | None:
"""Build a list of running app dicts from recent tasks + media sessions.
@@ -19,6 +20,9 @@ def running_apps_from_tasks(
recent_tasks: List of {"package": str} from ADB recent tasks.
media_sessions: Optional media sessions for playback state enrichment.
foreground_package: The current foreground app package.
last_known: Optional per-package TTL-filtered last-known-state cache
(P3-3b) — apps without a live session carry their last known
playback state as ``last_known_state``/``last_known_title``.
Returns None if there are fewer than 2 apps (no point showing a switcher
with only one option).
@@ -57,6 +61,15 @@ def running_apps_from_tasks(
app["artist"] = session.artist
else:
app["state"] = "running"
# P3-3b: no live session — surface the TTL-capped last-known state
cached = (last_known or {}).get(pkg)
if cached is not None:
if cached.playing:
app["last_known_state"] = "playing"
elif cached.paused:
app["last_known_state"] = "paused"
if cached.title:
app["last_known_title"] = cached.title
apps.append(app)