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): search nearby devices on a radar

baiyuze2469241ba214
diff --git a/docs/assets/screenshots/devices.png b/docs/assets/screenshots/devices.png
index 439cd51..1990e38 100644
Binary files a/docs/assets/screenshots/devices.png and b/docs/assets/screenshots/devices.png differ
diff --git a/docs/assets/screenshots/en/devices.png b/docs/assets/screenshots/en/devices.png
index 5589903..8648ad7 100644
Binary files a/docs/assets/screenshots/en/devices.png and b/docs/assets/screenshots/en/devices.png differ
diff --git a/docs/assets/screenshots/en/nearby-dark.png b/docs/assets/screenshots/en/nearby-dark.png
new file mode 100644
index 0000000..d0710cb
Binary files /dev/null and b/docs/assets/screenshots/en/nearby-dark.png differ
diff --git a/docs/assets/screenshots/en/nearby.png b/docs/assets/screenshots/en/nearby.png
new file mode 100644
index 0000000..f81c258
Binary files /dev/null and b/docs/assets/screenshots/en/nearby.png differ
diff --git a/docs/assets/screenshots/en/pairing-dark.png b/docs/assets/screenshots/en/pairing-dark.png
index db1c902..3e2ede9 100644
Binary files a/docs/assets/screenshots/en/pairing-dark.png and b/docs/assets/screenshots/en/pairing-dark.png differ
diff --git a/docs/assets/screenshots/en/pairing-join-dark.png b/docs/assets/screenshots/en/pairing-join-dark.png
index c99e133..966cafb 100644
Binary files a/docs/assets/screenshots/en/pairing-join-dark.png and b/docs/assets/screenshots/en/pairing-join-dark.png differ
diff --git a/docs/assets/screenshots/en/pairing-join-ts-dark.png b/docs/assets/screenshots/en/pairing-join-ts-dark.png
index a8ef8e7..62ad014 100644
Binary files a/docs/assets/screenshots/en/pairing-join-ts-dark.png and b/docs/assets/screenshots/en/pairing-join-ts-dark.png differ
diff --git a/docs/assets/screenshots/en/pairing.png b/docs/assets/screenshots/en/pairing.png
index ab07b8b..989f924 100644
Binary files a/docs/assets/screenshots/en/pairing.png and b/docs/assets/screenshots/en/pairing.png differ
diff --git a/docs/assets/screenshots/en/settings-cloud-dark.png b/docs/assets/screenshots/en/settings-cloud-dark.png
index a134efd..9a05f94 100644
Binary files a/docs/assets/screenshots/en/settings-cloud-dark.png and b/docs/assets/screenshots/en/settings-cloud-dark.png differ
diff --git a/docs/assets/screenshots/en/settings-lan-dark.png b/docs/assets/screenshots/en/settings-lan-dark.png
index bd350ac..121d00b 100644
Binary files a/docs/assets/screenshots/en/settings-lan-dark.png and b/docs/assets/screenshots/en/settings-lan-dark.png differ
diff --git a/docs/assets/screenshots/en/settings.png b/docs/assets/screenshots/en/settings.png
index 79ba4d5..fbbb8ac 100644
Binary files a/docs/assets/screenshots/en/settings.png and b/docs/assets/screenshots/en/settings.png differ
diff --git a/docs/assets/screenshots/en/verify.png b/docs/assets/screenshots/en/verify.png
index 3e1e736..a5f4542 100644
Binary files a/docs/assets/screenshots/en/verify.png and b/docs/assets/screenshots/en/verify.png differ
diff --git a/docs/assets/screenshots/ja/devices.png b/docs/assets/screenshots/ja/devices.png
index c1bb036..a7e6e4c 100644
Binary files a/docs/assets/screenshots/ja/devices.png and b/docs/assets/screenshots/ja/devices.png differ
diff --git a/docs/assets/screenshots/ja/nearby-dark.png b/docs/assets/screenshots/ja/nearby-dark.png
new file mode 100644
index 0000000..a826bfe
Binary files /dev/null and b/docs/assets/screenshots/ja/nearby-dark.png differ
diff --git a/docs/assets/screenshots/ja/nearby.png b/docs/assets/screenshots/ja/nearby.png
new file mode 100644
index 0000000..2ec08ec
Binary files /dev/null and b/docs/assets/screenshots/ja/nearby.png differ
diff --git a/docs/assets/screenshots/ja/pairing-dark.png b/docs/assets/screenshots/ja/pairing-dark.png
index 0645202..6006160 100644
Binary files a/docs/assets/screenshots/ja/pairing-dark.png and b/docs/assets/screenshots/ja/pairing-dark.png differ
diff --git a/docs/assets/screenshots/ja/pairing-join-dark.png b/docs/assets/screenshots/ja/pairing-join-dark.png
index d3ec8b0..4cb1ae0 100644
Binary files a/docs/assets/screenshots/ja/pairing-join-dark.png and b/docs/assets/screenshots/ja/pairing-join-dark.png differ
diff --git a/docs/assets/screenshots/ja/pairing-join-ts-dark.png b/docs/assets/screenshots/ja/pairing-join-ts-dark.png
index 789ea0e..623fa59 100644
Binary files a/docs/assets/screenshots/ja/pairing-join-ts-dark.png and b/docs/assets/screenshots/ja/pairing-join-ts-dark.png differ
diff --git a/docs/assets/screenshots/ja/pairing.png b/docs/assets/screenshots/ja/pairing.png
index 4ad1898..79b8cd3 100644
Binary files a/docs/assets/screenshots/ja/pairing.png and b/docs/assets/screenshots/ja/pairing.png differ
diff --git a/docs/assets/screenshots/ja/settings-cloud-dark.png b/docs/assets/screenshots/ja/settings-cloud-dark.png
index 3c22dbe..023659b 100644
Binary files a/docs/assets/screenshots/ja/settings-cloud-dark.png and b/docs/assets/screenshots/ja/settings-cloud-dark.png differ
diff --git a/docs/assets/screenshots/ja/settings-lan-dark.png b/docs/assets/screenshots/ja/settings-lan-dark.png
index 14125f2..6225703 100644
Binary files a/docs/assets/screenshots/ja/settings-lan-dark.png and b/docs/assets/screenshots/ja/settings-lan-dark.png differ
diff --git a/docs/assets/screenshots/ja/settings.png b/docs/assets/screenshots/ja/settings.png
index b3ec532..dd175de 100644
Binary files a/docs/assets/screenshots/ja/settings.png and b/docs/assets/screenshots/ja/settings.png differ
diff --git a/docs/assets/screenshots/ja/verify.png b/docs/assets/screenshots/ja/verify.png
index 967ec32..1b881a6 100644
Binary files a/docs/assets/screenshots/ja/verify.png and b/docs/assets/screenshots/ja/verify.png differ
diff --git a/docs/assets/screenshots/nearby-dark.png b/docs/assets/screenshots/nearby-dark.png
new file mode 100644
index 0000000..c220c98
Binary files /dev/null and b/docs/assets/screenshots/nearby-dark.png differ
diff --git a/docs/assets/screenshots/nearby.png b/docs/assets/screenshots/nearby.png
new file mode 100644
index 0000000..f212057
Binary files /dev/null and b/docs/assets/screenshots/nearby.png differ
diff --git a/docs/assets/screenshots/pairing-dark.png b/docs/assets/screenshots/pairing-dark.png
index 829145f..f015db2 100644
Binary files a/docs/assets/screenshots/pairing-dark.png and b/docs/assets/screenshots/pairing-dark.png differ
diff --git a/docs/assets/screenshots/pairing-join-dark.png b/docs/assets/screenshots/pairing-join-dark.png
index ab47cb8..a7c0408 100644
Binary files a/docs/assets/screenshots/pairing-join-dark.png and b/docs/assets/screenshots/pairing-join-dark.png differ
diff --git a/docs/assets/screenshots/pairing-join-ts-dark.png b/docs/assets/screenshots/pairing-join-ts-dark.png
index d19eb73..96b4e25 100644
Binary files a/docs/assets/screenshots/pairing-join-ts-dark.png and b/docs/assets/screenshots/pairing-join-ts-dark.png differ
diff --git a/docs/assets/screenshots/pairing.png b/docs/assets/screenshots/pairing.png
index 2045956..fc3c2ae 100644
Binary files a/docs/assets/screenshots/pairing.png and b/docs/assets/screenshots/pairing.png differ
diff --git a/docs/assets/screenshots/settings-cloud-dark.png b/docs/assets/screenshots/settings-cloud-dark.png
index 4cc9896..bdb3762 100644
Binary files a/docs/assets/screenshots/settings-cloud-dark.png and b/docs/assets/screenshots/settings-cloud-dark.png differ
diff --git a/docs/assets/screenshots/settings-lan-dark.png b/docs/assets/screenshots/settings-lan-dark.png
index 0f9e0f4..42cdbca 100644
Binary files a/docs/assets/screenshots/settings-lan-dark.png and b/docs/assets/screenshots/settings-lan-dark.png differ
diff --git a/docs/assets/screenshots/settings.png b/docs/assets/screenshots/settings.png
index d8a5b6c..652076e 100644
Binary files a/docs/assets/screenshots/settings.png and b/docs/assets/screenshots/settings.png differ
diff --git a/docs/assets/screenshots/verify.png b/docs/assets/screenshots/verify.png
index e9f5dd7..f109bf9 100644
Binary files a/docs/assets/screenshots/verify.png and b/docs/assets/screenshots/verify.png differ
diff --git a/ui/lib/app_state.dart b/ui/lib/app_state.dart
index 7cb35d3..43ac3f0 100644
--- a/ui/lib/app_state.dart
+++ b/ui/lib/app_state.dart
@@ -339,6 +339,23 @@ class AppState extends ChangeNotifier {
return peer;
}
+ /// 「搜索附近设备」窗口打开期间订阅:本机在局域网里公开设备名,
+ /// 收到附近同样打开了这个窗口的设备。取消订阅本机就撤下。
+ Stream<List<NearbyDevice>> watchNearby() =>
+ _client.watchNearby(Empty()).map((e) => e.devices.toList());
+
+ /// 向附近的一台设备发起配对,返回待核对指纹的对端信息。
+ Future<Device> pairNearby(String id) async {
+ final resp = await _client.pairNearby(
+ PairNearbyRequest(id: id),
+ options: CallOptions(timeout: const Duration(seconds: 15)),
+ );
+ final peer = resp.peer..pairingSession = resp.pairingSession;
+ _setPendingPairing(peer);
+ notifyListeners();
+ return peer;
+ }
+
Future<void> confirmPairing(String session, bool accept) async {
await _client.confirmPairing(
ConfirmPairingRequest(pairingSession: session, accept: accept),
diff --git a/ui/lib/icons.dart b/ui/lib/icons.dart
index 988766c..982a39c 100644
--- a/ui/lib/icons.dart
+++ b/ui/lib/icons.dart
@@ -26,6 +26,8 @@ abstract final class AppIcons {
static IconData get questionCircle =>
_pick(CupertinoIcons.question_circle, FluentIcons.question_circle_24_regular);
static IconData get plus => _pick(CupertinoIcons.plus, FluentIcons.add_24_regular);
+ static IconData get radar =>
+ _pick(CupertinoIcons.dot_radiowaves_left_right, FluentIcons.radar_20_regular);
static IconData get photo => _pick(CupertinoIcons.photo, FluentIcons.image_24_regular);
static IconData get lockShield => _pick(CupertinoIcons.lock_shield, FluentIcons.shield_lock_24_regular);
static IconData get filter =>
diff --git a/ui/lib/l10n/app_en.arb b/ui/lib/l10n/app_en.arb
index e39ba48..97e3fc7 100644
--- a/ui/lib/l10n/app_en.arb
+++ b/ui/lib/l10n/app_en.arb
@@ -240,7 +240,7 @@
}
},
"noDevicesTitle": "No paired devices yet",
- "noDevicesBody": "Open CopySync on your other computer and link the two with a 6-character pairing code. On the same network, nothing else is needed.",
+ "noDevicesBody": "Open CopySync on your other computer and link the two with a 6-character pairing code. On the same network, you can also open Search nearby on both and click the other one.",
"pairedDevices": "Paired devices",
"pairedFootnote": "Direct: data goes straight between the two devices. Relay: when the network blocks a direct path, data goes through your server and stays end-to-end encrypted.",
"offline": "Offline",
@@ -289,6 +289,37 @@
}
}
},
+ "searchNearby": "Search nearby",
+ "nearbyTitle": "Nearby devices",
+ "nearbySearching": "Looking for nearby devices…",
+ "nearbyHint": "Open Search nearby on the other computer too, and it shows up here. Click it to pair.",
+ "nearbyVisible": "While this window is open, devices on this network can see the name of {device}.",
+ "@nearbyVisible": {
+ "placeholders": {
+ "device": {
+ "type": "String"
+ }
+ }
+ },
+ "nearbyPaired": "Paired",
+ "nearbyRequesting": "Contacting “{name}”…",
+ "@nearbyRequesting": {
+ "placeholders": {
+ "name": {
+ "type": "String"
+ }
+ }
+ },
+ "nearbyNoReply": "“{name}” didn't answer. Make sure Search nearby is still open on it.",
+ "@nearbyNoReply": {
+ "placeholders": {
+ "name": {
+ "type": "String"
+ }
+ }
+ },
+ "nearbyLanOffTitle": "Local network discovery is off",
+ "nearbyLanOffBody": "Turn on “Find devices on this network” in Settings to see nearby devices, or pair with a code instead.",
"generateCode": "Show a code",
"enterCode": "Enter a code",
"codeFailedTitle": "Couldn't create a pairing code",
@@ -355,7 +386,7 @@
"localNetwork": "Local network",
"lanFootnote": "Uses UDP port 8788. If the devices are on different subnets, enter the other device's address when pairing.",
"lanDiscovery": "Find devices on this network",
- "lanDiscoveryDesc": "Pair and sync without a server. Others on the network only see an anonymous entry that changes daily.",
+ "lanDiscoveryDesc": "Pair and sync without a server. Others on the network only see an anonymous entry that changes daily, and the device name only while Search nearby is open.",
"macLocalNetwork": "Local Network access",
"macLocalNetworkDesc": "macOS asks once whether CopySync may connect to devices on your network. If you declined, turn on CopySync Daemon there.",
"allowLan": "Windows Firewall",
diff --git a/ui/lib/l10n/app_ja.arb b/ui/lib/l10n/app_ja.arb
index 2d61739..70c34d5 100644
--- a/ui/lib/l10n/app_ja.arb
+++ b/ui/lib/l10n/app_ja.arb
@@ -92,7 +92,7 @@
"addDevice": "デバイスを追加",
"thisDeviceFootnote": "ペアリング時、{both}に同じ 2 行のセキュリティ指紋(このデバイスと相手のもの)が表示されます。1 文字ずつ一致を確かめてから確定してください。",
"noDevicesTitle": "ペアリングしたデバイスはまだありません",
- "noDevicesBody": "もう一台のコンピューターで CopySync を開き、6 桁のペアリングコードでつなげます。同じネットワーク内なら、ほかに準備はいりません。",
+ "noDevicesBody": "もう一台のコンピューターで CopySync を開き、6 桁のペアリングコードでつなげます。同じネットワーク内なら、両方で「近くを検索」を開いて相手をクリックすることもできます。",
"pairedDevices": "ペアリング済みのデバイス",
"pairedFootnote": "直接接続:データは 2 台のデバイス間で直接やり取りされます。中継:直接つながらないネットワークでは、あなたのサーバーを経由します。内容はエンドツーエンドで暗号化されたままです。",
"offline": "オフライン",
@@ -113,6 +113,16 @@
"addressSaved": "そのアドレスで探しています",
"lanBlockedTitle": "macOS がローカルネットワークへのアクセスをブロックしています",
"lanBlockedBody": "「システム設定 → プライバシーとセキュリティ → ローカルネットワーク」で CopySync Daemon をオンにしてください。オンにするまで、{device}は同じネットワークのデバイスに接続できません。",
+ "searchNearby": "近くを検索",
+ "nearbyTitle": "近くのデバイス",
+ "nearbySearching": "近くのデバイスを探しています…",
+ "nearbyHint": "もう一台でも「近くを検索」を開くと、ここに表示されます。クリックしてペアリングします。",
+ "nearbyVisible": "このウィンドウを開いている間は、同じネットワークのデバイスから{device}の名前が見えます。",
+ "nearbyPaired": "ペアリング済み",
+ "nearbyRequesting": "「{name}」に接続しています…",
+ "nearbyNoReply": "「{name}」から応答がありません。相手で「近くを検索」が開いたままか確認してください。",
+ "nearbyLanOffTitle": "ローカルネットワークの検出がオフです",
+ "nearbyLanOffBody": "近くのデバイスを表示するには「設定」で「このネットワークでデバイスを探す」をオンにするか、コードでペアリングしてください。",
"generateCode": "コードを表示",
"enterCode": "コードを入力",
"codeFailedTitle": "ペアリングコードを作成できませんでした",
@@ -158,7 +168,7 @@
"localNetwork": "ローカルネットワーク",
"lanFootnote": "UDP ポート 8788 を使います。2 台が別のサブネットにある場合は、ペアリング時に相手のアドレスを入力します。",
"lanDiscovery": "このネットワークでデバイスを探す",
- "lanDiscoveryDesc": "サーバーなしでペアリングと同期ができます。ネットワーク上の他の人には、毎日変わる匿名の識別子しか見えません",
+ "lanDiscoveryDesc": "サーバーなしでペアリングと同期ができます。ネットワーク上の他の人には、毎日変わる匿名の識別子しか見えません。デバイス名が見えるのは「近くを検索」を開いている間だけです",
"macLocalNetwork": "ローカルネットワークへのアクセス",
"macLocalNetworkDesc": "CopySync がネットワーク上のデバイスに接続してよいか、macOS が一度だけ確認します。拒否した場合は、そこで CopySync Daemon をオンにしてください",
"allowLan": "Windows ファイアウォール",
diff --git a/ui/lib/l10n/app_localizations.dart b/ui/lib/l10n/app_localizations.dart
index df2714b..a87d47e 100644
--- a/ui/lib/l10n/app_localizations.dart
+++ b/ui/lib/l10n/app_localizations.dart
@@ -655,7 +655,7 @@ abstract class AppLocalizations {
/// No description provided for @noDevicesBody.
///
/// In en, this message translates to:
- /// **'Open CopySync on your other computer and link the two with a 6-character pairing code. On the same network, nothing else is needed.'**
+ /// **'Open CopySync on your other computer and link the two with a 6-character pairing code. On the same network, you can also open Search nearby on both and click the other one.'**
String get noDevicesBody;
/// No description provided for @pairedDevices.
@@ -778,6 +778,66 @@ abstract class AppLocalizations {
/// **'Turn on CopySync Daemon in System Settings → Privacy & Security → Local Network. Until then, {device} can\'t connect to devices on this network.'**
String lanBlockedBody(String device);
+ /// No description provided for @searchNearby.
+ ///
+ /// In en, this message translates to:
+ /// **'Search nearby'**
+ String get searchNearby;
+
+ /// No description provided for @nearbyTitle.
+ ///
+ /// In en, this message translates to:
+ /// **'Nearby devices'**
+ String get nearbyTitle;
+
+ /// No description provided for @nearbySearching.
+ ///
+ /// In en, this message translates to:
+ /// **'Looking for nearby devices…'**
+ String get nearbySearching;
+
+ /// No description provided for @nearbyHint.
+ ///
+ /// In en, this message translates to:
+ /// **'Open Search nearby on the other computer too, and it shows up here. Click it to pair.'**
+ String get nearbyHint;
+
+ /// No description provided for @nearbyVisible.
+ ///
+ /// In en, this message translates to:
+ /// **'While this window is open, devices on this network can see the name of {device}.'**
+ String nearbyVisible(String device);
+
+ /// No description provided for @nearbyPaired.
+ ///
+ /// In en, this message translates to:
+ /// **'Paired'**
+ String get nearbyPaired;
+
+ /// No description provided for @nearbyRequesting.
+ ///
+ /// In en, this message translates to:
+ /// **'Contacting “{name}”…'**
+ String nearbyRequesting(String name);
+
+ /// No description provided for @nearbyNoReply.
+ ///
+ /// In en, this message translates to:
+ /// **'“{name}” didn\'t answer. Make sure Search nearby is still open on it.'**
+ String nearbyNoReply(String name);
+
+ /// No description provided for @nearbyLanOffTitle.
+ ///
+ /// In en, this message translates to:
+ /// **'Local network discovery is off'**
+ String get nearbyLanOffTitle;
+
+ /// No description provided for @nearbyLanOffBody.
+ ///
+ /// In en, this message translates to:
+ /// **'Turn on “Find devices on this network” in Settings to see nearby devices, or pair with a code instead.'**
+ String get nearbyLanOffBody;
+
/// No description provided for @generateCode.
///
/// In en, this message translates to:
@@ -1051,7 +1111,7 @@ abstract class AppLocalizations {
/// No description provided for @lanDiscoveryDesc.
///
/// In en, this message translates to:
- /// **'Pair and sync without a server. Others on the network only see an anonymous entry that changes daily.'**
+ /// **'Pair and sync without a server. Others on the network only see an anonymous entry that changes daily, and the device name only while Search nearby is open.'**
String get lanDiscoveryDesc;
/// No description provided for @macLocalNetwork.
diff --git a/ui/lib/l10n/app_localizations_en.dart b/ui/lib/l10n/app_localizations_en.dart
index 1764b7f..1aede3f 100644
--- a/ui/lib/l10n/app_localizations_en.dart
+++ b/ui/lib/l10n/app_localizations_en.dart
@@ -387,7 +387,7 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get noDevicesBody =>
- 'Open CopySync on your other computer and link the two with a 6-character pairing code. On the same network, nothing else is needed.';
+ 'Open CopySync on your other computer and link the two with a 6-character pairing code. On the same network, you can also open Search nearby on both and click the other one.';
@override
String get pairedDevices => 'Paired devices';
@@ -459,6 +459,44 @@ class AppLocalizationsEn extends AppLocalizations {
return 'Turn on CopySync Daemon in System Settings → Privacy & Security → Local Network. Until then, $device can\'t connect to devices on this network.';
}
+ @override
+ String get searchNearby => 'Search nearby';
+
+ @override
+ String get nearbyTitle => 'Nearby devices';
+
+ @override
+ String get nearbySearching => 'Looking for nearby devices…';
+
+ @override
+ String get nearbyHint =>
+ 'Open Search nearby on the other computer too, and it shows up here. Click it to pair.';
+
+ @override
+ String nearbyVisible(String device) {
+ return 'While this window is open, devices on this network can see the name of $device.';
+ }
+
+ @override
+ String get nearbyPaired => 'Paired';
+
+ @override
+ String nearbyRequesting(String name) {
+ return 'Contacting “$name”…';
+ }
+
+ @override
+ String nearbyNoReply(String name) {
+ return '“$name” didn\'t answer. Make sure Search nearby is still open on it.';
+ }
+
+ @override
+ String get nearbyLanOffTitle => 'Local network discovery is off';
+
+ @override
+ String get nearbyLanOffBody =>
+ 'Turn on “Find devices on this network” in Settings to see nearby devices, or pair with a code instead.';
+
@override
String get generateCode => 'Show a code';
@@ -613,7 +651,7 @@ class AppLocalizationsEn extends AppLocalizations {
@override
String get lanDiscoveryDesc =>
- 'Pair and sync without a server. Others on the network only see an anonymous entry that changes daily.';
+ 'Pair and sync without a server. Others on the network only see an anonymous entry that changes daily, and the device name only while Search nearby is open.';
@override
String get macLocalNetwork => 'Local Network access';
diff --git a/ui/lib/l10n/app_localizations_ja.dart b/ui/lib/l10n/app_localizations_ja.dart
index 2561e9e..4e730f9 100644
--- a/ui/lib/l10n/app_localizations_ja.dart
+++ b/ui/lib/l10n/app_localizations_ja.dart
@@ -326,7 +326,7 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get noDevicesBody =>
- 'もう一台のコンピューターで CopySync を開き、6 桁のペアリングコードでつなげます。同じネットワーク内なら、ほかに準備はいりません。';
+ 'もう一台のコンピューターで CopySync を開き、6 桁のペアリングコードでつなげます。同じネットワーク内なら、両方で「近くを検索」を開いて相手をクリックすることもできます。';
@override
String get pairedDevices => 'ペアリング済みのデバイス';
@@ -398,6 +398,43 @@ class AppLocalizationsJa extends AppLocalizations {
return '「システム設定 → プライバシーとセキュリティ → ローカルネットワーク」で CopySync Daemon をオンにしてください。オンにするまで、$deviceは同じネットワークのデバイスに接続できません。';
}
+ @override
+ String get searchNearby => '近くを検索';
+
+ @override
+ String get nearbyTitle => '近くのデバイス';
+
+ @override
+ String get nearbySearching => '近くのデバイスを探しています…';
+
+ @override
+ String get nearbyHint => 'もう一台でも「近くを検索」を開くと、ここに表示されます。クリックしてペアリングします。';
+
+ @override
+ String nearbyVisible(String device) {
+ return 'このウィンドウを開いている間は、同じネットワークのデバイスから$deviceの名前が見えます。';
+ }
+
+ @override
+ String get nearbyPaired => 'ペアリング済み';
+
+ @override
+ String nearbyRequesting(String name) {
+ return '「$name」に接続しています…';
+ }
+
+ @override
+ String nearbyNoReply(String name) {
+ return '「$name」から応答がありません。相手で「近くを検索」が開いたままか確認してください。';
+ }
+
+ @override
+ String get nearbyLanOffTitle => 'ローカルネットワークの検出がオフです';
+
+ @override
+ String get nearbyLanOffBody =>
+ '近くのデバイスを表示するには「設定」で「このネットワークでデバイスを探す」をオンにするか、コードでペアリングしてください。';
+
@override
String get generateCode => 'コードを表示';
@@ -546,7 +583,7 @@ class AppLocalizationsJa extends AppLocalizations {
@override
String get lanDiscoveryDesc =>
- 'サーバーなしでペアリングと同期ができます。ネットワーク上の他の人には、毎日変わる匿名の識別子しか見えません';
+ 'サーバーなしでペアリングと同期ができます。ネットワーク上の他の人には、毎日変わる匿名の識別子しか見えません。デバイス名が見えるのは「近くを検索」を開いている間だけです';
@override
String get macLocalNetwork => 'ローカルネットワークへのアクセス';
diff --git a/ui/lib/l10n/app_localizations_zh.dart b/ui/lib/l10n/app_localizations_zh.dart
index 626b9bf..e5286e4 100644
--- a/ui/lib/l10n/app_localizations_zh.dart
+++ b/ui/lib/l10n/app_localizations_zh.dart
@@ -325,7 +325,7 @@ class AppLocalizationsZh extends AppLocalizations {
@override
String get noDevicesBody =>
- '在另一台电脑上打开 CopySync,用 6 位配对码把两台连起来。两台在同一个网络里时,不需要别的准备。';
+ '在另一台电脑上打开 CopySync,用 6 位配对码把两台连起来。两台在同一个网络里时,也可以在两台上都打开「搜索附近设备」,点一下对方。';
@override
String get pairedDevices => '已配对的设备';
@@ -396,6 +396,42 @@ class AppLocalizationsZh extends AppLocalizations {
return '在「系统设置 → 隐私与安全性 → 本地网络」里打开 CopySync Daemon。打开之前,$device连不上同一网络里的设备。';
}
+ @override
+ String get searchNearby => '搜索附近设备';
+
+ @override
+ String get nearbyTitle => '附近的设备';
+
+ @override
+ String get nearbySearching => '正在查找附近的设备…';
+
+ @override
+ String get nearbyHint => '在另一台电脑上也打开「搜索附近设备」,它就会出现在这里,点一下即可配对。';
+
+ @override
+ String nearbyVisible(String device) {
+ return '窗口打开期间,同一网络里的设备能看到$device的名字。';
+ }
+
+ @override
+ String get nearbyPaired => '已配对';
+
+ @override
+ String nearbyRequesting(String name) {
+ return '正在联系「$name」…';
+ }
+
+ @override
+ String nearbyNoReply(String name) {
+ return '「$name」没有回应。确认它还开着「搜索附近设备」。';
+ }
+
+ @override
+ String get nearbyLanOffTitle => '局域网发现已关闭';
+
+ @override
+ String get nearbyLanOffBody => '在「设置」里打开「在局域网中查找设备」才能看到附近的设备,或者改用配对码。';
+
@override
String get generateCode => '生成配对码';
@@ -540,7 +576,8 @@ class AppLocalizationsZh extends AppLocalizations {
String get lanDiscovery => '在局域网中查找设备';
@override
- String get lanDiscoveryDesc => '不用服务器就能配对和同步。网络里的其他人只能看到一个每天都变的匿名标识';
+ String get lanDiscoveryDesc =>
+ '不用服务器就能配对和同步。网络里的其他人只能看到一个每天都变的匿名标识;打开「搜索附近设备」期间才看得到设备名';
@override
String get macLocalNetwork => '本地网络权限';
diff --git a/ui/lib/l10n/app_zh.arb b/ui/lib/l10n/app_zh.arb
index d87fc09..781e9f9 100644
--- a/ui/lib/l10n/app_zh.arb
+++ b/ui/lib/l10n/app_zh.arb
@@ -92,7 +92,7 @@
"addDevice": "添加设备",
"thisDeviceFootnote": "配对时,{both}会显示同样的两行安全指纹:这台的和对方的。逐字核对一致才能确认。",
"noDevicesTitle": "还没有配对的设备",
- "noDevicesBody": "在另一台电脑上打开 CopySync,用 6 位配对码把两台连起来。两台在同一个网络里时,不需要别的准备。",
+ "noDevicesBody": "在另一台电脑上打开 CopySync,用 6 位配对码把两台连起来。两台在同一个网络里时,也可以在两台上都打开「搜索附近设备」,点一下对方。",
"pairedDevices": "已配对的设备",
"pairedFootnote": "直连:数据在两台设备之间直接传输。中转:网络环境打不通直连时,经你的服务器转发,内容依然是端到端加密的。",
"offline": "离线",
@@ -113,6 +113,16 @@
"addressSaved": "已记下,正在那个地址上找它",
"lanBlockedTitle": "macOS 阻止了局域网访问",
"lanBlockedBody": "在「系统设置 → 隐私与安全性 → 本地网络」里打开 CopySync Daemon。打开之前,{device}连不上同一网络里的设备。",
+ "searchNearby": "搜索附近设备",
+ "nearbyTitle": "附近的设备",
+ "nearbySearching": "正在查找附近的设备…",
+ "nearbyHint": "在另一台电脑上也打开「搜索附近设备」,它就会出现在这里,点一下即可配对。",
+ "nearbyVisible": "窗口打开期间,同一网络里的设备能看到{device}的名字。",
+ "nearbyPaired": "已配对",
+ "nearbyRequesting": "正在联系「{name}」…",
+ "nearbyNoReply": "「{name}」没有回应。确认它还开着「搜索附近设备」。",
+ "nearbyLanOffTitle": "局域网发现已关闭",
+ "nearbyLanOffBody": "在「设置」里打开「在局域网中查找设备」才能看到附近的设备,或者改用配对码。",
"generateCode": "生成配对码",
"enterCode": "输入配对码",
"codeFailedTitle": "没能生成配对码",
@@ -158,7 +168,7 @@
"localNetwork": "局域网",
"lanFootnote": "使用 UDP 端口 8788。两台不在同一网段时,配对时输入对方的地址。",
"lanDiscovery": "在局域网中查找设备",
- "lanDiscoveryDesc": "不用服务器就能配对和同步。网络里的其他人只能看到一个每天都变的匿名标识",
+ "lanDiscoveryDesc": "不用服务器就能配对和同步。网络里的其他人只能看到一个每天都变的匿名标识;打开「搜索附近设备」期间才看得到设备名",
"macLocalNetwork": "本地网络权限",
"macLocalNetworkDesc": "macOS 会问一次是否允许 CopySync 连接网络里的设备。拒绝过的话,到那里打开 CopySync Daemon",
"allowLan": "Windows 防火墙",
diff --git a/ui/lib/pages/devices_page.dart b/ui/lib/pages/devices_page.dart
index dfd7f13..66b51f8 100644
--- a/ui/lib/pages/devices_page.dart
+++ b/ui/lib/pages/devices_page.dart
@@ -7,6 +7,7 @@ import '../i18n.dart';
import '../main.dart';
import '../theme.dart';
import '../widgets/common.dart';
+import '../widgets/nearby_dialog.dart';
import '../widgets/pairing_dialog.dart';
import '../icons.dart';
import '../platform.dart';
@@ -30,6 +31,12 @@ class DevicesPage extends StatelessWidget {
? l.devicesSubtitleEmpty
: l.devicesSubtitle(state.peers.length, state.onlinePeerCount),
actions: [
+ // 配对码照常是主入口;想在局域网里点选对方时,才打开雷达
+ OutlinedButton.icon(
+ onPressed: canPair ? () => showNearbyDialog(context) : null,
+ icon: Icon(AppIcons.radar, size: 14),
+ label: Text(l.searchNearby),
+ ),
FilledButton.icon(
onPressed: canPair ? () => _startPairing(context) : null,
icon: Icon(AppIcons.plus, size: 14),
@@ -60,9 +67,19 @@ class DevicesPage extends StatelessWidget {
title: l.noDevicesTitle,
description: l.noDevicesBody,
action: canPair
- ? FilledButton(
- onPressed: () => _startPairing(context),
- child: Text(l.addDevice),
+ ? Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ FilledButton(
+ onPressed: () => _startPairing(context),
+ child: Text(l.addDevice),
+ ),
+ const SizedBox(width: Insets.sm),
+ OutlinedButton(
+ onPressed: () => showNearbyDialog(context),
+ child: Text(l.searchNearby),
+ ),
+ ],
)
: null,
),
diff --git a/ui/lib/widgets/nearby_dialog.dart b/ui/lib/widgets/nearby_dialog.dart
new file mode 100644
index 0000000..d77fb00
--- /dev/null
+++ b/ui/lib/widgets/nearby_dialog.dart
@@ -0,0 +1,438 @@
+import 'dart:async';
+import 'dart:io';
+import 'dart:math' as math;
+
+import 'package:flutter/material.dart';
+
+import '../app_state.dart';
+import '../gen/copysync/v1/daemon.pb.dart';
+import '../i18n.dart';
+import '../icons.dart';
+import '../main.dart';
+import '../pages/devices_page.dart' show LanBlockedNotice, platformIcon;
+import '../platform.dart';
+import '../theme.dart';
+import 'common.dart';
+import 'pairing_dialog.dart';
+
+Future<void> showNearbyDialog(BuildContext context) =>
+ pushPairingSetupRoute(context, (_) => const NearbyDialog());
+
+/// 搜索附近设备:本机在中间,附近同样打开了这个窗口的设备出现在周围,点一下发起配对。
+///
+/// 窗口开着时订阅后台服务的 WatchNearby:订阅期间本机在局域网里公开设备名,
+/// 窗口一关订阅就断,本机随之撤下。点了对方之后与输入配对码一样,双方核对指纹再确认。
+class NearbyDialog extends StatefulWidget {
+ const NearbyDialog({super.key});
+
+ @override
+ State<NearbyDialog> createState() => _NearbyDialogState();
+}
+
+/// 设备在雷达上的位置(角度,0 是正右方,顺时针)。先占左右两侧,再补正上、正下,
+/// 相邻两台的名字不会叠在一起;最多显示这么多台。
+const _slotAngles = [-30.0, 150.0, 30.0, 210.0, -90.0, 90.0];
+
+class _NearbyDialogState extends State<NearbyDialog> with SingleTickerProviderStateMixin {
+ late final AnimationController _pulse =
+ AnimationController(vsync: this, duration: const Duration(milliseconds: 2800));
+ StreamSubscription<List<NearbyDevice>>? _sub;
+ List<NearbyDevice> _devices = const [];
+
+ /// 每台设备占一个固定的位置:别的设备出现或离开时,已有的不会挪动
+ final Map<String, int> _slots = {};
+ String? _requesting; // 正在联系的设备
+ String? _message; // 出错时的提示
+ bool _lost = false; // 与后台服务的订阅断了
+
+ @override
+ void initState() {
+ super.initState();
+ _watch();
+ }
+
+ @override
+ void didChangeDependencies() {
+ super.didChangeDependencies();
+ // 系统设置里关掉了动画时,雷达静止
+ if (MediaQuery.disableAnimationsOf(context)) {
+ _pulse.stop();
+ } else if (!_pulse.isAnimating) {
+ _pulse.repeat();
+ }
+ }
+
+ @override
+ void dispose() {
+ _sub?.cancel();
+ _pulse.dispose();
+ super.dispose();
+ }
+
+ void _watch() {
+ _sub?.cancel();
+ _lost = false;
+ _message = null;
+ try {
+ _sub = AppScope.read(context).watchNearby().listen(
+ _onDevices,
+ onError: (Object e) => _onLost(AppState.describeError(e)),
+ onDone: () => _onLost(appL10n.linkServiceDisconnected),
+ );
+ } catch (e) {
+ _onLost(AppState.describeError(e));
+ }
+ }
+
+ void _onLost(String message) {
+ if (!mounted) return;
+ setState(() {
+ _lost = true;
+ _message = message;
+ _devices = const [];
+ });
+ }
+
+ void _onDevices(List<NearbyDevice> list) {
+ if (!mounted) return;
+ final ids = {for (final d in list) d.id};
+ _slots.removeWhere((id, _) => !ids.contains(id));
+ final shown = <NearbyDevice>[];
+ for (final d in list) {
+ var slot = _slots[d.id];
+ if (slot == null) {
+ final used = _slots.values.toSet();
+ slot = List.generate(_slotAngles.length, (i) => i).where((i) => !used.contains(i)).firstOrNull;
+ if (slot == null) continue; // 位置占满了
+ _slots[d.id] = slot;
+ }
+ shown.add(d);
+ }
+ setState(() => _devices = shown);
+ }
+
+ Future<void> _pair(NearbyDevice d) async {
+ if (_requesting != null || d.paired) return;
+ setState(() {
+ _requesting = d.id;
+ _message = null;
+ });
+ try {
+ // 成功后 Shell 弹出核对指纹,并移除这个窗口
+ await AppScope.read(context).pairNearby(d.id);
+ } catch (e) {
+ if (!mounted) return;
+ final l = context.l10n;
+ setState(() => _message = switch (AppState.pairingFailure(e)) {
+ PairingFailure.notFound => l.nearbyNoReply(d.name),
+ PairingFailure.noChannel => l.pairNoChannel,
+ _ => AppState.describeError(e),
+ });
+ } finally {
+ if (mounted) setState(() => _requesting = null);
+ }
+ }
+
+ @override
+ Widget build(BuildContext context) {
+ final state = AppScope.of(context);
+ final p = context.palette;
+ final l = context.l10n;
+ final requesting = _devices.where((d) => d.id == _requesting).firstOrNull;
+ final status = _message ??
+ (requesting != null
+ ? l.nearbyRequesting(requesting.name)
+ : _devices.isEmpty
+ ? l.nearbySearching
+ : null);
+
+ return Dialog(
+ child: SizedBox(
+ width: 460,
+ child: Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ Padding(
+ padding: const EdgeInsets.fromLTRB(Insets.xl, Insets.lg, Insets.md, 0),
+ child: Row(
+ children: [
+ Expanded(child: Text(l.nearbyTitle, style: context.text.titleMedium)),
+ IconAction(
+ icon: AppIcons.xmark,
+ tooltip: l.close,
+ onTap: () => Navigator.pop(context),
+ ),
+ ],
+ ),
+ ),
+ if (state.lanBlocked)
+ const Padding(
+ padding: EdgeInsets.fromLTRB(Insets.xl, Insets.md, Insets.xl, 0),
+ child: LanBlockedNotice(),
+ ),
+ SizedBox(
+ height: 300,
+ child: state.lanEnabled
+ ? _radar(context, state)
+ : Padding(
+ padding: const EdgeInsets.all(Insets.xl),
+ child: EmptyState(
+ icon: AppIcons.radar,
+ title: l.nearbyLanOffTitle,
+ description: l.nearbyLanOffBody,
+ ),
+ ),
+ ),
+ Padding(
+ padding: const EdgeInsets.fromLTRB(Insets.xl, 0, Insets.xl, Insets.xl),
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ children: [
+ if (state.lanEnabled) ...[
+ SizedBox(
+ height: 20,
+ child: status == null
+ ? null
+ : Text(
+ status,
+ textAlign: TextAlign.center,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ style: context.text.bodyMedium?.copyWith(
+ color: _message != null ? p.danger : p.textDim,
+ ),
+ ),
+ ),
+ if (_lost)
+ Center(child: TextButton(onPressed: () => setState(_watch), child: Text(l.retry))),
+ const SizedBox(height: 2),
+ Text(l.nearbyHint, textAlign: TextAlign.center, style: context.text.bodySmall),
+ ],
+ const SizedBox(height: Insets.lg),
+ Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Icon(AppIcons.lockShield, size: 15, color: p.textDim),
+ const SizedBox(width: Insets.sm),
+ Expanded(
+ child: Text(
+ l.nearbyVisible(Wording.thisDeviceInText),
+ style: context.text.bodySmall,
+ ),
+ ),
+ ],
+ ),
+ ],
+ ),
+ ),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Widget _radar(BuildContext context, AppState state) {
+ final p = context.palette;
+ final selfPlatform = state.self?.platform ?? (Platform.isWindows ? 'windows' : 'darwin');
+ return LayoutBuilder(
+ builder: (context, box) {
+ final center = box.biggest.center(Offset.zero);
+ // 设备排在一个椭圆上:横向空间多,名字不容易挤在一起
+ final rx = math.min(150.0, box.maxWidth / 2 - _NearbyNode.width / 2);
+ final ry = math.min(100.0, box.maxHeight / 2 - 50);
+ return Stack(
+ clipBehavior: Clip.none,
+ children: [
+ Positioned.fill(
+ child: RepaintBoundary(
+ child: CustomPaint(
+ painter: _RadarPainter(pulse: _pulse, ring: p.separator, wave: p.accent),
+ ),
+ ),
+ ),
+ Positioned(
+ left: center.dx - _NearbyNode.width / 2,
+ top: center.dy - _NearbyNode.avatar / 2,
+ width: _NearbyNode.width,
+ child: _SelfNode(platform: selfPlatform),
+ ),
+ for (final d in _devices)
+ Builder(builder: (context) {
+ final a = _slotAngles[_slots[d.id]!] * math.pi / 180;
+ final at = center + Offset(rx * math.cos(a), ry * math.sin(a));
+ return Positioned(
+ key: ValueKey(d.id),
+ left: at.dx - _NearbyNode.width / 2,
+ top: at.dy - _NearbyNode.avatar / 2,
+ width: _NearbyNode.width,
+ child: _NearbyNode(
+ device: d,
+ busy: d.id == _requesting,
+ onTap: _requesting == null ? () => _pair(d) : null,
+ ),
+ );
+ }),
+ ],
+ );
+ },
+ );
+ }
+}
+
+/// 雷达的底:几圈很淡的同心圆,两道波纹错开半个周期从本机向外扩散、逐渐变淡。
+class _RadarPainter extends CustomPainter {
+ _RadarPainter({required this.pulse, required this.ring, required this.wave}) : super(repaint: pulse);
+
+ final Animation<double> pulse;
+ final Color ring;
+ final Color wave;
+
+ @override
+ void paint(Canvas canvas, Size size) {
+ final c = size.center(Offset.zero);
+ final maxR = size.shortestSide / 2;
+ final rings = Paint()
+ ..style = PaintingStyle.stroke
+ ..strokeWidth = 1
+ ..color = ring;
+ for (final f in const [0.36, 0.68, 1.0]) {
+ canvas.drawCircle(c, maxR * f, rings);
+ }
+ for (final offset in const [0.0, 0.5]) {
+ final t = (pulse.value + offset) % 1.0;
+ final r = 28 + (maxR - 28) * Curves.easeOut.transform(t);
+ canvas.drawCircle(
+ c,
+ r,
+ Paint()
+ ..style = PaintingStyle.stroke
+ ..strokeWidth = 1.5
+ ..color = wave.withValues(alpha: 0.3 * (1 - t)),
+ );
+ }
+ }
+
+ @override
+ bool shouldRepaint(_RadarPainter old) => old.ring != ring || old.wave != wave;
+}
+
+class _SelfNode extends StatelessWidget {
+ const _SelfNode({required this.platform});
+
+ final String platform;
+
+ @override
+ Widget build(BuildContext context) {
+ final p = context.palette;
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Container(
+ width: _NearbyNode.avatar,
+ height: _NearbyNode.avatar,
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ color: p.surface,
+ border: Border.all(color: p.accent, width: 1.5),
+ ),
+ child: Icon(platformIcon(platform), size: 22, color: p.accent),
+ ),
+ const SizedBox(height: 6),
+ Text(
+ Wording.thisDevice,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ textAlign: TextAlign.center,
+ style: context.text.labelMedium,
+ ),
+ ],
+ );
+ }
+}
+
+/// 雷达上的一台附近设备:圆形图标加名字。已配对的变淡、不能点。
+class _NearbyNode extends StatefulWidget {
+ const _NearbyNode({required this.device, required this.busy, this.onTap});
+
+ static const width = 112.0;
+ static const avatar = 46.0;
+
+ final NearbyDevice device;
+ final bool busy;
+ final VoidCallback? onTap;
+
+ @override
+ State<_NearbyNode> createState() => _NearbyNodeState();
+}
+
+class _NearbyNodeState extends State<_NearbyNode> {
+ bool _hover = false;
+
+ @override
+ Widget build(BuildContext context) {
+ final p = context.palette;
+ final d = widget.device;
+ final enabled = !d.paired && widget.onTap != null;
+ final highlight = enabled && _hover;
+
+ final node = Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ SizedBox.square(
+ dimension: _NearbyNode.avatar,
+ child: Stack(
+ alignment: Alignment.center,
+ children: [
+ AnimatedContainer(
+ duration: const Duration(milliseconds: 120),
+ decoration: BoxDecoration(
+ shape: BoxShape.circle,
+ color: p.surface,
+ border: Border.all(color: highlight ? p.accent : p.border, width: highlight ? 1.5 : 1),
+ boxShadow: const [BoxShadow(color: Color(0x14000000), blurRadius: 6, offset: Offset(0, 2))],
+ ),
+ ),
+ Icon(platformIcon(d.platform), size: 22, color: highlight ? p.accent : p.textDim),
+ if (widget.busy) const SizedBox.expand(child: CircularProgressIndicator(strokeWidth: 1.5)),
+ ],
+ ),
+ ),
+ const SizedBox(height: 6),
+ Text(
+ d.name,
+ maxLines: 1,
+ overflow: TextOverflow.ellipsis,
+ textAlign: TextAlign.center,
+ style: context.text.labelMedium?.copyWith(color: p.text),
+ ),
+ if (d.paired) Text(context.l10n.nearbyPaired, style: context.text.labelSmall),
+ ],
+ );
+
+ // 新出现的设备从小到大淡入
+ return TweenAnimationBuilder<double>(
+ tween: Tween(begin: 0, end: 1),
+ duration: const Duration(milliseconds: 260),
+ curve: Curves.easeOut,
+ builder: (context, v, child) => Opacity(
+ opacity: v,
+ child: Transform.scale(scale: 0.7 + 0.3 * v, child: child),
+ ),
+ child: Semantics(
+ button: enabled,
+ label: d.name,
+ child: MouseRegion(
+ cursor: enabled ? SystemMouseCursors.click : SystemMouseCursors.basic,
+ onEnter: (_) => setState(() => _hover = true),
+ onExit: (_) => setState(() => _hover = false),
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: enabled ? widget.onTap : null,
+ child: Opacity(opacity: d.paired ? 0.55 : 1, child: node),
+ ),
+ ),
+ ),
+ );
+ }
+}
diff --git a/ui/lib/widgets/pairing_dialog.dart b/ui/lib/widgets/pairing_dialog.dart
index ccccf09..c38781e 100644
--- a/ui/lib/widgets/pairing_dialog.dart
+++ b/ui/lib/widgets/pairing_dialog.dart
@@ -10,16 +10,17 @@ import 'common.dart';
import '../icons.dart';
import '../platform.dart';
-// 保存“添加设备”这条路由。配对请求到达时只移除它,不误关上层的确认框。
+// 保存“添加设备”或“搜索附近设备”这条路由。配对请求到达时只移除它,不误关上层的确认框。
final _pairingSetupRoutes = Expando<DialogRoute<void>>();
-Future<void> showPairingDialog(BuildContext context) {
+Future<void> showPairingDialog(BuildContext context) =>
+ pushPairingSetupRoute(context, (_) => const PairingDialog());
+
+/// 推出一个发起配对的对话框。同一时间只开一个;配对请求到达、弹出核对指纹时它会被移除。
+Future<void> pushPairingSetupRoute(BuildContext context, WidgetBuilder builder) {
final navigator = Navigator.of(context, rootNavigator: true);
if (_pairingSetupRoutes[navigator] != null) return Future.value();
- final route = DialogRoute<void>(
- context: context,
- builder: (_) => const PairingDialog(),
- );
+ final route = DialogRoute<void>(context: context, builder: builder);
_pairingSetupRoutes[navigator] = route;
return navigator.push(route).whenComplete(() {
if (identical(_pairingSetupRoutes[navigator], route)) {
diff --git a/ui/test/pairing_flow_test.dart b/ui/test/pairing_flow_test.dart
index af33aca..e1dbf93 100644
--- a/ui/test/pairing_flow_test.dart
+++ b/ui/test/pairing_flow_test.dart
@@ -3,6 +3,7 @@ import 'dart:async';
import 'package:copysync_ui/app_state.dart';
import 'package:copysync_ui/gen/copysync/v1/daemon.pb.dart';
import 'package:copysync_ui/main.dart';
+import 'package:copysync_ui/widgets/nearby_dialog.dart';
import 'package:copysync_ui/widgets/pairing_dialog.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -22,6 +23,11 @@ class PairingState extends AppState {
Object? nextRedeemFailure;
bool failConfirmation = false;
+ bool nearbyCancelled = false;
+ late final nearby = StreamController<List<NearbyDevice>>(onCancel: () => nearbyCancelled = true);
+ final pairedNearby = <String>[];
+ Object? nextNearbyFailure;
+
// 没有服务器、只开着局域网:这是新装的默认状态,照样能配对
PairingState() {
debugSeed(
@@ -53,6 +59,22 @@ class PairingState extends AppState {
return peer;
}
+ @override
+ Stream<List<NearbyDevice>> watchNearby() => nearby.stream;
+
+ @override
+ Future<Device> pairNearby(String id) async {
+ pairedNearby.add(id);
+ final failure = nextNearbyFailure;
+ if (failure != null) {
+ nextNearbyFailure = null;
+ throw failure;
+ }
+ final peer = pendingPeer();
+ receive(peer);
+ return peer;
+ }
+
@override
Future<void> confirmPairing(String session, bool accept) async {
confirmations.add((session, accept));
@@ -70,6 +92,21 @@ Future<void> openSetup(WidgetTester tester, PairingState state) async {
await tester.pumpAndSettle();
}
+/// 打开「搜索附近设备」。雷达的波纹一直在动,不能用 pumpAndSettle 等它停下。
+Future<void> openNearby(WidgetTester tester, PairingState state) async {
+ await tester.pumpWidget(CopySyncApp(state: state));
+ await tester.tap(find.text('设备').first);
+ await tester.pumpAndSettle();
+ await tester.tap(find.text('搜索附近设备').first);
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 300));
+}
+
+final nearbyDevices = [
+ NearbyDevice(id: 'copysync-1', name: '光光的电脑', platform: 'windows'),
+ NearbyDevice(id: 'copysync-2', name: '旧 Mac', platform: 'darwin', paired: true),
+];
+
void expectSingleConfirmation() {
// 包括被第二个对话框盖住的路由,避免只检查最上层而漏掉叠加弹窗。
expect(
@@ -218,6 +255,77 @@ void main() {
expect(find.byType(TextField), findsOneWidget);
});
+ group('搜索附近设备', () {
+ testWidgets('原来的添加设备不变,雷达是单独的入口', (tester) async {
+ final state = PairingState();
+ addTearDown(state.dispose);
+ await openSetup(tester, state);
+ expect(find.byType(PairingDialog), findsOneWidget);
+ expect(find.byType(NearbyDialog), findsNothing);
+ expect(find.text('ABC123'), findsOneWidget);
+ expect(state.nearby.hasListener, isFalse, reason: '没打开雷达时不该公开本机');
+ });
+
+ testWidgets('显示附近的设备,点一下弹出核对指纹并关掉雷达', (tester) async {
+ final state = PairingState();
+ addTearDown(state.dispose);
+ await openNearby(tester, state);
+ expect(find.byType(NearbyDialog), findsOneWidget);
+ expect(find.text('正在查找附近的设备…'), findsOneWidget);
+ expect(state.nearby.hasListener, isTrue);
+
+ state.nearby.add(nearbyDevices);
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 300));
+ expect(find.text('光光的电脑'), findsOneWidget);
+ expect(find.text('已配对'), findsOneWidget);
+ expect(find.text('正在查找附近的设备…'), findsNothing);
+
+ // 已配对的点了没反应
+ await tester.tap(find.text('旧 Mac'));
+ await tester.pump();
+ expect(state.pairedNearby, isEmpty);
+
+ await tester.tap(find.text('光光的电脑'));
+ await tester.pumpAndSettle();
+ expect(state.pairedNearby, ['copysync-1']);
+ expectSingleConfirmation();
+ expect(find.byType(NearbyDialog, skipOffstage: false), findsNothing);
+ expect(state.nearbyCancelled, isTrue, reason: '雷达关掉后要撤下本机');
+ expect(tester.takeException(), isNull);
+ });
+
+ testWidgets('对方没有回应时给出原因,关掉窗口就撤下本机', (tester) async {
+ final state = PairingState()
+ ..nextNearbyFailure = GrpcError.notFound('not_found: 没在局域网里找到正在配对的设备');
+ addTearDown(state.dispose);
+ await openNearby(tester, state);
+ state.nearby.add(nearbyDevices);
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 300));
+
+ await tester.tap(find.text('光光的电脑'));
+ await tester.pump();
+ await tester.pump();
+ expect(find.text('「光光的电脑」没有回应。确认它还开着「搜索附近设备」。'), findsOneWidget);
+ expect(find.byType(NearbyDialog), findsOneWidget);
+
+ await tester.tap(find.byTooltip('关闭'));
+ await tester.pumpAndSettle();
+ expect(find.byType(NearbyDialog), findsNothing);
+ expect(state.nearbyCancelled, isTrue);
+ });
+
+ testWidgets('局域网发现关闭时说明原因', (tester) async {
+ final state = PairingState();
+ addTearDown(state.dispose);
+ state.debugSeed(status: Status(), config: Config(), self: Device(id: 'self', name: '本机'));
+ await openNearby(tester, state);
+ expect(find.text('局域网发现已关闭'), findsOneWidget);
+ expect(find.text('光光的电脑'), findsNothing);
+ });
+ });
+
group('侧边栏的连接状态', () {
Future<void> pumpWith(WidgetTester tester, Status status) async {
final state = PairingState();
diff --git a/ui/tool/l10n/strings.py b/ui/tool/l10n/strings.py
index dc29d45..ac1c6b4 100644
--- a/ui/tool/l10n/strings.py
+++ b/ui/tool/l10n/strings.py
@@ -119,7 +119,7 @@ S = [
("addDevice", "Add device", "添加设备", "デバイスを追加"),
("thisDeviceFootnote", "When pairing, {both} show the same two lines of security fingerprints, one for each device. Confirm only if they match character for character.", "配对时,{both}会显示同样的两行安全指纹:这台的和对方的。逐字核对一致才能确认。", "ペアリング時、{both}に同じ 2 行のセキュリティ指紋(このデバイスと相手のもの)が表示されます。1 文字ずつ一致を確かめてから確定してください。"),
("noDevicesTitle", "No paired devices yet", "还没有配对的设备", "ペアリングしたデバイスはまだありません"),
- ("noDevicesBody", "Open CopySync on your other computer and link the two with a 6-character pairing code. On the same network, nothing else is needed.", "在另一台电脑上打开 CopySync,用 6 位配对码把两台连起来。两台在同一个网络里时,不需要别的准备。", "もう一台のコンピューターで CopySync を開き、6 桁のペアリングコードでつなげます。同じネットワーク内なら、ほかに準備はいりません。"),
+ ("noDevicesBody", "Open CopySync on your other computer and link the two with a 6-character pairing code. On the same network, you can also open Search nearby on both and click the other one.", "在另一台电脑上打开 CopySync,用 6 位配对码把两台连起来。两台在同一个网络里时,也可以在两台上都打开「搜索附近设备」,点一下对方。", "もう一台のコンピューターで CopySync を開き、6 桁のペアリングコードでつなげます。同じネットワーク内なら、両方で「近くを検索」を開いて相手をクリックすることもできます。"),
("pairedDevices", "Paired devices", "已配对的设备", "ペアリング済みのデバイス"),
("pairedFootnote", "Direct: data goes straight between the two devices. Relay: when the network blocks a direct path, data goes through your server and stays end-to-end encrypted.", "直连:数据在两台设备之间直接传输。中转:网络环境打不通直连时,经你的服务器转发,内容依然是端到端加密的。", "直接接続:データは 2 台のデバイス間で直接やり取りされます。中継:直接つながらないネットワークでは、あなたのサーバーを経由します。内容はエンドツーエンドで暗号化されたままです。"),
("offline", "Offline", "离线", "オフライン"),
@@ -141,6 +141,18 @@ S = [
("lanBlockedTitle", "macOS is blocking the local network", "macOS 阻止了局域网访问", "macOS がローカルネットワークへのアクセスをブロックしています"),
("lanBlockedBody", "Turn on CopySync Daemon in System Settings → Privacy & Security → Local Network. Until then, {device} can't connect to devices on this network.", "在「系统设置 → 隐私与安全性 → 本地网络」里打开 CopySync Daemon。打开之前,{device}连不上同一网络里的设备。", "「システム設定 → プライバシーとセキュリティ → ローカルネットワーク」で CopySync Daemon をオンにしてください。オンにするまで、{device}は同じネットワークのデバイスに接続できません。"),
+ # ── 搜索附近设备 ──
+ ("searchNearby", "Search nearby", "搜索附近设备", "近くを検索"),
+ ("nearbyTitle", "Nearby devices", "附近的设备", "近くのデバイス"),
+ ("nearbySearching", "Looking for nearby devices…", "正在查找附近的设备…", "近くのデバイスを探しています…"),
+ ("nearbyHint", "Open Search nearby on the other computer too, and it shows up here. Click it to pair.", "在另一台电脑上也打开「搜索附近设备」,它就会出现在这里,点一下即可配对。", "もう一台でも「近くを検索」を開くと、ここに表示されます。クリックしてペアリングします。"),
+ ("nearbyVisible", "While this window is open, devices on this network can see the name of {device}.", "窗口打开期间,同一网络里的设备能看到{device}的名字。", "このウィンドウを開いている間は、同じネットワークのデバイスから{device}の名前が見えます。"),
+ ("nearbyPaired", "Paired", "已配对", "ペアリング済み"),
+ ("nearbyRequesting", "Contacting “{name}”…", "正在联系「{name}」…", "「{name}」に接続しています…"),
+ ("nearbyNoReply", "“{name}” didn't answer. Make sure Search nearby is still open on it.", "「{name}」没有回应。确认它还开着「搜索附近设备」。", "「{name}」から応答がありません。相手で「近くを検索」が開いたままか確認してください。"),
+ ("nearbyLanOffTitle", "Local network discovery is off", "局域网发现已关闭", "ローカルネットワークの検出がオフです"),
+ ("nearbyLanOffBody", "Turn on “Find devices on this network” in Settings to see nearby devices, or pair with a code instead.", "在「设置」里打开「在局域网中查找设备」才能看到附近的设备,或者改用配对码。", "近くのデバイスを表示するには「設定」で「このネットワークでデバイスを探す」をオンにするか、コードでペアリングしてください。"),
+
# ── 配对 ──
("generateCode", "Show a code", "生成配对码", "コードを表示"),
("enterCode", "Enter a code", "输入配对码", "コードを入力"),
@@ -189,7 +201,7 @@ S = [
("localNetwork", "Local network", "局域网", "ローカルネットワーク"),
("lanFootnote", "Uses UDP port 8788. If the devices are on different subnets, enter the other device's address when pairing.", "使用 UDP 端口 8788。两台不在同一网段时,配对时输入对方的地址。", "UDP ポート 8788 を使います。2 台が別のサブネットにある場合は、ペアリング時に相手のアドレスを入力します。"),
("lanDiscovery", "Find devices on this network", "在局域网中查找设备", "このネットワークでデバイスを探す"),
- ("lanDiscoveryDesc", "Pair and sync without a server. Others on the network only see an anonymous entry that changes daily.", "不用服务器就能配对和同步。网络里的其他人只能看到一个每天都变的匿名标识", "サーバーなしでペアリングと同期ができます。ネットワーク上の他の人には、毎日変わる匿名の識別子しか見えません"),
+ ("lanDiscoveryDesc", "Pair and sync without a server. Others on the network only see an anonymous entry that changes daily, and the device name only while Search nearby is open.", "不用服务器就能配对和同步。网络里的其他人只能看到一个每天都变的匿名标识;打开「搜索附近设备」期间才看得到设备名", "サーバーなしでペアリングと同期ができます。ネットワーク上の他の人には、毎日変わる匿名の識別子しか見えません。デバイス名が見えるのは「近くを検索」を開いている間だけです"),
("macLocalNetwork", "Local Network access", "本地网络权限", "ローカルネットワークへのアクセス"),
("macLocalNetworkDesc", "macOS asks once whether CopySync may connect to devices on your network. If you declined, turn on CopySync Daemon there.", "macOS 会问一次是否允许 CopySync 连接网络里的设备。拒绝过的话,到那里打开 CopySync Daemon", "CopySync がネットワーク上のデバイスに接続してよいか、macOS が一度だけ確認します。拒否した場合は、そこで CopySync Daemon をオンにしてください"),
("allowLan", "Windows Firewall", "Windows 防火墙", "Windows ファイアウォール"),
diff --git a/ui/tool/screenshots/screenshots_test.dart b/ui/tool/screenshots/screenshots_test.dart
index 05a2ca8..077efe5 100644
--- a/ui/tool/screenshots/screenshots_test.dart
+++ b/ui/tool/screenshots/screenshots_test.dart
@@ -5,6 +5,7 @@
//
// 放在 tool/ 而非 test/:它依赖本机字体,不该随 flutter test 在 CI 上跑。
// ignore_for_file: invalid_use_of_visible_for_testing_member
+import 'dart:async';
import 'dart:io';
import 'dart:ui' show ImageByteFormat;
@@ -14,6 +15,7 @@ import 'package:copysync_ui/gen/copysync/v1/daemon.pb.dart';
import 'package:copysync_ui/i18n.dart';
import 'package:copysync_ui/main.dart';
import 'package:copysync_ui/theme.dart';
+import 'package:copysync_ui/widgets/nearby_dialog.dart';
import 'package:copysync_ui/widgets/pairing_dialog.dart';
import 'package:fixnum/fixnum.dart';
import 'package:flutter/foundation.dart';
@@ -31,10 +33,20 @@ String _t(String zh, String en, String ja) => switch (_lang) { 'en' => en, 'ja'
/// 汉字的字形跟着语言走:日文界面用冬青黑体,否则用苹方
final _cjk = _lang == 'ja' ? const ['Hiragino', 'PingFang'] : const ['PingFang'];
-/// 生成配对码不走后台服务,直接给一个固定值。
+/// 生成配对码、搜索附近设备都不走后台服务,直接给固定的演示数据。
class _DemoState extends AppState {
@override
Future<PairingCode> createPairingCode() async => (code: 'K7MP2X', addresses: ['192.168.1.20']);
+
+ // 不关闭的流:后台服务那边的订阅一直开着,结束就表示后台服务断开了
+ @override
+ Stream<List<NearbyDevice>> watchNearby() => (StreamController<List<NearbyDevice>>()
+ ..add([
+ NearbyDevice(id: 'n1', name: _t('设计部的 PC', 'Design PC', 'デザイン部の PC'), platform: 'windows'),
+ NearbyDevice(id: 'n2', name: 'MacBook Air', platform: 'darwin', paired: true),
+ NearbyDevice(id: 'n3', name: _t('会议室的 iMac', 'Meeting room iMac', '会議室の iMac'), platform: 'darwin'),
+ ]))
+ .stream;
}
Future<void> _loadFonts() async {
@@ -97,7 +109,7 @@ AppState _demo({LinkState link = LinkState.online,
serviceState: service,
pendingPairing: pending,
status: Status(
- version: '1.4.0',
+ version: '1.5.0',
deviceName: 'MacBook Pro',
signalingConnected: link == LinkState.online && server.isNotEmpty,
serverConfigured: server.isNotEmpty,
@@ -297,6 +309,26 @@ void main() {
});
});
+ for (final dark in [false, true]) {
+ testWidgets(dark ? 'nearby-dark' : 'nearby', (tester) async {
+ await _shoot(tester, dark ? 'nearby-dark' : 'nearby',
+ state: _demo(),
+ section: Section.devices,
+ brightness: dark ? Brightness.dark : Brightness.light,
+ settle: false, // 雷达的波纹一直在动
+ arrange: () async {
+ showDialog<void>(
+ context: tester.element(find.byType(Shell)),
+ builder: (_) => const NearbyDialog(),
+ );
+ await tester.pump();
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 300));
+ await tester.pump(const Duration(milliseconds: 900));
+ });
+ });
+ }
+
testWidgets('verify', (tester) async {
await _shoot(tester, 'verify',
section: Section.devices,