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): 去掉多余的最新复制判断,后一次复制失败时保留上一次的清理凭据

Dash429d206ef008
diff --git a/apps/mobile/src/__tests__/copiedCodeClipboard.test.ts b/apps/mobile/src/__tests__/copiedCodeClipboard.test.ts
index a49882f6df..e789a259af 100644
--- a/apps/mobile/src/__tests__/copiedCodeClipboard.test.ts
+++ b/apps/mobile/src/__tests__/copiedCodeClipboard.test.ts
@@ -81,6 +81,33 @@ it("keeps the latest iOS copy clearable when the user taps copy twice quickly",
expect(h.text).toBe("");
});
+it("settles copies in call order and lets a failed copy keep the earlier token", async () => {
+ const settled: string[] = [];
+ h.setString.mockImplementationOnce(async (value: string) => {
+ h.text = value;
+ h.count++;
+ return true;
+ });
+ h.setString.mockRejectedValueOnce(new Error("write failed"));
+ let token: { code: string; version?: string } | undefined;
+ await Promise.allSettled([
+ copyCode("CODE-1").then((copied) => {
+ settled.push("first");
+ token = copied;
+ }),
+ copyCode("CODE-1").then(
+ (copied) => {
+ token = copied;
+ },
+ () => settled.push("second-failed"),
+ ),
+ ]);
+ expect(settled).toEqual(["first", "second-failed"]);
+ expect(token?.version).toBe("6");
+ await clearCopiedCode(token!);
+ expect(h.text).toBe("");
+});
+
it("compares contents on Android, so returning from the browser still clears the code", async () => {
h.os = "android";
const copied = await copyCode("CODE-1");
diff --git a/apps/mobile/src/plugins/PluginSetupNativeForm.tsx b/apps/mobile/src/plugins/PluginSetupNativeForm.tsx
index 112e3093f5..e5aa6cac5a 100644
--- a/apps/mobile/src/plugins/PluginSetupNativeForm.tsx
+++ b/apps/mobile/src/plugins/PluginSetupNativeForm.tsx
@@ -67,8 +67,7 @@ export default function PluginSetupNativeForm({
alive = useRef(true),
lock = useRef(false),
operation = useRef(0),
- copiedCode = useRef<CopiedCode | undefined>(undefined),
- copyAttempt = useRef(0);
+ copiedCode = useRef<CopiedCode | undefined>(undefined);
const live = useRef({ focused, epoch: link.connectionEpoch });
live.current = { focused, epoch: link.connectionEpoch };
const [selected, setSelected] = useState<MobilePluginSetupAction | undefined>(
@@ -339,11 +338,10 @@ export default function PluginSetupNativeForm({
accessibilityRole="button"
onPress={() => {
const code = browser.code!;
- const attempt = ++copyAttempt.current;
+ // Copies settle in order; a failed copy keeps the
+ // previous successful token.
void copyCode(code)
.then((copied) => {
- // Only the latest copy owns the cleanup token.
- if (attempt !== copyAttempt.current) return;
copiedCode.current = copied;
if (!alive.current) void releaseCopiedCode();
})