Skip to content

PasteFerry (隔空贴): clipboard and file sync across macOS, Windows and Linux. Direct-first, end-to-end encrypted. Optional official access: no server to host. Independent self-hosting remains available.

fix(core): retain clipboard write failures in received history

baiyuze838390d8202c
diff --git a/client-core/internal/store/store.go b/client-core/internal/store/store.go
index 67cbe78..4b500fd 100644
--- a/client-core/internal/store/store.go
+++ b/client-core/internal/store/store.go
@@ -399,6 +399,17 @@ func (s *Store) SetClipStatus(id string, st Status, errMsg string) error {
return err
}
+// SetClipboardError retains a write failure without changing local availability.
+// The predicate also prevents a late write result from reviving an expired clip.
+func (s *Store) SetClipboardError(id, message string) (bool, error) {
+ result, err := s.db.Exec(`UPDATE clips SET error=? WHERE id=? AND status=? AND outgoing=0 AND error<>?`, message, id, StatusReady, message)
+ if err != nil {
+ return false, err
+ }
+ n, err := result.RowsAffected()
+ return n > 0, err
+}
+
// RecoverReceives runs once before the daemon accepts connections. There are
// no live streams after a restart; show a retry action instead of a stale spinner.
func (s *Store) RecoverReceives() error {
diff --git a/client-core/internal/sync/receive.go b/client-core/internal/sync/receive.go
index c229610..cf3bb5b 100644
--- a/client-core/internal/sync/receive.go
+++ b/client-core/internal/sync/receive.go
@@ -188,6 +188,20 @@ func (e *Engine) writeClipboard(ctx context.Context, clip store.Clip, revision *
}
func (e *Engine) clipboardResult(result *pb.ClipboardWriteResult) {
+ message := ""
+ if result.GetOutcome() == pb.ClipboardWriteOutcome_CLIPBOARD_WRITE_OUTCOME_FAILED {
+ message = result.GetError()
+ }
+ if e.store != nil {
+ changed, err := e.store.SetClipboardError(result.GetClipId(), message)
+ if err != nil {
+ e.log.Warn("保存剪贴板写入结果失败", "err", err)
+ } else if changed {
+ if clip, err := e.store.GetClip(result.GetClipId()); err == nil {
+ e.emitRecord(clip)
+ }
+ }
+ }
if e.onClipboardResult != nil {
e.onClipboardResult(result)
}
diff --git a/client-core/internal/sync/receive_test.go b/client-core/internal/sync/receive_test.go
index 3eb1615..f94eb23 100644
--- a/client-core/internal/sync/receive_test.go
+++ b/client-core/internal/sync/receive_test.go
@@ -226,6 +226,19 @@ func TestReceiveCompletionProtectsClipboardAndRetainsDownload(t *testing.T) {
}
if scenario == "write-error" {
want = pb.ClipboardWriteOutcome_CLIPBOARD_WRITE_OUTCOME_FAILED
+ if clip.Error != "locked" {
+ t.Fatalf("clipboard failure was not retained in history: %q", clip.Error)
+ }
+ cb.mu.Lock()
+ cb.failure = nil
+ cb.mu.Unlock()
+ if err := e.ApplyToClipboard(context.Background(), clip.ID); err != nil {
+ t.Fatal(err)
+ }
+ retried, _ := e.store.GetClip(clip.ID)
+ if retried.Error != "" || retried.Status != store.StatusReady || retried.CachePath != clip.CachePath {
+ t.Fatal("clipboard retry did not clear the error and retain the download")
+ }
}
if event.Clipboard.Outcome != want {
t.Fatalf("outcome %v, want %v", event.Clipboard.Outcome, want)
diff --git a/ui/lib/pages/history_page.dart b/ui/lib/pages/history_page.dart
index 0e9c52b..85c189a 100644
--- a/ui/lib/pages/history_page.dart
+++ b/ui/lib/pages/history_page.dart
@@ -257,10 +257,12 @@ class _RecordRowState extends State<_RecordRow> {
// 剪贴板里的图片、以及复制的图片文件,点一下这一行就能预览,不另放按钮
final previewable = r.imageCount > 0;
final outcome = AppScope.of(context).clipboardResultOf(r.id);
+ final clipboardFailed = r.status == ClipStatus.CLIP_STATUS_READY && r.error.isNotEmpty;
final detail = switch (r.status) {
ClipStatus.CLIP_STATUS_REMOTE_ONLY => context.l10n.notReceived,
ClipStatus.CLIP_STATUS_FETCHING => context.l10n.receivingStatus,
ClipStatus.CLIP_STATUS_FAILED => r.error.isEmpty ? context.l10n.transferFailed : r.error,
+ _ when clipboardFailed => '${context.l10n.clipboardWriteFailed}\n${r.error}',
_ => switch (outcome?.outcome) {
ClipboardWriteOutcome.CLIPBOARD_WRITE_OUTCOME_PRESERVED => context.l10n.receivedPreserved,
ClipboardWriteOutcome.CLIPBOARD_WRITE_OUTCOME_FAILED => context.l10n.clipboardWriteFailed,
@@ -320,7 +322,7 @@ class _RecordRowState extends State<_RecordRow> {
message: outcome?.error.isNotEmpty == true ? outcome!.error : detail,
child: Text(detail, maxLines: 2, overflow: TextOverflow.ellipsis,
style: context.text.bodySmall?.copyWith(color:
- r.status == ClipStatus.CLIP_STATUS_FAILED || outcome?.outcome == ClipboardWriteOutcome.CLIPBOARD_WRITE_OUTCOME_FAILED
+ clipboardFailed || r.status == ClipStatus.CLIP_STATUS_FAILED || outcome?.outcome == ClipboardWriteOutcome.CLIPBOARD_WRITE_OUTCOME_FAILED
? p.danger : p.textDim)),
),
],
@@ -376,7 +378,7 @@ class _RecordRowState extends State<_RecordRow> {
// 悬停时才显示「放入剪贴板」与删除,静态时列表保持干净。
// 不悬停时它们只是看不见,位置照样留着:鼠标移上来时标题不会被挤短一截
Widget hoverOnly(Widget child) => Visibility(
- visible: _hovered || (AppScope.of(context).clipboardResultOf(r.id)?.outcome != null &&
+ visible: _hovered || r.error.isNotEmpty || (AppScope.of(context).clipboardResultOf(r.id)?.outcome != null &&
AppScope.of(context).clipboardResultOf(r.id)?.outcome != ClipboardWriteOutcome.CLIPBOARD_WRITE_OUTCOME_APPLIED),
maintainSize: true,
maintainAnimation: true,
diff --git a/ui/test/large_file_receive_test.dart b/ui/test/large_file_receive_test.dart
index a54c5f5..7ef0b9e 100644
--- a/ui/test/large_file_receive_test.dart
+++ b/ui/test/large_file_receive_test.dart
@@ -19,6 +19,14 @@ _ReceiveState _seed(ClipStatus status, {String language = 'en'}) => _ReceiveStat
]);
void main() {
+ testWidgets('reopened history retains clipboard failure and apply action', (tester) async {
+ final state = _seed(ClipStatus.CLIP_STATUS_READY);
+ state.records.single.error = 'Clipboard is busy';
+ await tester.pumpWidget(PasteFerryApp(state: state));
+ expect(find.textContaining('Clipboard is busy'), findsOneWidget);
+ expect(find.widgetWithText(TextButton, 'Copy to clipboard').hitTestable(), findsOneWidget);
+ expect(state.records.single.status, ClipStatus.CLIP_STATUS_READY);
+ });
testWidgets('pending item explains why paste is unavailable and offers receive', (tester) async {
final state = _seed(ClipStatus.CLIP_STATUS_REMOTE_ONLY);
await tester.pumpWidget(PasteFerryApp(state: state));