Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mobile): iOS 清理验证码改用原生比较后写入,避免清掉清理间隙里的新复制

Dashdb6aa1c18f26
diff --git a/apps/mobile/src/__tests__/copiedCodeClipboard.test.ts b/apps/mobile/src/__tests__/copiedCodeClipboard.test.ts
index 03deceba75..c4d5d86b85 100644
--- a/apps/mobile/src/__tests__/copiedCodeClipboard.test.ts
+++ b/apps/mobile/src/__tests__/copiedCodeClipboard.test.ts
@@ -30,7 +30,15 @@ vi.mock("expo-clipboard", () => ({
setStringAsync: h.setString,
}));
vi.mock("../../modules/cindy-remote-presentation/src", () => ({
- remotePresentation: { clipboardVersion: async () => String(h.count) },
+ remotePresentation: {
+ clipboardVersion: async () => String(h.count),
+ syncClipboard: async (json: string, version: string) => {
+ if (String(h.count) !== version) throw new Error("CLIPBOARD_CHANGED");
+ h.text = JSON.parse(json).text;
+ h.count++;
+ return String(h.count);
+ },
+ },
}));
import { clearCopiedCode, copyCode } from "@/plugins/copiedCodeClipboard";
diff --git a/apps/mobile/src/plugins/copiedCodeClipboard.ts b/apps/mobile/src/plugins/copiedCodeClipboard.ts
index e5559d4a00..a0f26c2875 100644
--- a/apps/mobile/src/plugins/copiedCodeClipboard.ts
+++ b/apps/mobile/src/plugins/copiedCodeClipboard.ts
@@ -31,11 +31,16 @@ export async function copyCode(code: string): Promise<CopiedCode> {
/** Clear the clipboard only while it still holds the copied code. */
export async function clearCopiedCode(copied: CopiedCode): Promise<void> {
- // iOS asks for paste permission when the contents are read, so compare the
- // change count there. Android has no such prompt; compare the contents.
- const owned =
- Platform.OS === "ios"
- ? copied.version !== undefined && (await iosVersion()) === copied.version
- : (await Clipboard.getStringAsync().catch(() => "")) === copied.code;
- if (owned) await Clipboard.setStringAsync("").catch(() => {});
+ if (Platform.OS === "ios") {
+ // Reading the contents would trigger the iOS paste prompt. The native
+ // write compares the change count and clears in one main-queue step.
+ if (copied.version !== undefined)
+ await remotePresentation
+ ?.syncClipboard?.(JSON.stringify({ text: "" }), copied.version)
+ .catch(() => {});
+ return;
+ }
+ // Android has no paste prompt; compare the contents.
+ if ((await Clipboard.getStringAsync().catch(() => "")) === copied.code)
+ await Clipboard.setStringAsync("").catch(() => {});
}