Skip to content

armgit / andee

Public Imported from GitHub
0

Andee lives on your phone or Mac and uses any app like you do—no integrations, no root, any model; memory and passwords never leave your device | Andee 住进你的手机或 Mac,像你一样操作任何 App——无需集成、无需 Root、支持任意模型,记忆和密码绝不离开设备。

feat(mac): the question card closes from its top-right corner

booboosuif2d654ed3f4a
diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/UiShot.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/UiShot.kt
index 8b7c413..804b579 100644
--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/UiShot.kt
+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/UiShot.kt
@@ -1,8 +1,15 @@
package net.kuafuai.andee.desktop
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Box
+import androidx.compose.foundation.layout.padding
+import androidx.compose.runtime.Composable
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.ImageComposeScene
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Density
+import androidx.compose.ui.unit.dp
import org.jetbrains.skia.EncodedImageFormat
import java.io.File
import kotlin.system.exitProcess
@@ -67,7 +74,17 @@ fun main(args: Array<String>) {
}
val nav = Nav().also { if (screen != "chat") it.go(screen) }
val density = Density(2f)
- val scene = ImageComposeScene(width = w * 2, height = h * 2, density = density) { AppRoot(nav) }
+ // `ask` draws one question card on its own: its layout (the close button in the corner, the
+ // text held clear of it) is only otherwise visible when the brain happens to ask something.
+ val askCard = if (screen == "ask") AskGate.Pending(
+ "要我继续吗?这一步会把桌面上的 14 张截图移进「截图」文件夹,按月份分三个子文件夹。",
+ listOf("继续", "先看看", "不用了"),
+ java.util.concurrent.CompletableFuture(),
+ System.currentTimeMillis() + 20_000,
+ ) else null
+ val scene = ImageComposeScene(width = w * 2, height = h * 2, density = density) {
+ if (askCard != null) AskShot(askCard) else AppRoot(nav)
+ }
// Let the backdrop (decoded off the main thread) and the layout settle.
repeat(12) { scene.render(it * 50_000_000L); Thread.sleep(60) }
val img = scene.render(700_000_000L)
@@ -77,6 +94,14 @@ fun main(args: Array<String>) {
exitProcess(0)
}
+/** One question card on a plain ground, so the card's edges and its corner button are unambiguous. */
+@Composable
+private fun AskShot(p: AskGate.Pending) {
+ Box(Modifier.background(Color(0xFFB9C0C8)).padding(24.dp)) {
+ AskCard(p)
+ }
+}
+
private fun seed() {
Scrollback.wipe()
Scrollback.add(Scrollback.Role.USER, "帮我把桌面上的截图整理一下")
diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/UserPrompts.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/UserPrompts.kt
index af0d7c3..a7ec72d 100644
--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/UserPrompts.kt
+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/UserPrompts.kt
@@ -278,8 +278,13 @@ object AskGate {
/** Lower-cased, spaces and punctuation dropped, so "好的。" equals "好的". */
private fun normalize(s: String): String = s.lowercase().filter { it.isLetterOrDigit() }
+ /**
+ * The user closed the card instead of answering it. The same outcome as waiting out the timeout —
+ * no button, no words — but the result says which of the two happened, so the brain can tell
+ * "not now" from "never answered".
+ */
fun dismiss() {
- current?.answer?.complete(Result(null, null, "tap_outside"))
+ current?.answer?.complete(Result(null, null, "closed"))
}
}
@@ -290,32 +295,45 @@ fun AskCard(p: AskGate.Pending) {
fun t(a: String, b: String) = if (zh) a else b
val isAlert = p.buttons.isEmpty()
run {
- Column(
+ Box(
Modifier.fillMaxWidth()
.background(Palette.card, RoundedCornerShape(18.dp))
- .border(1.dp, Palette.hairline, RoundedCornerShape(18.dp)).padding(20.dp),
- verticalArrangement = Arrangement.spacedBy(12.dp),
+ .border(1.dp, Palette.hairline, RoundedCornerShape(18.dp)),
) {
- Text(p.question ?: "", color = Palette.text, fontSize = 16.sp)
- if (isAlert) {
- Row(Modifier.align(Alignment.End)) {
- Pill(t("知道了", "OK")) { AskGate.answer(null) }
- }
- } else {
- Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
- p.buttons.forEachIndexed { i, b ->
- val primary = i == 0
- Text(
- b, color = if (primary) Color(0xFF0A2540) else Palette.text, fontSize = 15.sp,
- modifier = Modifier.fillMaxWidth()
- .background(if (primary) Palette.accent else Palette.panel, RoundedCornerShape(12.dp))
- .border(1.dp, if (primary) Color.Transparent else Palette.hairline, RoundedCornerShape(12.dp))
- .clickable { AskGate.answer(b) }
- .padding(horizontal = 14.dp, vertical = 10.dp),
- )
+ Column(
+ Modifier.fillMaxWidth().padding(20.dp),
+ verticalArrangement = Arrangement.spacedBy(12.dp),
+ ) {
+ // Held clear of the close button in the corner, which sits over the first line's end.
+ Text(p.question ?: "", color = Palette.text, fontSize = 16.sp, modifier = Modifier.padding(end = 22.dp))
+ if (isAlert) {
+ Row(Modifier.align(Alignment.End)) {
+ Pill(t("知道了", "OK")) { AskGate.answer(null) }
+ }
+ } else {
+ Column(verticalArrangement = Arrangement.spacedBy(8.dp)) {
+ p.buttons.forEachIndexed { i, b ->
+ val primary = i == 0
+ Text(
+ b, color = if (primary) Color(0xFF0A2540) else Palette.text, fontSize = 15.sp,
+ modifier = Modifier.fillMaxWidth()
+ .background(if (primary) Palette.accent else Palette.panel, RoundedCornerShape(12.dp))
+ .border(1.dp, if (primary) Color.Transparent else Palette.hairline, RoundedCornerShape(12.dp))
+ .clickable { AskGate.answer(b) }
+ .padding(horizontal = 14.dp, vertical = 10.dp),
+ )
+ }
}
}
}
+ // The way out, in the corner. A question is read out loud and then waits for its timeout,
+ // so a card the user is done with has to be closable by hand — and closing it stops the
+ // reading, the same as a tap on the ball does.
+ Box(
+ Modifier.align(Alignment.TopEnd).padding(top = 10.dp, end = 10.dp)
+ .clickable { MacVoice.stopSpeaking(); AskGate.dismiss() }
+ .padding(6.dp),
+ ) { Icon(AndeeIcon.CLOSE, Palette.secondary, 14.dp) }
}
}
}