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): open Add Phone after sign-in when no phone is linked

tonyf387bba42aa5
diff --git a/desktop/lib/screens/swarm_screen.dart b/desktop/lib/screens/swarm_screen.dart
index 57f57b9f4..e89f2d975 100644
--- a/desktop/lib/screens/swarm_screen.dart
+++ b/desktop/lib/screens/swarm_screen.dart
@@ -2916,19 +2916,27 @@ 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, it is the offer a sign-in makes ([_maybeOfferPhone]) — 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.
+ 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
// the callback would be refused. So it is remembered, and opened after.
var manageDevices = false;
- await _dialog(
- () => showAddPhoneDialog(
- context,
- app,
- keymap: _keymap,
- onConnectMachine: () => unawaited(_openMachines()),
- onManageDevices: () => manageDevices = true,
- ),
- );
+ try {
+ await _dialog(
+ () => showAddPhoneDialog(
+ context,
+ app,
+ keymap: _keymap,
+ onConnectMachine: () => unawaited(_openMachines()),
+ onManageDevices: () => manageDevices = true,
+ ),
+ );
+ } finally {
+ app.dropPhoneOffer();
+ }
if (manageDevices && mounted) {
await _settings(SettingsSection.accountDevices);
}
@@ -6361,6 +6369,53 @@ class _SwarmScreenState extends State<SwarmScreen> {
});
}
+ /// Add Phone, opened by itself right after a 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):** "Open
+ /// it and sign in — it shows a code on the screen". A newcomer 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()),
+ );
+ }
+
+ /// ⚠️ 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 {
+ var hasPhone = false;
+ 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;
+ }
+ // Signed out, or something opened meanwhile: not now.
+ if (!mounted || hasPhone || !app.signedIn || !_phoneOfferClear) return;
+ await _addPhone();
+ }
+
bool get _hasConnectedBrowserMachine => app.machineStates.values.any(
(machine) =>
!machine.machine.isShared &&
@@ -6992,6 +7047,7 @@ class _SwarmScreenState extends State<SwarmScreen> {
builder: (context, _) {
grid.AppTheme.watch(context);
_maybeLink();
+ _maybeOfferPhone();
_scheduleWelcomeComposer();
if (app.panes.isEmpty) {
WidgetsBinding.instance.addPostFrameCallback(
diff --git a/desktop/lib/state/app_state.dart b/desktop/lib/state/app_state.dart
index e7194797d..58230f810 100644
--- a/desktop/lib/state/app_state.dart
+++ b/desktop/lib/state/app_state.dart
@@ -988,6 +988,7 @@ class AppNotifier extends ChangeNotifier {
!_disposed && revision == _authRevision;
int _invalidateAuthWork() {
+ _phoneOfferSince = null;
_closeOwnerMemories();
_stopMachineRecovery();
api.resetAccountCache();
@@ -5653,6 +5654,7 @@ class AppNotifier extends ChangeNotifier {
return;
}
_guestDeskRestorePending = false;
+ _phoneOfferSince = DateTime.now();
} catch (error) {
if (!_authWorkCurrent(revision)) return;
status = wasGuest ? AppStatus.authenticated : AppStatus.unauthenticated;
@@ -5680,6 +5682,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 a sign-in by hand ([login]) last finished: Add Phone then opens by itself on an account
+ /// with no phone yet (`screens/swarm_screen.dart` `_maybeOfferPhone`). Null once taken, dropped,
+ /// or signed out.
+ ///
+ /// ⚠️ **The phone's first screen counts on it (owner, 2026-10-08).** It tells a newcomer "Open it
+ /// and sign in — it shows a code on the screen" (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.
+ DateTime? _phoneOfferSince;
+
+ /// How long after the sign-in 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);
+
+ /// A sign-in by hand is waiting to offer Add Phone — see [takePhoneOffer].
+ bool get phoneOfferPending => _phoneOfferSince != null;
+
+ /// Takes the offer: true at most once per sign-in, while still signed in, and only within
+ /// [_phoneOfferWindow] of it.
+ bool takePhoneOffer() {
+ final since = _phoneOfferSince;
+ _phoneOfferSince = null;
+ return since != null &&
+ signedIn &&
+ DateTime.now().difference(since) < _phoneOfferWindow;
+ }
+
+ /// Add Phone was opened — by hand, or by the offer itself: nothing is left to offer. Also how a
+ /// sign-in made from inside Add Phone (its "Sign in…") does not open it a second time once it
+ /// closes.
+ void dropPhoneOffer() => _phoneOfferSince = null;
+
/// Sign in by a QR a signed-in phone approves, then a yes here to the account it names.
Future<void> loginWithPhone() async {
final client = cliLogin;