Skip to content
Merged
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ The **Zendr app for Android** shows every session on your computers, says which
- **When an agent asks a question** (allow this command? 1. Yes 2. No), its choices are buttons.
- **The key bar** has **Esc**, **Tab**, the arrows, **Enter** and **Ctrl+C**. Send with an empty box presses Enter.
- **At a shell prompt**, the same command suggestions as on your computer show as you type. Tap one, or press → or Tab on a keyboard.
- **Light or dark**: the moon and sun at the top left switch it, and **About** (ⓘ) can also follow your phone's setting.
- **New versions** pop up by themselves with what's new and a **Download** button. **About** shows your version, checks for updates and links to the source, the releases and the issue tracker.

Your phone reaches your computer through [Tailscale](https://tailscale.com), a free private network that encrypts everything, so nothing on your computer is opened to the internet.

Expand Down
198 changes: 198 additions & 0 deletions mobile/android/app/src/main/java/dev/zendr/companion/AboutScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
package dev.zendr.companion

import android.text.format.DateUtils
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material3.Button
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SegmentedButton
import androidx.compose.material3.SegmentedButtonDefaults
import androidx.compose.material3.SingleChoiceSegmentedButtonRow
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import kotlinx.coroutines.launch

/** About Zendr: the version, updates, light or dark, and where the project lives. */
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AboutScreen(store: Store, onBack: () -> Unit) {
val context = LocalContext.current
val scope = rememberCoroutineScope()
val uri = LocalUriHandler.current
val installed = remember { Updates.installed(context) }
fun open(url: String) = runCatching { uri.openUri(url) }

Scaffold(topBar = {
TopAppBar(
title = { Text("About") },
navigationIcon = { IconButton(onClick = onBack) { Icon(Icons.AutoMirrored.Filled.ArrowBack, "Back") } },
)
}) { pad ->
Column(
Modifier.fillMaxSize().padding(pad).verticalScroll(rememberScrollState()).padding(horizontal = 16.dp),
verticalArrangement = Arrangement.spacedBy(14.dp),
) {
// The iguana, the name, the version.
Column(Modifier.fillMaxWidth().padding(top = 8.dp, bottom = 4.dp), horizontalAlignment = Alignment.CenterHorizontally) {
val green = MaterialTheme.colorScheme.primary
Box(
Modifier.size(120.dp).background(Brush.radialGradient(listOf(green.copy(alpha = 0.28f), green.copy(alpha = 0f))), CircleShape),
contentAlignment = Alignment.Center,
) { ZendrLogo(88.dp) }
Text("Zendr", fontSize = 30.sp, fontWeight = FontWeight.Bold)
Spacer(Modifier.height(6.dp))
Surface(color = MaterialTheme.colorScheme.secondaryContainer, shape = RoundedCornerShape(50)) {
Text(
"Version $installed", fontSize = 13.sp, fontWeight = FontWeight.Medium,
color = MaterialTheme.colorScheme.onSecondaryContainer, modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp),
)
}
Spacer(Modifier.height(12.dp))
Text(
"Your terminals and coding agents, in your pocket. See who needs you, read their screens and answer from anywhere.",
textAlign = TextAlign.Center, fontSize = 15.sp, lineHeight = 21.sp,
color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.padding(horizontal = 8.dp),
)
}

// Updates
Card {
Row(Modifier.padding(16.dp), verticalAlignment = Alignment.CenterVertically) {
Tile(Glyphs.Download)
Spacer(Modifier.width(14.dp))
Column(Modifier.weight(1f)) {
Text("Updates", fontWeight = FontWeight.SemiBold, fontSize = 16.sp)
val latest = Updates.latest
val line = when {
Updates.checking -> "Looking for a new version…"
Updates.error != null -> Updates.error!!
latest != null && Updates.newer(latest.version, installed) -> "Zendr ${latest.version} is out"
latest != null -> "You have the newest version"
store.updateCheckedAt > 0 -> "Checked " + DateUtils.getRelativeTimeSpanString(store.updateCheckedAt).toString().lowercase()
else -> "Zendr looks for new versions by itself"
}
Text(line, fontSize = 13.sp, color = if (Updates.error != null) Red else MaterialTheme.colorScheme.onSurfaceVariant)
}
Spacer(Modifier.width(8.dp))
val latest = Updates.latest
if (latest != null && Updates.newer(latest.version, installed) && !Updates.checking) {
Button(onClick = { Updates.offer = latest }) { Text("Get it") }
} else {
FilledTonalButton(onClick = { scope.launch { Updates.check(context, store, manual = true) } }, enabled = !Updates.checking) {
Text("Check")
}
}
}
}

// Light or dark
Card {
Column(Modifier.padding(16.dp)) {
Text("Appearance", fontWeight = FontWeight.SemiBold, fontSize = 16.sp)
Spacer(Modifier.height(10.dp))
val choices = listOf("system" to "Like the phone", "light" to "Light", "dark" to "Dark")
SingleChoiceSegmentedButtonRow(Modifier.fillMaxWidth()) {
choices.forEachIndexed { i, (value, label) ->
SegmentedButton(
selected = Appearance.theme == value,
onClick = { Appearance.set(store, value) },
shape = SegmentedButtonDefaults.itemShape(i, choices.size),
label = { Text(label, maxLines = 1, fontSize = 13.sp) },
)
}
}
}
}

// Where it lives
Card {
Column {
LinkRow(Glyphs.Code, "Source code", "github.com/ruchira-edirisinghe/zendr") { open(Updates.REPO) }
Divider()
LinkRow(Glyphs.Download, "All releases", "Zendr for Windows, Mac and Android") { open("${Updates.REPO}/releases") }
Divider()
LinkRow(Glyphs.Book, "Using the phone app", "Pairing, alerts and the terminal") { open("${Updates.REPO}#zendr-on-your-phone") }
Divider()
LinkRow(Glyphs.Alert, "Report a problem", "Open an issue on GitHub") { open("${Updates.REPO}/issues/new") }
Divider()
LinkRow(Glyphs.Licence, "Licence", "Apache 2.0, free and open source") { open("${Updates.REPO}/blob/main/LICENSE") }
Divider()
LinkRow(Glyphs.Heart, "Made from Herdr", "herdr.dev") { open("https://herdr.dev") }
}
}

Text(
"Your terminals go only between this phone and your computers, over your own Tailscale network. The app asks GitHub for new versions, nothing else.",
fontSize = 12.sp, lineHeight = 17.sp, textAlign = TextAlign.Center,
color = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.fillMaxWidth().padding(horizontal = 12.dp),
)
Spacer(Modifier.height(24.dp))
}
}
}

@Composable
private fun Card(content: @Composable () -> Unit) {
Surface(shape = RoundedCornerShape(18.dp), color = MaterialTheme.colorScheme.surfaceContainer, modifier = Modifier.fillMaxWidth()) { content() }
}

@Composable
private fun Divider() = HorizontalDivider(Modifier.padding(start = 68.dp), color = MaterialTheme.colorScheme.outlineVariant.copy(alpha = 0.6f))

@Composable
private fun Tile(icon: ImageVector) {
Box(Modifier.size(38.dp).background(MaterialTheme.colorScheme.secondaryContainer, RoundedCornerShape(11.dp)), contentAlignment = Alignment.Center) {
Icon(icon, null, tint = MaterialTheme.colorScheme.onSecondaryContainer, modifier = Modifier.size(20.dp))
}
}

@Composable
private fun LinkRow(icon: ImageVector, title: String, detail: String, onClick: () -> Unit) {
Surface(onClick = onClick, color = MaterialTheme.colorScheme.surfaceContainer) {
Row(Modifier.fillMaxWidth().padding(horizontal = 16.dp, vertical = 12.dp), verticalAlignment = Alignment.CenterVertically) {
Tile(icon)
Spacer(Modifier.width(14.dp))
Column(Modifier.weight(1f)) {
Text(title, fontWeight = FontWeight.Medium, fontSize = 15.sp)
Text(detail, fontSize = 13.sp, color = MaterialTheme.colorScheme.onSurfaceVariant)
}
Icon(Glyphs.Open, null, tint = MaterialTheme.colorScheme.onSurfaceVariant, modifier = Modifier.size(18.dp))
}
}
}
15 changes: 15 additions & 0 deletions mobile/android/app/src/main/java/dev/zendr/companion/Api.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,21 @@ class Store(context: Context) {
var wrap: Boolean
get() = prefs.getBoolean("wrap", false)
set(v) = prefs.edit().putBoolean("wrap", v).apply()

/** "system", "light" or "dark". */
var theme: String
get() = prefs.getString("theme", null) ?: "system"
set(v) = prefs.edit().putString("theme", v).apply()

/** When the app last asked GitHub for a new version (ms). */
var updateCheckedAt: Long
get() = prefs.getLong("updateCheckedAt", 0L)
set(v) = prefs.edit().putLong("updateCheckedAt", v).apply()

/** A version you chose to skip: no popup for it. */
var skipVersion: String?
get() = prefs.getString("skipVersion", null)
set(v) = prefs.edit().putString("skipVersion", v).apply()
}

class ApiError(message: String, val unpaired: Boolean = false) : Exception(message)
Expand Down
45 changes: 45 additions & 0 deletions mobile/android/app/src/main/java/dev/zendr/companion/Glyphs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package dev.zendr.companion

import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.StrokeCap
import androidx.compose.ui.graphics.StrokeJoin
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.graphics.vector.addPathNodes
import androidx.compose.ui.unit.dp

/** Line icons the core icon set doesn't have, drawn on a 24-unit grid (tinted like any icon). */
object Glyphs {
private fun line(name: String, vararg paths: String): ImageVector {
val b = ImageVector.Builder(name, 24.dp, 24.dp, 24f, 24f)
for (d in paths) {
b.addPath(
addPathNodes(d), stroke = SolidColor(Color.Black), strokeLineWidth = 2f,
strokeLineCap = StrokeCap.Round, strokeLineJoin = StrokeJoin.Round,
)
}
return b.build()
}

val Sun by lazy {
line(
"sun", "M12 8a4 4 0 1 0 0 8a4 4 0 1 0 0-8z",
"M12 2v2", "M12 20v2", "M4.93 4.93l1.41 1.41", "M17.66 17.66l1.41 1.41",
"M2 12h2", "M20 12h2", "M6.34 17.66l-1.41 1.41", "M19.07 4.93l-1.41 1.41",
)
}
val Moon by lazy { line("moon", "M12 3a6 6 0 0 0 9 9a9 9 0 1 1-9-9z") }
val Download by lazy { line("download", "M12 3v12", "M7 10l5 5l5-5", "M5 21h14") }
val Code by lazy { line("code", "M16 18l6-6l-6-6", "M8 6l-6 6l6 6") }
val Book by lazy {
line("book", "M4 19.5A2.5 2.5 0 0 1 6.5 17H20", "M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2z")
}
val Alert by lazy { line("alert", "M12 2a10 10 0 1 0 0 20a10 10 0 1 0 0-20z", "M12 8v4", "M12 16h.01") }
val Licence by lazy {
line("licence", "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z", "M14 2v6h6", "M16 13H8", "M16 17H8")
}
val Heart by lazy {
line("heart", "M19 14c1.49-1.46 3-3.21 3-5.5A5.5 5.5 0 0 0 16.5 3c-1.76 0-3 .5-4.5 2c-1.5-1.5-2.74-2-4.5-2A5.5 5.5 0 0 0 2 8.5c0 2.3 1.5 4.05 3 5.5l7 7z")
}
val Open by lazy { line("open", "M15 3h6v6", "M10 14L21 3", "M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6") }
}
Loading
Loading