ADFA-3645 | Open terminal in adjacent window on large screens#1173
ADFA-3645 | Open terminal in adjacent window on large screens#1173
Conversation
📝 Walkthrough
Risks & best-practice considerations
WalkthroughCentralizes multi-window/task intent-flag logic into Changes
Sequence Diagram(s)sequenceDiagram
participant Activity as Activity Component
participant Intent as Intent Object
participant Ext as applyMultiWindowFlags()
participant DFF as DeviceFormFactorUtils
participant AM as ActivityManager
Activity->>Intent: create Intent(context, TargetActivity)
Activity->>Ext: Intent.applyMultiWindowFlags(context)
Ext->>DFF: getCurrent(context)
alt Large-screen-like
Ext->>Intent: add NEW_TASK, NEW_DOCUMENT, SINGLE_TOP, LAUNCH_ADJACENT
else Non-large-screen
Ext->>Intent: add NEW_TASK (if context !is Activity)
end
Ext-->>Activity: return modified Intent
Activity->>AM: startActivity(modified Intent)
rect rgba(100,150,200,0.5)
Note over Activity,AM: Centralized multi-window flag application before launch
end
sequenceDiagram
participant System as System/Intent Router
participant TA as TerminalActivity
participant TS as TermuxService
participant Session as TermuxSession
System->>TA: deliver onNewIntent(intent)
TA->>TA: setIntent(intent)
TA->>TA: extract extras (workDir, sessionName, failsafe)
alt mTermuxService != null
TA->>TS: createTermuxSession(workDir, sessionName, failsafe)
TS-->>TA: newSession
alt newSession != null
TA->>TA: setCurrentSession(newSession.terminalSession)
end
else mTermuxService == null
TA->>TA: cache pendingWorkDir/pendingSessionName/pendingFailsafe
end
rect rgba(150,100,200,0.5)
Note over TA,TS: Incoming intents can spawn or queue terminal sessions
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
termux/termux-app/src/main/java/com/itsaky/androidide/activities/TerminalActivity.kt (1)
51-56:⚠️ Potential issue | 🟡 MinorQueue session requests when
mTermuxServiceis temporarily unavailable.If a relaunch intent arrives while
mTermuxServiceis null, the request is dropped and no session is created. Consider buffering the request and consuming it inonServiceConnectedto avoid missed opens in edge cases.🔧 Proposed fix
class TerminalActivity : TermuxActivity() { + private data class PendingSessionRequest( + val workingDir: String?, + val sessionName: String?, + val isFailsafe: Boolean, + ) + + private var pendingSessionRequest: PendingSessionRequest? = null + override fun onServiceConnected(componentName: ComponentName?, service: IBinder?) { super.onServiceConnected(componentName, service) + pendingSessionRequest?.let { req -> + pendingSessionRequest = null + createAndSelectSession(req.workingDir, req.sessionName, req.isFailsafe) + } lifecycleScope.launch(Dispatchers.IO) { Environment.mkdirIfNotExists(Environment.TMP_DIR) } } - override fun onNewIntent(intent: Intent?) { - super.onNewIntent(intent) - setIntent(intent) - if (intent == null) return + override fun onNewIntent(intent: Intent?) { + super.onNewIntent(intent) + if (intent == null) return + setIntent(intent) - val newWorkingDir = intent.getStringExtra(TermuxConstants.TERMUX_APP.TERMUX_ACTIVITY.EXTRA_SESSION_WORKING_DIR) - val newSessionName = intent.getStringExtra(TermuxConstants.TERMUX_APP.TERMUX_ACTIVITY.EXTRA_SESSION_NAME) - val isFailsafe = intent.getBooleanExtra(TermuxConstants.TERMUX_APP.TERMUX_ACTIVITY.EXTRA_FAILSAFE_SESSION, false) + val newWorkingDir = + intent.getStringExtra(TermuxConstants.TERMUX_APP.TERMUX_ACTIVITY.EXTRA_SESSION_WORKING_DIR) + val newSessionName = + intent.getStringExtra(TermuxConstants.TERMUX_APP.TERMUX_ACTIVITY.EXTRA_SESSION_NAME) + val isFailsafe = + intent.getBooleanExtra(TermuxConstants.TERMUX_APP.TERMUX_ACTIVITY.EXTRA_FAILSAFE_SESSION, false) - val service = mTermuxService - if (service != null) { - val newSession = service.createTermuxSession( - null, - null, - null, - newWorkingDir, - isFailsafe, - newSessionName - ) + if (mTermuxService == null) { + pendingSessionRequest = PendingSessionRequest(newWorkingDir, newSessionName, isFailsafe) + return + } - if (newSession != null) { - mTermuxTerminalSessionActivityClient.setCurrentSession(newSession.terminalSession) - } - } + createAndSelectSession(newWorkingDir, newSessionName, isFailsafe) + } + + private fun createAndSelectSession(workingDir: String?, sessionName: String?, isFailsafe: Boolean) { + val newSession = + mTermuxService?.createTermuxSession(null, null, null, workingDir, isFailsafe, sessionName) + if (newSession != null) { + mTermuxTerminalSessionActivityClient.setCurrentSession(newSession.terminalSession) } + } }Also applies to: 58-81
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@termux/termux-app/src/main/java/com/itsaky/androidide/activities/TerminalActivity.kt` around lines 51 - 56, The relaunch requests get dropped when mTermuxService is null; add a small queue (e.g., pendingRelaunchIntents: MutableList<Intent>) and update the code path that handles incoming relaunch intents (the method that currently creates sessions from the Intent—call it handleRelaunchIntent/processRelaunchIntent) to push the Intent into pendingRelaunchIntents if mTermuxService == null, otherwise process immediately; then in onServiceConnected, after mTermuxService is set, drain pendingRelaunchIntents and call the same session-creation logic for each queued Intent so no requests are lost.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In
`@termux/termux-app/src/main/java/com/itsaky/androidide/activities/TerminalActivity.kt`:
- Around line 51-56: The relaunch requests get dropped when mTermuxService is
null; add a small queue (e.g., pendingRelaunchIntents: MutableList<Intent>) and
update the code path that handles incoming relaunch intents (the method that
currently creates sessions from the Intent—call it
handleRelaunchIntent/processRelaunchIntent) to push the Intent into
pendingRelaunchIntents if mTermuxService == null, otherwise process immediately;
then in onServiceConnected, after mTermuxService is set, drain
pendingRelaunchIntents and call the same session-creation logic for each queued
Intent so no requests are lost.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ae7aeae2-66ea-4c03-aeb6-8847a462b72e
📒 Files selected for processing (5)
app/src/main/java/com/itsaky/androidide/actions/main/OpenTerminalAction.ktapp/src/main/java/com/itsaky/androidide/actions/sidebar/TerminalSidebarAction.ktcommon/src/main/java/com/itsaky/androidide/activities/editor/HelpActivity.ktcommon/src/main/java/com/itsaky/androidide/utils/IntentExtensions.kttermux/termux-app/src/main/java/com/itsaky/androidide/activities/TerminalActivity.kt
Extract multi-window intent flags and handle new intents in TerminalActivity.
05ab922 to
8430e53
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@termux/termux-app/src/main/java/com/itsaky/androidide/activities/TerminalActivity.kt`:
- Around line 67-81: Currently if mTermuxService is null the createTermuxSession
request is dropped; instead capture the pending session parameters
(newWorkingDir, isFailsafe, newSessionName or null) and enqueue them (e.g.,
store in a pendingSessionRequest field) and then replay/flush this request when
the service becomes available (in the service connection callback or where
mTermuxService is set) by calling createTermuxSession and then
mTermuxTerminalSessionActivityClient.setCurrentSession(...) as in the existing
success path; ensure only one pending request is stored or queued to avoid
duplication and clear the pendingSessionRequest after successful replay.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 451a9187-342f-4b26-8070-179d867de311
📒 Files selected for processing (5)
app/src/main/java/com/itsaky/androidide/actions/main/OpenTerminalAction.ktapp/src/main/java/com/itsaky/androidide/actions/sidebar/TerminalSidebarAction.ktcommon/src/main/java/com/itsaky/androidide/activities/editor/HelpActivity.ktcommon/src/main/java/com/itsaky/androidide/utils/IntentExtensions.kttermux/termux-app/src/main/java/com/itsaky/androidide/activities/TerminalActivity.kt
🚧 Files skipped from review as they are similar to previous changes (3)
- app/src/main/java/com/itsaky/androidide/actions/main/OpenTerminalAction.kt
- app/src/main/java/com/itsaky/androidide/actions/sidebar/TerminalSidebarAction.kt
- common/src/main/java/com/itsaky/androidide/utils/IntentExtensions.kt
termux/termux-app/src/main/java/com/itsaky/androidide/activities/TerminalActivity.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@termux/termux-app/src/main/java/com/itsaky/androidide/activities/TerminalActivity.kt`:
- Around line 61-67: The replay check in TerminalActivity incorrectly skips
creating a session when both pendingWorkingDir and pendingSessionName are null
but a pending intent still expects action (e.g., pendingIsFailsafe true); add a
dedicated flag (e.g., pendingSessionPending) that onNewIntent sets whenever you
cache intent state and clear only after replay, then change the service-ready
block to call createAndSetSession(termuxService, pendingWorkingDir,
pendingSessionName, pendingIsFailsafe) whenever pendingSessionPending is true
(or pendingIsFailsafe remains true) rather than relying solely on
(pendingWorkingDir != null || pendingSessionName != null); update
onServiceConnected and onNewIntent to set/clear pendingSessionPending
appropriately and ensure pendingWorkingDir/pendingSessionName/pendingIsFailsafe
are reset after createAndSetSession.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: dd196d5b-3d0c-4787-889f-9012224e3d55
📒 Files selected for processing (1)
termux/termux-app/src/main/java/com/itsaky/androidide/activities/TerminalActivity.kt
Description
Added support for launching the terminal in a secondary adjacent window (split-screen) when users are on a tablet or DeX device. This allows users to read their code in the editor and interact with the terminal at the same time. The multi-window intent flags were extracted into a reusable
Intent.applyMultiWindowFlags()extension function, which is now applied to terminal actions. Additionally,TerminalActivitywas updated to handleonNewIntentso that new terminal sessions are created correctly when the activity is already open.Details
IntentExtensions.ktto centralize large screen / multi-window intent flag configurations.OpenTerminalActionandTerminalSidebarAction.onNewIntentinTerminalActivityto instantiate anewTermuxSessionwhen the activity is launched again.document_5100351222519432845.mp4
Ticket
ADFA-3645
Observation
Because the multi-window launch uses
Intent.FLAG_ACTIVITY_SINGLE_TOP,TerminalActivityrequires theonNewIntentimplementation to ensure subsequent terminal open actions correctly initialize new sessions with the provided working directory and session name, rather than just bringing the existing window into focus silently.