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.

Devices: list only the devices that are plugged in (#1412)

0xdiego25fc7042ffe8ea
diff --git a/desktop/lib/devices/devices_screen.dart b/desktop/lib/devices/devices_screen.dart
index 72b539c96..2cd5065be 100644
--- a/desktop/lib/devices/devices_screen.dart
+++ b/desktop/lib/devices/devices_screen.dart
@@ -396,9 +396,15 @@ class _DevicesScreenState extends State<DevicesScreen> {
builder: (context, _) => LayoutBuilder(
builder: (context, bounds) {
// Keep saved identities for reconnection, but only present devices
- // whose host has answered. Other machines do not belong in this UI.
+ // that are plugged in now, on a host that has answered. A device
+ // seen once and unplugged since comes back when it is plugged in.
final devices = widget.controller.devices
- .where((device) => device.hostOnline && device.hostAvailable)
+ .where(
+ (device) =>
+ device.hostOnline &&
+ device.hostAvailable &&
+ device.status.attached,
+ )
.toList();
final selected =
devices.where((d) => d.key == _selectedKey).firstOrNull ??
diff --git a/desktop/test/devices_screen_test.dart b/desktop/test/devices_screen_test.dart
index 888c701fa..663e08ceb 100644
--- a/desktop/test/devices_screen_test.dart
+++ b/desktop/test/devices_screen_test.dart
@@ -228,7 +228,11 @@ void main() {
expect(tester.takeException(), isNull);
expect(find.text('Shop'), findsOneWidget);
if (!empty) {
- expect(find.text('Harness Pro'), findsNWidgets(3));
+ // Five known devices, four plugged in: the unplugged Travel Pro
+ // has no card, and the count is of the plugged-in ones.
+ expect(find.text('4 devices'), findsOneWidget);
+ expect(find.text('Travel'), findsNothing);
+ expect(find.text('Harness Pro'), findsNWidgets(2));
expect(find.text('Faces'), findsOneWidget);
}
await capture(
@@ -443,7 +447,7 @@ void main() {
});
testWidgets(
- 'selected device owns changes through reorder and disconnect; Faces is a single choice',
+ 'selected device owns changes through reorder; Faces is a single choice; unplugged it leaves the page',
(tester) async {
final dial = DialState();
final sent = <(String, Map<String, Object?>)>[];
@@ -475,9 +479,6 @@ void main() {
report(dial, [deviceStatus('b', muted: false)]);
await tester.pumpAndSettle();
expect(tester.widget<Switch>(sound).value, isTrue);
- report(dial, []);
- await tester.pumpAndSettle();
- expect(tester.widget<Switch>(sound).onChanged, isNull);
final faces = find.byKey(const Key('devices-faces'));
await tester.ensureVisible(faces);
await tester.tap(faces);
@@ -491,6 +492,13 @@ void main() {
hasLength(1),
reason: 'Inspecting the current face never writes',
);
+ // Unplugged, the device leaves the page: no card, no settings to change.
+ report(dial, []);
+ await tester.pumpAndSettle();
+ expect(find.byKey(ValueKey('device-card-$key')), findsNothing);
+ expect(find.byType(DeviceSettingsPanel), findsNothing);
+ expect(find.text('No devices connected'), findsOneWidget);
+ expect(sent, hasLength(1));
await tester.pumpWidget(const SizedBox());
controller.dispose();
dial.dispose();