Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

fix: address Termux setup review — dead guided-setup link, step gating, copy button

Rishabh Bajpai2a49352c335c
diff --git a/app/src/main/java/com/gotcha/ui/PermissionsSection.kt b/app/src/main/java/com/gotcha/ui/PermissionsSection.kt
index ae6ab8b..633af08 100644
--- a/app/src/main/java/com/gotcha/ui/PermissionsSection.kt
+++ b/app/src/main/java/com/gotcha/ui/PermissionsSection.kt
@@ -40,6 +40,7 @@ import androidx.lifecycle.LifecycleEventObserver
import com.gotcha.service.GotchaDeviceAdminReceiver
import com.gotcha.tools.HealthPermissionState
import com.gotcha.tools.HealthTool
+import com.gotcha.tools.TermuxTool
import com.gotcha.tools.ToolResult
import android.provider.Settings as AndroidSettings
@@ -131,7 +132,7 @@ fun PermissionsSection(
onRequestRuntime = { perms ->
runtimeLauncher.launch(perms)
},
- onOpenDetails = if (item.specialMarker == ToolResult.TERMUX_ACCESS) {
+ onOpenDetails = if (item.androidPermission == TermuxTool.PERMISSION_RUN_COMMAND) {
onOpenTermuxSetup
} else {
null
diff --git a/app/src/main/java/com/gotcha/ui/TermuxSetupScreen.kt b/app/src/main/java/com/gotcha/ui/TermuxSetupScreen.kt
index 9dcef6f..9f12c63 100644
--- a/app/src/main/java/com/gotcha/ui/TermuxSetupScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/TermuxSetupScreen.kt
@@ -1,5 +1,8 @@
package com.gotcha.ui
+import android.content.ClipData
+import android.content.ClipboardManager
+import android.content.Context
import android.content.Intent
import android.net.Uri
import androidx.activity.compose.rememberLauncherForActivityResult
@@ -37,6 +40,11 @@ import com.gotcha.tools.ToolResult
import com.gotcha.ui.theme.GotchaMono
import kotlinx.coroutines.launch
+/** The two lines the user runs in Termux to enable external apps; also what the Copy button shares. */
+private const val TERMUX_SETUP_COMMANDS =
+ "echo 'allow-external-apps=true' >> ~/.termux/termux.properties\n" +
+ "termux-reload-settings"
+
/**
* Guided Termux setup: a live checklist of the four things that must be true for
* `run_termux_command` to work, each with the action to fix it. The cheap checks
@@ -49,6 +57,7 @@ fun TermuxSetupScreen(onBack: () -> Unit) {
val tool = remember(context) { TermuxTool(context) }
val overlay = rememberSettingsOverlayState()
val scope = rememberCoroutineScope()
+ val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as? ClipboardManager
var state by remember { mutableStateOf(TermuxTool.TermuxSetupState.from(tool.status())) }
var probing by remember { mutableStateOf(false) }
@@ -126,6 +135,8 @@ fun TermuxSetupScreen(onBack: () -> Unit) {
Intent(Intent.ACTION_VIEW, Uri.parse(TermuxTool.TERMUX_FDROID_URL))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
)
+ }.onFailure {
+ overlay.show("Could not open the F-Droid page.")
}
}
}
@@ -153,12 +164,13 @@ fun TermuxSetupScreen(onBack: () -> Unit) {
"Termux must let Gotcha run commands. If no permission dialog appears, " +
"Termux was installed after Gotcha — update or reinstall Gotcha."
},
- action = if (state.permissionGranted) {
- null
- } else {
- SetupAction("Grant permission") {
- permissionLauncher.launch(TermuxTool.PERMISSION_RUN_COMMAND)
- }
+ action = when {
+ state.permissionGranted -> null
+ state.installed && state.pluginApiAvailable ->
+ SetupAction("Grant permission") {
+ permissionLauncher.launch(TermuxTool.PERMISSION_RUN_COMMAND)
+ }
+ else -> null
}
)
@@ -183,24 +195,34 @@ fun TermuxSetupScreen(onBack: () -> Unit) {
}
)
- if (state.installed && state.pluginApiAvailable && !state.ready) {
+ if (state.installed && state.pluginApiAvailable && state.permissionGranted && !state.ready) {
Surface(
shape = MaterialTheme.shapes.medium,
color = MaterialTheme.colorScheme.surfaceVariant,
modifier = Modifier.fillMaxWidth()
) {
Text(
- "echo 'allow-external-apps=true' >> ~/.termux/termux.properties\n" +
- "termux-reload-settings",
+ TERMUX_SETUP_COMMANDS,
style = MaterialTheme.typography.bodySmall.copy(fontFamily = GotchaMono),
modifier = Modifier.padding(12.dp)
)
}
- OutlinedButton(
- onClick = { checkConfiguration() },
- enabled = !probing,
- modifier = Modifier.fillMaxWidth()
- ) { Text(if (probing) "Checking…" else "Check configuration") }
+ Row(horizontalArrangement = Arrangement.spacedBy(8.dp)) {
+ OutlinedButton(
+ onClick = {
+ clipboard?.setPrimaryClip(
+ ClipData.newPlainText("Termux setup", TERMUX_SETUP_COMMANDS)
+ )
+ overlay.show("Copied to clipboard.")
+ },
+ modifier = Modifier.weight(1f)
+ ) { Text("Copy commands") }
+ OutlinedButton(
+ onClick = { checkConfiguration() },
+ enabled = !probing,
+ modifier = Modifier.weight(1f)
+ ) { Text(if (probing) "Checking…" else "Check configuration") }
+ }
}
probeFeedback?.let { feedback ->
@@ -225,7 +247,7 @@ fun TermuxSetupScreen(onBack: () -> Unit) {
}
/** A named action for a setup step, kept small so the checklist reads top-down. */
-private data class SetupAction(val label: String, val onClick: () -> Unit)
+private class SetupAction(val label: String, val onClick: () -> Unit)
/**
* One row of the checklist: a ✓/○ status marker, title, detail line, and an
diff --git a/docs/termux-setup.md b/docs/termux-setup.md
index 998a003..8e6a459 100644
--- a/docs/termux-setup.md
+++ b/docs/termux-setup.md
@@ -33,17 +33,21 @@ action button.
## Guided setup (Settings → Termux)
Open **Settings → Termux (Linux shell)**. It re-reads the first three checks on
-every resume and offers:
+every resume and offers, one step at a time:
- **Install Termux from F-Droid** when Termux is missing.
-- **Grant permission** when the RUN_COMMAND grant is missing.
-- **Open Termux** plus copy-paste lines when `allow-external-apps` is not confirmed:
+- **Grant permission** when the RUN_COMMAND grant is missing — the button only
+ appears once Termux is installed and the build is usable.
+- **Open Termux** plus the two copy-paste lines when `allow-external-apps` is
+ not confirmed. A **Copy commands** button puts both lines on the clipboard:
```
echo 'allow-external-apps=true' >> ~/.termux/termux.properties
termux-reload-settings
```
-- **Check configuration** re-runs the probe and reports configured / not-configured /
- unknown.
+- **Check configuration** re-runs the probe and reports configured /
+ not-configured / unknown. It (and the copy box) only appears once the
+ RUN_COMMAND permission is granted, so a probe is never run before it can
+ answer.
The Settings → Permissions → *Termux Commands (Optional)* row links to the same page.
@@ -63,9 +67,10 @@ The Settings → Permissions → *Termux Commands (Optional)* row links to the s
permission button appears.
4. **Grant the permission**: the step ticks off; if no dialog appears, Termux was
installed after Gotcha (reinstall Gotcha).
-5. **Open Termux**, run the two copy-paste lines, restart Termux, tap **Check
- configuration** → "Termux answered — allow-external-apps is enabled."
+5. **Open Termux**, use **Copy commands** (the paste box reads correctly), paste and
+ run the two lines, restart Termux, tap **Check configuration** → "Termux answered —
+ allow-external-apps is enabled."
6. All four steps are checked and the "Termux is set up" banner shows. Ask the
assistant to run something: `pkg install python -y` and `python3 --version`.
7. Revoke the permission in system Settings → the page's permission step unchecks on
- the next resume.
+ the next resume, and the copy box / Check button disappear until it is granted again.