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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
Profiles: a computer that is not connected or is offline cannot be chosen
bubu-dudu4ae455b5a30b
diff --git a/desktop/lib/settings/sections/profiles_section.dart b/desktop/lib/settings/sections/profiles_section.dartindex b2d21f673..93cf8fd9e 100644--- a/desktop/lib/settings/sections/profiles_section.dart+++ b/desktop/lib/settings/sections/profiles_section.dart@@ -45,10 +45,16 @@ class ProfilesSection extends StatelessWidget {machine,localId: localId,sharedName: (names[machine.displayName] ?? 0) > 1,+ unavailable: _unavailable(machine),),control: _choice(selected: selected == machine.machineId,- onPressed: () => notifier.setMachineProfile(machine.machineId),+ // A computer this window cannot reach has no live tabs to+ // narrow down to, so it cannot be chosen until it is back.+ // One already chosen stays shown.+ onPressed: _unavailable(machine) == null+ ? () => notifier.setMachineProfile(machine.machineId)+ : null,),),],@@ -58,18 +64,38 @@ class ProfilesSection extends StatelessWidget {},);- String _detail(Machine machine, {String? localId, required bool sharedName}) {+ /// Why [machine] cannot be chosen right now, or null when it can: this+ /// window has no live connection to it, it has to be linked again, or it+ /// reports itself offline.+ String? _unavailable(Machine machine) {+ final state = notifier.stateOf(machine.machineId);+ if (state == null || state.needsLink) return 'Not connected.';+ if (state.nodeOnline == false) return 'Offline.';+ if (state.connectionStatus != ConnectionStatus.connected) {+ return 'Not connected.';+ }+ return null;+ }++ String _detail(+ Machine machine, {+ String? localId,+ required bool sharedName,+ String? unavailable,+ }) {final where = machine.machineId == localId? 'This computer. Tabs whose agents are all here.': 'That computer. Tabs whose agents are all there.';- if (!sharedName) return where;final short = machine.machineId.length > 8? machine.machineId.substring(0, 8): machine.machineId;- return '$where ($short)';+ final named = sharedName ? '$where ($short)' : where;+ return unavailable == null ? named : '$unavailable $named';}- Widget _choice({required bool selected, required VoidCallback onPressed}) {+ /// [onPressed] null is a machine that cannot be chosen now: the button is+ /// disabled. A chosen one reads Showing, and is disabled for being chosen.+ Widget _choice({required bool selected, required VoidCallback? onPressed}) {return OutlinedButton(onPressed: selected ? null : onPressed,child: Text(selected ? 'Showing' : 'Show'),diff --git a/desktop/test/profiles_section_test.dart b/desktop/test/profiles_section_test.dartnew file mode 100644index 000000000..30ccf1c0e--- /dev/null+++ b/desktop/test/profiles_section_test.dart@@ -0,0 +1,65 @@+import 'package:flutter/material.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:harness/core/models.dart';+import 'package:harness/settings/sections/profiles_section.dart';+import 'package:harness/shared/theme/app_theme.dart' as grid;+import 'package:harness/state/app_state.dart';++import 'swarm_state_test.dart' show createApp;++OutlinedButton _button(WidgetTester tester, int row) => tester+ .widgetList<OutlinedButton>(find.byType(OutlinedButton))+ .elementAt(row);++void main() {+ testWidgets(+ 'a computer that is not connected or is offline cannot be chosen',+ (tester) async {+ tester.view.physicalSize = const Size(1200, 900);+ tester.view.devicePixelRatio = 1;+ addTearDown(tester.view.reset);+ final app = createApp(connected: true);+ addTearDown(app.dispose);+ const other = Machine(+ machineId: 'far',+ authMode: MachineAuthMode.remote,+ name: 'Far host',+ );+ app.machines = [...app.machines, other];+ app.machineStates['far'] = MachineState(other)+ ..connectionStatus = ConnectionStatus.disconnected;++ await tester.pumpWidget(+ MaterialApp(+ theme: grid.buildAppTheme(brightness: Brightness.dark),+ home: Scaffold(body: ProfilesSection(notifier: app)),+ ),+ );+ // All machines is the default, and chosen.+ expect(_button(tester, 0).onPressed, isNull);+ expect(find.text('Showing'), findsOneWidget);+ // Connected and online: can be chosen.+ expect(_button(tester, 1).onPressed, isNotNull);+ // Not connected: cannot, and says why.+ expect(_button(tester, 2).onPressed, isNull);+ expect(find.textContaining('Not connected.'), findsOneWidget);++ // A connection that is up to a machine that reports itself offline.+ app.machineStates['far']!+ ..connectionStatus = ConnectionStatus.connected+ ..nodeOnline = false;+ app.notifyListeners();+ await tester.pump();+ expect(_button(tester, 2).onPressed, isNull);+ expect(find.textContaining('Offline.'), findsOneWidget);++ app.machineStates['far']!.nodeOnline = true;+ app.notifyListeners();+ await tester.pump();+ expect(_button(tester, 2).onPressed, isNotNull);+ await tester.tap(find.byType(OutlinedButton).at(2));+ await tester.pump();+ expect(app.machineProfileId, 'far');+ },+ );+}