Orin power options: one confirmation that chooses power off or reboot
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDwfd6Ki8UfG4hK6W5YpJz
This commit is contained in:
+25
-15
@@ -262,9 +262,9 @@ class LinkBar extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
if (b.state == LinkState.up && b.hello?['boot_id'] is String)
|
if (b.state == LinkState.up && b.hello?['boot_id'] is String)
|
||||||
TextButton.icon(
|
TextButton.icon(
|
||||||
onPressed: () => shutDownOrin(context, b),
|
onPressed: () => orinPowerOptions(context, b),
|
||||||
icon: const Icon(Icons.power_settings_new),
|
icon: const Icon(Icons.power_settings_new),
|
||||||
label: const Text('Shut down Orin'),
|
label: const Text('Orin power options'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
@@ -276,33 +276,42 @@ class LinkBar extends StatelessWidget {
|
|||||||
|
|
||||||
/// Confirm, then send `poweroff` once (contracts BOUNDARY.md): it carries this
|
/// Confirm, then send `poweroff` once (contracts BOUNDARY.md): it carries this
|
||||||
/// connection's boot id, so it can never take effect on a later boot.
|
/// connection's boot id, so it can never take effect on a later boot.
|
||||||
Future<void> shutDownOrin(BuildContext context, Boundary b) async {
|
/// Power off or reboot the Orin: one confirmation that is also the choice. Sent once,
|
||||||
|
/// never resent (contracts BOUNDARY.md: the ack cache does not survive the restart).
|
||||||
|
Future<void> orinPowerOptions(BuildContext context, Boundary b) async {
|
||||||
final host = b.hello?['host'] ?? 'the Orin';
|
final host = b.hello?['host'] ?? 'the Orin';
|
||||||
final yes = await showDialog<bool>(
|
final verb = await showDialog<String>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (context) => AlertDialog(
|
builder: (context) => AlertDialog(
|
||||||
title: Text('Shut down $host?'),
|
title: Text('Power options: $host'),
|
||||||
content: const Text(
|
content: const Text(
|
||||||
'Recording stops and the session is closed cleanly. '
|
'Either way, recording stops and the session is closed cleanly.\n\n'
|
||||||
'The Orin stays off until its power button is pressed.',
|
'Power off: the Orin stays off until its power button is pressed.\n'
|
||||||
|
'Reboot: it is back in about a minute; this screen reconnects by itself.',
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () => Navigator.of(context).pop(false),
|
onPressed: () => Navigator.of(context).pop(),
|
||||||
child: const Text('Cancel'),
|
child: const Text('Cancel'),
|
||||||
),
|
),
|
||||||
FilledButton(
|
OutlinedButton.icon(
|
||||||
|
onPressed: () => Navigator.of(context).pop('reboot'),
|
||||||
|
icon: const Icon(Icons.restart_alt),
|
||||||
|
label: const Text('Reboot'),
|
||||||
|
),
|
||||||
|
FilledButton.icon(
|
||||||
style: FilledButton.styleFrom(backgroundColor: Colors.red.shade700),
|
style: FilledButton.styleFrom(backgroundColor: Colors.red.shade700),
|
||||||
onPressed: () => Navigator.of(context).pop(true),
|
onPressed: () => Navigator.of(context).pop('poweroff'),
|
||||||
child: const Text('Shut down'),
|
icon: const Icon(Icons.power_settings_new),
|
||||||
|
label: const Text('Power off'),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (yes != true || !context.mounted) return;
|
if (verb == null || !context.mounted) return;
|
||||||
final messenger = ScaffoldMessenger.of(context);
|
final messenger = ScaffoldMessenger.of(context);
|
||||||
final id = b.commandOnce('poweroff', {
|
final id = b.commandOnce(verb, {
|
||||||
'confirm': 'poweroff',
|
'confirm': verb,
|
||||||
'boot_id': b.hello?['boot_id'],
|
'boot_id': b.hello?['boot_id'],
|
||||||
});
|
});
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
@@ -312,11 +321,12 @@ Future<void> shutDownOrin(BuildContext context, Boundary b) async {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final ack = await b.ackFor(id);
|
final ack = await b.ackFor(id);
|
||||||
|
final what = verb == 'reboot' ? 'rebooting' : 'shutting down';
|
||||||
messenger.showSnackBar(
|
messenger.showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
content: Text(
|
content: Text(
|
||||||
ack == null
|
ack == null
|
||||||
? 'No reply: the Orin may or may not be shutting down'
|
? 'No reply: the Orin may or may not be $what'
|
||||||
: ack.ok
|
: ack.ok
|
||||||
? 'Orin: ${ack.detail}'
|
? 'Orin: ${ack.detail}'
|
||||||
: 'Refused: ${ack.detail}',
|
: 'Refused: ${ack.detail}',
|
||||||
|
|||||||
Reference in New Issue
Block a user