show TCP/UDP/IPv6 in tooltip (#12613)

* add punch type log

Signed-off-by: 21pages <sunboeasy@gmail.com>

* show TCP/UDP/IPv6 in tooltip

Signed-off-by: 21pages <sunboeasy@gmail.com>

* Skip udp punch if udp nat port is 0

Signed-off-by: 21pages <sunboeasy@gmail.com>

---------

Signed-off-by: 21pages <sunboeasy@gmail.com>
This commit is contained in:
21pages
2025-08-11 16:13:31 +08:00
committed by GitHub
parent 77064cc2f8
commit a0659a277a
14 changed files with 156 additions and 52 deletions

View File

@@ -61,6 +61,7 @@ class CachedPeerData {
bool secure = false;
bool direct = false;
String streamType = '';
CachedPeerData();
@@ -74,6 +75,7 @@ class CachedPeerData {
'permissions': permissions,
'secure': secure,
'direct': direct,
'streamType': streamType,
});
}
@@ -92,6 +94,7 @@ class CachedPeerData {
});
data.secure = map['secure'];
data.direct = map['direct'];
data.streamType = map['streamType'];
return data;
} catch (e) {
debugPrint('Failed to parse CachedPeerData: $e');
@@ -223,27 +226,45 @@ class FfiModel with ChangeNotifier {
timerScreenshot?.cancel();
}
setConnectionType(String peerId, bool secure, bool direct) {
setConnectionType(
String peerId, bool secure, bool direct, String streamType) {
cachedPeerData.secure = secure;
cachedPeerData.direct = direct;
cachedPeerData.streamType = streamType;
_secure = secure;
_direct = direct;
try {
var connectionType = ConnectionTypeState.find(peerId);
connectionType.setSecure(secure);
connectionType.setDirect(direct);
connectionType.setStreamType(streamType);
} catch (e) {
//
}
}
Widget? getConnectionImage() {
Widget? getConnectionImageText() {
if (secure == null || direct == null) {
return null;
} else {
final icon =
'${secure == true ? 'secure' : 'insecure'}${direct == true ? '' : '_relay'}';
return SvgPicture.asset('assets/$icon.svg', width: 48, height: 48);
final iconWidget =
SvgPicture.asset('assets/$icon.svg', width: 48, height: 48);
String connectionText =
getConnectionText(secure!, direct!, cachedPeerData.streamType);
return Column(
mainAxisSize: MainAxisSize.min,
children: [
iconWidget,
SizedBox(height: 4),
Text(
connectionText,
style: TextStyle(fontSize: 12),
textAlign: TextAlign.center,
),
],
);
}
}
@@ -260,7 +281,7 @@ class FfiModel with ChangeNotifier {
'link': '',
}, sessionId, peerId);
updatePrivacyMode(data.updatePrivacyMode, sessionId, peerId);
setConnectionType(peerId, data.secure, data.direct);
setConnectionType(peerId, data.secure, data.direct, data.streamType);
await handlePeerInfo(data.peerInfo, peerId, true);
for (final element in data.cursorDataList) {
updateLastCursorId(element);
@@ -289,8 +310,8 @@ class FfiModel with ChangeNotifier {
} else if (name == 'sync_platform_additions') {
handlePlatformAdditions(evt, sessionId, peerId);
} else if (name == 'connection_ready') {
setConnectionType(
peerId, evt['secure'] == 'true', evt['direct'] == 'true');
setConnectionType(peerId, evt['secure'] == 'true',
evt['direct'] == 'true', evt['stream_type'] ?? '');
} else if (name == 'switch_display') {
// switch display is kept for backward compatibility
handleSwitchDisplay(evt, sessionId, peerId);