import 'package:flutter/material.dart'; import '../link/boundary.dart'; import '../theme/palette.dart'; /// 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 orinPowerOptions(BuildContext context, Boundary b) async { final host = b.hello?['host'] ?? 'the Orin'; final verb = await showDialog( context: context, builder: (context) => AlertDialog( title: Text('Power options: $host'), content: const Text( 'Either way, recording stops and the session is closed cleanly.\n\n' '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: [ TextButton( onPressed: () => Navigator.of(context).pop(), child: const Text('Cancel'), ), OutlinedButton.icon( onPressed: () => Navigator.of(context).pop('reboot'), icon: const Icon(Icons.restart_alt), label: const Text('Reboot'), ), FilledButton.icon( style: FilledButton.styleFrom( backgroundColor: AppTheme.of(context).alarm, foregroundColor: AppTheme.of(context) .onFill(AppTheme.of(context).alarm), ), onPressed: () => Navigator.of(context).pop('poweroff'), icon: const Icon(Icons.power_settings_new), label: const Text('Power off'), ), ], ), ); if (verb == null || !context.mounted) return; final messenger = ScaffoldMessenger.of(context); final id = b.commandOnce(verb, { 'confirm': verb, 'boot_id': b.hello?['boot_id'], }); if (id == null) { messenger.showSnackBar( const SnackBar(content: Text('Not sent: no link to the Orin')), ); return; } final ack = await b.ackFor(id); final what = verb == 'reboot' ? 'rebooting' : 'shutting down'; messenger.showSnackBar( SnackBar( content: Text( ack == null ? 'No reply: the Orin may or may not be $what' : ack.ok ? 'Orin: ${ack.detail}' : 'Refused: ${ack.detail}', ), ), ); }