Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): show clipboard invitation after first paste permission
Davidad585b311309
diff --git a/apps/mobile/src/__tests__/clipboardSharedTaskInvitation.test.tsx b/apps/mobile/src/__tests__/clipboardSharedTaskInvitation.test.tsxindex f422fd0a1a..c94038f989 100644--- a/apps/mobile/src/__tests__/clipboardSharedTaskInvitation.test.tsx+++ b/apps/mobile/src/__tests__/clipboardSharedTaskInvitation.test.tsx@@ -68,6 +68,38 @@ it('does not reread after an inactive/active permission prompt', async () => {await render(); clearSharedTaskInvitationIntent();await state('inactive'); await state('active'); expect(h.read).toHaveBeenCalledTimes(1);});+it('offers the first allowed clipboard invitation when the permission prompt returns to active', async () => {+ let finish!: (text: string) => void;+ h.read.mockImplementation(() => new Promise(resolve => { finish = resolve; }));+ await render();+ await state('inactive');+ await act(async () => finish(link));+ expect(getPendingSharedTaskInvitationIntent()).toBeNull();+ await state('active');+ expect(getPendingSharedTaskInvitationIntent()).toMatchObject({ invitation: token, source: 'clipboard' });+ expect(h.read).toHaveBeenCalledTimes(1);+});+it('does not offer a permission-prompt result after a link invitation replaces it', async () => {+ let finish!: (text: string) => void;+ h.read.mockImplementation(() => new Promise(resolve => { finish = resolve; }));+ await render(); await state('inactive');+ await act(async () => finish(link));+ receiveSharedTaskInvitationIntent('cindy://shared-session?invitation=' + 'B'.repeat(43) + '&server=https%3A%2F%2Frelay.example.test');+ await state('active');+ expect(getPendingSharedTaskInvitationIntent()).toMatchObject({ invitation: 'B'.repeat(43), source: 'link' });+ expect(h.read).toHaveBeenCalledTimes(1);+});+it('rereads for a new account after a permission prompt returns to active', async () => {+ const finishes: Array<(text: string) => void> = [];+ h.read.mockImplementation(() => new Promise(resolve => { finishes.push(resolve); }));+ await render(); await state('inactive');+ await act(async () => finishes[0](link));+ await act(async () => { setMobileAuthOwner('another'); await vi.runAllTicks(); });+ await state('active');+ expect(h.read).toHaveBeenCalledTimes(2);+ await act(async () => finishes[1](link.replace(token, 'B'.repeat(43))));+ expect(getPendingSharedTaskInvitationIntent()).toMatchObject({ invitation: 'B'.repeat(43), source: 'clipboard' });+});it('waits for login and leaves an open admission form alone', async () => {await render(false); expect(h.read).not.toHaveBeenCalled();await render(true, true); expect(h.read).not.toHaveBeenCalled();diff --git a/apps/mobile/src/device-link/useClipboardSharedTaskInvitation.ts b/apps/mobile/src/device-link/useClipboardSharedTaskInvitation.tsindex ea175a728a..acb69d24d3 100644--- a/apps/mobile/src/device-link/useClipboardSharedTaskInvitation.ts+++ b/apps/mobile/src/device-link/useClipboardSharedTaskInvitation.ts@@ -21,6 +21,7 @@ export function useClipboardSharedTaskInvitation(enabled: boolean, joining: boollet started = false;let background = false;let activation = 0;+ let deferredOffer: (() => void) | null = null;const check = async () => {if (reading || joiningRef.current || getPendingSharedTaskInvitationIntent()) return;const owner = getMobileAuthOwner();@@ -35,14 +36,19 @@ export function useClipboardSharedTaskInvitation(enabled: boolean, joining: boolif (!/https?:\/\//.test(text)) return;const parsed = parseSharedTaskInvitation(text, DEVICE_LINK_API_BASE_URL);if (!parsed.ok || seenInvitations.current.has(parsed.invitation)) return;- if (joiningRef.current || !isMobileAuthOwnerCurrent(owner)- || sequence !== getSharedTaskInvitationIntentSequence() || getPendingSharedTaskInvitationIntent()) {- return;- }- if (captured !== activation || AppState.currentState !== 'active') return;- const url = 'cindy://shared-session?invitation=' + encodeURIComponent(parsed.invitation)- + '&server=' + encodeURIComponent(DEVICE_LINK_API_BASE_URL);- if (receiveSharedTaskInvitationIntent(url, 'clipboard')) seenInvitations.current.add(parsed.invitation);+ const offer = () => {+ if (disposed || captured !== activation || joiningRef.current || !isMobileAuthOwnerCurrent(owner)+ || sequence !== getSharedTaskInvitationIntentSequence() || getPendingSharedTaskInvitationIntent()) {+ return;+ }+ // The iOS paste permission sheet can resolve the read while the app is inactive.+ // Keep that result until focus returns instead of reading the clipboard again.+ if (AppState.currentState !== 'active') { deferredOffer = offer; return; }+ const url = 'cindy://shared-session?invitation=' + encodeURIComponent(parsed.invitation)+ + '&server=' + encodeURIComponent(DEVICE_LINK_API_BASE_URL);+ if (receiveSharedTaskInvitationIntent(url, 'clipboard')) seenInvitations.current.add(parsed.invitation);+ };+ offer();} catch {// Denied/unavailable clipboard access leaves the current page usable.} finally {@@ -51,19 +57,24 @@ export function useClipboardSharedTaskInvitation(enabled: boolean, joining: bool}};const activate = (state: AppStateStatus) => {- if (state === 'background') { background = true; activation++; }- if (state !== 'active' || (started && !background)) return;+ if (state === 'background') { background = true; activation++; deferredOffer = null; }+ if (state !== 'active') return;+ const offer = deferredOffer;+ deferredOffer = null;+ offer?.();+ if (started && !background) return;started = true; background = false;void check();};const subscription = AppState.addEventListener('change', activate);const stopWatchingOwner = subscribeMobileAuthOwner(() => {// Cancel the old owner's read; a fresh read belongs to the settled account.- activation++;+ activation++; deferredOffer = null;+ if (AppState.currentState !== 'active') started = false;// Let the intent store retire the old owner's pending link first.queueMicrotask(() => { if (!disposed && AppState.currentState === 'active') void check(); });});activate(AppState.currentState);- return () => { disposed = true; subscription.remove(); stopWatchingOwner(); };+ return () => { disposed = true; deferredOffer = null; subscription.remove(); stopWatchingOwner(); };}, [enabled]);}