Skip to content

Commit 24abae2

Browse files
myleshortonclaude
andcommitted
smc: MediaQuery copyWith + symmetric wire format + drop stale fromJson
Three Copilot findings: 1. _GlobeView wrapped its body in MediaQuery(data: MediaQueryData(size: widgetSize), ...) — constructing MediaQueryData from scratch drops inherited fields (devicePixelRatio, textScaleFactor, padding, viewInsets, etc.). On high-DPI displays the pixel ratio fell to 1.0, breaking globe rendering crispness; accessibility scaling for any descendants would also break. Switched to MediaQuery.of(context).copyWith(size: widgetSize) which keeps the inherited fields and only overrides what we need. 2. lantern-core/core.go's doc comment said the peer-connection wire payload was always {state, source, timestamp}, but the peer.ConnectionEvent marshal block emitted only {state, source}. Added timestamp to the peer marshal (both peer.ConnectionEvent and unbounded.ConnectionEvent carry Timestamp on the radiance side, so the consumer-facing shape is now symmetric) and updated the comment to spell out the source format difference between protocols and call out Unix-millis for timestamp. 3. UnboundedConnectionEvent.fromJson was stale: it expected {workerIdx, addr} keys, but the actual wire format is {state, source, timestamp}. The factory is never called from anywhere in lib/ — wire-format parsing happens inline in share_my_connection.dart, and the class is only constructed directly by the notifier as an internal Dart-side event model. Dropped the dead factory and clarified the class docstring to distinguish 'internal Dart-side model' from 'wire format', including a note that workerIdx is a Dart-side identity counter (_workerSeq), not the broflake worker index. dart analyze clean; Go build clean. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 0bcd729 commit 24abae2

3 files changed

Lines changed: 25 additions & 16 deletions

File tree

lantern-core/core.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,10 +407,11 @@ func (lc *LanternCore) listenDataCapEvents() {
407407
// The wire format unifies both protocols on a single event type
408408
// (EventTypePeerConnection) with a {state, source, timestamp}
409409
// payload — peer.ConnectionEvent and unbounded.ConnectionEvent both
410-
// expose the same shape on the radiance side, so consumers don't
411-
// need to disambiguate which protocol produced an event. Source is
412-
// "host:port" (IPv4) or "[host]:port" (IPv6) for peer-share, and
413-
// the broflake-reported consumer IP for Unbounded (no port).
410+
// carry the same three fields on the radiance side, so the Dart
411+
// consumer can deserialize each frame uniformly without caring
412+
// which protocol produced it. Source is "host:port" /
413+
// "[host]:port" for peer-share, and the broflake-reported consumer
414+
// IP (no port) for Unbounded. Timestamp is Unix milliseconds.
414415
func (lc *LanternCore) listenPeerConnectionEvents() {
415416
// unbounded.ConnectionEvent stays on in-process events.Subscribe for
416417
// now. Unbounded runs in the same process as the consumer in mobile
@@ -452,8 +453,9 @@ func (lc *LanternCore) listenPeerConnectionEvents() {
452453
// immediately.
453454
err := lc.client.PeerConnectionEvents(lc.ctx, func(evt peer.ConnectionEvent) {
454455
jsonBytes, err := json.Marshal(map[string]any{
455-
"state": evt.State,
456-
"source": evt.Source,
456+
"state": evt.State,
457+
"source": evt.Source,
458+
"timestamp": evt.Timestamp,
457459
})
458460
if err != nil {
459461
slog.Error("marshal peer connection event", "error", err)

lib/core/models/unbounded_connection_event.dart

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import 'package:flutter_earth_globe/globe_coordinates.dart';
22

3-
/// Represents a consumer connection change from the broflake widget proxy.
3+
/// Internal Dart-side connection-change model the ShareNotifier emits
4+
/// to the globe via _eventController. NOT the wire format —
5+
/// FlutterEvent messages from lantern-core (forwarded from radiance)
6+
/// are parsed inline in share_my_connection.dart's event subscription
7+
/// as `{state, source, timestamp}` and synthesized into this model
8+
/// after geo-resolution.
9+
///
10+
/// workerIdx here is the Dart-side identity counter (_workerSeq++ in
11+
/// the notifier), not the broflake worker index — it's a stable
12+
/// handle for matching accept/close pairs and cancelling pending arc
13+
/// removals when a peer reconnects from the same IP.
414
class UnboundedConnectionEvent {
515
final int state; // 1 = connected, -1 = disconnected
616
final int workerIdx;
@@ -27,14 +37,6 @@ class UnboundedConnectionEvent {
2737
this.coordinates,
2838
this.isReplay = false,
2939
});
30-
31-
factory UnboundedConnectionEvent.fromJson(Map<String, dynamic> json) {
32-
return UnboundedConnectionEvent(
33-
state: json['state'] as int,
34-
workerIdx: json['workerIdx'] as int,
35-
addr: json['addr'] as String? ?? '',
36-
);
37-
}
3840
}
3941

4042
/// Tracks live and cumulative connection counts for Unbounded.

lib/features/share_my_connection/share_my_connection.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,8 +974,13 @@ class _GlobeViewState extends ConsumerState<_GlobeView> {
974974
final radius =
975975
min(constraints.maxWidth, constraints.maxHeight) / 2 * 0.7;
976976
return ClipRect(
977+
// copyWith preserves the inherited devicePixelRatio,
978+
// textScaleFactor, padding/insets etc. — constructing
979+
// MediaQueryData from scratch with just `size:` would drop
980+
// those, breaking high-DPI rendering (pixel ratio falls to
981+
// 1.0) and accessibility scaling for the globe subtree.
977982
child: MediaQuery(
978-
data: MediaQueryData(size: widgetSize),
983+
data: MediaQuery.of(context).copyWith(size: widgetSize),
979984
child: Stack(
980985
children: [
981986
Positioned.fill(

0 commit comments

Comments
 (0)