Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Shared harness: the first live frame brings the viewer forward

0xdiego25c69e1532e4f2
diff --git a/desktop/lib/sharing/shared_harness_panel.dart b/desktop/lib/sharing/shared_harness_panel.dart
index b3f74a344..7b787bd54 100644
--- a/desktop/lib/sharing/shared_harness_panel.dart
+++ b/desktop/lib/sharing/shared_harness_panel.dart
@@ -41,6 +41,13 @@ class _SharedHarnessPanelState extends State<SharedHarnessPanel> {
String _viewerMessage = 'Waiting for the live viewer…';
Uint8List? _image;
bool _viewerSelected = false, _ended = false;
+
+ /// The person picked Terminal or Viewer themselves. Until they do, the first
+ /// live frame brings the viewer forward on a narrow pane — a shared Blender
+ /// or Marp harness was shared for what it shows, and a "Viewer" tab nobody
+ /// noticed left the person looking at a terminal they cannot type into
+ /// (owner, 2026-09-18: "chỉ thấy màn hình terminal").
+ bool _viewerChosen = false;
int _generation = 0;
@override
void initState() {
@@ -92,7 +99,10 @@ class _SharedHarnessPanelState extends State<SharedHarnessPanel> {
return;
}
setState(() {
- if (next != null) _image = next;
+ if (next != null) {
+ if (_image == null && !_viewerChosen) _viewerSelected = true;
+ _image = next;
+ }
_viewerMessage =
payload['message'] as String? ??
(payload['state'] == 'live'
@@ -289,8 +299,10 @@ class _SharedHarnessPanelState extends State<SharedHarnessPanel> {
Row(
children: [
TextButton(
- onPressed: () =>
- setState(() => _viewerSelected = false),
+ onPressed: () => setState(() {
+ _viewerChosen = true;
+ _viewerSelected = false;
+ }),
child: Text(
'Terminal',
style: TextStyle(
@@ -301,7 +313,10 @@ class _SharedHarnessPanelState extends State<SharedHarnessPanel> {
),
),
TextButton(
- onPressed: () => setState(() => _viewerSelected = true),
+ onPressed: () => setState(() {
+ _viewerChosen = true;
+ _viewerSelected = true;
+ }),
child: Text(
'Viewer',
style: TextStyle(
diff --git a/desktop/test/shared_harness_panel_test.dart b/desktop/test/shared_harness_panel_test.dart
index 0073ccb54..424783c88 100644
--- a/desktop/test/shared_harness_panel_test.dart
+++ b/desktop/test/shared_harness_panel_test.dart
@@ -208,11 +208,15 @@ void main() {
await settleNetwork(
() => requests.any((r) => r['type'] == 'observer_viewer'),
);
+ // Narrow: the terminal is in front and the viewer waits behind its tab —
+ // until the first frame lands, which brings it forward by itself (below).
+ expect(
+ find.textContaining('The viewer will appear', skipOffstage: false),
+ findsOneWidget,
+ );
if (width < 880) {
- await tester.tap(find.text('Viewer'));
- await tester.pump();
+ expect(find.textContaining('The viewer will appear'), findsNothing);
}
- expect(find.textContaining('The viewer will appear'), findsOneWidget);
expect(
requests.map((r) => r['type']),
isNot(contains('terminal_resize')),
@@ -223,7 +227,10 @@ void main() {
);
viewer({'state': 'loading'});
await settleNetwork(
- () => find.text('Opening the viewer…').evaluate().isNotEmpty,
+ () => find
+ .text('Opening the viewer…', skipOffstage: false)
+ .evaluate()
+ .isNotEmpty,
);
viewer({'state': 'live', 'data': 'not-base64!'});
await tester.runAsync(
@@ -231,6 +238,8 @@ void main() {
);
await tester.pump();
expect(tester.takeException(), isNull);
+ // The first frame that decodes brings the viewer to the front on a
+ // narrow pane: nobody had to find the "Viewer" tab.
viewer({'state': 'live', 'data': 'aW52YWxpZC1pbWFnZQ=='});
await settleNetwork(
() => find
@@ -244,8 +253,18 @@ void main() {
});
await settleNetwork(() => find.byType(Image).evaluate().isNotEmpty);
if (width < 880) {
+ // …and a person's own pick stands over any later frame.
await tester.tap(find.text('Terminal'));
await tester.pump();
+ viewer({
+ 'state': 'live',
+ 'data': 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+/lZkAAAAASUVORK5CYII=',
+ });
+ await tester.runAsync(
+ () => Future<void>.delayed(const Duration(milliseconds: 30)),
+ );
+ await tester.pump();
+ expect(find.byType(Image), findsNothing);
}
await tester.runAsync(() async {
closingSockets.add(sockets.last);