Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions android/app/src/main/java/dev/opencode/mobile/Navigation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
Expand Down Expand Up @@ -334,8 +335,8 @@ fun MainNavigation() {
AppRootState.Loading -> {
ProductRouteScreenViewEffect(screenId = ProductAnalytics.Screen.APP_LOADING)
OpenCodeStatusStack(
title = "Loading sessions",
subtitle = "Checking server…",
title = stringResource(R.string.common_loading_sessions),
subtitle = stringResource(R.string.common_checking_server),
testTag = "appRootLoading",
modifier = Modifier.fillMaxSize(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,6 @@ object CleartextPolicy {
/** mDNS, Tailscale MagicDNS, and the common private-DNS suffixes. */
val trustedNameSuffixes: List<String> = listOf("local", "ts.net", "lan", "internal", "home.arpa")

const val WARNING_TITLE = "Connection isn't encrypted"

fun warningMessage(hosts: List<String>): String {
val subject = if (hosts.isEmpty()) "This address" else hosts.joinToString(", ")
val verb = if (hosts.size > 1) "use" else "uses"
return "$subject $verb plain http outside your local network or Tailscale. " +
"Your server password and everything in your sessions would travel unencrypted. " +
"Prefer https, a VPN, or a tunnel."
}

fun verdict(raw: String): Verdict {
val uri = parse(raw) ?: return Verdict.UntrustedCleartext
val scheme = uri.scheme?.lowercase() ?: "http"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import dev.opencode.mobile.R
import dev.opencode.mobile.ui.components.OpenCodeButton
import dev.opencode.mobile.ui.components.OpenCodeButtonVariant
import dev.opencode.mobile.ui.components.OpenCodeReadableColumn
Expand All @@ -28,21 +30,20 @@ fun ConnectionOnboardingScreen(
) {
Spacer(modifier = Modifier.weight(1f))
Text(
text = "Connect to your server",
text = stringResource(R.string.connection_onboarding_title),
style = MaterialTheme.typography.titleLarge,
textAlign = TextAlign.Center,
)
Spacer(modifier = Modifier.height(12.dp))
Text(
text =
"OpenCode Mobile controls sessions on an opencode server running on your development machine.",
text = stringResource(R.string.connection_onboarding_body),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
textAlign = TextAlign.Center,
)
Spacer(modifier = Modifier.height(24.dp))
OpenCodeButton(
variant = OpenCodeButtonVariant.FullWidthText("Connect to server"),
variant = OpenCodeButtonVariant.FullWidthText(stringResource(R.string.connection_onboarding_connect)),
onClick = onConnectClick,
)
Spacer(modifier = Modifier.weight(1f))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.selected
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import dev.opencode.mobile.R
import dev.opencode.mobile.domain.connection.ConnectionProfileIdentity
import dev.opencode.mobile.domain.connection.PairingQRPayload
import dev.opencode.mobile.theme.LocalOpenCodeDarkTheme
Expand All @@ -41,34 +43,38 @@ import dev.opencode.mobile.ui.components.OpenCodeServerAddressInput
import dev.opencode.mobile.ui.components.OpenCodeTextInput
import dev.opencode.mobile.ui.components.OpenCodeTextInputKind
import dev.opencode.mobile.ui.components.OpenCodeTextInputSubmitAction
import dev.opencode.mobile.ui.text.UiText
import dev.opencode.mobile.ui.text.resolve

internal fun qrAddressHint(urls: List<String>): String {
internal fun qrAddressHint(urls: List<String>): UiText {
val tunnel = urls.filter(PairingQRPayload::isRemoteTunnelUrl)
val tailscale = urls.filter(PairingQRPayload::isTailscaleUrl)
val local =
urls.filter { url ->
!PairingQRPayload.isTailscaleUrl(url) && !PairingQRPayload.isRemoteTunnelUrl(url)
}
if (tunnel.isNotEmpty() && tailscale.isEmpty() && local.isEmpty()) {
return "Remote tunnel saved. Nothing else to pick. It stays until you turn remote access off."
return UiText.resource(R.string.connection_setup_addresses_hint_tunnel_only)
}
if (tailscale.isNotEmpty() && local.isNotEmpty() && tunnel.isEmpty()) {
return "Tailscale is used when it answers. Local network is the fallback."
return UiText.resource(R.string.connection_setup_addresses_hint_tailscale_fallback)
}
return "Saved addresses are tried until one answers. Tailscale is preferred when it answers."
return UiText.resource(R.string.connection_setup_addresses_hint_default)
}

internal fun qrAddressTitle(url: String): String =
when {
PairingQRPayload.isTailscaleUrl(url) -> "Tailscale"
PairingQRPayload.isRemoteTunnelUrl(url) -> "Remote tunnel"
else -> "Local network"
}
internal fun qrAddressTitle(url: String): UiText =
UiText.resource(
when {
PairingQRPayload.isTailscaleUrl(url) -> R.string.connection_setup_address_tailscale
PairingQRPayload.isRemoteTunnelUrl(url) -> R.string.connection_setup_address_remote_tunnel
else -> R.string.connection_setup_address_local_network
},
)

internal data class QrAddressRowUi(
val title: String,
val subtitle: String,
val badge: String,
val title: UiText,
val subtitle: UiText,
val badge: UiText,
val dimmed: Boolean,
)

Expand All @@ -78,11 +84,14 @@ internal fun qrAddressRows(uiState: ConnectionSetupUiState): List<QrAddressRowUi
val normalized = ConnectionProfileIdentity.normalizeBaseUrl(url)
val unreachable = uiState.addressProbeFinished && normalized in uiState.unreachableUrls
val isChosen = chosen != null && ConnectionProfileIdentity.normalizeBaseUrl(chosen) == normalized
val host = ConnectionProfileIdentity.hostLabel(url)
val host = UiText.verbatim(ConnectionProfileIdentity.hostLabel(url))
QrAddressRowUi(
title = qrAddressTitle(url),
subtitle = if (unreachable) "$host · not reachable" else host,
badge = if (isChosen) "Using now" else "Saved",
subtitle = if (unreachable) UiText.resource(R.string.connection_setup_address_not_reachable, host) else host,
badge =
UiText.resource(
if (isChosen) R.string.connection_setup_address_using_now else R.string.connection_setup_address_saved,
),
dimmed = unreachable,
)
}
Expand Down Expand Up @@ -124,7 +133,7 @@ fun ConnectionSetupFields(
val pairAgainMessage = uiState.pairAgainMessage
if (pairAgainMessage != null && uiState.usesQrLayout) {
Text(
text = pairAgainMessage,
text = pairAgainMessage.resolve(),
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
)
Expand All @@ -134,7 +143,7 @@ fun ConnectionSetupFields(
}
if (uiState.usesQrLayout) {
Text(
text = qrAddressHint(uiState.serverUrls),
text = qrAddressHint(uiState.serverUrls).resolve(),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(start = 2.dp),
Expand All @@ -145,7 +154,7 @@ fun ConnectionSetupFields(
OpenCodeTextInput(
value = uiState.name,
onValueChange = onNameChanged,
hint = "Optional name",
hint = stringResource(R.string.connection_setup_name_hint),
submitAction = OpenCodeTextInputSubmitAction.Next,
enabled = !uiState.isBusy,
)
Expand All @@ -158,13 +167,13 @@ fun ConnectionSetupFields(
OpenCodeServerAddressInput(
value = uiState.baseUrl,
onValueChange = onBaseUrlChanged,
hint = "macbook.local:4096",
accessibilityLabel = "Host",
hint = stringResource(R.string.connection_setup_host_hint),
accessibilityLabel = stringResource(R.string.connection_setup_host_label),
submitAction = OpenCodeTextInputSubmitAction.Next,
enabled = !uiState.isBusy,
)
Text(
text = "LAN, Tailscale MagicDNS, or tunnel — not localhost on a phone.",
text = stringResource(R.string.connection_setup_host_help),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(top = 6.dp, start = 2.dp),
Expand All @@ -173,7 +182,7 @@ fun ConnectionSetupFields(
OpenCodeTextInput(
value = uiState.name,
onValueChange = onNameChanged,
hint = "Optional name",
hint = stringResource(R.string.connection_setup_name_hint),
submitAction = OpenCodeTextInputSubmitAction.Next,
enabled = !uiState.isBusy,
)
Expand All @@ -189,7 +198,7 @@ fun ConnectionSetupFields(
OpenCodeTextInput(
value = uiState.username,
onValueChange = onUsernameChanged,
hint = "Username",
hint = stringResource(R.string.connection_setup_username_hint),
kind = OpenCodeTextInputKind.Username,
submitAction = OpenCodeTextInputSubmitAction.Next,
enabled = !uiState.isBusy,
Expand All @@ -198,13 +207,13 @@ fun ConnectionSetupFields(
OpenCodeTextInput(
value = uiState.password,
onValueChange = onPasswordChanged,
hint = "Password, optional",
hint = stringResource(R.string.connection_setup_password_hint),
kind = OpenCodeTextInputKind.Password,
enabled = !uiState.isBusy,
modifier = Modifier.focusRequester(passwordFocusRequester),
)
Text(
text = "Default user is opencode. Password is optional.",
text = stringResource(R.string.connection_setup_password_help),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(top = 6.dp, start = 2.dp),
Expand All @@ -214,12 +223,12 @@ fun ConnectionSetupFields(
OpenCodeTextInput(
value = uiState.pairingCode,
onValueChange = onPairingCodeChanged,
hint = "Pairing code",
hint = stringResource(R.string.connection_setup_pairing_code_hint),
kind = OpenCodeTextInputKind.Url,
enabled = !uiState.isBusy,
)
Text(
text = "From the pair link. Works once and expires in 5 minutes.",
text = stringResource(R.string.connection_setup_pairing_code_help),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(top = 6.dp, start = 2.dp),
Expand All @@ -232,27 +241,26 @@ fun ConnectionSetupFields(
@Composable
private fun PairingInstructions() {
Text(
text = "On your computer, run this, then scan the QR.",
text = stringResource(R.string.connection_setup_instructions_run),
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
)
Spacer(modifier = Modifier.height(12.dp))
OpenCodeCodeSnippet(code = "opencode pair --remote")
Text(
text =
"First run takes about a minute. Needs OpenCode 2.0.25 or later. The service starts if it is not already running.",
text = stringResource(R.string.connection_setup_instructions_first_run),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(top = 8.dp),
)
Text(
text = "Same Wi-Fi instead",
text = stringResource(R.string.connection_setup_instructions_same_wifi_title),
style = MaterialTheme.typography.titleSmall,
color = MaterialTheme.colorScheme.onSurface,
modifier = Modifier.padding(top = 20.dp),
)
Text(
text = "Plain pair shows a QR only after the server is reachable beyond localhost.",
text = stringResource(R.string.connection_setup_instructions_same_wifi_body),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
modifier = Modifier.padding(top = 6.dp),
Expand Down Expand Up @@ -284,8 +292,8 @@ private fun CredentialSegmentControl(
.padding(2.dp),
) {
listOf(
ConnectionCredentialSegment.Password to "Password",
ConnectionCredentialSegment.PairingCode to "Pairing code",
ConnectionCredentialSegment.Password to stringResource(R.string.connection_setup_segment_password),
ConnectionCredentialSegment.PairingCode to stringResource(R.string.connection_setup_segment_pairing_code),
).forEach { (segment, label) ->
val isSelected = segment == selected
Box(
Expand Down Expand Up @@ -347,18 +355,18 @@ private fun QrAddressRow(row: QrAddressRowUi) {
) {
Column(modifier = Modifier.weight(1f)) {
Text(
text = row.title,
text = row.title.resolve(),
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface,
)
Text(
text = row.subtitle,
text = row.subtitle.resolve(),
style = MaterialTheme.typography.bodySmall,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
}
Text(
text = row.badge,
text = row.badge.resolve(),
style = MaterialTheme.typography.bodyMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Expand Down
Loading