diff --git a/app/lib/features/chat/shell/chat_shell_dismiss.dart b/app/lib/features/chat/shell/chat_shell_dismiss.dart index 22006dc2..d1f013cf 100644 --- a/app/lib/features/chat/shell/chat_shell_dismiss.dart +++ b/app/lib/features/chat/shell/chat_shell_dismiss.dart @@ -4,16 +4,11 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../ui/adaptive/segmented_bar_overflow.dart'; -import '../ui/sessions/chat_adaptive.dart'; import 'chat_shell_runs_controller.dart'; const String chatShellDismissLabel = 'Dismiss'; const String chatShellDismissAllLabel = 'Dismiss all finished commands'; -const String chatShellUndoLabel = 'Undo'; -/// How long the Undo notice stays. The server keeps a dismissed run -/// restorable for longer (protocol ChatShellRunUndoWindow, 30 s). -const Duration chatShellUndoDuration = Duration(seconds: 5); /// The card's Dismiss button, offered once the command has finished. class ChatShellDismissButton extends StatelessWidget { @@ -62,9 +57,8 @@ Widget chatShellDismissAllMenuAction({required VoidCallback onPressed}) => child: const SizedBox.shrink(), ); -/// Dismisses [ids] for every client of the chat, then offers Undo for -/// [chatShellUndoDuration]: a Material SnackBar, or a transient Cupertino -/// notice floating over the conversation. A refusal goes to [onRefused]. +/// Dismisses [ids] for every client of the chat. The card simply goes away; +/// no notice is shown. A refusal goes to [onRefused]. Future dismissChatShellRuns( BuildContext context, ChatShellRunsController controller, @@ -73,94 +67,6 @@ Future dismissChatShellRuns( void Function(String refusal)? onRefused, }) async { if (ids.isEmpty) return; - final messenger = cupertino ? null : ScaffoldMessenger.maybeOf(context); - final overlay = Overlay.maybeOf(context, rootOverlay: true); final refusal = await controller.dismiss(ids); - if (refusal != null) { - onRefused?.call(refusal); - return; - } - void show(String message, {VoidCallback? onUndo}) { - if (messenger != null) { - messenger.hideCurrentSnackBar(); - messenger.showSnackBar( - SnackBar( - key: const Key('chat-shell-undo-notice'), - content: Text(message), - duration: chatShellUndoDuration, - // An action would otherwise keep it until dismissed by hand. - persist: false, - action: onUndo == null - ? null - : SnackBarAction(label: chatShellUndoLabel, onPressed: onUndo), - ), - ); - } else if (overlay != null && overlay.mounted) { - _showOverlayNotice(overlay, message, onUndo); - } - } - - show( - ids.length == 1 ? 'Command dismissed' : '${ids.length} commands dismissed', - onUndo: () => unawaited(() async { - final failed = await controller.restore(ids); - if (failed != null) show("Couldn't restore: $failed"); - }()), - ); -} - -OverlayEntry? _overlayNotice; -Timer? _overlayTimer; - -void _hideOverlayNotice() { - _overlayTimer?.cancel(); - _overlayTimer = null; - final entry = _overlayNotice; - _overlayNotice = null; - if (entry != null && entry.mounted) entry.remove(); -} - -void _showOverlayNotice( - OverlayState overlay, - String message, - VoidCallback? onUndo, -) { - _hideOverlayNotice(); - final entry = OverlayEntry( - builder: (context) => Positioned( - left: 16, - right: 16, - bottom: 16, - child: SafeArea( - child: Semantics( - container: true, - explicitChildNodes: true, - liveRegion: true, - child: KeyedSubtree( - key: const Key('chat-shell-undo-notice'), - child: onUndo == null - ? CupertinoPopupSurface( - child: Padding( - padding: const EdgeInsets.all(16), - child: DefaultTextStyle.merge( - style: CupertinoTheme.of(context).textTheme.textStyle, - child: Text(message), - ), - ), - ) - : ChatUndoBar( - message: message, - onUndo: () { - _hideOverlayNotice(); - onUndo(); - }, - ), - ), - ), - ), - ), - ); - _overlayNotice = entry; - overlay.insert(entry); - _overlayTimer = Timer(chatShellUndoDuration, _hideOverlayNotice); + if (refusal != null) onRefused?.call(refusal); } diff --git a/app/notes/chat-shell-commands.md b/app/notes/chat-shell-commands.md index 6bdb51f8..384f6850 100644 --- a/app/notes/chat-shell-commands.md +++ b/app/notes/chat-shell-commands.md @@ -245,3 +245,7 @@ change, and `{session_id, run_id, output, offset, end}` for output chunks. Not verified: a live server and browser session running a real command end to end. The Go websocket tests cover the server with real processes, and the browser captures use the fixture channel. Mobile devices were not tested. + +**Update:** dismissing no longer shows a notice or Undo; the card simply +goes away (operator request). The server still accepts `chat_shell_restore` +within its 30 s window, but the app no longer offers it. diff --git a/app/test/features/chat/shell/chat_shell_dismiss_test.dart b/app/test/features/chat/shell/chat_shell_dismiss_test.dart index 4d3c1e33..f7ffa701 100644 --- a/app/test/features/chat/shell/chat_shell_dismiss_test.dart +++ b/app/test/features/chat/shell/chat_shell_dismiss_test.dart @@ -28,7 +28,7 @@ void main() { for (final cupertino in [false, true]) { final host = cupertino ? 'Cupertino' : 'Material'; - testWidgets('$host: Dismiss removes a finished card and Undo restores it', ( + testWidgets('$host: Dismiss removes a finished card without a notice', ( tester, ) async { gateway.runs = [finished('run_done'), shellRecord('run_live')]; @@ -53,34 +53,9 @@ void main() { ]); expect(card(), findsOneWidget); expect(find.text('\$ true'), findsNothing); - expect(notice, findsOneWidget); - expect(find.text('Command dismissed'), findsOneWidget); - - await tester.tap(find.text('Undo')); - await tester.pump(); - await tester.pump(const Duration(milliseconds: 300)); - expect(gateway.bodies('chat_shell_restore').single['run_ids'], [ - 'run_done', - ]); - expect(card(), findsNWidgets(2)); - expect(find.text('\$ true'), findsOneWidget); - }); - - testWidgets('$host: the Undo notice goes away after five seconds', ( - tester, - ) async { - gateway.runs = [finished('run_done')]; - await tester.pumpWidget(shellThread(gateway, cupertino: cupertino)); - await tester.pump(); - await tester.tap(dismiss); - await tester.pump(); - await tester.pump(const Duration(milliseconds: 300)); - expect(notice, findsOneWidget); - await tester.pump(const Duration(seconds: 5)); - await tester.pumpAndSettle(); expect(notice, findsNothing); - expect(card(), findsNothing); - expect(gateway.bodies('chat_shell_restore'), isEmpty); + expect(find.text('Command dismissed'), findsNothing); + expect(find.text('Undo'), findsNothing); }); } @@ -137,13 +112,8 @@ void main() { 'run_b', ]); expect(card(), findsOneWidget); - expect(find.text('2 commands dismissed'), findsOneWidget); - // Let the SnackBar finish entering. - await tester.pump(const Duration(milliseconds: 500)); - await tester.tap(find.text('Undo')); - await tester.pump(); - await tester.pump(const Duration(milliseconds: 300)); - expect(card(), findsNWidgets(3)); + expect(find.text('2 commands dismissed'), findsNothing); + expect(find.text('Undo'), findsNothing); }); testWidgets('another client dismissing a run removes its card here', ( @@ -156,7 +126,7 @@ void main() { gateway.emitDismissed('run_done'); await tester.pump(); expect(card(), findsNothing); - // Its Undo there restores it here too, output read back. + // A restore there brings it back here too, output read back. gateway.emitRun(finished('run_done')); await tester.pump(); await tester.pump();