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: the Mac self-check asks for updates, and being behind is red on both bodies
booboosui7a3cd3870f19
diff --git a/app/src/main/java/net/kuafuai/andee/device/SelfCheck.kt b/app/src/main/java/net/kuafuai/andee/device/SelfCheck.ktindex be593a6..94c74b0 100644--- a/app/src/main/java/net/kuafuai/andee/device/SelfCheck.kt+++ b/app/src/main/java/net/kuafuai/andee/device/SelfCheck.kt@@ -555,7 +555,10 @@ object SelfCheck {)}val deviceId = VoiceConfig.hubConfig(context).deviceId- return when (val v = probeVersion(VERSION_API_BASE, BuildConfig.VERSION_NAME, deviceId)) {+ return when (val v = probeVersion(+ VERSION_API_BASE, BuildConfig.VERSION_NAME, deviceId,+ VoiceConfig.brainMode(context) == VoiceConfig.BRAIN_CODEFLYING,+ )) {is Verdict.Current -> Finding(id = "version",title = R.string.check_title_version,@@ -567,7 +570,9 @@ object SelfCheck {is Verdict.Update -> Finding(id = "version",title = R.string.check_title_version,- level = if (v.forced) Level.WARN else Level.NOTE,+ // Behind is red, forced or not: the user asked for it to be impossible to miss, and the text+ // says where to get the new one. (It used to be a grey note — "the old one still works".)+ level = Level.FAIL,detail = if (v.forced) R.string.check_detail_version_forcedelse R.string.check_detail_version_stale,// %1$s is always the release we want you on and %2$s is always@@ -575,10 +580,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),- // No published download URL means nowhere to send the user, and- // a button that goes nowhere is the small lie this list exists- // to avoid -- see Fix.Link.- fix = v.url?.let { Fix.Link(it) } ?: Fix.Nothing,+ // 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),)is Verdict.QuotaSpent -> Finding(@@ -1340,7 +1343,7 @@ object SelfCheck {* "(wifi)" on some clones). Hand-joined, those go out raw and the service* records a truncated model name.*/- private fun probeVersion(base: String, current: String, deviceId: String): Verdict {+ private fun probeVersion(base: String, current: String, deviceId: String, codeFlying: Boolean): Verdict {val url = base.toHttpUrlOrNull()?.newBuilder()?.addPathSegments("api/version")@@ -1351,6 +1354,9 @@ object SelfCheck {?.addQueryParameter("os_version", "Android ${Build.VERSION.RELEASE} (API ${Build.VERSION.SDK_INT})")?.addQueryParameter("device_id", deviceId)?.addQueryParameter("app_package", BuildConfig.APPLICATION_ID)+ // Whether the CodeFlying backend is the one in force right now: "1" / "0". Only the on/off fact,+ // never the key or the address.+ ?.addQueryParameter("codeflying", if (codeFlying) "1" else "0")?.addQueryParameter("lang", Locale.getDefault().toLanguageTag())?.build()?: return Verdict.Unreachable("bad address: $base")@@ -1489,6 +1495,9 @@ 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 0340c22..19ee5eb 100644--- a/app/src/main/res/values-en/strings.xml+++ b/app/src/main/res/values-en/strings.xml@@ -568,8 +568,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">%1$s is available; you are on %2$s. The old one still works — update whenever you like.</string>- <string name="check_detail_version_forced">Update to %1$s. The build you are on (%2$s) is no longer supported.</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_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 3e43c4e..f735675 100644--- a/app/src/main/res/values/strings.xml+++ b/app/src/main/res/values/strings.xml@@ -652,8 +652,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。旧的还能用,想换再换。</string>- <string name="check_detail_version_forced">请更新到 %1$s —— 你现在这个(%2$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_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/desktop/build.gradle b/desktop/build.gradleindex eea6988..6327b48 100644--- a/desktop/build.gradle+++ b/desktop/build.gradle@@ -51,11 +51,16 @@ sourceSets.main.resources.srcDir(nativeOut)// The CodeFlying build settings, read from local.properties exactly as :app does// (CODEFLYING_ENABLED / _DOMAIN / _SSL_ENABLED / _KEY). local.properties is gitignored, so a// checkout with nothing configured builds a Mac app with no CodeFlying server, as before.+// The product version, read from the phone's versionName so there is one number for both bodies+// (the bundle's packageVersion below is only what macOS requires of a .dmg).+def productVersion = (rootProject.file('app/build.gradle').text =~ /versionName\s+"([^"]+)"/).with { it.find() ? it.group(1) : '0.0.0' }+def codeFlyingOut = layout.buildDirectory.dir('generated/codeflying')tasks.register('generateCodeFlyingConfig') {def localFile = rootProject.file('local.properties')def out = codeFlyingOut.get().file('codeflying.properties').asFileinputs.files(localFile).optional()+ inputs.property('productVersion', productVersion)outputs.file(out)doLast {def lp = new Properties()@@ -64,6 +69,7 @@ tasks.register('generateCodeFlyingConfig') {['CODEFLYING_ENABLED', 'CODEFLYING_DOMAIN', 'CODEFLYING_SSL_ENABLED', 'CODEFLYING_KEY'].each {o.setProperty(it, lp.getProperty(it, '').trim())}+ o.setProperty('PRODUCT_VERSION', productVersion)out.parentFile.mkdirs()out.withOutputStream { o.store(it, 'generated from local.properties') }}@@ -77,6 +83,8 @@ dependencies {implementation compose.desktop.currentOs// Android has org.json built in; a JVM app has to bring it.implementation 'org.json:json:20240303'+ // The version check's HTTP client; core keeps its own copy to itself. Same version.+ implementation 'com.squareup.okhttp3:okhttp:4.12.0'// Bonjour/mDNS on the JVM, for finding the phone on the LAN (the JDK has none). Pure Java, no native part.implementation 'org.jmdns:jmdns:3.5.9'// PeerServer extends its WebSocketServer, and core keeps that dependency to itself.diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Cards.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Cards.ktindex b4c33ba..038c620 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Cards.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/Cards.kt@@ -40,7 +40,7 @@ import androidx.compose.ui.unit.sp@Composablefun SelfCheckCard(onDone: () -> Unit, onOpenSettings: () -> Unit) {val zh = Strings.lang() == "zh"- data class CheckRow(val id: String, val name: String, val ok: Boolean, val why: String, val fix: (() -> Unit)?)+ data class CheckRow(val id: String, val name: String, val ok: Boolean, val why: String, val fix: (() -> Unit)?, val red: Boolean = false, val quiet: Boolean = false)// Re-read on demand. Every row here is changed in *another* app — System// Settings for the three permissions, the settings card for the two keys —// and a card that computed its rows once would go on saying "cannot see the@@ -48,7 +48,13 @@ fun SelfCheckCard(onDone: () -> Unit, onOpenSettings: () -> Unit) {// phone's card carries 重新检查: checking whether a fix took should not mean// closing this card and finding it again.var refresh by remember { mutableStateOf(0) }- val rows = remember(refresh) { buildList {+ // The one row that asks the network, so it is read off the UI thread and starts as "checking".+ var version by remember { mutableStateOf<VersionCheck.Result?>(null) }+ LaunchedEffect(refresh) {+ version = null+ version = kotlinx.coroutines.withContext(kotlinx.coroutines.Dispatchers.IO) { VersionCheck.probe() }+ }+ val rows = remember(refresh, version) { buildList {val ax = net.kuafuai.andee.desktop.mac.Bridge.axTrusted()add(CheckRow("ax", if (zh) "辅助功能" else "Accessibility", ax,if (ax) if (zh) "能读、能操作别的 app" else "Can read and drive other apps" else if (zh) "读不到屏幕,也无法操作" else "Cannot read or drive the screen",@@ -76,6 +82,18 @@ fun SelfCheckCard(onDone: () -> Unit, onOpenSettings: () -> Unit) {else if (cf) if (zh) "还没填 CodeFlying 密钥,说不了话" else "No CodeFlying key — Andee cannot speak"else if (zh) "还没配,说不了话" else "Missing — Andee cannot speak",{ onOpenSettings() }))+ val v = VersionCheck.current()+ 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)+ // 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)+ })}}// Re-reading is instant and, more often than not, changes nothing — so a tap@@ -94,14 +112,14 @@ fun SelfCheckCard(onDone: () -> Unit, onOpenSettings: () -> Unit) {Modifier.fillMaxWidth().glassPanel(14).padding(12.dp),verticalAlignment = Alignment.CenterVertically,) {- Icon(if (r.ok) AndeeIcon.CHECK_CIRCLE else AndeeIcon.ALERT_CIRCLE, if (r.ok) Palette.ok else Palette.warn, 20.dp)+ Icon(if (r.ok) AndeeIcon.CHECK_CIRCLE else AndeeIcon.ALERT_CIRCLE, if (r.ok) (if (r.quiet) Palette.secondary else Palette.ok) else if (r.red) Palette.danger else Palette.warn, 20.dp)Spacer(Modifier.width(10.dp))Column(Modifier.weight(1f)) {Text(r.name, color = Palette.label, fontSize = 14.sp)- Text(r.why, color = Palette.secondary, fontSize = 11.sp)+ Text(r.why, color = if (r.red) Palette.danger else Palette.secondary, fontSize = 11.sp)}if (!r.ok && r.fix != null) {- Text(if (zh) "去处理" else "Fix", color = Palette.accent, fontSize = 13.sp,+ Text(if (r.id == "version") (if (zh) "去 GitHub" else "GitHub") 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/CodeFlyingBuild.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/CodeFlyingBuild.ktindex a3f0c8f..fc956c2 100644--- a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/CodeFlyingBuild.kt+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/CodeFlyingBuild.kt@@ -21,4 +21,7 @@ object CodeFlyingBuild {val domain: String get() = p.getProperty("CODEFLYING_DOMAIN", "").trim()val ssl: Boolean get() = flag("CODEFLYING_SSL_ENABLED")val key: String get() = p.getProperty("CODEFLYING_KEY", "").trim()++ /** The product's version, the phone's `versionName`: one number for both bodies. */+ val productVersion: String get() = p.getProperty("PRODUCT_VERSION", "").trim().ifEmpty { "0.0.0" }}diff --git a/desktop/src/main/kotlin/net/kuafuai/andee/desktop/VersionCheck.kt b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/VersionCheck.ktnew file mode 100644index 0000000..c17d084--- /dev/null+++ b/desktop/src/main/kotlin/net/kuafuai/andee/desktop/VersionCheck.kt@@ -0,0 +1,84 @@+package net.kuafuai.andee.desktop++import okhttp3.HttpUrl.Companion.toHttpUrlOrNull+import okhttp3.OkHttpClient+import okhttp3.Request+import org.json.JSONObject+import java.util.concurrent.TimeUnit++/**+ * The self-check's version row on the Mac: the phone's `SelfCheck.probeVersion`, against the same service.+ *+ * What it sends, and nothing else: this build's version, `platform=mac`, the Mac's model and macOS release, the+ * interface language, this install's own random id, and whether CodeFlying is the backend in force (on / off —+ * 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.+ */+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_000L++ sealed 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+ /** Could not be determined; [why] is for the row's text. */+ data class Unknown(val why: String) : Result+ }++ fun current(): String = CodeFlyingBuild.productVersion++ /** One GET. Blocking: call it off the UI thread. */+ fun probe(): Result {+ val url = BASE.toHttpUrlOrNull()?.newBuilder()+ ?.addPathSegments("api/version")+ ?.addQueryParameter("current", current())+ ?.addQueryParameter("platform", "mac")+ ?.addQueryParameter("model", macModel())+ ?.addQueryParameter("brand", "Apple")+ ?.addQueryParameter("os_version", "macOS ${System.getProperty("os.version")} (${System.getProperty("os.arch")})")+ ?.addQueryParameter("device_id", Settings.uid())+ ?.addQueryParameter("app_package", "net.kuafuai.andee.mac")+ ?.addQueryParameter("codeflying", if (Assistant.config().mode == net.kuafuai.andee.config.BrainConfig.BRAIN_CODEFLYING) "1" else "0")+ ?.addQueryParameter("lang", Strings.locale().toLanguageTag())+ ?.build() ?: return Result.Unknown("bad address")+ val http = OkHttpClient.Builder()+ .connectTimeout(3, TimeUnit.SECONDS).readTimeout(3, TimeUnit.SECONDS)+ .callTimeout(CALL_MS, TimeUnit.MILLISECONDS).build()+ return try {+ http.newCall(Request.Builder().url(url).get().build()).execute().use { resp ->+ // Ten a day per address, and 重新检测 spends one per tap: the service says "enough today" with 429.+ if (resp.code == 429) return Result.Unknown("quota")+ val json = runCatching { JSONObject(resp.body?.string().orEmpty()) }.getOrNull()+ ?: return Result.Unknown("HTTP ${resp.code}")+ 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()+ Result.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) {+ Result.Unknown(e.message ?: e.javaClass.simpleName)+ }+ }++ /** "Mac14,5"-style model identifier; empty when sysctl is not answering. */+ private fun macModel(): String = runCatching {+ val p = ProcessBuilder("/usr/sbin/sysctl", "-n", "hw.model").redirectErrorStream(true).start()+ p.inputStream.bufferedReader().readText().trim().also { p.waitFor(2, TimeUnit.SECONDS) }+ }.getOrDefault("")+}