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.

feat(web): enhance web download button functionality and add tests for new tab behavior

Dev jacobec813a981c5a
diff --git a/desktop/lib/web/picker/web_picker_bar.dart b/desktop/lib/web/picker/web_picker_bar.dart
index 9c0b52226..0706f63d8 100644
--- a/desktop/lib/web/picker/web_picker_bar.dart
+++ b/desktop/lib/web/picker/web_picker_bar.dart
@@ -22,8 +22,9 @@ class WebPickerBar extends StatelessWidget {
listenable: search,
builder: (context, _) => Padding(
key: const ValueKey('web-picker-bar'),
+ // Four cells in, like the input and the result titles under it.
padding: EdgeInsets.fromLTRB(
- cell.width * 2,
+ cell.width * 4,
cell.height * .5,
cell.width,
0,
@@ -105,7 +106,9 @@ class _BarText extends StatelessWidget {
),
child: SizedBox(
height: terminalCellSizeOf(context).height * 1.5,
- child: Center(child: Text(label)),
+ // Centered on the row's height only: a plain Center would take the
+ // whole width and stack every scope on a line of its own.
+ child: Center(widthFactor: 1, child: Text(label)),
),
);
}
diff --git a/desktop/lib/widgets/web_download_button.dart b/desktop/lib/widgets/web_download_button.dart
index a464b878b..d0c9c656e 100644
--- a/desktop/lib/widgets/web_download_button.dart
+++ b/desktop/lib/widgets/web_download_button.dart
@@ -1,15 +1,27 @@
import 'package:flutter/material.dart';
-import 'package:url_launcher/link.dart';
+import 'package:url_launcher/url_launcher.dart';
import '../shared/theme/app_theme.dart' as grid;
import '../shared/theme/workspace_bar_style.dart';
import 'workspace_bar_control.dart';
-/// The browser's consistent handoff to the existing macOS/Linux download page.
+/// Opens [uri] in a new browser tab, inside the click that asked for it: a
+/// `window.open` made later is outside the user's gesture, which browsers
+/// block as a popup or open as a separate window.
+Future<bool> openInNewTab(Uri uri) =>
+ launchUrl(uri, webOnlyWindowName: '_blank');
+
+/// The browser's consistent handoff to the existing macOS/Linux download page,
+/// in a new tab so the workspace stays open behind it.
class WebDownloadButton extends StatelessWidget {
- const WebDownloadButton({super.key});
+ const WebDownloadButton({super.key, this.open = openInNewTab});
+
+ /// How the page is opened; tests pass a recorder.
+ final Future<bool> Function(Uri uri) open;
- static final uri = Uri.parse('https://harness.autonomous.ai/download');
+ static final uri = Uri.parse(
+ 'https://www.autonomous.ai/harness-app?page=download',
+ );
static const _text = '[ Download app ]';
static double widthOf(BuildContext context) =>
@@ -19,12 +31,12 @@ class WebDownloadButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
grid.AppTheme.watch(context);
- return Link(
- uri: uri,
- target: LinkTarget.blank,
- builder: (context, followLink) => WorkspaceBarControl(
+ return Semantics(
+ link: true,
+ linkUrl: uri,
+ child: WorkspaceBarControl(
label: 'Download app',
- onPressed: followLink,
+ onPressed: () => open(uri),
builder: (context, emphasized) => SizedBox(
width: widthOf(context),
height: workspaceBarControlHeight(context),
diff --git a/desktop/test/web/web_download_button_test.dart b/desktop/test/web/web_download_button_test.dart
new file mode 100644
index 000000000..10b8dee78
--- /dev/null
+++ b/desktop/test/web/web_download_button_test.dart
@@ -0,0 +1,31 @@
+@TestOn('browser')
+library;
+
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/widgets/web_download_button.dart';
+
+void main() {
+ testWidgets('a click opens the download page through the new-tab opener', (
+ tester,
+ ) async {
+ final opened = <Uri>[];
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Center(
+ child: WebDownloadButton(
+ open: (uri) async {
+ opened.add(uri);
+ return true;
+ },
+ ),
+ ),
+ ),
+ );
+ await tester.tap(find.byType(WebDownloadButton));
+ await tester.pump();
+ expect(opened, [WebDownloadButton.uri]);
+ // The default opener is the new-tab one, not a same-tab navigation.
+ expect(const WebDownloadButton().open, openInNewTab);
+ });
+}
diff --git a/desktop/test/web_picker_layout_test.dart b/desktop/test/web_picker_layout_test.dart
new file mode 100644
index 000000000..a1cef5fe5
--- /dev/null
+++ b/desktop/test/web_picker_layout_test.dart
@@ -0,0 +1,105 @@
+import 'dart:io';
+import 'dart:ui' as ui;
+
+import 'package:flutter/material.dart';
+import 'package:flutter/rendering.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/shared/theme/app_theme.dart' as grid;
+import 'package:harness/state/app_state.dart';
+import 'package:harness/web/picker/web_picker_scopes.dart';
+import 'package:harness/web/shell/web_chrome.dart';
+
+import 'support/real_fonts.dart';
+
+/// The web picker bar, laid out with real fonts: a regression here once
+/// stacked every scope on a centered line of its own.
+void main() {
+ setUpAll(loadRealFonts);
+
+ testWidgets('picker scopes sit on one row, left to right', (tester) async {
+ final app = AppNotifier(
+ config: AppConfig.dev,
+ authSession: AuthSession(),
+ configStore: null,
+ )..newSwarm(newTabPage: true);
+ const machine = Machine(
+ machineId: 'remote-box',
+ name: 'harness-remote-box',
+ authMode: MachineAuthMode.remote,
+ );
+ app.machines.add(machine);
+ app.machineStates['remote-box'] = MachineState(machine)
+ ..nodeOnline = true
+ ..needsLink = true;
+ final boundary = GlobalKey();
+ tester.view.devicePixelRatio = 1;
+ tester.view.physicalSize = const Size(1440, 800);
+ addTearDown(tester.view.reset);
+ await tester.pumpWidget(
+ RepaintBoundary(
+ key: boundary,
+ child: MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ home: SwarmScreen(
+ notifier: app,
+ nativeTabs: false,
+ chrome: webWorkspaceChrome(app),
+ ),
+ ),
+ ),
+ );
+ await tester.pump(const Duration(milliseconds: 200));
+ await tester.tap(find.byKey(const ValueKey('swarm-search-button')));
+ await tester.pump(const Duration(milliseconds: 200));
+ await tester.tap(find.byKey(const ValueKey('web-picker-scope:@')));
+ await tester.pump(const Duration(milliseconds: 200));
+
+ final rects = [
+ for (final scope in kWebPickerScopes)
+ tester.getRect(
+ find.byKey(ValueKey('web-picker-scope:${scope.prefix}')),
+ ),
+ ];
+ final close = tester.getRect(
+ find.byKey(const ValueKey('web-picker-close')),
+ );
+ for (final rect in [...rects, close]) {
+ expect(rect.center.dy, moreOrLessEquals(rects.first.center.dy));
+ }
+ for (var i = 1; i < rects.length; i++) {
+ expect(rects[i].left, greaterThan(rects[i - 1].right));
+ }
+ // The bar starts where the input's text does.
+ expect(
+ rects.first.left,
+ moreOrLessEquals(
+ tester.getRect(find.byKey(const ValueKey('swarm-search-input'))).left,
+ epsilon: 1,
+ ),
+ );
+ // Each scope hugs its label rather than taking the row.
+ expect(rects.first.width, lessThan(120));
+ expect(tester.takeException(), isNull);
+
+ final output = Platform.environment['HARNESS_REFINEMENT_CAPTURE_DIR'];
+ if (output != null) {
+ await tester.runAsync(() async {
+ final image =
+ await (boundary.currentContext!.findRenderObject()
+ as RenderRepaintBoundary)
+ .toImage();
+ final data = await image.toByteData(format: ui.ImageByteFormat.png);
+ Directory(output).createSync(recursive: true);
+ File('$output/web-picker-bar.png')
+ .writeAsBytesSync(data!.buffer.asUint8List());
+ image.dispose();
+ });
+ }
+ await tester.pumpWidget(const SizedBox.shrink());
+ app.dispose();
+ });
+}