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、支持任意模型,记忆和密码绝不离开设备。
fix(self-check): stop the launcher page and the assistant fighting for the screen
booboosui5cf81b31e151
diff --git a/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt b/app/src/main/java/net/kuafuai/andee/BodyCoreService.ktindex 8840e7f..8696ea0 100644--- a/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt+++ b/app/src/main/java/net/kuafuai/andee/BodyCoreService.kt@@ -1819,7 +1819,20 @@ class BodyCoreService : Service() {if (selfCheck?.isShowing() == true) returnval s = net.kuafuai.andee.ui.SelfCheckUi(context = this,- onDismiss = { selfCheck = null },+ // A user closing the check is asking for the assistant back, so it+ // comes back full size. Unfolding here and not in the ✕ handler is+ // the point of the flag: this same callback also fires on the way+ // out to a Settings page, and unfolding *there* would put the card+ // back over the screen we just folded it to clear. See+ // SelfCheckUi.onDismiss and SelfCheckUi.hide.+ //+ // Safe when the card was never folded, which is the ordinary case:+ // `expand()` is idempotent, and ✕ from a full-size card is the user+ // asking for the screen they already have.+ onDismiss = { yielding ->+ selfCheck = null+ if (!yielding) dispatcher.expand()+ },// Our own sheet, reached through the service because that is where// it lives. Never null from here: if this method is running, we are.onOpenSettings = { openSettings() },@@ -1843,7 +1856,7 @@ class BodyCoreService : Service() {// that is what clears [selfCheck].onYieldScreen = {dispatcher.compactForUser()- selfCheck?.hide()+ selfCheck?.hide(yielding = true)},// The card owns its language switch; the ball and the scrollback live// in this service and have to be told the same way [openSettings]diff --git a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.ktindex 14218c9..df6a347 100644--- a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckActivity.kt@@ -254,7 +254,10 @@ class SelfCheckActivity : StageActivity() {ui = SelfCheckUi(context = this,host = stage,- onDismiss = { leave() },+ // The flag is not consulted here: this host has no assistant to+ // unfold *at this point* — but see [onStageLeaving], which is where+ // that assumption gets checked rather than trusted.+ onDismiss = { _ -> leave() },// The two rows a first-run user actually has to act on — 大脑 and// 语音密钥 — are `Fix.OurSettings`, and this page used to draw them// with no button at all on the argument that the sheet belongs to the@@ -283,9 +286,38 @@ class SelfCheckActivity : StageActivity() {revealStage()}- /** Give the ball back. Nothing to unfold: see [onCreate]. */+ /**+ * Give the screen back to the assistant — which, by now, may well exist.+ *+ * The first half is the original job: drop the ball off the ledge it was+ * parked on while this page covered the screen.+ *+ * The second half corrects the assumption the first version was written on+ * ("nothing to unfold: see [onCreate]"). That assumption is true when this+ * page *opens* and false by the time it *closes*, because the page's own+ * first row is the overlay grant and its own buttons send the user off to+ * fix the rows they can. So the device this page exists for is precisely the+ * one where the assistant comes up while the page is on screen — and the+ * user closes the page onto a lone ball in the corner, with the full card+ * they were just setting up nowhere to be found.+ *+ * That is the report: grant the permission, close the check, and get a ball+ * instead of the assistant. The card is not "somewhere else" on that device;+ * it is there and folded, and the one surface that knows the user has+ * finished with the diagnosis is this one, on its way out.+ *+ * Unfolding here rather than after the exit animation is deliberate:+ * [StageActivity.leave] hands the screen back synchronously before the+ * window shrinks, so the card grows into place *underneath* the shrinking+ * page rather than appearing after it — see that method's `onStageLeaving`.+ *+ * `BodyCoreService.get()` may be null, and that is the ordinary case this+ * page opens in: nothing to hand back, and nothing to unfold.+ */override fun onStageLeaving() {- BodyCoreService.get()?.ballWindow()?.setPagePerched(false)+ val svc = BodyCoreService.get()+ svc?.ballWindow()?.setPagePerched(false)+ svc?.dispatcherForNotification()?.expand()}/**@@ -426,6 +458,12 @@ class SelfCheckActivity : StageActivity() {override fun onResume() {super.onResume()++ // Before anything else, and before the `ui` guard: the card this page+ // drew may have stopped being the right surface to be showing while the+ // user was away fixing it. See [handOverToBody].+ if (handOverToBody()) return+if (!::ui.isInitialized) returnval now = VoiceConfig.uiLanguage(this)if (paintedLang.isNotEmpty() && now != paintedLang) ui.repaintForLanguage()@@ -458,6 +496,49 @@ class SelfCheckActivity : StageActivity() {ui.refreshLocal()}+ /**+ * Hand the screen to the assistant, if it has arrived.+ *+ * [onCreate] asks this question once, at launch, and at that moment the+ * answer is usually *no*: this page is drawn before the body it starts has+ * attached its overlays. But this page is also where the user fixes the+ * reasons it was drawn at all — its first row *is* the overlay grant, and+ * its buttons are all doors to system screens — so the answer changes while+ * the page is up, and nothing asks again.+ *+ * What that looks like from the outside is the report this fixes: grant the+ * permission, come back, and there is a diagnostic page on screen with a+ * full-size assistant card painted over it. Two surfaces, one vision, and no+ * way to tell which one the ✕ in the corner belongs to — it belongs to the+ * card, so the user who means "close the check" folds the assistant instead+ * and is left looking at a ball.+ *+ * So the page's job is over the moment the assistant can draw itself, which+ * is the same question `SelfCheck.overlay` answers: this closes the page and+ * unfolds the card in one breath, and the two never share the screen.+ *+ * Asked on *every* resume, unlike the local re-read below — and for the same+ * reason, from the other side: the user is very often returning from exactly+ * the Settings screen that granted this, which is a resume with the service+ * newly up.+ *+ * Returns whether the hand-over happened, so [onResume] can stop: everything+ * after that point is work on a card that is on its way out.+ *+ * Nothing happens unless the card is genuinely drawable. A red overlay row+ * is on this very page, and closing the page for a card that cannot appear+ * would trade a diagnosis for an empty screen — the one outcome worse than+ * the bug being fixed here.+ */+ private fun handOverToBody(): Boolean {+ val svc = BodyCoreService.get() ?: return false+ if (!svc.ensureOverlays()) return false+ val d = svc.dispatcherForNotification() ?: return false+ d.expand()+ leave()+ return true+ }+override fun onDestroy() {// Our sheet is a window, not a child of this Activity, so nothing takes// it down with us — an Activity destroyed with it up would leave andiff --git a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.ktindex e5a0a58..6e21916 100644--- a/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt+++ b/app/src/main/java/net/kuafuai/andee/ui/SelfCheckUi.kt@@ -95,7 +95,17 @@ import java.util.concurrent.Executors*/class SelfCheckUi(private val context: Context,- private val onDismiss: () -> Unit,+ /**+ * The card is gone — put your house in order.+ *+ * @param yielding true when this close is the host stepping out of the way+ * of another screen (see [onYieldScreen]), false when the user asked for+ * it with ✕ or 完成. A host needs the difference, and only a host can act+ * on it: a user closing the check is asking for the assistant back, while+ * a yield is one step of handing the screen to somebody else and must not+ * undo itself. See `BodyCoreService.openSelfCheck`.+ */+ private val onDismiss: (yielding: Boolean) -> Unit,private val onOpenSettings: (() -> Unit)? = null,/** Fired when this card's own picker moved the language — see the class doc. */private val onLocaleChanged: () -> Unit = {},@@ -285,15 +295,25 @@ class SelfCheckUi(* only from a user pressing ✕ — [onYieldScreen] has the host close the card* on the way out to the browser. Fold, reopen the check, and the stale exit* would land after the second card was up.+ *+ * ### [yielding], and why the caller has to say+ *+ * The two closes look identical from in here and mean opposite things out+ * there, so the one caller that knows which it is passes it: ✕ and 完成+ * close with the default, and [onYieldScreen]'s host closes with `true`.+ * The distinction exists because of what the *host* does with it — see+ * [onDismiss] — and it cannot be inferred here, because the fold that+ * accompanies a yield is the host's own doing and is already in flight by+ * the time this runs.*/- fun hide() {+ fun hide(yielding: Boolean = false) {val v = root ?: returnroot = nullval stage = hostif (stage != null) {runCatching { stage.removeView(v) }OwnCard.hidden()- onDismiss()+ onDismiss(yielding)return}val wm = wm ?: return@@ -303,7 +323,7 @@ class SelfCheckUi(runCatching { wm.removeView(v) }closing = nullOwnCard.hidden()- onDismiss()+ onDismiss(yielding)}}}