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(mobile): add back button to sample pick-up header

tonyd30c70f13b6d
diff --git a/mobile/lib/demo/sample_mode.dart b/mobile/lib/demo/sample_mode.dart
index 3003b7576..98e479cc4 100644
--- a/mobile/lib/demo/sample_mode.dart
+++ b/mobile/lib/demo/sample_mode.dart
@@ -39,7 +39,8 @@ export 'sample_runtime.dart' show SampleConnection, SampleRuntime;
/// Opens sample mode over whatever is on screen, and completes when it is left.
///
/// A route of its own on the root navigator, so it is independent of the app under it — signed
-/// out or signed in — and leaving it (Settings → Leave sample, or the system back at its root)
+/// out or signed in — and leaving it (Settings → Leave sample, the back chevron on its first screen,
+/// or the system back at its root)
/// takes all of it away: the harnesses, their timers and its app state.
/// Opens the sample. Completes when it is left — with [SampleExit.setUp] when it was left to set up
/// a real computer (the end card's green button), so the caller can go there next.
diff --git a/mobile/lib/phone/phone_shell.dart b/mobile/lib/phone/phone_shell.dart
index 04432dcaf..25096d5b5 100644
--- a/mobile/lib/phone/phone_shell.dart
+++ b/mobile/lib/phone/phone_shell.dart
@@ -186,11 +186,23 @@ class _PhoneShellState extends State<PhoneShell> with WidgetsBindingObserver {
/// when the root has nothing to close. `canPop` is false at the root even while something there
/// holds the press itself — Find over the terminal, whose own [PopScope] steps out of it — and
/// back used to leave the app from under an open Find because of it.
+ ///
+ /// ⚠️ **Only the app's own root asks.** The sample runs this same shell on a route pushed over the
+ /// welcome screen, and back at ITS root has always left the sample for that screen — so a shell
+ /// with a route under it pops that route instead. `pop`, not `maybePop`: this shell's own
+ /// [PopScope] is what refuses the pop, and asking the route again would land straight back here.
Future<void> _back() async {
final handled = await _navigator.currentState?.maybePop() ?? false;
if (!mounted) return;
_syncCanPop();
- if (!handled && confirmsExitOnBack) await confirmExitApp(context);
+ if (handled || !confirmsExitOnBack) return;
+ final route = ModalRoute.of(context);
+ if (route != null && !route.isFirst) {
+ // Only while it is still on top: a sheet pushed meanwhile is what the next press closes.
+ if (route.isCurrent) Navigator.of(context).pop();
+ return;
+ }
+ await confirmExitApp(context);
}
@override
diff --git a/mobile/lib/phone/welcome/pick_up_page.dart b/mobile/lib/phone/welcome/pick_up_page.dart
index 98cf52e8d..b7ccd7d96 100644
--- a/mobile/lib/phone/welcome/pick_up_page.dart
+++ b/mobile/lib/phone/welcome/pick_up_page.dart
@@ -84,6 +84,7 @@ class _PickUpPageState extends State<PickUpPage> {
builder: (context, _) {
AppTheme.watch(context);
final tty = Tty.of(context);
+ final sample = SampleMode.maybeOf(context);
return Scaffold(
backgroundColor: tty.ground,
body: SafeArea(
@@ -91,16 +92,23 @@ class _PickUpPageState extends State<PickUpPage> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
+ // The sample's way back to the welcome screen it was opened from, placed where the
+ // set-up pages put theirs.
+ if (sample != null)
+ Align(
+ alignment: Alignment.centerLeft,
+ child: TtyBackButton(onPressed: sample.leave),
+ ),
Padding(
- padding: const EdgeInsets.fromLTRB(
+ padding: EdgeInsets.fromLTRB(
Tty.origin,
- 20,
+ sample != null ? 8 : 20,
Tty.origin,
0,
),
child: Text(
// Broken by hand: at 28pt it wraps with "off" alone on the second line.
- SampleMode.maybeOf(context) != null
+ sample != null
? 'Try a sample\nharness'
: 'Pick up where\nyou left off',
key: const ValueKey('pick-up-title'),