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: an out-of-date build is told once at launch, on both bodies, and sent to CodeFlying
booboosuid24d380200c7
diff --git a/app/src/main/java/net/kuafuai/andee/device/SelfCheck.kt b/app/src/main/java/net/kuafuai/andee/device/SelfCheck.ktindex ba8c110..223618a 100644--- a/app/src/main/java/net/kuafuai/andee/device/SelfCheck.kt+++ b/app/src/main/java/net/kuafuai/andee/device/SelfCheck.kt@@ -509,14 +509,15 @@ object SelfCheck {* nagware, so the mapping is deliberate:** * Answered, and this build is current → [Level.OK].- * * **A newer version exists → [Level.NOTE], not WARN.** An outdated app- * is not a broken one, and this list's contract is that only FAIL and- * WARN may interrupt. Putting up a card every time we ship a patch would- * be exactly the failure the [Level] doc is written against.- * * The one exception is a *forced* update — `force_update` set in- * `version.json`, or this build sitting below `min_supported_version` —- * which is [Level.WARN], because the service is saying this build is no- * longer supported.+ * * **Answered, and a release strictly newer than this build exists →+ * [Level.FAIL]**, forced or not, so the startup card says so once (the+ * card's own dedup keeps it from repeating). The user asked for it to be+ * impossible to miss. The button goes to CodeFlying's site in the+ * interface language ([Upgrade.url]), and the text names GitHub as the+ * other place to get it.+ * * **A build ahead of the release is current**, whatever the service says:+ * `has_update` is believed only when [Upgrade.newer] agrees, so a+ * development build is never told to "upgrade" to an older one.* * **Anything undetermined is [Level.NOTE]**: no network, today's quota* spent, connection refused, a 500, a domain that does not resolve. A* statistics endpoint being down is never the user's problem, and@@ -583,8 +584,8 @@ object SelfCheck {// one word apart and swapping the order in one of them would be// a silent lie about which version is which.detailArgs = listOf(v.latest, BuildConfig.VERSION_NAME),- // The release page is always a place to go, so the row never ends in a button that does nothing.- fix = Fix.Link(v.url ?: RELEASES_URL),+ // CodeFlying's site in the interface language; the text names GitHub as the other way.+ fix = Fix.Link(net.kuafuai.andee.config.Upgrade.url(VoiceConfig.uiLanguage(context))),)is Verdict.QuotaSpent -> Finding(@@ -1321,7 +1322,7 @@ object SelfCheck {object Current : Verdict/** Reached and answered: there is a newer release than this build. */- data class Update(val latest: String, val forced: Boolean, val url: String?) : Verdict+ data class Update(val latest: String, val forced: Boolean) : Verdict/** Reached, but today's allowance is spent. A normal state, not a fault. */object QuotaSpent : Verdict@@ -1387,17 +1388,12 @@ object SelfCheck {val data = json.optJSONObject("data")?: return Verdict.Unreachable("HTTP ${resp.code}: no data")if (!data.optBoolean("has_update", false)) return Verdict.Current+ // Ahead of (or level with) the release is not behind, whatever the service says.+ if (!net.kuafuai.andee.config.Upgrade.newer(data.optString("latest_version"), current)) return Verdict.Current- // `org.json.optString` hands back the four-letter *string*- // "null" for a JSON null, and the service sends exactly that- // when no download URL is published. So the scheme is what gets- // checked, not emptiness: a Fix.Link holding "null" opens a- // browser at a broken address.- val raw = data.optString("download_url").orEmpty()Verdict.Update(latest = data.optString("latest_version").ifEmpty { "?" },forced = data.optBoolean("force_update", false),- url = raw.takeIf { it.startsWith("http://") || it.startsWith("https://") },)}} catch (e: Exception) {@@ -1498,9 +1494,6 @@ object SelfCheck {*/private const val VERSION_API_BASE = "https://api.heyandee.com"- /** Where a newer build is published. */- const val RELEASES_URL = "https://github.com/kuafuai/andee/releases"-/*** The whole-call ceiling on the version probe, in milliseconds.*diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xmlindex e7f323b..2cac715 100644--- a/app/src/main/res/values-en/strings.xml+++ b/app/src/main/res/values-en/strings.xml@@ -636,8 +636,8 @@move to and %2$s is always the build in hand; the two rows differ by aword, so do not swap the arguments between them. See SelfCheck.version. --><string name="check_detail_version_current">%1$s is the current release.</string>- <string name="check_detail_version_stale">Out of date: the latest is %1$s, you are on %2$s. Please upgrade from GitHub.</string>- <string name="check_detail_version_forced">Please upgrade to %1$s — this build (%2$s) is no longer supported. Get it from GitHub.</string>+ <string name="check_detail_version_stale">Out of date: the latest is %1$s, you are on %2$s. Upgrade from GitHub or CodeFlying.</string>+ <string name="check_detail_version_forced">Please upgrade to %1$s — this build (%2$s) is no longer supported. Upgrade from GitHub or CodeFlying.</string><string name="check_detail_version_offline">Offline, so not tested. You are on %1$s.</string><string name="check_detail_version_quota">Today\'s checks are used up; they reset tomorrow. You are on %1$s.</string><string name="check_detail_version_unreachable">Could not be checked: %1$s. You are on %2$s.</string>diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xmlindex 28aa423..09a3977 100644--- a/app/src/main/res/values/strings.xml+++ b/app/src/main/res/values/strings.xml@@ -720,8 +720,8 @@唯一一次主动往外发东西。%1$s 恒为「该升到的版本」,%2$s 恒为「你手上这个」,两条文案的参数顺序不许对调。见 SelfCheck.version。 --><string name="check_detail_version_current">%1$s 已经是最新。</string>- <string name="check_detail_version_stale">版本落后了:最新是 %1$s,你现在是 %2$s。请到 GitHub 下载升级。</string>- <string name="check_detail_version_forced">请升级到 %1$s —— 你现在这个(%2$s)已经不再支持了。到 GitHub 下载。</string>+ <string name="check_detail_version_stale">版本落后了:最新是 %1$s,你现在是 %2$s。请到 GitHub 或 CodeFlying 升级。</string>+ <string name="check_detail_version_forced">请升级到 %1$s —— 你现在这个(%2$s)已经不再支持了。到 GitHub 或 CodeFlying 升级。</string><string name="check_detail_version_offline">没网,先不测。当前 %1$s。</string><string name="check_detail_version_quota">今天的检查次数用完了,明天恢复。当前 %1$s。</string><string name="check_detail_version_unreachable">查不到:%1$s。当前是 %2$s。</string>diff --git a/core/src/main/kotlin/net/kuafuai/andee/config/Upgrade.kt b/core/src/main/kotlin/net/kuafuai/andee/config/Upgrade.ktnew file mode 100644index 0000000..f7b5dc6--- /dev/null+++ b/core/src/main/kotlin/net/kuafuai/andee/config/Upgrade.kt@@ -0,0 +1,32 @@+package net.kuafuai.andee.config++/**+ * What both bodies say and do when this build is behind. The version service decides whether there is an update;+ * this decides whether to *believe* it, and where to send the user.+ */+object Upgrade {++ /**+ * True only when [latest] is strictly newer than [current], compared number by number (`0.7.10` > `0.7.9`).+ * A build ahead of the release — a development build, or one installed before the service was updated — is+ * never told to "upgrade" to an older one. Anything that does not parse as numbers is not newer: a reminder+ * nobody can act on is worse than none.+ */+ fun newer(latest: String, current: String): Boolean {+ val a = parts(latest) ?: return false+ val b = parts(current) ?: return false+ for (i in 0 until maxOf(a.size, b.size)) {+ val x = a.getOrElse(i) { 0 }+ val y = b.getOrElse(i) { 0 }+ if (x != y) return x > y+ }+ return false+ }++ private fun parts(v: String): List<Int>? =+ v.trim().removePrefix("v").removePrefix("V").substringBefore('-').substringBefore('+').split('.')+ .map { it.toIntOrNull() ?: return null }.takeIf { it.isNotEmpty() }++ /** Where the upgrade button goes: CodeFlying's Chinese site for a Chinese interface, the international one otherwise. */+ fun url(lang: String): String = if (lang.startsWith("zh")) "https://www.codeflying.net" else "https://www.codeflying.app"+}diff --git a/core/src/test/kotlin/net/kuafuai/andee/config/UpgradeTest.kt b/core/src/test/kotlin/net/kuafuai/andee/config/UpgradeTest.ktnew file mode 100644index 0000000..be86894--- /dev/null+++ b/core/src/test/kotlin/net/kuafuai/andee/config/UpgradeTest.kt@@ -0,0 +1,23 @@+package net.kuafuai.andee.config++import org.junit.Assert.assertEquals+import org.junit.Assert.assertFalse+import org.junit.Assert.assertTrue+import org.junit.Test++class UpgradeTest {+ @Test fun onlyStrictlyNewerCounts() {+ assertTrue(Upgrade.newer("0.7.2", "0.7.1"))+ assertTrue(Upgrade.newer("0.7.10", "0.7.9"))+ assertTrue(Upgrade.newer("v0.8", "0.7.9"))+ assertFalse(Upgrade.newer("0.7.1", "0.7.1"))+ assertFalse(Upgrade.newer("0.7.0", "0.7.1")) // ahead of the release: no reminder+ assertFalse(Upgrade.newer("0.7", "0.7.0"))+ assertFalse(Upgrade.newer("?", "0.7.1"))+ }++ @Test fun theLinkFollowsTheLanguage() {+ assertEquals("https://www.codeflying.net", Upgrade.url("zh"))+ assertEquals("https://www.codeflying.app", Upgrade.url("en"))+ }+}diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Assistant.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Assistant.ktindex 8d6b343..6623a9f 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Assistant.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Assistant.kt@@ -533,6 +533,7 @@ object Assistant {DesktopScheduler.catchUp()DesktopScheduler.syncPlan()PlanTicks.start()+ VersionCheck.remindAtLaunch()}/**diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Cards.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Cards.ktindex 85aad1e..53ffd49 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Cards.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Cards.kt@@ -95,10 +95,8 @@ fun SelfCheckCard(onDone: () -> Unit, onOpenSettings: () -> Unit) {add(when (val r = version) {null -> CheckRow("version", if (zh) "版本" else "Version", true, if (zh) "检查中…(当前 $v)" else "Checking… (you are on $v)", null, quiet = true)is VersionCheck.Result.Current -> CheckRow("version", if (zh) "版本" else "Version", true, if (zh) "$v 已经是最新。" else "$v is the latest.", null)- is VersionCheck.Result.Behind -> CheckRow("version", if (zh) "版本" else "Version", false,- if (r.forced) { if (zh) "请升级到 ${r.latest} —— 你现在这个($v)已经不再支持了。到 GitHub 下载。" else "Please upgrade to ${r.latest} — this build ($v) is no longer supported. Get it from GitHub." }- else { if (zh) "版本落后了:最新是 ${r.latest},你现在是 $v。请到 GitHub 下载升级。" else "Out of date: the latest is ${r.latest}, you are on $v. Please upgrade from GitHub." },- { runCatching { net.kuafuai.andee.desktop.mac.Bridge.open(r.url) } }, red = true)+ is VersionCheck.Result.Behind -> CheckRow("version", if (zh) "版本" else "Version", false, VersionCheck.behindText(r),+ { runCatching { net.kuafuai.andee.desktop.mac.Bridge.open(VersionCheck.upgradeUrl()) } }, red = true)// Could not be determined is never the user's fault: a quiet note that still names the build.is VersionCheck.Result.Unknown -> CheckRow("version", if (zh) "版本" else "Version", true,if (zh) "没能查到最新版本。当前 $v。" else "Could not check for updates. You are on $v.", null, quiet = true)@@ -128,7 +126,7 @@ fun SelfCheckCard(onDone: () -> Unit, onOpenSettings: () -> Unit) {Text(r.why, color = if (r.red) Palette.danger else Palette.secondary, fontSize = 11.sp)}if (!r.ok && r.fix != null) {- Text(if (r.id == "version") (if (zh) "去 GitHub" else "GitHub") else if (zh) "去处理" else "Fix", color = Palette.accent, fontSize = 13.sp,+ Text(if (r.id == "version") (if (zh) "去升级" else "Upgrade") else if (zh) "去处理" else "Fix", color = Palette.accent, fontSize = 13.sp,modifier = Modifier.clickable { r.fix?.invoke() }.padding(6.dp))}}diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/UserPrompts.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/UserPrompts.ktindex 6c41fd6..6e3e109 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/UserPrompts.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/UserPrompts.kt@@ -236,13 +236,14 @@ object AskGate {private val waiting = androidx.compose.runtime.mutableStateOf(false)val isWaiting: Boolean get() = waiting.value- fun ask(question: String, buttons: List<String>, timeoutMs: Long): Result =- run(question, buttons, timeoutMs)+ /** [speak] = false for a card the device raises itself (the launch-time version reminder): nobody asked. */+ fun ask(question: String, buttons: List<String>, timeoutMs: Long, speak: Boolean = true): Result =+ run(question, buttons, timeoutMs, speak)fun alert(text: String, timeoutMs: Long): Result =run(text, emptyList(), timeoutMs)- private fun run(question: String, buttons: List<String>, timeoutMs: Long): Result {+ private fun run(question: String, buttons: List<String>, timeoutMs: Long, speak: Boolean = true): Result {val p = Pending(question, buttons, CompletableFuture(), System.currentTimeMillis() + timeoutMs)synchronized(this) {current?.answer?.complete(Result(null, null, "superseded"))@@ -251,7 +252,7 @@ object AskGate {waiting.value = p.buttons.isNotEmpty()onChange()// Voice-first: the question is read out, exactly as the phone says it.- MacVoice.speak(question)+ if (speak) MacVoice.speak(question)val r = runCatching { p.answer.get(timeoutMs, TimeUnit.MILLISECONDS) }.getOrDefault(Result(null, null, "timeout"))synchronized(this) { if (current === p) current = null }diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/VersionCheck.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/VersionCheck.ktindex af3495e..1439e8f 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/VersionCheck.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/VersionCheck.kt@@ -14,23 +14,22 @@ import java.util.concurrent.TimeUnit* never the key or the address). No conversation, no screen content, no file names. It is the one call the app* makes to a host the maintainers run, and docs/permissions.md says so.*- * Behind is red and says where to upgrade (GitHub). Anything that could not be determined — no network, the- * day's allowance spent, a server error — is a quiet note, never a fault: a statistics endpoint being down is- * not the user's problem.+ * Behind — a release strictly newer than this build ([net.kuafuai.andee.config.Upgrade.newer]; a build ahead of+ * the release is current) — is red, says to upgrade from GitHub or CodeFlying, and its button opens CodeFlying's+ * site in the interface language. Checked once at launch ([remindAtLaunch]) and again whenever the self-check card+ * opens. Anything that could not be determined — no network, the day's allowance spent, a server error — is a+ * quiet note, never a fault: a statistics endpoint being down is not the user's problem.*/object VersionCheck {- /** Where a newer build is published, and the fallback when the service names no download address. */- const val RELEASES_URL = "https://github.com/kuafuai/andee/releases"-private const val BASE = "https://api.heyandee.com"private const val CALL_MS = 4_000Lsealed interface Result {/** Reached, and this is the current release. */object Current : Result- /** Reached, and there is a newer one. [url] is where to get it. */- data class Behind(val latest: String, val forced: Boolean, val url: String) : Result+ /** Reached, and there is a strictly newer release. */+ data class Behind(val latest: String, val forced: Boolean) : Result/** Could not be determined; [why] is for the row's text. */data class Unknown(val why: String) : Result}@@ -64,12 +63,11 @@ object VersionCheck {if (json.optInt("code", -1) != 0) return Result.Unknown("HTTP ${resp.code} code=${json.optInt("code")}")val data = json.optJSONObject("data") ?: return Result.Unknown("no data")if (!data.optBoolean("has_update", false)) return Result.Current- // org.json hands back the four-letter string "null" for a JSON null: check the scheme, not emptiness.- val raw = data.optString("download_url").orEmpty()+ // Ahead of (or level with) the release is not behind, whatever the service says.+ if (!net.kuafuai.andee.config.Upgrade.newer(data.optString("latest_version"), current())) return Result.CurrentResult.Behind(latest = data.optString("latest_version").ifEmpty { "?" },forced = data.optBoolean("force_update", false),- url = raw.takeIf { it.startsWith("http://") || it.startsWith("https://") } ?: RELEASES_URL,)}} catch (e: Exception) {@@ -77,6 +75,43 @@ object VersionCheck {}}+ /** Where the upgrade button goes, in the interface language. */+ fun upgradeUrl(): String = net.kuafuai.andee.config.Upgrade.url(Strings.lang())++ /** The row's and the reminder's sentence. */+ fun behindText(r: Result.Behind): String {+ val zh = Strings.lang() == "zh"+ val v = current()+ return if (r.forced) {+ if (zh) "请升级到 ${r.latest} —— 你现在这个($v)已经不再支持了。到 GitHub 或 CodeFlying 升级。"+ else "Please upgrade to ${r.latest} — this build ($v) is no longer supported. Upgrade from GitHub or CodeFlying."+ } else {+ if (zh) "版本落后了:最新是 ${r.latest},你现在是 $v。请到 GitHub 或 CodeFlying 升级。"+ else "Out of date: the latest is ${r.latest}, you are on $v. Upgrade from GitHub or CodeFlying."+ }+ }++ /**+ * The phone's startup card, on the Mac: check once at launch and, only if behind, put up one card beside the+ * ball with 去升级 / 以后再说. Silent (not read aloud — nobody asked a question), and only when no other card is+ * up. Nothing at all when current, ahead, or undeterminable.+ */+ fun remindAtLaunch() {+ Thread({+ Thread.sleep(LAUNCH_DELAY_MS)+ val r = probe() as? Result.Behind ?: return@Thread+ if (AskGate.current != null) return@Thread+ val zh = Strings.lang() == "zh"+ val go = if (zh) "去升级" else "Upgrade"+ val a = AskGate.ask(behindText(r), listOf(go, if (zh) "以后再说" else "Later"), REMIND_MS, speak = false)+ if (a.button == go) runCatching { net.kuafuai.andee.desktop.mac.Bridge.open(upgradeUrl()) }+ }, "version-remind").apply { isDaemon = true }.start()+ }++ /** Long enough for the ball to be up before the card is placed beside it. */+ private const val LAUNCH_DELAY_MS = 8_000L+ private const val REMIND_MS = 120_000L+private fun usingCodeFlyingWithKey(): Boolean = Assistant.config().let {it.mode == net.kuafuai.andee.config.BrainConfig.BRAIN_CODEFLYING && it.apiKey.isNotBlank()}