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.

fix(desktop): add Sign in to Add Phone for guests

tony59a74c65a3b4
diff --git a/desktop/lib/screens/login_screen.dart b/desktop/lib/screens/login_screen.dart
index ac16e0809..5a88a07f4 100644
--- a/desktop/lib/screens/login_screen.dart
+++ b/desktop/lib/screens/login_screen.dart
@@ -55,7 +55,26 @@ class LoginScreen extends StatelessWidget {
/// 2026-09-23).
final VoidCallback? onClose;
- const LoginScreen({super.key, required this.notifier, this.onClose});
+ /// Why this sign-in, now — said in place of the pitch under the title. Null
+ /// keeps the pitch. See [showSignInSheet].
+ final String? reason;
+
+ /// Offers Scan with your phone where this app can sign in that way. False
+ /// where the person is here to add a phone: that way in needs a phone that
+ /// is already signed in.
+ final bool offerPhone;
+
+ const LoginScreen({
+ super.key,
+ required this.notifier,
+ this.onClose,
+ this.reason,
+ this.offerPhone = true,
+ });
+
+ static const _pitch =
+ 'At home, at the office, in the cloud — every machine you '
+ 'sign in to becomes part of one desk, here.';
/// Matches `EnvironmentSetupScreen` (560) and `LinkMachineScreen` (460) —
/// wide enough for the diagram to breathe, still centred at the 880×560
@@ -145,8 +164,7 @@ class LoginScreen extends StatelessWidget {
),
const SizedBox(height: 8),
Text(
- 'At home, at the office, in the cloud — every machine you '
- 'sign in to becomes part of one desk, here.',
+ reason ?? _pitch,
textAlign: TextAlign.center,
style: Theme.of(context)
.textTheme
@@ -161,6 +179,7 @@ class LoginScreen extends StatelessWidget {
notifier: notifier,
waiting: waiting,
compact: compact,
+ offerPhone: offerPhone,
),
if (notifier.lastError != null &&
!notifier.sessionExpired) ...[
@@ -248,8 +267,7 @@ class LoginScreen extends StatelessWidget {
maxWidth: 650,
),
child: Text(
- 'At home, at the office, in the cloud — every machine you '
- 'sign in to becomes part of one desk, here.',
+ reason ?? _pitch,
textAlign: TextAlign.center,
style: grid.AppType.body().copyWith(
fontSize: 16,
@@ -274,6 +292,7 @@ class LoginScreen extends StatelessWidget {
waiting: waiting,
compact: compact,
prominent: true,
+ offerPhone: offerPhone,
),
),
if (notifier.lastError != null &&
@@ -319,6 +338,7 @@ class _Action extends StatefulWidget {
required this.waiting,
required this.compact,
this.prominent = false,
+ this.offerPhone = true,
});
final AppNotifier notifier;
@@ -330,6 +350,9 @@ class _Action extends StatefulWidget {
final bool compact;
final bool prominent;
+ /// See [LoginScreen.offerPhone].
+ final bool offerPhone;
+
@override
State<_Action> createState() => _ActionState();
}
@@ -409,7 +432,8 @@ class _ActionState extends State<_Action> {
otherWays: [
// The other way in: a QR a phone already signed in scans and approves. Not on a
// web page at phone width — that page IS the phone.
- if (notifier.canSignInWithPhone &&
+ if (widget.offerPhone &&
+ notifier.canSignInWithPhone &&
!(kIsWeb && MediaQuery.sizeOf(context).width < 720)) ...[
if (!widget.compact) const OrDivider(),
OutlinedButton.icon(
@@ -799,7 +823,10 @@ class _AppMark extends StatelessWidget {
/// asked for at the moment the person reaches for it. This is [LoginScreen]
/// ITSELF on a route above the desk, not a smaller copy: a second layout was a
/// second sign-in to keep in step, and it read as the screen having been
-/// redesigned. [reason] is accepted for the call sites that have one to give.
+/// redesigned. [reason], when a call site has one, takes the place of the
+/// pitch under the title: the person reached for something, and this says
+/// what the sign-in is for. [offerPhone] false leaves out Scan with your phone
+/// — see [LoginScreen.offerPhone].
///
/// Closes itself the moment the account arrives — [AppNotifier.signedIn] flips
/// — or when the person cancels, whichever comes first. Returns whether the
@@ -809,6 +836,7 @@ Future<bool> showSignInSheet(
BuildContext context,
AppNotifier notifier, {
String? reason,
+ bool offerPhone = true,
}) async {
if (notifier.signedIn) return true;
final completed = await Navigator.of(context).push<bool>(
@@ -817,18 +845,26 @@ Future<bool> showSignInSheet(
barrierDismissible: false,
transitionDuration: Duration.zero,
reverseTransitionDuration: Duration.zero,
- pageBuilder: (_, _, _) =>
- _SignInSheet(notifier: notifier, reason: reason),
+ pageBuilder: (_, _, _) => _SignInSheet(
+ notifier: notifier,
+ reason: reason,
+ offerPhone: offerPhone,
+ ),
),
);
return completed ?? notifier.signedIn;
}
class _SignInSheet extends StatefulWidget {
- const _SignInSheet({required this.notifier, this.reason});
+ const _SignInSheet({
+ required this.notifier,
+ this.reason,
+ this.offerPhone = true,
+ });
final AppNotifier notifier;
final String? reason;
+ final bool offerPhone;
@override
State<_SignInSheet> createState() => _SignInSheetState();
@@ -889,7 +925,12 @@ class _SignInSheetState extends State<_SignInSheet> {
},
child: ListenableBuilder(
listenable: notifier,
- builder: (_, _) => LoginScreen(notifier: notifier, onClose: _dismiss),
+ builder: (_, _) => LoginScreen(
+ notifier: notifier,
+ onClose: _dismiss,
+ reason: widget.reason,
+ offerPhone: widget.offerPhone,
+ ),
),
);
}
diff --git a/desktop/lib/widgets/add_phone_dialog.dart b/desktop/lib/widgets/add_phone_dialog.dart
index a0762c1f8..8ab7516de 100644
--- a/desktop/lib/widgets/add_phone_dialog.dart
+++ b/desktop/lib/widgets/add_phone_dialog.dart
@@ -8,6 +8,7 @@ import 'package:flutter/material.dart';
import '../shared/widgets/qr_code_view.dart';
import '../api/api_client.dart';
+import '../screens/login_screen.dart' show showSignInSheet;
import '../shared/theme/app_theme.dart' as grid;
import '../shortcuts/app_keymap.dart';
import '../state/app_state.dart';
@@ -302,6 +303,21 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
bool _signInAsked = false;
Timer? _signInTimer;
+ /// Bumped to start the renewal over (see [_restartSignIn]): an answer to an
+ /// older ask is dropped, so only one chain of renewals ever runs.
+ int _signInRound = 0;
+
+ /// This computer had no account while the dialog was open, so the sign-in
+ /// code it asked for then was refused. When the account lands it asks again
+ /// at once — see [_appChanged].
+ bool _awaitingAccount = false;
+
+ /// The account landed while the dialog was open — see [_appChanged].
+ bool _signedInWhileOpen = false;
+
+ /// The sign-in sheet raised from here is up — see [_signInHere].
+ bool _signingIn = false;
+
/// No pairing to be had from this daemon — asking stopped for good.
bool _stopped = false;
String? _connected;
@@ -315,6 +331,7 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
@override
void initState() {
super.initState();
+ _awaitingAccount = app.isGuest;
app.addListener(_appChanged);
_syncLoop();
unawaited(_renewSignIn());
@@ -340,10 +357,43 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
void _appChanged() {
if (_closed) return;
+ if (app.isGuest) {
+ _awaitingAccount = true;
+ } else if (_awaitingAccount && _target != null) {
+ // Signed in while the dialog was open. The code asked for before was
+ // refused, and the next renewal is a minute off: without asking now,
+ // the first QR the phone can scan has no sign-in in it, and the phone
+ // falls back to an emailed code.
+ _awaitingAccount = false;
+ _signedInWhileOpen = true;
+ _restartSignIn();
+ }
setState(() {});
_syncLoop();
}
+ /// A guest's way in, raised over this dialog rather than instead of it: the
+ /// sheet closes itself when the account lands, and the QR comes up here.
+ ///
+ /// Without Scan with your phone: that way in needs a phone already signed
+ /// in, and the person here is adding one.
+ Future<void> _signInHere() async {
+ if (_signingIn || _closed) return;
+ _signingIn = true;
+ try {
+ await showSignInSheet(
+ context,
+ app,
+ reason:
+ 'Sign in to add your phone. Your phone signs in to the same '
+ 'account when it scans the code.',
+ offerPhone: false,
+ );
+ } finally {
+ _signingIn = false;
+ }
+ }
+
/// Who and what the QR is for, or null while there is nothing to show yet.
///
/// The machine is the one the phone will see in its own list: this
@@ -351,7 +401,9 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
/// daemon serves this computer under the account's `machineId` then — see
/// `AppNotifier._followLocalMachineId`).
({String email, String machineId})? get _target {
- if (app.isGuest) return null;
+ // Mid sign-in the daemon moves onto the account, and this computer's id
+ // with it (`AppNotifier.login`): nothing to show or arm until it lands.
+ if (app.isGuest || app.signingIn) return null;
final email = app.currentUser?.email.trim();
final machineId = app.viewer == null
? app.localMachineState?.machine.machineId
@@ -445,14 +497,16 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
/// Ask for a sign-in code, put it in the QR, and ask again before it runs
/// out — for as long as the QR is on screen. A failure is not retried
/// sooner: the QR works without one, and the next renewal tries again.
+ /// The one exception is an account arriving — see [_restartSignIn].
Future<void> _renewSignIn() async {
+ final round = _signInRound;
({String code, Duration ttl})? next;
try {
next = await widget.signInCode();
} catch (_) {
next = null;
}
- if (_closed || !mounted) return;
+ if (_closed || !mounted || round != _signInRound) return;
setState(() {
_signIn = next?.code;
_signInAsked = true;
@@ -468,6 +522,17 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
);
}
+ /// The renewal from the top, now: the pending one is cancelled, an ask
+ /// still in flight is dropped when it lands, and the QR waits on
+ /// "Preparing your code…" for the new code. The caller rebuilds.
+ void _restartSignIn() {
+ _signInTimer?.cancel();
+ _signInRound++;
+ _signIn = null;
+ _signInAsked = false;
+ unawaited(_renewSignIn());
+ }
+
void _say(String message, {bool sticky = false}) => setState(() {
_message = message;
_sticky = sticky;
@@ -517,18 +582,38 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
),
),
),
- actions: [TextButton(onPressed: _close, child: const Text('Done'))],
+ actions: [
+ TextButton(onPressed: _close, child: const Text('Done')),
+ if (app.isGuest)
+ FilledButton(
+ key: const ValueKey('add-phone-sign-in'),
+ autofocus: true,
+ onPressed: () => unawaited(_signInHere()),
+ child: const Text('Sign in…'),
+ ),
+ ],
),
);
}
List<Widget> _body(double qrSide, double row) {
if (app.isGuest) {
- return [Text('Sign in to add your phone.', style: _ink())];
+ // ⚠️ 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),
+ ),
+ ];
}
final target = _target;
if (target == null) {
- if (app.viewer != null && app.currentUser?.email.contains('@') == true) {
+ if (app.viewer != null &&
+ !app.signingIn &&
+ app.currentUser?.email.contains('@') == true) {
return [
Text('Connect a computer to add your phone.', style: _ink()),
if (widget.onConnectMachine case final connect?) ...[
@@ -590,7 +675,10 @@ class _AddPhoneDialogState extends State<AddPhoneDialog> {
// 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(),
- if (widget.onManageDevices case final manage?) ...[
+ // 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'),