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.

feat(ui): keep the send page side by side at every window size

baiyuze9fa8c20349e7
diff --git a/ui/lib/l10n/app_en.arb b/ui/lib/l10n/app_en.arb
index 1dfc40e..9901634 100644
--- a/ui/lib/l10n/app_en.arb
+++ b/ui/lib/l10n/app_en.arb
@@ -1294,6 +1294,5 @@
"listSeparator": ", ",
"sendLayout": "Transfer list",
"sendLayoutSide": "Beside the radar",
- "sendLayoutBelow": "Below the radar",
- "sendLayoutNarrow": "Moves below the radar when the window is narrow"
+ "sendLayoutBelow": "Below the radar"
}
diff --git a/ui/lib/l10n/app_ja.arb b/ui/lib/l10n/app_ja.arb
index 4a685c7..a0b27fe 100644
--- a/ui/lib/l10n/app_ja.arb
+++ b/ui/lib/l10n/app_ja.arb
@@ -498,6 +498,5 @@
"listSeparator": "、",
"sendLayout": "転送リスト",
"sendLayoutSide": "レーダーの右",
- "sendLayoutBelow": "レーダーの下",
- "sendLayoutNarrow": "ウィンドウが狭いときは自動でレーダーの下に表示します"
+ "sendLayoutBelow": "レーダーの下"
}
diff --git a/ui/lib/l10n/app_localizations.dart b/ui/lib/l10n/app_localizations.dart
index 30972f6..82e4f99 100644
--- a/ui/lib/l10n/app_localizations.dart
+++ b/ui/lib/l10n/app_localizations.dart
@@ -3103,12 +3103,6 @@ abstract class AppLocalizations {
/// In en, this message translates to:
/// **'Below the radar'**
String get sendLayoutBelow;
-
- /// No description provided for @sendLayoutNarrow.
- ///
- /// In en, this message translates to:
- /// **'Moves below the radar when the window is narrow'**
- String get sendLayoutNarrow;
}
class _AppLocalizationsDelegate
diff --git a/ui/lib/l10n/app_localizations_en.dart b/ui/lib/l10n/app_localizations_en.dart
index c16231a..b56c219 100644
--- a/ui/lib/l10n/app_localizations_en.dart
+++ b/ui/lib/l10n/app_localizations_en.dart
@@ -1903,8 +1903,4 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get sendLayoutBelow => 'Below the radar';
-
- @override
- String get sendLayoutNarrow =>
- 'Moves below the radar when the window is narrow';
}
diff --git a/ui/lib/l10n/app_localizations_ja.dart b/ui/lib/l10n/app_localizations_ja.dart
index 2bb5e20..18b9d62 100644
--- a/ui/lib/l10n/app_localizations_ja.dart
+++ b/ui/lib/l10n/app_localizations_ja.dart
@@ -1748,7 +1748,4 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get sendLayoutBelow => 'レーダーの下';
-
- @override
- String get sendLayoutNarrow => 'ウィンドウが狭いときは自動でレーダーの下に表示します';
}
diff --git a/ui/lib/l10n/app_localizations_zh.dart b/ui/lib/l10n/app_localizations_zh.dart
index 96406f8..0ffacc9 100644
--- a/ui/lib/l10n/app_localizations_zh.dart
+++ b/ui/lib/l10n/app_localizations_zh.dart
@@ -1729,9 +1729,6 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get sendLayoutBelow => '在雷达下面';
-
- @override
- String get sendLayoutNarrow => '窗口较窄时自动放到雷达下面';
}
/// The translations for Chinese, as used in Hong Kong, using the Han script (`zh_Hant_HK`).
@@ -3459,9 +3456,6 @@ class AppLocalizationsZhHantHk extends AppLocalizationsZh {
@override
String get sendLayoutBelow => '在雷達下面';
-
- @override
- String get sendLayoutNarrow => '視窗較窄時自動放到雷達下面';
}
/// The translations for Chinese, as used in Taiwan, using the Han script (`zh_Hant_TW`).
@@ -5189,7 +5183,4 @@ class AppLocalizationsZhHantTw extends AppLocalizationsZh {
@override
String get sendLayoutBelow => '在雷達下面';
-
- @override
- String get sendLayoutNarrow => '視窗較窄時自動放到雷達下面';
}
diff --git a/ui/lib/l10n/app_zh.arb b/ui/lib/l10n/app_zh.arb
index 851db7f..341d449 100644
--- a/ui/lib/l10n/app_zh.arb
+++ b/ui/lib/l10n/app_zh.arb
@@ -498,6 +498,5 @@
"listSeparator": "、",
"sendLayout": "传输列表",
"sendLayoutSide": "在雷达右边",
- "sendLayoutBelow": "在雷达下面",
- "sendLayoutNarrow": "窗口较窄时自动放到雷达下面"
+ "sendLayoutBelow": "在雷达下面"
}
diff --git a/ui/lib/l10n/app_zh_Hant_HK.arb b/ui/lib/l10n/app_zh_Hant_HK.arb
index dd9add8..e8270fd 100644
--- a/ui/lib/l10n/app_zh_Hant_HK.arb
+++ b/ui/lib/l10n/app_zh_Hant_HK.arb
@@ -498,6 +498,5 @@
"listSeparator": "、",
"sendLayout": "傳輸列表",
"sendLayoutSide": "在雷達右邊",
- "sendLayoutBelow": "在雷達下面",
- "sendLayoutNarrow": "視窗較窄時自動放到雷達下面"
+ "sendLayoutBelow": "在雷達下面"
}
diff --git a/ui/lib/l10n/app_zh_Hant_TW.arb b/ui/lib/l10n/app_zh_Hant_TW.arb
index 089f385..0289dd1 100644
--- a/ui/lib/l10n/app_zh_Hant_TW.arb
+++ b/ui/lib/l10n/app_zh_Hant_TW.arb
@@ -498,6 +498,5 @@
"listSeparator": "、",
"sendLayout": "傳輸列表",
"sendLayoutSide": "在雷達右邊",
- "sendLayoutBelow": "在雷達下面",
- "sendLayoutNarrow": "視窗較窄時自動放到雷達下面"
+ "sendLayoutBelow": "在雷達下面"
}
diff --git a/ui/lib/pages/send_page.dart b/ui/lib/pages/send_page.dart
index 040aabb..7ef60c6 100644
--- a/ui/lib/pages/send_page.dart
+++ b/ui/lib/pages/send_page.dart
@@ -125,12 +125,10 @@ class _SendPageState extends State<SendPage> with SingleTickerProviderStateMixin
return LayoutBuilder(builder: (context, box) => _body(context, state, box.biggest));
}
- /// 默认左右排:雷达在左、列表在右,各自撑满高度。设置里可以改成上下排,雷达限高;
- /// 窗口太窄、左右排放不下时也临时上下排。
+ /// 默认左右排:雷达在左、列表在右,各自撑满高度,窗口再窄也是这样。设置里可以改成上下排,雷达限高。
Widget _body(BuildContext context, AppState state, Size size) {
final l = context.l10n;
- // 左栏窄于约 480 时雷达放不下设备名字(960 宽的窗口就是这样),自动上下排
- final wide = !(state.config?.sendLayoutStacked ?? false) && size.width >= 880;
+ final wide = !(state.config?.sendLayoutStacked ?? false);
final radar = state.peers.isEmpty
? EmptyState(
icon: AppIcons.send,
@@ -146,7 +144,9 @@ class _SendPageState extends State<SendPage> with SingleTickerProviderStateMixin
),
)
: _radar(context, state);
- final list = _TransferList(direction: _tab, onDirection: (d) => setState(() => _tab = d), compact: wide);
+ final listWidth = (size.width * 0.45).clamp(260.0, 460.0);
+ final list = _TransferList(
+ direction: _tab, onDirection: (d) => setState(() => _tab = d), compact: wide, narrow: wide && listWidth < 340);
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
@@ -168,9 +168,10 @@ class _SendPageState extends State<SendPage> with SingleTickerProviderStateMixin
? Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
- Expanded(flex: 11, child: Padding(padding: const EdgeInsets.only(bottom: Insets.xl), child: radar)),
+ Expanded(child: Padding(padding: const EdgeInsets.only(bottom: Insets.xl), child: radar)),
VerticalDivider(width: 1, color: context.palette.border),
- Expanded(flex: 9, child: list),
+ // 列表占四成五(宽窗口下与雷达 11:9),最窄的窗口里也留出 260
+ SizedBox(width: listWidth, child: list),
],
)
: Column(
@@ -248,13 +249,17 @@ class _SendPageState extends State<SendPage> with SingleTickerProviderStateMixin
final hasOuter = _slots.values.any((s) => !s.$1);
// 轨道的大小:外圈接近正圆,横纵比不超过 1.35,也不比宽度高。
- // 太矮时横向至少 190,内圈斜角上的设备才不会压到中间的本机
+ // 太矮时横向至少 190,内圈斜角上的设备才不会压到中间的本机。
+ // 雷达这一栏很窄时(小窗口里列表仍在右边):设备名字缩窄,轨道可以竖着拉长、内圈放大,同样不压到本机
+ final narrow = space.width < 420;
+ final nodeW = (space.width * 0.3).clamp(96.0, _SendNode.width);
+ final innerScale = narrow ? 0.74 : _innerScale;
final below = (overflow.isNotEmpty ? 40.0 : 0) + (offline.isNotEmpty ? 28.0 : 0);
final maxRy = (space.height - below) / 2 - 22;
- final outerRx = math.min(math.max(maxRy * 1.35, 190.0), space.width / 2 - _SendNode.width / 2);
- final outerRy = math.max(80.0, math.min(maxRy, outerRx));
- final innerRx = outerRx * _innerScale;
- final innerRy = outerRy * _innerScale;
+ final outerRx = math.min(math.max(maxRy * 1.35, 190.0), space.width / 2 - nodeW / 2);
+ final outerRy = math.max(80.0, math.min(maxRy, narrow ? math.max(outerRx, 190.0) : outerRx));
+ final innerRx = outerRx * innerScale;
+ final innerRy = outerRy * innerScale;
final radar = DropTarget(
enable: !_dialogOpen,
@@ -296,13 +301,13 @@ class _SendPageState extends State<SendPage> with SingleTickerProviderStateMixin
final at = center +
Offset((inner ? innerRx : outerRx) * math.cos(a), (inner ? innerRy : outerRy) * math.sin(a));
final rect = Rect.fromLTWH(
- at.dx - _SendNode.width / 2, at.dy - _SendNode.avatar / 2, _SendNode.width, _SendNode.avatar + 40);
+ at.dx - nodeW / 2, at.dy - _SendNode.avatar / 2, nodeW, _SendNode.avatar + 40);
_nodeRects[d.id] = rect;
nodes.add(Positioned(
key: ValueKey(d.id),
left: rect.left,
top: rect.top,
- width: _SendNode.width,
+ width: nodeW,
child: _node(context, state, d),
));
}
@@ -351,9 +356,9 @@ class _SendPageState extends State<SendPage> with SingleTickerProviderStateMixin
caption(l.sendRingLan, innerRy),
if (hasOuter) caption(l.sendRingOther, outerRy),
Positioned(
- left: center.dx - _SendNode.width / 2,
+ left: center.dx - nodeW / 2,
top: center.dy - _SendNode.avatar / 2,
- width: _SendNode.width,
+ width: nodeW,
child: RadarSelfNode(platform: selfPlatform, size: _SendNode.avatar),
),
...nodes,
@@ -690,7 +695,7 @@ class _SendNodeState extends State<_SendNode> {
/// 收到的、发出的列表。
class _TransferList extends StatelessWidget {
- const _TransferList({required this.direction, required this.onDirection, this.compact = false});
+ const _TransferList({required this.direction, required this.onDirection, this.compact = false, this.narrow = false});
final TransferDirection direction;
final ValueChanged<TransferDirection> onDirection;
@@ -698,6 +703,9 @@ class _TransferList extends StatelessWidget {
/// 放在雷达右边时:左边距收窄一些
final bool compact;
+ /// 列表很窄(小窗口里放在雷达右边):按钮换成带提示的图标,名字放不下时省略
+ final bool narrow;
+
@override
Widget build(BuildContext context) {
final state = AppScope.of(context);
@@ -709,7 +717,8 @@ class _TransferList extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Padding(
- padding: EdgeInsets.fromLTRB(compact ? Insets.lg : Insets.xl, Insets.sm, Insets.xl, Insets.sm),
+ padding: EdgeInsets.fromLTRB(
+ narrow ? Insets.md : (compact ? Insets.lg : Insets.xl), Insets.sm, narrow ? Insets.md : Insets.xl, Insets.sm),
child: Row(
children: [
Segmented<TransferDirection>(
@@ -722,11 +731,17 @@ class _TransferList extends StatelessWidget {
),
const Spacer(),
if (finished.isNotEmpty)
- TextButton(onPressed: () => _clearAll(context), child: Text(l.transfersClearAll)),
+ narrow
+ ? IconAction(icon: AppIcons.trash, tooltip: l.transfersClearAll, onTap: () => _clearAll(context))
+ : TextButton(onPressed: () => _clearAll(context), child: Text(l.transfersClearAll)),
],
),
),
- Divider(height: 1, indent: compact ? Insets.lg : Insets.xl, endIndent: Insets.xl, color: context.palette.border),
+ Divider(
+ height: 1,
+ indent: narrow ? Insets.md : (compact ? Insets.lg : Insets.xl),
+ endIndent: narrow ? Insets.md : Insets.xl,
+ color: context.palette.border),
Expanded(
child: list.isEmpty
? Center(
@@ -738,7 +753,7 @@ class _TransferList extends StatelessWidget {
key: PageStorageKey(direction),
padding: const EdgeInsets.fromLTRB(Insets.lg, Insets.sm, Insets.lg, Insets.xl),
itemCount: list.length,
- itemBuilder: (context, i) => _TransferRow(key: ValueKey(list[i].id), transfer: list[i]),
+ itemBuilder: (context, i) => _TransferRow(key: ValueKey(list[i].id), transfer: list[i], narrow: narrow),
),
),
],
@@ -769,9 +784,10 @@ class _TransferList extends StatelessWidget {
/// 列表里的一批:名称与大小;来自(发给)哪台、时间、状态;进行中的显示进度。
class _TransferRow extends StatefulWidget {
- const _TransferRow({super.key, required this.transfer});
+ const _TransferRow({super.key, required this.transfer, this.narrow = false});
final Transfer transfer;
+ final bool narrow;
@override
State<_TransferRow> createState() => _TransferRowState();
@@ -901,14 +917,18 @@ class _TransferRowState extends State<_TransferRow> {
final l = context.l10n;
final state = AppScope.read(context);
final buttons = <Widget>[];
+ // 列表很窄时用图标按钮,文字放进提示里
+ Widget button(IconData icon, String label, VoidCallback onTap) => widget.narrow
+ ? IconAction(icon: icon, tooltip: label, onTap: onTap)
+ : OutlinedButton(onPressed: onTap, child: Text(label));
if (!_out && t.status == 'done' && _present.isNotEmpty) {
- buttons.add(OutlinedButton(onPressed: () => revealFile(_present.first), child: Text(revealLabel(l))));
+ buttons.add(button(AppIcons.folder, revealLabel(l), () => revealFile(_present.first)));
}
if (_out && (t.status == 'interrupted' || t.status == 'paused')) {
- buttons.add(OutlinedButton(onPressed: () => _run(() => state.resumeTransfer(t.id)), child: Text(l.continueAction)));
+ buttons.add(button(AppIcons.arrowClockwise, l.continueAction, () => _run(() => state.resumeTransfer(t.id))));
}
if (_out && (t.status == 'failed' || t.status == 'declined') && t.paths.isNotEmpty) {
- buttons.add(OutlinedButton(onPressed: _resend, child: Text(l.transferResend)));
+ buttons.add(button(AppIcons.arrowClockwise, l.transferResend, _resend));
}
if (!_finished) {
buttons.add(IconAction(icon: AppIcons.xmark, tooltip: l.cancel, onTap: () => _run(() => state.cancelTransfer(t.id))));
diff --git a/ui/lib/pages/send_settings.dart b/ui/lib/pages/send_settings.dart
index bdefc6f..4ae6ad4 100644
--- a/ui/lib/pages/send_settings.dart
+++ b/ui/lib/pages/send_settings.dart
@@ -98,7 +98,6 @@ class _SendSectionState extends State<SendSection> {
),
SettingRow(
title: l.sendLayout,
- description: l.sendLayoutNarrow,
child: Segmented<bool>(
value: cfg.sendLayoutStacked,
segments: [(false, l.sendLayoutSide), (true, l.sendLayoutBelow)],
diff --git a/ui/test/send_page_test.dart b/ui/test/send_page_test.dart
index 3940e10..dc052a5 100644
--- a/ui/test/send_page_test.dart
+++ b/ui/test/send_page_test.dart
@@ -101,10 +101,11 @@ void main() {
// 发出的
await tester.tap(find.text(l.transfersSent));
await tester.pump();
- await tester.scrollUntilVisible(find.text(l.continueAction), 60, scrollable: list);
+ // 最小窗口下列表很窄,按钮是图标,文字在提示里
+ await tester.scrollUntilVisible(find.byTooltip(l.continueAction), 60, scrollable: list);
await tester.scrollUntilVisible(find.textContaining(l.reasonNoSpacePeer('MacBook Air', '1.2 GB')), 60,
scrollable: list);
- expect(find.text(l.transferResend), findsOneWidget);
+ expect(find.byTooltip(l.transferResend), findsOneWidget);
});
testWidgets('发送窗口', (tester) async {
@@ -157,9 +158,15 @@ void main() {
expect(find.text('把文件拖到一台设备上,直接发过去'), findsOneWidget);
});
- for (final stacked in [false, true]) {
- testWidgets(stacked ? '设置里选了上下排,列表在雷达下面' : '默认左右排,列表在雷达右边', (tester) async {
- tester.view.physicalSize = const Size(1180, 720);
+ // 默认左右排,窗口再窄也是;设置里选了上下排才放到雷达下面
+ for (final (stacked, size) in [
+ (false, const Size(1180, 720)),
+ (false, const Size(960, 640)),
+ (false, const Size(760, 520)),
+ (true, const Size(1180, 720)),
+ ]) {
+ testWidgets(stacked ? '设置里选了上下排,列表在雷达下面' : '默认左右排,列表在雷达右边(${size.width.round()} 宽)', (tester) async {
+ tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final state = _demo('zh-Hans');
@@ -169,7 +176,8 @@ void main() {
await tester.tap(find.text('隔空传送').first);
await tester.pump();
// 本机的叫法随平台变:Mac 上「这台 Mac」,其他平台「这台电脑」
- final radar = tester.getCenter(find.text(Wording.thisDevice));
+ final self = find.text(Wording.thisDevice);
+ final radar = tester.getCenter(self);
final tabs = tester.getCenter(find.text('收到的'));
if (stacked) {
expect(tabs.dy, greaterThan(radar.dy), reason: '列表在雷达下面');
@@ -177,6 +185,19 @@ void main() {
expect(tabs.dx, greaterThan(radar.dx), reason: '列表在雷达右边');
expect(tabs.dy, lessThan(radar.dy), reason: '列表从顶上开始');
}
+ // 雷达上的设备名字不压到中间的本机,也不互相压
+ final selfRect = tester.getRect(self);
+ final names = [
+ for (final d in state.peers.where((d) => d.online))
+ if (find.text(d.name).evaluate().isNotEmpty) tester.getRect(find.text(d.name).first)
+ ];
+ expect(names, isNotEmpty);
+ for (final (i, r) in names.indexed) {
+ expect(r.overlaps(selfRect), isFalse, reason: '设备名字压到了本机');
+ for (final o in names.skip(i + 1)) {
+ expect(r.overlaps(o), isFalse, reason: '两个设备的名字叠在一起');
+ }
+ }
});
}