Keep the session drawer open while the agent's file picker is up (#3696)

Preserve the Agent page and its result handler while the system picker covers the session, including on a docked second screen.
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-12-04 11:00:09 -05:00
1 parent a9f2017aa3
commit 26b11c6838
5 files changed
+36 -3

No files matched your search

@@ -6495,7 +6495,13 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
displayManager.unregisterDisplayListener(displayListener)
com.droiddeck.launcher.input.DualScreen.unwatchTaken(bottomScreenListener)
contentResolver.unregisterContentObserver(refreshSettingObserver)
if (!screenIsOff()) closeSecondScreen(reset = false)
// Closing the presentation removes the docked Agent page and unregisters its picker.
if (com.droiddeck.launcher.session.SessionVisibilityPolicy.shouldCloseSecondScreenOnStop(
screenOff = screenIsOff(),
dockedDrawerOpen = menuShownOnBottom(),
attachmentPickerOpen = com.droiddeck.launcher.agent.AgentAttachments.picking,
)
) closeSecondScreen(reset = false)
sessionTextInput.stop()
startedScreens = (startedScreens - 1).coerceAtLeast(0)
updateGlassesScreen()
@@ -6532,6 +6538,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
override fun onResume() {
super.onResume()
com.droiddeck.launcher.agent.AgentAttachments.picking = false
drawerGameInventoryRevision++
com.droiddeck.launcher.input.SystemKeyCapture.attach(this, { hasWindowFocus() && !appUiOwnsPointer() && CompositorHost.isStarted }) { event ->
com.droiddeck.launcher.input.GuestKeys.send(event) { code, down -> sendGuestKey(code, down, 8) }
@@ -6645,7 +6652,7 @@ class SessionActivity : ComponentActivity(), SurfaceHolder.Callback, com.droidde
heldButtons.clear()
if (!screenOff) {
val menuUp = menuShownOnBottom()
drawerOpen = false
if (!com.droiddeck.launcher.agent.AgentAttachments.picking) drawerOpen = false
if (menuUp) SessionState.bottomMenu = true
pcKeyboardOpen = false
achievementsOpen = false
@@ -19,6 +19,9 @@ object AgentAttachments {
/** Guest paths waiting to go with the next message. */
val pending = mutableStateListOf<String>()
/** True while the file picker is open over a session: it answers the drawer's agent page, so the drawer must stay. */
@Volatile var picking = false
private const val NEW = "new"
private const val GUEST_DIR = "/root/.cache/droiddeck/attachments"
private val IMAGE = setOf("png", "jpg", "jpeg", "webp", "gif", "bmp")
@@ -1,6 +1,12 @@
package com.droiddeck.launcher.session
internal object SessionVisibilityPolicy {
fun shouldCloseSecondScreenOnStop(
screenOff: Boolean,
dockedDrawerOpen: Boolean,
attachmentPickerOpen: Boolean,
): Boolean = !screenOff && !(dockedDrawerOpen && attachmentPickerOpen)
fun isHidden(
activityStarted: Boolean,
defaultDisplayOn: Boolean,
@@ -1007,6 +1007,7 @@ private fun AttachButton() {
val context = LocalContext.current
val pal = LocalPalette.current
val picker = rememberLauncherForActivityResult(ActivityResultContracts.OpenMultipleDocuments()) { uris ->
AgentAttachments.picking = false
if (uris.isEmpty()) return@rememberLauncherForActivityResult
val chat = AgentHost.chat
Thread({
@@ -1017,7 +1018,8 @@ private fun AttachButton() {
}, "agent-attach").start()
}
RoundButton(Icons.Outlined.AttachFile, stringResource(R.string.agent_attach), pal.surfaceVariant, pal.onBackground, "agent-attach") {
runCatching { picker.launch(arrayOf("*/*")) }
AgentAttachments.picking = true
if (runCatching { picker.launch(arrayOf("*/*")) }.isFailure) AgentAttachments.picking = false
}
}
@@ -5,6 +5,21 @@ import org.junit.Assert.assertTrue
import org.junit.Test
class SessionVisibilityPolicyTest {
@Test fun attachmentPickerKeepsTheDockedDrawerAliveDuringActivityStop() {
assertFalse(SessionVisibilityPolicy.shouldCloseSecondScreenOnStop(
screenOff = false, dockedDrawerOpen = true, attachmentPickerOpen = true,
))
assertTrue(SessionVisibilityPolicy.shouldCloseSecondScreenOnStop(
screenOff = false, dockedDrawerOpen = true, attachmentPickerOpen = false,
))
assertTrue(SessionVisibilityPolicy.shouldCloseSecondScreenOnStop(
screenOff = false, dockedDrawerOpen = false, attachmentPickerOpen = true,
))
assertFalse(SessionVisibilityPolicy.shouldCloseSecondScreenOnStop(
screenOff = true, dockedDrawerOpen = false, attachmentPickerOpen = false,
))
}
@Test fun handsetScreenStateControlsActivityOnDefaultDisplay() {
assertFalse(SessionVisibilityPolicy.isHidden(true, true, true, false))
assertTrue(SessionVisibilityPolicy.isHidden(true, false, true, true))