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(desktop): offer Add Phone as a card, add store codes to its dialog

tony596410dcbd00
diff --git a/desktop/assets/stores/app-store.svg b/desktop/assets/stores/app-store.svg
new file mode 100644
index 000000000..14f45efe9
--- /dev/null
+++ b/desktop/assets/stores/app-store.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><defs><linearGradient id="g" x1="0" y1="0" x2="0" y2="1"><stop offset="0" stop-color="#1bc2fa"/><stop offset="1" stop-color="#1d6ff2"/></linearGradient></defs><rect width="24" height="24" rx="5.5" fill="url(#g)"/><path d="M12.9 5.8 7.1 15.9M11.1 5.8l5.8 10.1M5.7 13.9h7.1M15.6 13.9h2.7" fill="none" stroke="#fff" stroke-width="1.9" stroke-linecap="round"/></svg>
diff --git a/desktop/assets/stores/google-play.svg b/desktop/assets/stores/google-play.svg
new file mode 100644
index 000000000..88efdf360
--- /dev/null
+++ b/desktop/assets/stores/google-play.svg
@@ -0,0 +1 @@
+<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="#4285f4" d="M1.337.924a1.486 1.486 0 0 0-.112.568v21.017c0 .217.045.419.124.6l11.155-11.087L1.337.924z"/><path fill="#34a853" d="M13.544 10.989l3.258-3.238L3.45.195a1.466 1.466 0 0 0-.946-.179l11.04 10.973z"/><path fill="#fbbc04" d="M22.018 13.298l-3.919 2.218-3.515-3.493 3.543-3.521 3.891 2.202a1.49 1.49 0 0 1 0 2.594z"/><path fill="#ea4335" d="M13.544 13.056l-11 10.933c.298.036.612-.016.906-.183l13.324-7.54-3.23-3.21z"/></svg>
diff --git a/desktop/lib/core/phone_app_links.dart b/desktop/lib/core/phone_app_links.dart
new file mode 100644
index 000000000..13dd72c70
--- /dev/null
+++ b/desktop/lib/core/phone_app_links.dart
@@ -0,0 +1,11 @@
+/// The Harness phone app in its stores: the bar a phone's browser shows
+/// (`web/shell/web_store_banner.dart`) and the download codes in Add Phone
+/// (`widgets/add_phone_dialog.dart`). One place, so a store listing that moves
+/// moves both.
+const kAppStoreUrl =
+ 'https://apps.apple.com/us/app/harness-like-a-boss/id6812264068';
+
+/// The Play listing of package `ai.autonomous.harness.android` — the phone
+/// app's `applicationId` (mobile `android/app/build.gradle.kts`).
+const kGooglePlayUrl =
+ 'https://play.google.com/store/apps/details?id=ai.autonomous.harness.android';
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dart
index b1ef1abd4..493862a4c 100644
--- a/desktop/lib/screens/swarm_screen.dart
+++ b/desktop/lib/screens/swarm_screen.dart
@@ -156,6 +156,7 @@ import '../widgets/workspace_welcome.dart';
import '../widgets/workspace_machine_prompt.dart';
import '../shortcuts/keyboard_practice.dart';
import '../widgets/agent_alert_banners.dart';
+import '../widgets/phone_offer_card.dart';
import '../settings/experimental_features.dart';
class SwarmScreen extends StatefulWidget {
@@ -2916,10 +2917,10 @@ class _SwarmScreenState extends State<SwarmScreen> {
/// Harness ▸ Add Phone… and `> add phone`: the QR a phone scans to sign in
/// and pair with this computer. See `widgets/add_phone_dialog.dart`.
Future<void> _addPhone() async {
- // Open, by hand or not, it is this computer's offer ([_maybeOfferPhone]),
- // spent for good — and a sign-in made from inside it (its "Sign in…") must
- // not open it again once it closes, so the offer is dropped on the way out
- // too.
+ // Open, from its card or by hand, it is this computer's offer
+ // ([_phoneOfferCard]) spent for good — and a sign-in made from inside it
+ // (its "Sign in…") must not bring the card back once it closes, so the
+ // offer is dropped on the way out too.
app.dropPhoneOffer();
// "Manage devices…" pops the dialog and asks for Settings, but this
// [_dialog] is still open until the pop lands — a [_settings] made from
@@ -6370,65 +6371,18 @@ class _SwarmScreenState extends State<SwarmScreen> {
});
}
- /// Add Phone, opened by itself once on this computer: at the first launch
- /// as a guest — the dialog asks for the sign-in, then shows the code — or
- /// after the first sign-in by hand, when the account has no phone yet
- /// ([AppNotifier.takePhoneOffer]).
- ///
- /// ⚠️ **The phone's first screen counts on it (owner, 2026-10-08):** a
- /// newcomer who got Harness from the phone is not sent looking for Add Phone
- /// in a menu, or in the command palette on Linux.
- ///
- /// Waits for a clear screen — the sign-in sheet closed, no dialog or palette
- /// up — rather than opening over what somebody is in the middle of; the
- /// offer lapses by itself if that takes too long.
- void _maybeOfferPhone() {
- if (kIsWeb || !app.phoneOfferPending || !_phoneOfferClear) return;
- if (!app.takePhoneOffer()) return;
- WidgetsBinding.instance.addPostFrameCallback(
- (_) => unawaited(_offerPhone()),
+ /// Add Phone's card ([AppNotifier.phoneOfferShowing]) — not while a new
+ /// computer's first agents are being opened (`state/first_arrival.dart`): it
+ /// comes once the work is on the screen, and stands beside it.
+ Widget? _phoneOfferCard() {
+ if (kIsWeb || !app.phoneOfferShowing) return null;
+ if (app.firstArrival.pending || app.firstArrival.running) return null;
+ return PhoneOfferCard(
+ onAdd: () => unawaited(_addPhone()),
+ onDismiss: app.dropPhoneOffer,
);
}
- /// ⚠️ New Harness counts only open over the screen: embedded in the welcome
- /// page it is what an empty workspace shows — the very screen a first
- /// sign-in lands on, which waiting on it would never offer Add Phone from.
- bool get _phoneOfferClear =>
- _routeIsCurrent &&
- !_dialogOpen &&
- !_commandBarOpen &&
- !_spokenPaletteOpen &&
- _search == null &&
- (_newHarness == null || _newHarnessEmbedded);
-
- Future<void> _offerPhone() async {
- // A guest has no account to ask: its Add Phone asks for the sign-in.
- final signedIn = app.signedIn;
- var hasPhone = false;
- if (signedIn) {
- try {
- final devices = await app.loadDevices();
- // Any app on the account but this one — a phone, or a browser — has
- // its way in already. A list that cannot be read offers it anyway:
- // closing Add Phone costs less than a newcomer left looking for its
- // code.
- hasPhone =
- devices?.devices.any(
- (device) => !device.isMachine && !device.self,
- ) ??
- false;
- } catch (_) {
- hasPhone = false;
- }
- }
- if (!mounted) return;
- // Nothing to offer on this computer again.
- if (hasPhone) return app.dropPhoneOffer();
- // Signed in or out meanwhile, or something opened: not now.
- if (app.signedIn != signedIn || !_phoneOfferClear) return;
- await _addPhone();
- }
-
bool get _hasConnectedBrowserMachine => app.machineStates.values.any(
(machine) =>
!machine.machine.isShared &&
@@ -7060,7 +7014,6 @@ class _SwarmScreenState extends State<SwarmScreen> {
builder: (context, _) {
grid.AppTheme.watch(context);
_maybeLink();
- _maybeOfferPhone();
_scheduleWelcomeComposer();
if (app.panes.isEmpty) {
WidgetsBinding.instance.addPostFrameCallback(
@@ -7394,7 +7347,10 @@ class _SwarmScreenState extends State<SwarmScreen> {
// Last in the stack, so a banner is never painted
// under a pane, a tab or the palette. It takes
// pointers only on the banners themselves.
- AgentAlertBanners(notifier: app),
+ AgentAlertBanners(
+ notifier: app,
+ footer: _phoneOfferCard(),
+ ),
],
),
),
diff --git a/desktop/lib/shared/widgets/qr_code_view.dart b/desktop/lib/shared/widgets/qr_code_view.dart
index 3a5a88598..090cc107c 100644
--- a/desktop/lib/shared/widgets/qr_code_view.dart
+++ b/desktop/lib/shared/widgets/qr_code_view.dart
@@ -19,18 +19,24 @@ class QrCodeView extends StatelessWidget {
static const _quietModules = 4;
- // One entry: the dialog rebuilds on every font or palette change, and
- // choosing the best of eight mask patterns is not free.
- static (String, QrImage)? _cached;
+ // A few entries, the most recently drawn kept: the dialog rebuilds on every
+ // font or palette change, and choosing the best of eight mask patterns is not
+ // free. ⚠️ Not one: Add Phone shows three codes at once — the App Store's,
+ // Google Play's and the pairing code — and a single entry recomputed all
+ // three on every rebuild.
+ static final _cached = <String, QrImage>{};
+ static const _cacheSize = 4;
static QrImage _imageOf(String data) {
- if (_cached case (final cachedData, final image) when cachedData == data) {
+ if (_cached.remove(data) case final image?) {
+ _cached[data] = image;
return image;
}
final image = QrImage(
QrCode.fromData(data: data, errorCorrectLevel: QrErrorCorrectLevel.M),
);
- _cached = (data, image);
+ _cached[data] = image;
+ if (_cached.length > _cacheSize) _cached.remove(_cached.keys.first);
return image;
}
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index 8b0d1a457..2af71df1b 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -988,7 +988,7 @@ class AppNotifier extends ChangeNotifier {
!_disposed && revision == _authRevision;
int _invalidateAuthWork() {
- _phoneOfferSince = null;
+ _phoneOffer = false;
_closeOwnerMemories();
_stopMachineRecovery();
api.resetAccountCache();
@@ -5656,9 +5656,7 @@ class AppNotifier extends ChangeNotifier {
}
_guestDeskRestorePending = false;
// The first sign-in on this computer offers Add Phone; a later one does not.
- if (!await _phoneOfferDone() && _authWorkCurrent(revision)) {
- _phoneOfferSince = DateTime.now();
- }
+ unawaited(_offerPhoneAfterSignIn(revision));
} catch (error) {
if (!_authWorkCurrent(revision)) return;
status = wasGuest ? AppStatus.authenticated : AppStatus.unauthenticated;
@@ -5686,46 +5684,38 @@ class AppNotifier extends ChangeNotifier {
/// The failed sign-in again, to the account the person chose the first time.
Future<void> retryLogin() => login(signInProvider);
- /// When Add Phone was last offered: Add Phone then opens by itself (`screens/swarm_screen.dart`
- /// `_maybeOfferPhone`) — signed in, on an account with no phone yet; as a guest, asking for the
- /// sign-in itself. Null once taken, dropped, or the account changes.
+ /// Whether the workspace offers Add Phone — "Your agents in your pocket.", a card in the window's
+ /// top-right (`widgets/phone_offer_card.dart`): as a guest, whose Add Phone asks for the sign-in
+ /// itself; signed in, on an account with no phone yet. Cleared when the account changes.
+ ///
+ /// ⚠️ **The phone's first screen counts on it (owner, 2026-10-08).** It tells a newcomer to open
+ /// Add Phone on the computer (mobile `set_up_computer.dart`), so the button has to be on the
+ /// screen without anyone finding it in a menu, or in the command palette on Linux. Not after
+ /// [loginWithPhone]: that sign-in was a phone's, which has its way in already.
///
- /// ⚠️ **The phone's first screen counts on it (owner, 2026-10-08).** It tells a newcomer to get
- /// Harness on the computer and pair it (mobile `set_up_computer.dart`), so the code has to come up
- /// without anyone finding Add Phone in a menu. Not after [loginWithPhone]: that sign-in was a
- /// phone's, which has its way in already.
+ /// ⚠️ **A card, not Add Phone opened by itself (owner, 2026-10-09).** A new install opens on
+ /// agents already at work (`state/first_arrival.dart`); a dialog over them broke that first moment
+ /// for everyone without a phone, to serve those with one. The card waits beside the work until it
+ /// is used or put away.
///
/// ⚠️ **Once per computer (owner, 2026-10-09)**, not once per sign-in: it is offered at the first
/// launch, which a new install makes as a guest ([_offerPhoneAtLaunch]), or else after the first
- /// sign-in by hand ([login]) — never again once Add Phone has been opened here or the account was
- /// found to have a phone ([_phoneOfferDone]).
- DateTime? _phoneOfferSince;
-
- /// How long the offer stands: long enough for a sign-in sheet or Settings to close, not so long
- /// that Add Phone opens over unrelated work later.
- static const _phoneOfferWindow = Duration(minutes: 2);
-
- /// Add Phone is waiting to be offered — see [takePhoneOffer].
- bool get phoneOfferPending => _phoneOfferSince != null;
-
- /// Takes the offer: true at most once per offer, and only within [_phoneOfferWindow] of it.
- bool takePhoneOffer() {
- final since = _phoneOfferSince;
- _phoneOfferSince = null;
- return since != null &&
- viewer == null &&
- DateTime.now().difference(since) < _phoneOfferWindow;
- }
-
- /// Add Phone was opened — by hand, or by the offer itself — or the account turned out to have a
- /// phone: nothing is left to offer, now or on a later launch or sign-in. Also how a sign-in made
- /// from inside Add Phone (its "Sign in…") does not open it a second time once it closes.
+ /// sign-in by hand ([_offerPhoneAfterSignIn]) — never again once Add Phone has been opened here,
+ /// the card put away, or the account found to have a phone ([_phoneOfferDone]).
+ bool get phoneOfferShowing => _phoneOffer;
+ bool _phoneOffer = false;
+
+ /// Add Phone was opened — from the card or by hand — or the card was put away: nothing is left to
+ /// offer, now or on a later launch or sign-in. Also how a sign-in made from inside Add Phone (its
+ /// "Sign in…") does not bring the card back.
void dropPhoneOffer() {
- _phoneOfferSince = null;
+ final showing = _phoneOffer;
+ _phoneOffer = false;
_markPhoneOfferDone();
+ if (showing) notifyListeners();
}
- /// This computer's record that Add Phone has had its offer ([_phoneOfferSince]), in the desktop's
+ /// This computer's record that Add Phone has had its offer ([phoneOfferShowing]), in the desktop's
/// state file beside the dial's ([DialState]).
static const _phoneOfferDoneKey = 'phone_offer_done';
@@ -5771,7 +5761,35 @@ class AppNotifier extends ChangeNotifier {
}
if (!isGuest || await _phoneOfferDone()) return;
if (!_authWorkCurrent(revision) || !isGuest) return;
- _phoneOfferSince = DateTime.now();
+ _phoneOffer = true;
+ notifyListeners();
+ }
+
+ /// [_offerPhoneAtLaunch] or [_offerPhoneAfterSignIn], as launch and a sign-in by hand run them.
+ @visibleForTesting
+ Future<void> offerPhoneForTest({required bool atLaunch}) => atLaunch
+ ? _offerPhoneAtLaunch(_authRevision)
+ : _offerPhoneAfterSignIn(_authRevision);
+
+ /// The first sign-in by hand on this computer offers Add Phone — unless the account already has a
+ /// phone or a browser on it, which has its way in.
+ Future<void> _offerPhoneAfterSignIn(int revision) async {
+ if (viewer != null || await _phoneOfferDone()) return;
+ var hasPhone = false;
+ try {
+ final devices = await loadDevices();
+ hasPhone =
+ devices?.devices.any((device) => !device.isMachine && !device.self) ??
+ false;
+ } catch (_) {
+ // A list that cannot be read offers the card anyway: it costs one × to put away.
+ }
+ if (!_authWorkCurrent(revision) || !signedIn) return;
+ if (hasPhone) {
+ _markPhoneOfferDone();
+ return;
+ }
+ _phoneOffer = true;
notifyListeners();
}
diff --git a/desktop/lib/web/shell/web_store_banner.dart b/desktop/lib/web/shell/web_store_banner.dart
index 1c0a7d78d..ebd99afa1 100644
--- a/desktop/lib/web/shell/web_store_banner.dart
+++ b/desktop/lib/web/shell/web_store_banner.dart
@@ -5,18 +5,15 @@ import 'package:flutter/material.dart';
import '../../core/harness_file_store.dart';
import '../../core/local_key_value_store.dart';
+import '../../core/phone_app_links.dart';
import '../../shared/theme/app_icons.dart';
import '../../shared/theme/app_theme.dart' as grid;
import '../../shared/theme/app_type.dart';
import '../../widgets/web_download_button.dart' show openInNewTab;
import 'web_hidden_under_keyboard.dart';
-final _appStore = Uri.parse(
- 'https://apps.apple.com/us/app/harness-like-a-boss/id6812264068',
-);
-final _googlePlay = Uri.parse(
- 'https://play.google.com/store/apps/details?id=ai.autonomous.harness.android',
-);
+final _appStore = Uri.parse(kAppStoreUrl);
+final _googlePlay = Uri.parse(kGooglePlayUrl);
/// The Harness app's store page for the phone or tablet this browser runs on;
/// null on a computer, which has no store app to send anyone to.
diff --git a/desktop/lib/widgets/add_phone_dialog.dart b/desktop/lib/widgets/add_phone_dialog.dart
index 8ab7516de..22a8e8e18 100644
--- a/desktop/lib/widgets/add_phone_dialog.dart
+++ b/desktop/lib/widgets/add_phone_dialog.dart
@@ -5,9 +5,11 @@ import 'dart:math' as math;
import 'package:dio/dio.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
+import 'package:flutter_svg/flutter_svg.dart';
import '../shared/widgets/qr_code_view.dart';
import '../api/api_client.dart';
+import '../core/phone_app_links.dart';
import '../screens/login_screen.dart' show showSignInSheet;
import '../shared/theme/app_theme.dart' as grid;
import '../shortcuts/app_keymap.dart';
@@ -553,7 +555,6 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
void _close() => Navigator.of(context).maybePop();
Color get _faint => DesktopChrome.muted;
- TextStyle _ink([Color? color]) => DesktopChrome.text(color: color);
@override
Widget build(BuildContext context) {
@@ -565,7 +566,6 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
return TerminalPromptKeys(
cancel: _close,
child: DesktopPromptSurface(
- width: 440,
body: LayoutBuilder(
builder: (context, constraints) => DesktopPromptScrollBody(
child: Column(
@@ -576,8 +576,32 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
header: true,
child: Text('Add your phone', style: DesktopChrome.heading()),
),
- const SizedBox(height: 24),
- ..._body(math.min(240, constraints.maxWidth), 16),
+ const SizedBox(height: 18),
+ // Folded, the step is its one line, in the title's place: signed in, the
+ // pairing code is what the dialog is for, and at a large text size a
+ // title over the line pushed it below the fold.
+ _downloadsShown
+ ? _AddPhoneStep(
+ number: 1,
+ title: Text(
+ 'Get Harness on your phone',
+ style: _AddPhoneStep.titleStyle(),
+ ),
+ children: _downloads(),
+ )
+ : _AddPhoneStep(number: 1, title: _downloadsClosed()),
+ Divider(
+ height: 1,
+ thickness: 1,
+ color: grid.AppPalette.divider,
+ ),
+ _AddPhoneStep(
+ number: 2,
+ title: Text(_pairingTitle, style: _AddPhoneStep.titleStyle()),
+ children: _pairing(
+ math.min(200, constraints.maxWidth - _AddPhoneStep.indent),
+ ),
+ ),
],
),
),
@@ -596,36 +620,91 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
);
}
- List<Widget> _body(double qrSide, double row) {
+ /// Step 1's download codes, opened by hand once they are folded away. Null
+ /// follows the account: open for a guest, who is likeliest to be new to
+ /// Harness altogether; folded once signed in, so the one code on screen is
+ /// the one to scan from the app.
+ bool? _downloadsOpen;
+
+ bool get _downloadsShown => _downloadsOpen ?? app.isGuest;
+
+ /// The Harness app in its two stores, as codes a phone's camera opens —
+ /// not links: a link clicked here opens the store on this computer, which
+ /// cannot install a phone's app.
+ List<Widget> _downloads() => [
+ Text('Scan with your phone’s camera.', style: _note()),
+ Wrap(
+ spacing: 40,
+ runSpacing: 16,
+ children: const [
+ _StoreCode(
+ name: 'App Store',
+ mark: 'assets/stores/app-store.svg',
+ url: kAppStoreUrl,
+ ),
+ _StoreCode(
+ name: 'Google Play',
+ mark: 'assets/stores/google-play.svg',
+ url: kGooglePlayUrl,
+ ),
+ ],
+ ),
+ ];
+
+ Widget _downloadsClosed() => Wrap(
+ crossAxisAlignment: WrapCrossAlignment.center,
+ spacing: 4,
+ children: [
+ Text('Not on your phone yet?', style: _note()),
+ TextButton(
+ key: const ValueKey('add-phone-show-downloads'),
+ onPressed: () => setState(() => _downloadsOpen = true),
+ child: const Text('Show download codes'),
+ ),
+ ],
+ );
+
+ /// A browser with none of the account's computers to pair through.
+ bool get _connectFirst =>
+ app.viewer != null &&
+ !app.signingIn &&
+ app.currentUser?.email.contains('@') == true;
+
+ String get _pairingTitle {
+ if (app.isGuest) return 'Sign in on this ${_thisComputer()}';
+ if (_target == null && _connectFirst) return 'Connect a computer first';
+ return 'Scan this code with Harness';
+ }
+
+ /// Step 2: what signing in brings — the code, then whether it worked.
+ List<Widget> _pairing(double qrSide) {
if (app.isGuest) {
- // ⚠️ Keep the first line word for word: the phone app's scan screen
- // quotes it, to tell someone who sees it here what to do.
return [
- Text('Sign in to add your phone.', style: _ink()),
- SizedBox(height: row / 2),
Text(
- 'Your phone signs in to the same account when it scans the code.',
- style: _ink(_faint),
+ 'A code appears here. Scan it with Harness on your phone.',
+ style: _note(),
),
];
}
final target = _target;
if (target == null) {
- if (app.viewer != null &&
- !app.signingIn &&
- app.currentUser?.email.contains('@') == true) {
+ if (_connectFirst) {
return [
- Text('Connect a computer to add your phone.', style: _ink()),
- if (widget.onConnectMachine case final connect?) ...[
- SizedBox(height: row),
- TextButton(
- onPressed: () {
- Navigator.of(context).pop();
- connect();
- },
- child: const Text('Connect a machine'),
+ Text(
+ 'Your phone pairs with a computer on your account.',
+ style: _note(),
+ ),
+ if (widget.onConnectMachine case final connect?)
+ Align(
+ alignment: AlignmentDirectional.centerStart,
+ child: TextButton(
+ onPressed: () {
+ Navigator.of(context).pop();
+ connect();
+ },
+ child: const Text('Connect a machine'),
+ ),
),
- ],
];
}
return [
@@ -633,7 +712,7 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
app.currentUser?.email.contains('@') == true
? 'Waiting for Harness on this ${_thisComputer()}…'
: 'Waiting for your account…',
- style: _ink(_faint),
+ style: _note(),
),
];
}
@@ -642,9 +721,10 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
if (!_signInAsked) {
return [
SizedBox(
- height: qrSide + row * 2,
- child: Center(
- child: Text('Preparing your code…', style: _ink(_faint)),
+ height: qrSide,
+ child: Align(
+ alignment: AlignmentDirectional.centerStart,
+ child: Text('Preparing your code…', style: _note()),
),
),
];
@@ -656,61 +736,178 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
signIn: _signIn,
).toString();
return [
- Center(
+ Align(
+ alignment: AlignmentDirectional.centerStart,
// Dimmed once it has done its job, so nobody scans a spent code.
child: Opacity(
opacity: _connected == null && !_stopped ? 1 : .25,
child: PhonePairQr(data: link, side: qrSide),
),
),
- SizedBox(height: row),
- if (_remoteMachineId case final machineId?) ...[
+ if (_remoteMachineId case final machineId?)
Text(
app.stateOf(machineId)?.machine.displayName ?? 'Computer',
- textAlign: TextAlign.center,
- style: _ink(_faint),
+ style: _note(),
),
- SizedBox(height: row),
- ],
// One line, and it is the status too: what to do, then that it worked.
- // The phone's own screen says the rest (Yes — scan to connect).
_status(),
// Not after a sign-in from here: it rebuilt the screen that opened this
// dialog, and that screen is the one the link would open Settings from.
- if (widget.onManageDevices case final manage?
- when !_signedInWhileOpen) ...[
- SizedBox(height: row),
- TextButton(
- key: const ValueKey('add-phone-manage-devices'),
- onPressed: () {
- Navigator.of(context).pop();
- manage();
- },
- child: const Text('Manage devices…'),
+ if (widget.onManageDevices case final manage? when !_signedInWhileOpen)
+ Align(
+ alignment: AlignmentDirectional.centerStart,
+ child: TextButton(
+ key: const ValueKey('add-phone-manage-devices'),
+ onPressed: () {
+ Navigator.of(context).pop();
+ manage();
+ },
+ child: const Text('Manage devices…'),
+ ),
),
- ],
];
}
+ /// A line under a step's title: smaller and quieter than the title.
+ TextStyle _note([Color? color]) =>
+ DesktopChrome.text(color: color ?? _faint, size: 13);
+
Widget _status() {
final connected = _connected;
final (text, color) = connected != null
? ('✓ Connected $connected', grid.AppPalette.online)
: _message != null
? (_message!, Theme.of(context).colorScheme.error)
- : ('Scan with Harness on your iPhone', _faint);
+ // The phone's own button (mobile `set_up_computer.dart`).
+ : ('On your phone, open Harness and tap Pair computer.', _faint);
return Semantics(
liveRegion: true,
child: Text(
text,
key: const ValueKey('add-phone-status'),
- textAlign: TextAlign.center,
- style: _ink(color),
+ style: _note(color),
+ ),
+ );
+ }
+}
+
+/// One step of Add Phone: its number in a quiet circle, its title beside it,
+/// and what the step takes under the title.
+class _AddPhoneStep extends StatelessWidget {
+ const _AddPhoneStep({
+ required this.number,
+ required this.title,
+ this.children = const [],
+ });
+
+ static TextStyle titleStyle() =>
+ DesktopChrome.text(size: 14).copyWith(fontWeight: FontWeight.w600);
+
+ /// The number's circle and the gap after it — where a step's lines start.
+ static const double indent = _circle + 12;
+ static const double _circle = 24;
+
+ final int number;
+
+ /// Beside the number: the step's name — or, folded, the line it folds to.
+ final Widget title;
+ final List<Widget> children;
+
+ @override
+ Widget build(BuildContext context) {
+ return Padding(
+ padding: const EdgeInsets.symmetric(vertical: 14),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ ExcludeSemantics(
+ child: Container(
+ width: _circle,
+ height: _circle,
+ alignment: Alignment.center,
+ decoration: BoxDecoration(
+ color: DesktopChrome.field,
+ shape: BoxShape.circle,
+ ),
+ child: Text(
+ '$number',
+ style: DesktopChrome.metadata().copyWith(
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+ ),
+ ),
+ const SizedBox(width: indent - _circle),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.stretch,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ // Centred on the circle while it is one line; wraps under itself after.
+ ConstrainedBox(
+ constraints: const BoxConstraints(minHeight: _circle),
+ child: Align(
+ alignment: AlignmentDirectional.centerStart,
+ child: title,
+ ),
+ ),
+ for (final child in children) ...[
+ const SizedBox(height: 10),
+ child,
+ ],
+ ],
+ ),
+ ),
+ ],
),
);
}
}
+/// One store's download code: the code, then the store's own mark and name.
+class _StoreCode extends StatelessWidget {
+ const _StoreCode({required this.name, required this.mark, required this.url});
+
+ final String name;
+
+ /// The store's mark, in its own colours whatever the theme — it is the
+ /// store's brand, the way the sign-in buttons' marks are.
+ final String mark;
+ final String url;
+
+ static const double _side = 120;
+
+ @override
+ Widget build(BuildContext context) {
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ QrCodeView(
+ data: url,
+ side: _side,
+ semanticLabel: 'QR code for Harness on $name',
+ ),
+ const SizedBox(height: 8),
+ Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ ExcludeSemantics(
+ child: SvgPicture.asset(mark, width: 18, height: 18),
+ ),
+ const SizedBox(width: 7),
+ Text(
+ name,
+ style: DesktopChrome.control().copyWith(
+ fontWeight: FontWeight.w600,
+ ),
+ ),
+ ],
+ ),
+ ],
+ );
+ }
+}
+
/// "Mac" where the menu says Harness ▸ Add Phone…; the command palette also
/// reaches this dialog on Linux, where "this Mac" would be wrong.
String _thisComputer() =>
diff --git a/desktop/lib/widgets/agent_alert_banners.dart b/desktop/lib/widgets/agent_alert_banners.dart
index 95bd4e6ec..a610ea7d7 100644
--- a/desktop/lib/widgets/agent_alert_banners.dart
+++ b/desktop/lib/widgets/agent_alert_banners.dart
@@ -27,10 +27,15 @@ import 'engine_identity.dart';
/// hit test for the whole subtree before the child is ever asked. Written that
/// way first, the banners were dead to the mouse.
class AgentAlertBanners extends StatelessWidget {
- const AgentAlertBanners({super.key, required this.notifier});
+ const AgentAlertBanners({super.key, required this.notifier, this.footer});
final AppNotifier notifier;
+ /// Under the banners, in the same corner and on the same terms: what else
+ /// the window offers without blocking the work — Add Phone's card
+ /// (`phone_offer_card.dart`).
+ final Widget? footer;
+
@override
Widget build(BuildContext context) {
grid.AppTheme.watch(context);
@@ -41,7 +46,7 @@ class AgentAlertBanners extends StatelessWidget {
listenable: notifier.agentAlerts,
builder: (context, _) {
final alerts = notifier.agentAlerts.alerts;
- if (alerts.isEmpty) return const SizedBox.shrink();
+ if (alerts.isEmpty && footer == null) return const SizedBox.shrink();
return Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.end,
@@ -51,6 +56,7 @@ class AgentAlertBanners extends StatelessWidget {
padding: const EdgeInsets.only(bottom: 8),
child: _Banner(alert: alert, notifier: notifier),
),
+ ?footer,
],
);
},
diff --git a/desktop/lib/widgets/phone_offer_card.dart b/desktop/lib/widgets/phone_offer_card.dart
new file mode 100644
index 000000000..10dd099fe
--- /dev/null
+++ b/desktop/lib/widgets/phone_offer_card.dart
@@ -0,0 +1,104 @@
+import 'package:flutter/material.dart';
+import 'package:harness/shared/theme/app_icons.dart';
+
+import '../shared/theme/app_theme.dart' as grid;
+import '../shared/theme/app_type.dart';
+import '../theme/app_theme.dart';
+
+/// Add Phone offered beside the work rather than over it
+/// ([AppNotifier.phoneOfferShowing]), under the agents' banners in the window's
+/// top-right ([AgentAlertBanners.footer]) and in their shape.
+///
+/// ```
+/// ┌──────────────────────────────────────┐
+/// │ ▯ Your agents in your pocket. × │
+/// │ When an agent needs you, answer │
+/// │ from anywhere. │
+/// │ ( Add Phone ) │
+/// └──────────────────────────────────────┘
+/// ```
+///
+/// The words are the Welcome Tour's phone slide (`setup_tour.dart`, "On the
+/// go"), which a new computer has just shown. The button is named as the phone
+/// names it — "Open Add Phone on your computer" (mobile `set_up_computer.dart`)
+/// — so somebody the phone sent here finds the thing it told them about.
+class PhoneOfferCard extends StatelessWidget {
+ const PhoneOfferCard({
+ super.key,
+ required this.onAdd,
+ required this.onDismiss,
+ });
+
+ /// Add Phone: the code a phone scans — or, for a guest, the sign-in first.
+ final VoidCallback onAdd;
+
+ /// Put away for good on this computer; Add Phone stays in the menu and the
+ /// command palette.
+ final VoidCallback onDismiss;
+
+ @override
+ Widget build(BuildContext context) {
+ grid.AppTheme.watch(context);
+ return Container(
+ key: const Key('phone-offer-card'),
+ width: 288,
+ padding: const EdgeInsets.fromLTRB(12, 10, 8, 12),
+ decoration: BoxDecoration(
+ color: AppColors.surface,
+ borderRadius: BorderRadius.circular(11),
+ border: Border.all(color: AppColors.border),
+ boxShadow: const [
+ BoxShadow(
+ color: Color(0x40000000),
+ blurRadius: 14,
+ offset: Offset(0, 4),
+ ),
+ ],
+ ),
+ child: Row(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ Padding(
+ padding: const EdgeInsets.only(top: 2),
+ child: Icon(AppIcons.smartphone, size: 15, color: AppColors.text),
+ ),
+ const SizedBox(width: 9),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ Text(
+ 'Your agents in your pocket.',
+ style: AppType.body(color: AppColors.text)
+ .copyWith(fontWeight: FontWeight.w600, fontSize: 13),
+ ),
+ const SizedBox(height: 1),
+ Text(
+ 'When an agent needs you, answer from anywhere.',
+ style: AppType.body(color: AppColors.mutedStrong)
+ .copyWith(fontSize: 12),
+ ),
+ const SizedBox(height: 10),
+ FilledButton(
+ key: const Key('phone-offer-add'),
+ onPressed: onAdd,
+ child: const Text('Add Phone'),
+ ),
+ ],
+ ),
+ ),
+ IconButton(
+ key: const Key('phone-offer-dismiss'),
+ icon: const Icon(AppIcons.close, size: 14),
+ color: AppColors.mutedStrong,
+ splashRadius: 14,
+ visualDensity: VisualDensity.compact,
+ tooltip: 'Dismiss',
+ onPressed: onDismiss,
+ ),
+ ],
+ ),
+ );
+ }
+}
diff --git a/desktop/pubspec.yaml b/desktop/pubspec.yaml
index d2d6ca096..4bd03c3af 100644
--- a/desktop/pubspec.yaml
+++ b/desktop/pubspec.yaml
@@ -150,6 +150,9 @@ flutter:
- assets/octicons/
# The marks on the login screen's two buttons (`widgets/sign_in_provider_button.dart`).
- assets/sign-in/
+ # The App Store's and Google Play's marks under Add Phone's download codes
+ # (`widgets/add_phone_dialog.dart`).
+ - assets/stores/
- assets/harness_device_studio.jpg
- assets/devices/
- assets/harness_store_card.jpg
diff --git a/desktop/test/add_phone_dialog_test.dart b/desktop/test/add_phone_dialog_test.dart
index c7c4c3453..2d87d8fcc 100644
--- a/desktop/test/add_phone_dialog_test.dart
+++ b/desktop/test/add_phone_dialog_test.dart
@@ -7,10 +7,12 @@ import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/core/models.dart';
import 'package:harness/core/config.dart';
+import 'package:harness/core/phone_app_links.dart';
import 'package:harness/auth/auth_session.dart';
import 'package:harness/viewer/viewer_services.dart';
import 'package:harness/viewer/viewer_key_store.dart';
import 'package:harness/shared/theme/app_theme.dart' as grid;
+import 'package:harness/shared/widgets/qr_code_view.dart';
import 'package:harness/state/app_state.dart';
import 'package:harness/widgets/add_phone_dialog.dart';
@@ -103,6 +105,15 @@ String _qrData(WidgetTester tester) =>
String _status(WidgetTester tester) =>
tester.widget<Text>(find.byKey(const ValueKey('add-phone-status'))).data!;
+/// What the phone is told while the code waits to be scanned: its own button.
+const _scanIt = 'On your phone, open Harness and tap Pair computer.';
+
+/// The download codes on screen: what each QR in step 1 says.
+Set<String> _storeCodes(WidgetTester tester) => {
+ for (final qr in tester.widgetList<QrCodeView>(find.byType(QrCodeView)))
+ if (qr.data == kAppStoreUrl || qr.data == kGooglePlayUrl) qr.data,
+};
+
void main() {
AppNotifier browserApp() {
final storage = MemoryStore();
@@ -172,6 +183,7 @@ void main() {
);
expect(find.byType(PhonePairQr), findsNothing);
expect(daemon.codes, isEmpty);
+ expect(find.text('Connect a computer first'), findsOneWidget);
await tester.tap(find.widgetWithText(TextButton, 'Connect a machine'));
await tester.pump();
expect(opened, isTrue);
@@ -375,7 +387,7 @@ void main() {
signIn: 'h1',
).toString(),
);
- expect(_status(tester), 'Scan with Harness on your iPhone');
+ expect(_status(tester), _scanIt);
await tester.pump(const Duration(milliseconds: 1500));
expect(daemon.codes, [code, code]);
@@ -441,7 +453,7 @@ void main() {
await tester.pump(const Duration(seconds: 1));
await tester.pump();
expect(daemon.codes, hasLength(2));
- expect(_status(tester), 'Scan with Harness on your iPhone');
+ expect(_status(tester), _scanIt);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
await tester.pump();
});
@@ -487,7 +499,12 @@ void main() {
addTearDown(app.dispose);
final daemon = _FakeDaemon([]);
await _open(tester, app, daemon.call);
- expect(find.text('Sign in to add your phone.'), findsOneWidget);
+ expect(find.textContaining('Sign in on this '), findsOneWidget);
+ expect(
+ find.text('A code appears here. Scan it with Harness on your phone.'),
+ findsOneWidget,
+ );
+ expect(find.byKey(const ValueKey('add-phone-sign-in')), findsOneWidget);
expect(find.byType(PhonePairQr), findsNothing);
expect(daemon.codes, isEmpty);
await tester.sendKeyEvent(LogicalKeyboardKey.escape);
@@ -495,6 +512,121 @@ void main() {
});
});
+ group('the two steps', () {
+ testWidgets(
+ 'a guest gets the app from either store first: codes, not links',
+ (tester) async {
+ final app = _signedInApp()..signedIn = false;
+ addTearDown(app.dispose);
+ await _open(tester, app, _FakeDaemon([]).call);
+ expect(find.text('Get Harness on your phone'), findsOneWidget);
+ expect(find.text('Scan with your phone’s camera.'), findsOneWidget);
+ expect(_storeCodes(tester), {kAppStoreUrl, kGooglePlayUrl});
+ expect(find.text('App Store'), findsOneWidget);
+ expect(find.text('Google Play'), findsOneWidget);
+ // Each code says which store it opens, to a screen reader too.
+ expect(
+ find.bySemanticsLabel('QR code for Harness on App Store'),
+ findsOneWidget,
+ );
+ expect(
+ find.bySemanticsLabel('QR code for Harness on Google Play'),
+ findsOneWidget,
+ );
+ // Step 1 above step 2, and the two codes side by side, apart.
+ expect(
+ tester.getTopLeft(find.text('Get Harness on your phone')).dy,
+ lessThan(
+ tester.getTopLeft(find.textContaining('Sign in on this ')).dy,
+ ),
+ );
+ // Each code over its store's mark and name: the two side by side, 40 apart.
+ final stores = [
+ for (final qr in find.byType(QrCodeView).evaluate())
+ tester.getRect(
+ find
+ .ancestor(
+ of: find.byWidget(qr.widget),
+ matching: find.byType(Column),
+ )
+ .first,
+ ),
+ ];
+ expect(stores, hasLength(2));
+ expect(stores[0].top, stores[1].top);
+ expect(stores[1].left - stores[0].right, 40);
+ expect(
+ find.byKey(const ValueKey('add-phone-show-downloads')),
+ findsNothing,
+ );
+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);
+ await tester.pump();
+ },
+ );
+
+ testWidgets(
+ 'signed in, the download codes fold away, so the one code on screen is '
+ 'the one to scan from the app — and open again on request',
+ (tester) async {
+ final app = _signedInApp();
+ addTearDown(app.dispose);
+ await _open(
+ tester,
+ app,
+ _FakeDaemon(List.filled(4, _failed('NO_INTENT'))).call,
+ );
+ expect(find.text('Scan this code with Harness'), findsOneWidget);
+ expect(find.byType(PhonePairQr), findsOneWidget);
+ expect(_storeCodes(tester), isEmpty);
+ expect(find.text('Not on your phone yet?'), findsOneWidget);
+
+ await tester.tap(
+ find.byKey(const ValueKey('add-phone-show-downloads')),
+ );
+ await tester.pump();
+ expect(_storeCodes(tester), {kAppStoreUrl, kGooglePlayUrl});
+ expect(find.byType(PhonePairQr), findsOneWidget);
+ expect(find.text('Not on your phone yet?'), findsNothing);
+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);
+ await tester.pump();
+ },
+ );
+
+ testWidgets(
+ 'a guest who signs in while it is open: the codes fold, the pairing '
+ 'code comes up',
+ (tester) async {
+ final app = _signedInApp()..signedIn = false;
+ addTearDown(app.dispose);
+ final signIn = _FakeSignIn();
+ await _open(
+ tester,
+ app,
+ _FakeDaemon(List.filled(4, _failed('NO_INTENT'))).call,
+ signInCode: signIn.call,
+ );
+ expect(_storeCodes(tester), hasLength(2));
+ expect(find.byType(PhonePairQr), findsNothing);
+
+ app.signedIn = true;
+ app.notifyListeners();
+ await tester.pump();
+ await tester.pump();
+ expect(_storeCodes(tester), isEmpty);
+ expect(find.text('Scan this code with Harness'), findsOneWidget);
+ expect(find.byType(PhonePairQr), findsOneWidget);
+ // Asked again on landing, so the first code the phone can read signs it in.
+ expect(
+ Uri.splitQueryString(Uri.parse(_qrData(tester)).fragment)['h'],
+ 'h${signIn.minted}',
+ );
+ expect(find.byKey(const ValueKey('add-phone-sign-in')), findsNothing);
+ await tester.sendKeyEvent(LogicalKeyboardKey.escape);
+ await tester.pump();
+ },
+ );
+ });
+
group('the way in', () {
// `createApp` has no profile and no local machine, so the dialog opens
// with nothing to arm — these tests never reach for a real daemon.
diff --git a/desktop/test/agent_alert_banner_widget_test.dart b/desktop/test/agent_alert_banner_widget_test.dart
index 28d436569..41c1eb204 100644
--- a/desktop/test/agent_alert_banner_widget_test.dart
+++ b/desktop/test/agent_alert_banner_widget_test.dart
@@ -116,5 +116,56 @@ void main() {
expect(find.byKey(const Key('agent-alert-banner')), findsNothing);
expect(app.panes, isEmpty);
});
-}
+ testWidgets(
+ 'the footer stands in the same corner, under the banners, with none or some',
+ (tester) async {
+ tester.view.physicalSize = const Size(1200, 900);
+ tester.view.devicePixelRatio = 1;
+ addTearDown(tester.view.reset);
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: Stack(
+ children: [
+ AgentAlertBanners(
+ notifier: app,
+ footer: const SizedBox(
+ key: Key('banner-footer'),
+ width: 288,
+ height: 40,
+ ),
+ ),
+ ],
+ ),
+ ),
+ ),
+ );
+ await tester.pump();
+ // No news: the footer alone, in the top-right.
+ final alone = tester.getRect(find.byKey(const Key('banner-footer')));
+ expect(alone.right, 1200 - 12);
+ expect(alone.top, 12);
+
+ app.agentAlerts.post(
+ AgentAlert(
+ machineId: 'm1',
+ agentId: 'a1',
+ title: 'Respond to greeting',
+ kind: AlertKind.done,
+ at: DateTime.now(),
+ ),
+ );
+ await tester.pump();
+ // News: the banner first, the footer under it, on the same right edge.
+ final banner = tester.getRect(
+ find.byKey(const Key('agent-alert-banner')),
+ );
+ final under = tester.getRect(find.byKey(const Key('banner-footer')));
+ expect(under.top, greaterThan(banner.bottom));
+ expect(under.right, banner.right);
+ await tester.tap(find.byKey(const Key('agent-alert-dismiss')));
+ await tester.pumpAndSettle();
+ },
+ );
+}
diff --git a/desktop/test/phone_offer_test.dart b/desktop/test/phone_offer_test.dart
new file mode 100644
index 000000000..38b1df78b
--- /dev/null
+++ b/desktop/test/phone_offer_test.dart
@@ -0,0 +1,233 @@
+import 'package:flutter/material.dart';
+import 'package:flutter_test/flutter_test.dart';
+import 'package:harness/api/api_client.dart';
+import 'package:harness/auth/auth_session.dart';
+import 'package:harness/core/config.dart';
+import 'package:harness/shared/theme/app_theme.dart' as grid;
+import 'package:harness/state/app_state.dart';
+import 'package:harness/widgets/add_phone_dialog.dart';
+import 'package:harness/widgets/phone_offer_card.dart';
+
+import 'swarm_screen_test.dart' show mount;
+import 'swarm_state_test.dart' show createApp, MemoryStore;
+
+/// This computer's record that Add Phone has had its offer.
+const _done = 'phone_offer_done';
+
+/// The daemon's device list, answered in memory: [listing], or a read that fails.
+class _DevicesApi extends ApiClient {
+ _DevicesApi(this.listing, {this.fails = false})
+ : super(config: AppConfig.dev, session: AuthSession());
+
+ final Map<String, dynamic>? listing;
+ final bool fails;
+
+ @override
+ Future<Map<String, dynamic>?> daemonDevices() async {
+ if (fails) throw StateError('The network connection was lost.');
+ return listing;
+ }
+}
+
+Map<String, Object?> _device(String kind, {bool self = false}) => {
+ 'pub': 'pub-$kind${self ? '-self' : ''}',
+ 'label': kind,
+ 'kind': kind,
+ 'addedAt': 1,
+ 'fingerprint': 'fp',
+ 'self': self,
+};
+
+/// This computer alone on the account, plus [others].
+Map<String, dynamic> _listing(List<Map<String, Object?>> others) => {
+ 'members': [_device('machine', self: true), ...others],
+};
+
+/// "Your agents in your pocket.": Add Phone offered once per computer, as a card beside the work —
+/// at a guest's first launch, or after the first sign-in by hand on an account with no phone.
+void main() {
+ group('the offer', () {
+ test(
+ 'a guest is offered it at the first launch, and only that once',
+ () async {
+ final store = MemoryStore();
+ final app = createApp(store: store)..signedIn = false;
+ addTearDown(app.dispose);
+ await app.offerPhoneForTest(atLaunch: true);
+ expect(app.phoneOfferShowing, isTrue);
+
+ // Put away: gone, and remembered on this computer.
+ app.dropPhoneOffer();
+ expect(app.phoneOfferShowing, isFalse);
+ await pumpEventQueue();
+ expect(store.values[_done], '1');
+
+ // The next launch, as a guest again: nothing.
+ final next = createApp(store: store)..signedIn = false;
+ addTearDown(next.dispose);
+ await next.offerPhoneForTest(atLaunch: true);
+ expect(next.phoneOfferShowing, isFalse);
+ await next.offerPhoneForTest(atLaunch: false);
+ expect(next.phoneOfferShowing, isFalse);
+ },
+ );
+
+ test('a computer that opens signed in has had its first sign-in', () async {
+ final store = MemoryStore();
+ final app = createApp(store: store)
+ ..signedIn = true
+ ..api = _DevicesApi(_listing([]));
+ addTearDown(app.dispose);
+ await app.offerPhoneForTest(atLaunch: true);
+ expect(app.phoneOfferShowing, isFalse);
+ await pumpEventQueue();
+ expect(store.values[_done], '1');
+ // So a later sign-in by hand offers nothing either.
+ await app.offerPhoneForTest(atLaunch: false);
+ expect(app.phoneOfferShowing, isFalse);
+ });
+
+ test('with nowhere to remember it, nothing is offered', () async {
+ // No state file — a test, a fixture — would mean an offer at every launch.
+ final app = createApp()..signedIn = false;
+ addTearDown(app.dispose);
+ await app.offerPhoneForTest(atLaunch: true);
+ expect(app.phoneOfferShowing, isFalse);
+ });
+
+ test(
+ 'the first sign-in by hand offers it on an account with no phone',
+ () async {
+ for (final (name, api) in [
+ ('this computer only', _DevicesApi(_listing([]))),
+ ('another computer', _DevicesApi(_listing([_device('machine')]))),
+ // Unreadable costs one × to put away; a newcomer left without the code costs more.
+ ('a list that cannot be read', _DevicesApi(null, fails: true)),
+ ('no list at all', _DevicesApi(null)),
+ ]) {
+ final store = MemoryStore();
+ final app = createApp(store: store)
+ ..signedIn = true
+ ..api = api;
+ await app.offerPhoneForTest(atLaunch: false);
+ expect(app.phoneOfferShowing, isTrue, reason: name);
+ expect(store.values[_done], isNull, reason: name);
+ app.dispose();
+ }
+ },
+ );
+
+ test('an account with a phone or a browser on it is not offered it, '
+ 'ever again here', () async {
+ for (final kind in ['phone', 'browser']) {
+ final store = MemoryStore();
+ final app = createApp(store: store)
+ ..signedIn = true
+ ..api = _DevicesApi(_listing([_device(kind)]));
+ await app.offerPhoneForTest(atLaunch: false);
+ expect(app.phoneOfferShowing, isFalse, reason: kind);
+ await pumpEventQueue();
+ expect(store.values[_done], '1', reason: kind);
+ app.dispose();
+ }
+ });
+
+ test('a sign-in that is no longer signed in offers nothing', () async {
+ final store = MemoryStore();
+ final app = createApp(store: store)
+ ..signedIn = false
+ ..api = _DevicesApi(_listing([]));
+ addTearDown(app.dispose);
+ await app.offerPhoneForTest(atLaunch: false);
+ expect(app.phoneOfferShowing, isFalse);
+ });
+ });
+
+ group('the card', () {
+ Future<({List<String> taps})> card(WidgetTester tester) async {
+ final taps = <String>[];
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: grid.buildAppTheme(brightness: Brightness.dark),
+ home: Scaffold(
+ body: Align(
+ alignment: Alignment.topRight,
+ child: PhoneOfferCard(
+ onAdd: () => taps.add('add'),
+ onDismiss: () => taps.add('dismiss'),
+ ),
+ ),
+ ),
+ ),
+ );
+ return (taps: taps);
+ }
+
+ testWidgets('says what the Welcome Tour said, and does what it says', (
+ tester,
+ ) async {
+ final (:taps) = await card(tester);
+ expect(find.text('Your agents in your pocket.'), findsOneWidget);
+ expect(
+ find.text('When an agent needs you, answer from anywhere.'),
+ findsOneWidget,
+ );
+ // Named as the phone names it: "Open Add Phone on your computer".
+ expect(find.widgetWithText(FilledButton, 'Add Phone'), findsOneWidget);
+ await tester.tap(find.byKey(const Key('phone-offer-add')));
+ await tester.tap(find.byKey(const Key('phone-offer-dismiss')));
+ expect(taps, ['add', 'dismiss']);
+ });
+ });
+
+ group('on the workspace', () {
+ Future<(AppNotifier, MemoryStore)> offered(WidgetTester tester) async {
+ final store = MemoryStore();
+ final app = createApp(store: store)
+ ..status = AppStatus.authenticated
+ ..signedIn = false;
+ await app.offerPhoneForTest(atLaunch: true);
+ expect(app.phoneOfferShowing, isTrue);
+ await mount(tester, app);
+ return (app, store);
+ }
+
+ testWidgets(
+ 'the card stands in the top-right, and Add Phone opens from it',
+ (tester) async {
+ final (app, store) = await offered(tester);
+ addTearDown(app.dispose);
+ final card = find.byKey(const Key('phone-offer-card'));
+ expect(card, findsOneWidget);
+ // Beside the work, in the agents' banners' corner — not over the middle of the window.
+ final box = tester.getRect(card);
+ expect(box.right, greaterThan(1280 - 40));
+ expect(box.top, lessThan(200));
+
+ await tester.tap(find.byKey(const Key('phone-offer-add')));
+ await tester.pump();
+ await tester.pump(const Duration(milliseconds: 100));
+ expect(find.byType(AddPhoneDialog), findsOneWidget);
+ expect(find.byKey(const Key('phone-offer-card')), findsNothing);
+ await tester.pump();
+ expect(store.values[_done], '1');
+
+ await tester.pumpWidget(const SizedBox());
+ await tester.pump(const Duration(seconds: 5));
+ },
+ );
+
+ testWidgets('× puts it away for good', (tester) async {
+ final (app, store) = await offered(tester);
+ addTearDown(app.dispose);
+ await tester.tap(find.byKey(const Key('phone-offer-dismiss')));
+ await tester.pump();
+ expect(find.byKey(const Key('phone-offer-card')), findsNothing);
+ expect(find.byType(AddPhoneDialog), findsNothing);
+ await tester.pump();
+ expect(store.values[_done], '1');
+ await tester.pumpWidget(const SizedBox());
+ await tester.pump(const Duration(seconds: 5));
+ });
+ });
+}
diff --git a/desktop/test/web_store_banner_test.dart b/desktop/test/web_store_banner_test.dart
index e87ed6d7a..8f0f77ae8 100644
--- a/desktop/test/web_store_banner_test.dart
+++ b/desktop/test/web_store_banner_test.dart
@@ -2,6 +2,7 @@ import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/core/local_key_value_store.dart';
+import 'package:harness/core/phone_app_links.dart';
import 'package:harness/shared/theme/app_theme.dart' as grid;
import 'package:harness/web/shell/web_store_banner.dart';
@@ -53,6 +54,9 @@ void main() {
tearDown(() => debugDefaultTargetPlatformOverride = null);
test('a phone has a store page; a computer has none', () {
+ // The links Add Phone's download codes carry too (`core/phone_app_links.dart`).
+ expect(webStoreLink(TargetPlatform.iOS), Uri.parse(kAppStoreUrl));
+ expect(webStoreLink(TargetPlatform.android), Uri.parse(kGooglePlayUrl));
expect(webStoreLink(TargetPlatform.iOS)!.host, 'apps.apple.com');
expect(
webStoreLink(TargetPlatform.android)!.queryParameters['id'],