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(ui): close the incoming request dialog only once

baiyuze517eee018742
diff --git a/ui/lib/widgets/incoming_dialog.dart b/ui/lib/widgets/incoming_dialog.dart
index 0935301..d6c0b4a 100644
--- a/ui/lib/widgets/incoming_dialog.dart
+++ b/ui/lib/widgets/incoming_dialog.dart
@@ -34,6 +34,7 @@ class IncomingDialog extends StatefulWidget {
class _IncomingDialogState extends State<IncomingDialog> {
bool _always = false;
bool _busy = false;
+ bool _closed = false;
late final Timer _tick;
@override
@@ -58,7 +59,22 @@ class _IncomingDialogState extends State<IncomingDialog> {
} catch (e) {
if (mounted) showToast(context, AppState.describeError(e), error: true);
}
- if (mounted) Navigator.pop(context);
+ _close();
+ }
+
+ /// 只关一次,而且只关这个对话框:倒计时每秒重建,请求结束后的几次重建和点按钮都会走到这里,
+ /// 多 pop 一次会把主界面弹掉(窗口变黑)
+ void _close() {
+ if (_closed || !mounted) return;
+ final route = ModalRoute.of(context);
+ if (route == null || !route.isActive) return;
+ _closed = true;
+ _tick.cancel();
+ if (route.isCurrent) {
+ Navigator.of(context).pop();
+ } else {
+ Navigator.of(context).removeRoute(route);
+ }
}
@override
@@ -70,7 +86,7 @@ class _IncomingDialogState extends State<IncomingDialog> {
if (t == null || t.status != 'asking') {
// 对方取消了、超时了,或者在别处处理过了
WidgetsBinding.instance.addPostFrameCallback((_) {
- if (mounted && !_busy) Navigator.pop(context);
+ if (!_busy) _close();
});
return const SizedBox.shrink();
}
diff --git a/ui/test/friends_test.dart b/ui/test/friends_test.dart
index d3f997c..7afad43 100644
--- a/ui/test/friends_test.dart
+++ b/ui/test/friends_test.dart
@@ -201,4 +201,39 @@ void main() {
await _settle(tester);
expect(state.autoCalls, [('xm', true)]);
});
+
+ testWidgets('在通知里接受后接收框只关自己,主界面还在,下一个请求照常弹出', (tester) async {
+ Transfer ask(String id, String status) => Transfer(
+ id: id,
+ direction: TransferDirection.TRANSFER_DIRECTION_INCOMING,
+ deviceId: 'xm',
+ deviceName: '小明 · MacBook Air',
+ status: status,
+ peerRole: 'friend',
+ items: [ClipItem(name: '说明.txt', size: Int64(5))],
+ totalBytes: Int64(5),
+ createdAtUnix: _now(2),
+ );
+ final state = _demo(transfers: [ask('t1', 'asking')]);
+ await tester.pumpWidget(PasteFerryApp(state: state));
+ await tester.pump();
+ await tester.pump();
+ final l = AppLocalizations.of(tester.element(find.byType(Shell)));
+ final title = find.text(l.incomingTitle('小明 · MacBook Air'));
+ expect(title, findsOneWidget);
+ // 在别处(通知)接受了:后台服务把状态改掉,倒计时还在跳
+ state.debugEvent(Event(transferChanged: ask('t1', 'active')));
+ for (var i = 0; i < 5; i++) {
+ await tester.pump(const Duration(seconds: 1));
+ }
+ expect(tester.takeException(), isNull);
+ expect(title, findsNothing);
+ expect(find.byType(Shell), findsOneWidget);
+ // 下一个请求照常弹出
+ state.debugEvent(Event(transferChanged: ask('t2', 'asking')));
+ await tester.pump();
+ await tester.pump();
+ expect(title, findsOneWidget);
+ });
}
+