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(remote-desktop): 统一新剪贴板冲突与跳过提示计数

Dashc075a0b82a0d
diff --git a/apps/desktop/src/main/remote-desktop-viewer/__tests__/safety.test.ts b/apps/desktop/src/main/remote-desktop-viewer/__tests__/safety.test.ts
index f1a1b29578..62b462d9fc 100644
--- a/apps/desktop/src/main/remote-desktop-viewer/__tests__/safety.test.ts
+++ b/apps/desktop/src/main/remote-desktop-viewer/__tests__/safety.test.ts
@@ -378,10 +378,19 @@ it.each([
local.unreadable = unreadable === 'local';
remote.unreadable = unreadable === 'remote';
expect((await safety.tick(options)).notice).toBe('clipboardSyncConflict');
+ expect(safety.snapshot().clipboardNoticeVersion).toBe(1);
// An idle poll cannot pick a winner or clear the conflict on its own.
safety.wake();
expect((await safety.tick(options)).notice).toBe('clipboardSyncConflict');
+ expect(safety.snapshot().clipboardNoticeVersion).toBe(1);
+ // Another pair of copies is a new conflict, even if its notice is identical.
+ local.version++;
+ remote.version++;
+ expect((await safety.tick(options)).notice).toBe('clipboardSyncConflict');
+ expect(safety.snapshot().clipboardNoticeVersion).toBe(2);
+ safety.wake();
+ expect((await safety.tick(options)).clipboardNoticeVersion).toBe(2);
expect(write).not.toHaveBeenCalled();
expect(paste).not.toHaveBeenCalled();
diff --git a/apps/desktop/src/main/remote-desktop-viewer/safety.ts b/apps/desktop/src/main/remote-desktop-viewer/safety.ts
index 2ba5aa0707..43cca68cc1 100644
--- a/apps/desktop/src/main/remote-desktop-viewer/safety.ts
+++ b/apps/desktop/src/main/remote-desktop-viewer/safety.ts
@@ -222,7 +222,6 @@ export class ViewerSafety {
trace: (stage, code) => {
if (!valid()) return;
if (stage === 'content-skipped') {
- this.clipboardNoticeVersion++;
this.notices.set(
'clipboardSync',
code === 'CLIPBOARD_TOO_LONG' ? 'clipboardSyncTooLarge' : 'clipboardSyncSkipped',
@@ -248,6 +247,7 @@ export class ViewerSafety {
);
// Authority changes stop pending reads. Their late results must not count
// as sync failures for the next control session.
+ const { local: previousLocal, remote: previousRemote } = this.baseline;
try {
await engine.tick();
if (current()) {
@@ -263,6 +263,16 @@ export class ViewerSafety {
if (!current()) return this.snapshot();
this.recordClipboardFailure(error);
}
+ // Count accepted snapshots once, after skipped-content can become a conflict.
+ // Idle polls, backoff and rejected/stale reads must not replay the old toast.
+ if (
+ current() &&
+ (this.baseline.local !== previousLocal || this.baseline.remote !== previousRemote) &&
+ ['clipboardSyncSkipped', 'clipboardSyncTooLarge', 'clipboardSyncConflict'].includes(
+ this.notices.get('clipboardSync') ?? '',
+ )
+ )
+ this.clipboardNoticeVersion++;
return this.snapshot();
}
}
diff --git a/apps/desktop/src/renderer/features/remote-desktop/__tests__/viewerWindow.test.tsx b/apps/desktop/src/renderer/features/remote-desktop/__tests__/viewerWindow.test.tsx
index 2b6abed9f0..11ac868fba 100644
--- a/apps/desktop/src/renderer/features/remote-desktop/__tests__/viewerWindow.test.tsx
+++ b/apps/desktop/src/renderer/features/remote-desktop/__tests__/viewerWindow.test.tsx
@@ -62,7 +62,8 @@ afterEach(() => {
vi.clearAllMocks();
});
-it('shows clipboard status as a transient toast without retry and keeps privacy failures visible', async () => {
+const clipboardNotices = ['clipboardSyncSkipped', 'clipboardSyncConflict'] as const;
+it.each(clipboardNotices)('shows %s briefly without retry', async (notice) => {
await i18n.changeLanguage('zh-CN');
Object.assign(window, {
electronAPI: {
@@ -101,7 +102,7 @@ it('shows clipboard status as a transient toast without retry and keeps privacy
clipboardSync: true,
lockOnExit: false,
},
- safety: { privacyActive: false, notice: 'clipboardSyncSkipped', clipboardProgress: null },
+ safety: { privacyActive: false, notice, clipboardProgress: null },
credential: null,
credentialBusy: false,
credentialNotice: null,
@@ -109,7 +110,7 @@ it('shows clipboard status as a transient toast without retry and keeps privacy
};
try {
act(() => lifecycle.update?.(snapshot));
- const text = i18n.t('remoteDesktop.clipboardSyncSkipped');
+ const text = i18n.t(`remoteDesktop.${notice}`);
expect(screen.getByText(text)).toBeDefined();
expect(screen.queryByRole('button', { name: i18n.t('remoteDesktop.retry') })).toBeNull();
expect(document.querySelector('.remote-viewer-feedback')).toBeNull();
@@ -143,7 +144,10 @@ it('shows clipboard status as a transient toast without retry and keeps privacy
expect(getToastSnapshot()).toHaveLength(0);
act(() =>
- lifecycle.update?.({ ...snapshot, safety: { ...snapshot.safety, notice: 'privacyFailed' } }),
+ lifecycle.update?.({
+ ...snapshot,
+ safety: { ...snapshot.safety, notice: 'privacyFailed' },
+ }),
);
await act(async () => vi.advanceTimersByTimeAsync(5000));
expect(screen.getByRole('button', { name: i18n.t('remoteDesktop.retry') })).toBeDefined();
diff --git a/apps/desktop/src/shared/remoteDesktopViewer.ts b/apps/desktop/src/shared/remoteDesktopViewer.ts
index 845eb6137f..a6da588dd9 100644
--- a/apps/desktop/src/shared/remoteDesktopViewer.ts
+++ b/apps/desktop/src/shared/remoteDesktopViewer.ts
@@ -55,7 +55,7 @@ export const DEFAULT_VIEWER_PREFERENCES: RemoteViewerPreferences = {
export interface RemoteViewerSafety {
privacyActive: boolean;
notice: string | null;
- /** New skipped clipboard item; idle polls retain the same occurrence. Local IPC only. */
+ /** New skipped/conflicting snapshot; idle polls keep the occurrence. Local IPC only. */
clipboardNoticeVersion?: number;
clipboardProgress: number | null;
}
diff --git a/docs/remote-desktop.md b/docs/remote-desktop.md
index c2348ad7c3..dd05216774 100644
--- a/docs/remote-desktop.md
+++ b/docs/remote-desktop.md
@@ -92,8 +92,10 @@ alone, but copying the same content again can restore the cleared side. Successf
sync restores normal deduplication; an initially empty clipboard only establishes
the baseline and does not import old content. Desktop clipboard sync notices
use the shared transient toast (4 seconds, no retry action); unchanged status
-polls do not reopen it, while a newly skipped item gets a fresh notice even when
-its failure type matches the previous one. The occurrence counter stays in local
+polls do not reopen it, while a newly skipped item or conflict gets a fresh notice
+even when its failure type matches the previous one. A pass counts at most once,
+after accepting new version tokens; stale reads and backoff do not count.
+The occurrence counter stays in local
Main-to-Renderer status; it does not change the device-link protocol. Unsupported
formats and size limits have distinct copy, including when the other peer was
cleared in the same pass.