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.

Web UX 1: menus, New Swarm and phone hit sizes (#1675)

Jacob Pham771ec7c285df
diff --git a/desktop/lib/settings/settings_compact.dart b/desktop/lib/settings/settings_compact.dart
index e83da2949..5c0b111b1 100644
--- a/desktop/lib/settings/settings_compact.dart
+++ b/desktop/lib/settings/settings_compact.dart
@@ -4,12 +4,13 @@ import 'package:flutter/material.dart';
import '../shared/layouts/widgets/sidebar_item.dart';
import '../shared/theme/app_theme.dart' as grid;
import '../shared/widgets/section_scaffold.dart';
+import '../widgets/finger_target.dart';
import 'settings_nav.dart';
import 'settings_section.dart';
/// One settings section on a narrow screen (the web on a phone): the section
/// takes the width, and the way back to the list of sections sits above it,
-/// shaped like the list's own "Back to app" row.
+/// shaped like the list's own "Back to app" row and as easy to hit.
class SettingsCompactSection extends StatelessWidget {
const SettingsCompactSection({
super.key,
@@ -32,13 +33,19 @@ class SettingsCompactSection extends StatelessWidget {
0,
),
child: SizedBox(
- height: SectionScaffold.headingHeight(context),
+ height: fingerHeight(
+ SectionScaffold.headingHeight(context),
+ enabled: true,
+ ),
child: Center(
- child: SidebarItem(
- key: const Key('settings-compact-back'),
- icon: AppIcons.arrowLeft,
- label: 'Settings',
- onTap: onBack,
+ child: fingerTarget(
+ enabled: true,
+ SidebarItem(
+ key: const Key('settings-compact-back'),
+ icon: AppIcons.arrowLeft,
+ label: 'Settings',
+ onTap: onBack,
+ ),
),
),
),
@@ -86,6 +93,7 @@ class SettingsCompactScreen extends StatelessWidget {
onSelect: onSelect,
railWidth: double.infinity,
autofocusSearch: false,
+ compact: true,
),
),
),
diff --git a/desktop/lib/settings/settings_nav.dart b/desktop/lib/settings/settings_nav.dart
index 4b9719ae9..7b6233697 100644
--- a/desktop/lib/settings/settings_nav.dart
+++ b/desktop/lib/settings/settings_nav.dart
@@ -6,6 +6,7 @@ import '../shared/layouts/widgets/rail_section_header.dart';
import '../shared/layouts/widgets/sidebar_item.dart';
import '../shared/theme/app_theme.dart' as grid;
import '../shared/widgets/section_scaffold.dart';
+import '../widgets/finger_target.dart';
import 'settings_section.dart';
/// The settings list: the way back, a field that narrows the list to what you
@@ -17,6 +18,7 @@ class SettingsNav extends StatefulWidget {
required this.onSelect,
this.railWidth = SettingsNav.width,
this.autofocusSearch = true,
+ this.compact = false,
});
final SettingsSection section;
@@ -30,6 +32,9 @@ class SettingsNav extends StatefulWidget {
/// raises the on-screen keyboard over half the list.
final bool autofocusSearch;
+ /// True on a phone: the way back is a finger's size.
+ final bool compact;
+
/// The machine rail's own default width, so Settings opens without the left
/// column jumping.
static const double width = 260;
@@ -135,13 +140,19 @@ class _SettingsNavState extends State<SettingsNav> {
// highlights and aligns exactly like them instead of being a
// shrink-wrapped button in its own grey.
SizedBox(
- height: SectionScaffold.headingHeight(context),
+ height: fingerHeight(
+ SectionScaffold.headingHeight(context),
+ enabled: widget.compact,
+ ),
child: Center(
- child: SidebarItem(
- key: const Key('settings-back-button'),
- icon: AppIcons.arrowLeft,
- label: 'Back to app',
- onTap: () => Navigator.of(context).maybePop(),
+ child: fingerTarget(
+ enabled: widget.compact,
+ SidebarItem(
+ key: const Key('settings-back-button'),
+ icon: AppIcons.arrowLeft,
+ label: 'Back to app',
+ onTap: () => Navigator.of(context).maybePop(),
+ ),
),
),
),
diff --git a/desktop/lib/web/footer/web_footer_bar.dart b/desktop/lib/web/footer/web_footer_bar.dart
index 39f49f7e4..a011a51cc 100644
--- a/desktop/lib/web/footer/web_footer_bar.dart
+++ b/desktop/lib/web/footer/web_footer_bar.dart
@@ -7,6 +7,7 @@ import '../../state/workspace_chrome.dart';
import '../../terminal/terminal_theme.dart';
import '../../terminal/terminal_theme_store.dart';
import '../../widgets/box_chrome.dart' show kWorkspaceInset;
+import '../../widgets/finger_target.dart';
import '../../widgets/pane_menu.dart';
import '../../widgets/web_download_button.dart';
import '../../widgets/workspace_bar_control.dart';
@@ -86,10 +87,14 @@ class WebFooterBar extends StatelessWidget {
onTap: () => close(item),
child: KeyedSubtree(
key: ValueKey('web-footer:${item.title}'),
- child: PaneMenuRow(
- selected: false,
- title: item.title,
- status: item.detail.isEmpty ? null : item.detail,
+ // The footer is a phone's: its rows are a finger's size.
+ child: fingerTarget(
+ enabled: true,
+ PaneMenuRow(
+ selected: false,
+ title: item.title,
+ status: item.detail.isEmpty ? null : item.detail,
+ ),
),
),
),
diff --git a/desktop/lib/web/shell/web_app_menu.dart b/desktop/lib/web/shell/web_app_menu.dart
index aeb478df0..9cdc6d0fa 100644
--- a/desktop/lib/web/shell/web_app_menu.dart
+++ b/desktop/lib/web/shell/web_app_menu.dart
@@ -11,6 +11,7 @@ import '../../state/workspace_chrome.dart';
import '../../terminal/terminal_theme.dart';
import '../../theme/app_theme.dart' show AppColors;
import '../../terminal/terminal_theme_store.dart';
+import '../../widgets/finger_target.dart';
import '../../widgets/pane_menu.dart';
import '../../widgets/workspace_bar_control.dart';
import 'web_layout.dart';
@@ -68,10 +69,8 @@ class WebAppMenuButton extends StatelessWidget {
if (box == null || overlay == null) return;
final origin = box.localToGlobal(Offset.zero, ancestor: overlay);
// Resolved as it opens, so the rows match the workspace's state right now.
- final groups = runnableWebMenu(
- commands.canRun,
- compact: isWebCompact(context),
- );
+ final compact = isWebCompact(context);
+ final groups = runnableWebMenu(commands.canRun, compact: compact);
final chosen = await showPaneMenu<String>(
context: context,
// Opened by a click: no row is lit until the pointer picks one.
@@ -84,7 +83,7 @@ class WebAppMenuButton extends StatelessWidget {
),
minWidth: 240,
maxWidth: 320,
- children: (close) => _rows(groups, close),
+ children: (close) => _rows(groups, close, compact: compact),
);
// Run after the menu closed and handed focus back, never inside it.
if (chosen == _signOut) {
@@ -98,19 +97,24 @@ class WebAppMenuButton extends StatelessWidget {
List<Widget> _rows(
List<List<WebMenuItem>> groups,
- void Function(String?) close,
- ) {
+ void Function(String?) close, {
+ required bool compact,
+ }) {
// Uncoloured on purpose: the row's ink tints it, so it turns with the
// label when the row lights up.
Widget row(String id, String label, Widget icon) => paneMenuItem(
onTap: () => close(id),
- child: PaneMenuRow(
- key: ValueKey('web-menu:$id'),
- selected: false,
- title: label,
- leading: IconTheme.merge(
- data: const IconThemeData(size: AppIcons.inlineSize),
- child: icon,
+ // On a phone the row is a finger's height; a mouse keeps it as it was.
+ child: fingerTarget(
+ enabled: compact,
+ PaneMenuRow(
+ key: ValueKey('web-menu:$id'),
+ selected: false,
+ title: label,
+ leading: IconTheme.merge(
+ data: const IconThemeData(size: AppIcons.inlineSize),
+ child: icon,
+ ),
),
),
);
diff --git a/desktop/lib/web/shell/web_menu_items.dart b/desktop/lib/web/shell/web_menu_items.dart
index bbd2067b7..cb6b60601 100644
--- a/desktop/lib/web/shell/web_menu_items.dart
+++ b/desktop/lib/web/shell/web_menu_items.dart
@@ -21,12 +21,21 @@ typedef WebMenuItem = ({
/// other door in the browser chrome: new work is the `+` beside the tabs
/// (a new tab opens on "Start an agent"), agents the search button, tabs the
/// tab bar and switcher, attention the bell, closing a pane its own header;
-/// keyboard tours and grid layout stay out of a mouse-first menu. Splitting is
-/// here because the header gave it up: a split is an edge to hover, which a
-/// finger cannot. Sharing is not — Share is an experimental button, off until
+/// keyboard tours and grid layout stay out of a mouse-first menu. New Swarm is
+/// here because its only other door is a key (Alt+S), which a phone has not.
+/// Splitting is here because the header gave it up: a split is an edge to
+/// hover, which a finger cannot. Sharing is not — Share is an experimental button, off until
/// its setting is switched on, and a row here would put it back for everyone.
/// All commands still reaches every one.
const List<List<WebMenuItem>> kWebMenuGroups = [
+ [
+ (
+ command: 'super_tab.new',
+ label: 'New Swarm',
+ icon: Icon(AppIcons.users),
+ width: WebMenuWidth.any,
+ ),
+ ],
[
(
command: 'machines.list',
diff --git a/desktop/lib/web/tabs/web_tab_menu.dart b/desktop/lib/web/tabs/web_tab_menu.dart
index be3340a3d..c6a72270c 100644
--- a/desktop/lib/web/tabs/web_tab_menu.dart
+++ b/desktop/lib/web/tabs/web_tab_menu.dart
@@ -7,6 +7,7 @@ import '../../state/terminal_pane.dart';
import '../../state/workspace_chrome.dart';
import '../../state/workspace_status.dart';
import '../../widgets/pane_grid.dart' show soloPaneId;
+import '../../widgets/finger_target.dart';
import '../../widgets/pane_menu.dart';
/// What a row of the tab menu asks for, carried out once the menu is gone.
@@ -66,7 +67,8 @@ const _tabSharingRows = [
/// The menu's rows: this tab's harnesses (a phone draws one at a time), then
/// every tab, then this tab's sharing and Agent Messages, then rename.
-/// Harnesses and tabs both close from their row.
+/// Harnesses and tabs both close from their row. It opens from the phone's tab
+/// switcher only, so its rows and closes are a finger's size.
List<Widget> webTabMenuRows(
AppNotifier app,
WorkspaceCommands commands,
@@ -77,7 +79,10 @@ List<Widget> webTabMenuRows(
Widget row(String key, WebTabChoice choice, PaneMenuRow content) =>
paneMenuItem(
onTap: () => close(choice),
- child: KeyedSubtree(key: ValueKey(key), child: content),
+ child: KeyedSubtree(
+ key: ValueKey(key),
+ child: fingerTarget(content, enabled: true),
+ ),
);
Widget closable({
required String key,
@@ -95,7 +100,10 @@ List<Widget> webTabMenuRows(
IconButton(
key: ValueKey('$key:close'),
tooltip: closeTooltip,
- visualDensity: VisualDensity.compact,
+ constraints: const BoxConstraints.tightFor(
+ width: kFingerTarget,
+ height: kFingerTarget,
+ ),
iconSize: 16,
onPressed: () => close(closeChoice),
icon: const Icon(AppIcons.close),
@@ -153,7 +161,7 @@ List<Widget> webTabMenuRows(
row(
'web-tab-run:swarm.rename',
const WebRunCommand('swarm.rename'),
- const PaneMenuRow(selected: false, title: 'Rename this tab'),
+ const PaneMenuRow(selected: false, title: 'Rename Tab…'),
),
];
}
diff --git a/desktop/lib/widgets/desktop_workspace_tab.dart b/desktop/lib/widgets/desktop_workspace_tab.dart
index f376deee5..a122d0665 100644
--- a/desktop/lib/widgets/desktop_workspace_tab.dart
+++ b/desktop/lib/widgets/desktop_workspace_tab.dart
@@ -9,6 +9,7 @@ import 'package:flutter/services.dart';
import '../shared/theme/app_icons.dart';
import '../shared/theme/app_theme.dart' as grid;
import '../shared/widgets/app_menu.dart';
+import '../state/workspace_chrome.dart';
import 'box_chrome.dart';
import 'desktop_chrome.dart';
@@ -27,7 +28,8 @@ import 'desktop_chrome.dart';
/// Right-click (or the context-menu key, or the "Tab options" accessibility
/// action) opens the menu the native tab has: Invite People…, Show Agent
/// Messages, Stop Sharing Tab, Move Here, Leave Tab — each row only where its
-/// callback is given.
+/// callback is given. A host whose [WorkspaceChrome.menuOnEveryTab] is on (the
+/// web) gives every tab that menu, with Rename Tab… first and Close Tab last.
class DesktopWorkspaceTab extends StatefulWidget {
const DesktopWorkspaceTab({
super.key,
@@ -199,7 +201,19 @@ class _DesktopWorkspaceTabState extends State<DesktopWorkspaceTab> {
bool _hovered = false, _focused = false;
final _menu = MenuController();
+ /// The host's [WorkspaceChrome.menuOnEveryTab]: Desktop leaves it off, so
+ /// only a tab with sharing rows has a menu there.
+ bool _everyTab = false;
+
+ @override
+ void didChangeDependencies() {
+ super.didChangeDependencies();
+ _everyTab = WorkspaceChrome.of(context).menuOnEveryTab;
+ _syncBrowserMenu();
+ }
+
bool get _hasMenu =>
+ (_everyTab && (widget.onRename != null || widget.onClose != null)) ||
widget.onPauseNewWork != null ||
widget.onInvitePeople != null ||
widget.onShowAgentMessages != null ||
@@ -255,15 +269,15 @@ class _DesktopWorkspaceTabState extends State<DesktopWorkspaceTab> {
},
);
return [
- if (widget.onPauseNewWork != null) ...[
- if (widget.onRename != null)
- row('rename', 'Rename Tab…', widget.onRename),
+ if (widget.onRename != null &&
+ (_everyTab || widget.onPauseNewWork != null))
+ row('rename', 'Rename Tab…', widget.onRename),
+ if (widget.onPauseNewWork != null)
row(
'pause',
widget.newWorkPaused ? 'Resume new work' : 'Pause new work',
widget.onPauseNewWork,
),
- ],
if (widget.onInvitePeople != null)
row('invite', 'Invite People…', widget.onInvitePeople),
if (widget.onShowAgentMessages != null)
@@ -273,6 +287,8 @@ class _DesktopWorkspaceTabState extends State<DesktopWorkspaceTab> {
if (widget.onMoveHere != null)
row('move', 'Move Here', widget.onMoveHere),
if (widget.onLeave != null) row('leave', 'Leave Tab', widget.onLeave),
+ if (_everyTab && widget.onClose != null)
+ row('close', 'Close Tab', widget.onClose),
];
}
diff --git a/desktop/lib/widgets/finger_target.dart b/desktop/lib/widgets/finger_target.dart
new file mode 100644
index 000000000..2877d45f6
--- /dev/null
+++ b/desktop/lib/widgets/finger_target.dart
@@ -0,0 +1,30 @@
+import 'dart:math' as math;
+
+import 'package:flutter/widgets.dart';
+
+import '../state/workspace_chrome.dart';
+
+/// The smallest target a finger can hit, both ways (audit finding S1).
+const double kFingerTarget = 44;
+
+/// [child] grown to at least [kFingerTarget] each way when [enabled] (a
+/// phone), its content centered; otherwise [child] as it is.
+Widget fingerTarget(Widget child, {required bool enabled}) => enabled
+ ? ConstrainedBox(
+ constraints: const BoxConstraints(
+ minWidth: kFingerTarget,
+ minHeight: kFingerTarget,
+ ),
+ child: child,
+ )
+ : child;
+
+/// A row [height] tall, or tall enough for a finger when [enabled].
+double fingerHeight(double height, {required bool enabled}) =>
+ enabled ? math.max(height, kFingerTarget) : height;
+
+/// Whether the workspace around [context] is laid out for a phone: narrower
+/// than its host's [WorkspaceChrome.compactBelow]. Never on Desktop, which
+/// sets none.
+bool workspaceIsCompact(BuildContext context) =>
+ MediaQuery.sizeOf(context).width < WorkspaceChrome.of(context).compactBelow;
diff --git a/desktop/lib/widgets/machine_picker_extras.dart b/desktop/lib/widgets/machine_picker_extras.dart
index 0cd4bc68b..fbcdcbbf1 100644
--- a/desktop/lib/widgets/machine_picker_extras.dart
+++ b/desktop/lib/widgets/machine_picker_extras.dart
@@ -10,6 +10,7 @@ import '../state/app_state.dart';
import '../state/machine_devices.dart';
import '../state/swarm_search.dart';
import 'desktop_chrome.dart';
+import 'finger_target.dart';
/// What the Machines picker needs from the screen around it for the parts that are not rows: a
/// dialog has to be shown with the picker stepped aside, and Add Phone belongs to the workspace.
@@ -133,21 +134,24 @@ class MachineWindowChoice extends StatelessWidget {
Text('Show in this window', style: DesktopChrome.metadata()),
SizedBox(
width: 240,
- child: AppSelectField<String?>(
- key: const Key('machine-window-choice-field'),
- semanticLabel: 'Show in this window',
- value: selected,
- options: options,
- onChanged: (id) {
- if (id != null &&
- id != selected &&
- machines
- .where((m) => m.machineId == id)
- .any((m) => _unavailable(m) != null)) {
- return;
- }
- app.setMachineProfile(id);
- },
+ child: fingerTarget(
+ enabled: workspaceIsCompact(context),
+ AppSelectField<String?>(
+ key: const Key('machine-window-choice-field'),
+ semanticLabel: 'Show in this window',
+ value: selected,
+ options: options,
+ onChanged: (id) {
+ if (id != null &&
+ id != selected &&
+ machines
+ .where((m) => m.machineId == id)
+ .any((m) => _unavailable(m) != null)) {
+ return;
+ }
+ app.setMachineProfile(id);
+ },
+ ),
),
),
],
@@ -325,6 +329,7 @@ class MachinePickerFooter extends StatelessWidget {
builder: (context, _) {
grid.AppTheme.watch(context);
final history = devices?.devices?.historyAvailable ?? false;
+ final finger = workspaceIsCompact(context);
return Padding(
padding: const EdgeInsets.fromLTRB(20, 10, 20, 10),
child: Wrap(
@@ -332,35 +337,48 @@ class MachinePickerFooter extends StatelessWidget {
spacing: 8,
runSpacing: 8,
children: [
- DesktopPill(
- key: const Key('machine-picker-add-machine'),
- label: 'Add machine',
- compact: true,
- onPressed: onAddMachine,
- ),
- if (hooks.onAddPhone case final addPhone?)
+ fingerTarget(
+ enabled: finger,
DesktopPill(
- key: const Key('machine-picker-add-phone'),
- label: 'Add phone',
+ key: const Key('machine-picker-add-machine'),
+ label: 'Add machine',
compact: true,
- onPressed: addPhone,
+ onPressed: onAddMachine,
+ ),
+ ),
+ if (hooks.onAddPhone case final addPhone?)
+ fingerTarget(
+ enabled: finger,
+ DesktopPill(
+ key: const Key('machine-picker-add-phone'),
+ label: 'Add phone',
+ compact: true,
+ onPressed: addPhone,
+ ),
),
if (hooks.onApproveDevice case final approve?)
+ fingerTarget(
+ enabled: finger,
+ DesktopPill(
+ key: const Key('machine-picker-approve-device'),
+ label: 'Approve a device',
+ compact: true,
+ tooltip:
+ 'Type the code a device with no screen says aloud.',
+ onPressed: approve,
+ ),
+ ),
+ fingerTarget(
+ enabled: finger,
DesktopPill(
- key: const Key('machine-picker-approve-device'),
- label: 'Approve a device',
+ key: const Key('account-devices-history'),
+ label: 'History…',
compact: true,
- tooltip: 'Type the code a device with no screen says aloud.',
- onPressed: approve,
+ tooltip: history || devices?.devices == null
+ ? null
+ : 'Update Harness on this computer to see history.',
+ onPressed: history ? hooks.onHistory : null,
),
- DesktopPill(
- key: const Key('account-devices-history'),
- label: 'History…',
- compact: true,
- tooltip: history || devices?.devices == null
- ? null
- : 'Update Harness on this computer to see history.',
- onPressed: history ? hooks.onHistory : null,
),
],
),
diff --git a/desktop/lib/widgets/swarm_resource_preview.dart b/desktop/lib/widgets/swarm_resource_preview.dart
index 93cc6bd5b..b69c6eb5a 100644
--- a/desktop/lib/widgets/swarm_resource_preview.dart
+++ b/desktop/lib/widgets/swarm_resource_preview.dart
@@ -23,6 +23,7 @@ import '../state/harness_placement.dart';
import '../state/swarm_navigation.dart';
import '../state/swarm_search.dart';
import '../terminal/terminal_text.dart';
+import 'finger_target.dart';
import '../terminal/terminal_theme.dart';
import '../terminal/terminal_theme_store.dart';
import 'account_device_detail.dart'
@@ -719,16 +720,19 @@ class _SwarmResourcePreviewState extends State<SwarmResourcePreview> {
);
return Semantics(
liveRegion: action.label == 'Working…',
- child: DesktopPill(
- key: ValueKey('resource-action:${action.command}'),
- focusNode: node,
- label: action.label,
- compact: true,
- onPressed: invoke,
- foregroundColor: action.command == 'picker.resource_remove'
- ? Theme.of(context).colorScheme.error
- : null,
- tooltip: [action.label, ?shortcut].join(' · '),
+ child: fingerTarget(
+ enabled: workspaceIsCompact(context),
+ DesktopPill(
+ key: ValueKey('resource-action:${action.command}'),
+ focusNode: node,
+ label: action.label,
+ compact: true,
+ onPressed: invoke,
+ foregroundColor: action.command == 'picker.resource_remove'
+ ? Theme.of(context).colorScheme.error
+ : null,
+ tooltip: [action.label, ?shortcut].join(' · '),
+ ),
),
);
}
diff --git a/desktop/test/web/web_app_menu_test.dart b/desktop/test/web/web_app_menu_test.dart
index f788d10d4..69876d383 100644
--- a/desktop/test/web/web_app_menu_test.dart
+++ b/desktop/test/web/web_app_menu_test.dart
@@ -84,10 +84,11 @@ void main() {
Focus.of(tester.element(find.byKey(ValueKey('web-menu:$id'))))
.hasPrimaryFocus;
// Opened by a click: the pointer picks the row, so none starts lit.
- expect(lit('machines.list'), isFalse);
+ expect(lit('super_tab.new'), isFalse);
await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
await tester.pump();
- expect(lit('machines.list'), isTrue);
+ // The first row: New Swarm.
+ expect(lit('super_tab.new'), isTrue);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pump(const Duration(milliseconds: 100));
expect(find.byKey(const ValueKey('web-menu:machines.list')), findsNothing);
diff --git a/desktop/test/web/web_tab_context_menu_test.dart b/desktop/test/web/web_tab_context_menu_test.dart
index 0d0a85c51..5c9e2ad9b 100644
--- a/desktop/test/web/web_tab_context_menu_test.dart
+++ b/desktop/test/web/web_tab_context_menu_test.dart
@@ -6,6 +6,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/shared/theme/app_theme.dart' as grid;
+import 'package:harness/state/workspace_chrome.dart';
import 'package:harness/widgets/desktop_workspace_tab.dart';
/// In a browser the page's own context menu would open over a tab's menu
@@ -27,26 +28,33 @@ void main() {
.setMockMethodCallHandler(SystemChannels.contextMenu, null);
});
- Widget host({VoidCallback? onInvite, bool shown = true}) => MaterialApp(
+ Widget host({
+ VoidCallback? onInvite,
+ bool shown = true,
+ WorkspaceChrome? chrome,
+ }) => MaterialApp(
theme: grid.buildAppTheme(brightness: Brightness.dark),
home: Scaffold(
- body: Align(
- alignment: Alignment.topLeft,
- child: SizedBox(
- width: 220,
- height: 40,
- child: shown
- ? DesktopWorkspaceTab(
- id: 'app',
- label: 'app',
- selected: true,
- showShortcuts: const AlwaysStoppedAnimation(false),
- onSelect: () {},
- onClose: () {},
- onInvitePeople: onInvite,
- onShowAgentMessages: onInvite == null ? null : () {},
- )
- : null,
+ body: WorkspaceChromeScope(
+ chrome: chrome,
+ child: Align(
+ alignment: Alignment.topLeft,
+ child: SizedBox(
+ width: 220,
+ height: 40,
+ child: shown
+ ? DesktopWorkspaceTab(
+ id: 'app',
+ label: 'app',
+ selected: true,
+ showShortcuts: const AlwaysStoppedAnimation(false),
+ onSelect: () {},
+ onClose: () {},
+ onInvitePeople: onInvite,
+ onShowAgentMessages: onInvite == null ? null : () {},
+ )
+ : null,
+ ),
),
),
),
@@ -92,6 +100,37 @@ void main() {
await tester.pumpWidget(const SizedBox());
});
+ testWidgets('a host with a menu on every tab turns it off for any tab', (
+ tester,
+ ) async {
+ await tester.pumpWidget(
+ host(
+ chrome: WorkspaceChrome(
+ leadingWidth: (_) => 0,
+ leading: (_, _) => const SizedBox.shrink(),
+ menuOnEveryTab: true,
+ ),
+ ),
+ );
+ final mouse = await tester.createGesture(kind: PointerDeviceKind.mouse);
+ addTearDown(mouse.removePointer);
+ await mouse.addPointer(location: const Offset(500, 500));
+ final tab = tester.getCenter(find.byKey(const ValueKey('tab-label:app')));
+ await mouse.moveTo(tab);
+ await tester.pump();
+ expect(calls, ['disableContextMenu']);
+
+ await tester.tap(
+ find.byKey(const ValueKey('tab-label:app')),
+ buttons: kSecondaryButton,
+ kind: PointerDeviceKind.mouse,
+ );
+ await tester.pumpAndSettle();
+ expect(find.text('Close Tab'), findsOneWidget);
+ await tester.pumpWidget(const SizedBox());
+ expect(calls.last, 'enableContextMenu');
+ });
+
testWidgets('a tab without a menu leaves the browser menu alone', (
tester,
) async {
diff --git a/desktop/test/web_menus_test.dart b/desktop/test/web_menus_test.dart
new file mode 100644
index 000000000..49bf468ba
--- /dev/null
+++ b/desktop/test/web_menus_test.dart
@@ -0,0 +1,515 @@
+// The web workspace's menus: what they offer and how big a finger's target
+// is on a phone.
+
+import 'package:flutter/gestures.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/core/models.dart';
+import 'package:harness/screens/swarm_screen.dart';
+import 'package:harness/settings/settings_screen.dart';
+import 'package:harness/settings/settings_section.dart';
+import 'package:harness/shared/theme/app_theme.dart' as grid;
+import 'package:harness/state/app_state.dart';
+import 'package:harness/state/terminal_pane.dart';
+import 'package:harness/state/workspace_chrome.dart';
+import 'package:harness/web/shell/web_app_menu.dart';
+import 'package:harness/web/shell/web_chrome.dart';
+import 'package:harness/web/tabs/web_tab_menu.dart';
+import 'package:harness/widgets/desktop_workspace_tab.dart';
+import 'package:harness/widgets/swarm_switcher.dart';
+
+const _phone = Size(390, 844);
+const _computer = Size(1440, 900);
+
+/// An account whose machine list has answered, as it has once the app is in
+/// use: the workspace shows, not a page still looking for computers.
+class _Account extends AppNotifier {
+ _Account()
+ : super(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ );
+
+ @override
+ bool get machineInventoryLoaded => true;
+}
+
+AppNotifier _app() {
+ final app = _Account()..newSwarm(newTabPage: true);
+ addTearDown(app.dispose);
+ return app;
+}
+
+void _size(WidgetTester tester, Size size) {
+ tester.view.devicePixelRatio = 1;
+ tester.view.physicalSize = size;
+ addTearDown(tester.view.reset);
+}
+
+/// The web workspace, as the browser build composes it (or Desktop's, when
+/// [desktop]), for an account with one connected machine — so the workspace
+/// shows, not the page for connecting a first computer. With [harness], a
+/// tab holds a harness on it, so the footer has a menu to open and Machines a
+/// machine to show.
+Future<AppNotifier> _workspace(
+ WidgetTester tester,
+ Size size, {
+ bool harness = false,
+ bool desktop = false,
+}) async {
+ final app = _app();
+ const machine = Machine(
+ machineId: 'm',
+ name: 'box',
+ authMode: MachineAuthMode.remote,
+ );
+ app.machines.add(machine);
+ app.machineStates['m'] = MachineState(machine)
+ ..nodeOnline = true
+ ..connectionStatus = ConnectionStatus.connected
+ ..agents = [const Agent(id: 'a0', name: 'Agent 0')];
+ if (harness) {
+ app.newSwarm(newTabPage: true);
+ app.activeSwarm.panes.add(
+ TerminalPane(id: 100, machineId: 'm', agentId: 'a0'),
+ );
+ }
+ _size(tester, size);
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ home: SwarmScreen(
+ notifier: app,
+ nativeTabs: false,
+ chrome: desktop ? null : webWorkspaceChrome(app),
+ ),
+ ),
+ );
+ await tester.pump(const Duration(milliseconds: 200));
+ return app;
+}
+
+/// Machines, with the connected machine chosen so its actions show.
+Future<void> _openMachines(WidgetTester tester) async {
+ final search = tester
+ .widget<SwarmSearchResults>(find.byType(SwarmSearchResults))
+ .search;
+ final index = search.rows.indexWhere(
+ (row) => row.isMachine && row.machineId == 'm',
+ );
+ search.move(index - search.cursor);
+ await tester.pump(const Duration(milliseconds: 200));
+}
+
+/// Settings as the web opens it: the phone layout below 720 px.
+Future<void> _openSettings(WidgetTester tester, Size size) async {
+ final app = _app();
+ _size(tester, size);
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ home: Builder(
+ builder: (context) => Scaffold(
+ body: TextButton(
+ onPressed: () => showSettingsScreen(
+ context,
+ app,
+ source: 'test',
+ compactBelow: 720,
+ ),
+ child: const Text('Open'),
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.tap(find.text('Open'));
+ await tester.pumpAndSettle();
+}
+
+Future<void> _openAppMenu(WidgetTester tester) async {
+ await tester.tap(find.byKey(const ValueKey('web-app-menu-button')));
+ await tester.pump(const Duration(milliseconds: 100));
+}
+
+/// One ordinary tab, unshared, under [chrome] (none is Desktop's).
+Widget _tab({
+ WorkspaceChrome? chrome,
+ VoidCallback? onRename,
+ VoidCallback? onClose,
+}) => MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ home: Scaffold(
+ body: WorkspaceChromeScope(
+ chrome: chrome,
+ child: Align(
+ alignment: Alignment.topLeft,
+ child: SizedBox(
+ width: 220,
+ height: 40,
+ child: DesktopWorkspaceTab(
+ id: 'docs',
+ label: 'docs',
+ selected: false,
+ showShortcuts: const AlwaysStoppedAnimation(false),
+ onSelect: () {},
+ onRename: onRename,
+ onClose: onClose,
+ ),
+ ),
+ ),
+ ),
+ ),
+);
+
+Future<void> _rightClick(WidgetTester tester, Finder target) async {
+ await tester.tap(
+ target,
+ buttons: kSecondaryButton,
+ kind: PointerDeviceKind.mouse,
+ );
+ await tester.pumpAndSettle();
+}
+
+const _tabLabel = ValueKey('tab-label:docs');
+
+/// What a finger or the mouse hits for the control at [key]: its button.
+Size _target(WidgetTester tester, Key key) {
+ final control = find.byKey(key);
+ final button = find.ancestor(
+ of: control,
+ matching: find.byWidgetPredicate((w) => w is ButtonStyleButton),
+ );
+ return tester.getSize(button.evaluate().isEmpty ? control : button.first);
+}
+
+/// A phone's target is at least this big both ways (S1).
+const _finger = 44.0;
+
+void main() {
+ late WorkspaceChrome web;
+ setUp(() {
+ final app = AppNotifier(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ );
+ addTearDown(app.dispose);
+ web = webWorkspaceChrome(app);
+ });
+
+ testWidgets('on web, right-clicking an ordinary tab renames or closes it', (
+ tester,
+ ) async {
+ var renames = 0, closes = 0;
+ await tester.pumpWidget(
+ _tab(chrome: web, onRename: () => renames++, onClose: () => closes++),
+ );
+
+ await _rightClick(tester, find.byKey(_tabLabel));
+ expect(find.text('Rename Tab…'), findsOneWidget);
+ expect(find.text('Close Tab'), findsOneWidget);
+ await tester.tap(find.text('Rename Tab…'));
+ await tester.pumpAndSettle();
+ expect(renames, 1);
+ expect(find.text('Close Tab'), findsNothing);
+
+ await _rightClick(tester, find.byKey(_tabLabel));
+ await tester.tap(find.text('Close Tab'));
+ await tester.pumpAndSettle();
+ expect(closes, 1);
+ expect(renames, 1);
+ await tester.pumpWidget(const SizedBox());
+ });
+
+ testWidgets('on web, a double click on a tab still renames it', (
+ tester,
+ ) async {
+ var renames = 0;
+ await tester.pumpWidget(_tab(chrome: web, onRename: () => renames++));
+
+ await tester.tap(find.byKey(_tabLabel));
+ await tester.pump(const Duration(milliseconds: 80));
+ await tester.tap(find.byKey(_tabLabel));
+ await tester.pumpAndSettle();
+
+ expect(renames, 1);
+ expect(find.text('Rename Tab…'), findsNothing);
+ await tester.pumpWidget(const SizedBox());
+ });
+
+ testWidgets('on Desktop, an ordinary tab still has no right-click menu', (
+ tester,
+ ) async {
+ var renames = 0, closes = 0;
+ await tester.pumpWidget(
+ _tab(onRename: () => renames++, onClose: () => closes++),
+ );
+
+ await _rightClick(tester, find.byKey(_tabLabel));
+
+ expect(find.text('Rename Tab…'), findsNothing);
+ expect(find.text('Close Tab'), findsNothing);
+ expect((renames, closes), (0, 0));
+ await tester.pumpWidget(const SizedBox());
+ });
+
+ testWidgets('the web workspace at 1440 gives a tab the menu', (tester) async {
+ final app = await _workspace(tester, _computer);
+ final tab = app.activeSwarmId;
+
+ await _rightClick(tester, find.byKey(ValueKey('tab-label:$tab')));
+
+ expect(find.text('Rename Tab…'), findsOneWidget);
+ expect(find.text('Close Tab'), findsOneWidget);
+ await tester.tap(find.text('Close Tab'));
+ await tester.pump(const Duration(milliseconds: 400));
+ expect(app.swarms.any((swarm) => swarm.id == tab), isFalse);
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ });
+
+ testWidgets('the phone tab menu renames with Rename Tab…', (tester) async {
+ final app = _app();
+ WebTabChoice? chosen;
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ home: Material(
+ child: Column(
+ children: webTabMenuRows(
+ app,
+ WorkspaceCommands(
+ enabled: () => true,
+ canRun: (command) => command == 'swarm.rename',
+ run: (_) {},
+ ),
+ (choice) => chosen = choice,
+ ),
+ ),
+ ),
+ ),
+ );
+
+ await tester.tap(find.text('Rename Tab…'));
+
+ expect((chosen! as WebRunCommand).command, 'swarm.rename');
+ expect(find.text('Rename this tab'), findsNothing);
+ await tester.pumpWidget(const SizedBox());
+ });
+
+ testWidgets('a phone app menu has rows a finger can hit', (tester) async {
+ await _workspace(tester, _phone);
+ await _openAppMenu(tester);
+
+ for (final row in ['super_tab.new', 'machines.list', 'web.sign_out']) {
+ expect(
+ _target(tester, ValueKey('web-menu:$row')).height,
+ greaterThanOrEqualTo(_finger),
+ reason: row,
+ );
+ }
+ await tester.pumpWidget(const SizedBox.shrink());
+ });
+
+ testWidgets('a mouse keeps the app menu rows as they were', (tester) async {
+ await _workspace(tester, _computer);
+ await _openAppMenu(tester);
+
+ expect(
+ _target(tester, const ValueKey('web-menu:machines.list')).height,
+ 32,
+ );
+ await tester.pumpWidget(const SizedBox.shrink());
+ });
+
+ testWidgets('a phone tab menu has rows and closes a finger can hit', (
+ tester,
+ ) async {
+ final app = await _workspace(tester, _phone);
+ app.newSwarm(newTabPage: true);
+ await tester.pump(const Duration(milliseconds: 100));
+ await tester.tap(find.byKey(const ValueKey('web-tab-switcher')));
+ await tester.pump(const Duration(milliseconds: 100));
+
+ final tab = app.swarms.first.id;
+ for (final key in [
+ ValueKey('web-tab:$tab'),
+ ValueKey('web-tab-run:swarm.rename'),
+ ]) {
+ expect(
+ _target(tester, key).height,
+ greaterThanOrEqualTo(_finger),
+ reason: '$key',
+ );
+ }
+ final close = _target(tester, ValueKey('web-tab:$tab:close'));
+ expect(close.width, greaterThanOrEqualTo(_finger));
+ expect(close.height, greaterThanOrEqualTo(_finger));
+ await tester.pumpWidget(const SizedBox.shrink());
+ });
+
+ testWidgets('a phone footer menu has rows a finger can hit', (tester) async {
+ final app = await _workspace(tester, _phone, harness: true);
+ app.focusPane(100);
+ await tester.pump(const Duration(milliseconds: 100));
+ await tester.tap(find.byKey(const ValueKey('web-footer-menu-button')));
+ await tester.pump(const Duration(milliseconds: 100));
+
+ for (final row in ['Machine', 'Subscriptions']) {
+ expect(
+ _target(tester, ValueKey('web-footer:$row')).height,
+ greaterThanOrEqualTo(_finger),
+ reason: row,
+ );
+ }
+ await tester.pumpWidget(const SizedBox.shrink());
+ });
+
+ const machineActions = [
+ ValueKey('resource-action:picker.resource_view'),
+ ValueKey('resource-action:picker.resource_rename'),
+ Key('machine-picker-add-machine'),
+ Key('account-devices-history'),
+ Key('machine-window-choice-field'),
+ ];
+
+ Future<void> machines(
+ WidgetTester tester,
+ Size size, {
+ bool desktop = false,
+ }) async {
+ await _workspace(tester, size, harness: true, desktop: desktop);
+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);
+ final menu = find.byKey(const ValueKey('web-app-menu-button'));
+ if (menu.evaluate().isNotEmpty) {
+ await _openAppMenu(tester);
+ await tester.tap(find.byKey(const ValueKey('web-menu:machines.list')));
+ } else {
+ await tester.tap(find.byKey(const ValueKey('swarm-search-button')));
+ await tester.pump(const Duration(milliseconds: 200));
+ await tester.enterText(find.byType(EditableText).first, '@');
+ }
+ await tester.pump(const Duration(milliseconds: 400));
+ await _openMachines(tester);
+ }
+
+ testWidgets('a phone Machines picker has actions a finger can hit', (
+ tester,
+ ) async {
+ await machines(tester, _phone);
+
+ for (final key in machineActions) {
+ expect(
+ _target(tester, key).height,
+ greaterThanOrEqualTo(_finger),
+ reason: '$key',
+ );
+ }
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ });
+
+ testWidgets('Machines keeps its actions under a mouse and on Desktop', (
+ tester,
+ ) async {
+ await machines(tester, _computer);
+ final web = {
+ for (final key in machineActions) key: _target(tester, key).height,
+ };
+ await tester.pumpWidget(const SizedBox.shrink());
+ await machines(tester, _phone, desktop: true);
+ final desktop = {
+ for (final key in machineActions) key: _target(tester, key).height,
+ };
+
+ for (final key in machineActions) {
+ expect(web[key], lessThan(_finger), reason: 'web 1440 $key');
+ expect(desktop[key], web[key], reason: 'Desktop 390 $key');
+ }
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ });
+
+ testWidgets('phone Settings has a Back a finger can hit, both ways back', (
+ tester,
+ ) async {
+ await _openSettings(tester, _phone);
+ expect(
+ _target(tester, const Key('settings-back-button')).height,
+ greaterThanOrEqualTo(_finger),
+ );
+
+ await tester.tap(find.text(SettingsSection.notifications.label));
+ await tester.pumpAndSettle();
+ expect(
+ _target(tester, const Key('settings-compact-back')).height,
+ greaterThanOrEqualTo(_finger),
+ );
+ await tester.pumpWidget(const SizedBox.shrink());
+ });
+
+ testWidgets('a wide Settings keeps its Back as it was', (tester) async {
+ await _openSettings(tester, _computer);
+
+ expect(_target(tester, const Key('settings-back-button')).height, 38);
+ await tester.pumpWidget(const SizedBox.shrink());
+ });
+
+ for (final size in [_phone, _computer]) {
+ testWidgets('New Swarm in the menu runs what Alt+S runs at ${size.width}', (
+ tester,
+ ) async {
+ final app = _app();
+ final ran = <String>[];
+ _size(tester, size);
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ home: Scaffold(
+ body: Align(
+ alignment: Alignment.topLeft,
+ child: WebAppMenuButton(
+ app: app,
+ commands: WorkspaceCommands(
+ enabled: () => true,
+ canRun: (_) => true,
+ run: ran.add,
+ ),
+ ),
+ ),
+ ),
+ ),
+ );
+ await _openAppMenu(tester);
+ expect(find.text('New Swarm'), findsOneWidget);
+
+ await tester.tap(find.byKey(const ValueKey('web-menu:super_tab.new')));
+ await tester.pump(const Duration(milliseconds: 100));
+
+ // super_tab.new is the command Alt+S is bound to (keymap_host_test).
+ expect(ran, ['super_tab.new']);
+ await tester.pumpWidget(const SizedBox.shrink());
+ });
+
+ testWidgets('New Swarm in the menu opens a new Swarm at ${size.width}', (
+ tester,
+ ) async {
+ final app = await _workspace(tester, size);
+ final tabs = app.swarms.length;
+
+ await _openAppMenu(tester);
+ await tester.tap(find.byKey(const ValueKey('web-menu:super_tab.new')));
+ await tester.pump(const Duration(milliseconds: 200));
+
+ expect(app.swarms, hasLength(tabs + 1));
+ expect(app.activeSwarm.isSuperTab, isTrue);
+ expect(tester.takeException(), isNull);
+ await tester.pumpWidget(const SizedBox.shrink());
+ });
+ }
+}
diff --git a/desktop/tool/web_ux/flows/menus.mjs b/desktop/tool/web_ux/flows/menus.mjs
index 1c1cbffee..b8cd5ff9b 100644
--- a/desktop/tool/web_ux/flows/menus.mjs
+++ b/desktop/tool/web_ux/flows/menus.mjs
@@ -13,4 +13,9 @@ export const FLOWS = [
{ name: 'all-commands', scenario: 'workspace', steps: menu('All commands') },
{ name: 'machines', scenario: 'workspace', steps: menu('Machines') },
{ name: 'settings', scenario: 'workspace', steps: menu('Settings') },
+ // Group 1's own: what New Swarm opens, and the phone tab menu's Rename Tab… dialog.
+ { name: 'new-swarm', scenario: 'workspace', steps: menu('New Swarm') },
+ // The same Swarm by its key, for comparison with the menu's.
+ { name: 'new-swarm-key', scenario: 'workspace', steps: [['key', 'Alt+s']] },
+ { name: 'tab-menu-rename', scenario: 'many-tabs', only: 'wide', steps: [['rclick', 'docs'], ['text', 'Rename Tab…']] },
];