App: agent notifications on the web (system notification, toast, tab title count)
The app subscribes to the notification stream on every connection and delivers chat_notify notices: a toast when the page is focused (none if that chat is in view), a browser notification titled '<chat>: <title>' plus a '(n)' tab title count when it is not, and on insecure http pages a toast, the title count and a short chime. Low priority posts only when hidden. Replays within an hour show once; ids persist in the ledger. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../notify/agent_notices.dart';
|
||||
|
||||
/// The toast's root, so tests and captures can find it.
|
||||
const agentNoticeToastKey = ValueKey<String>('agent-notice-toast');
|
||||
|
||||
/// How long an agent notice toast stays up. Long enough to read while coming
|
||||
/// back to the window; the Open action keeps it reachable.
|
||||
const agentNoticeToastDuration = Duration(seconds: 10);
|
||||
|
||||
/// The in-app toast for one agent notice: the `<chat>: <title>` headline, the
|
||||
/// message, and an Open action that opens the chat.
|
||||
SnackBar agentNoticeSnackBar(AgentToast toast) => SnackBar(
|
||||
key: agentNoticeToastKey,
|
||||
behavior: SnackBarBehavior.floating,
|
||||
duration: agentNoticeToastDuration,
|
||||
showCloseIcon: true,
|
||||
content: Builder(
|
||||
builder: (context) {
|
||||
final theme = Theme.of(context).snackBarTheme.contentTextStyle;
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
toast.headline,
|
||||
style:
|
||||
theme?.copyWith(fontWeight: FontWeight.w600) ??
|
||||
const TextStyle(fontWeight: FontWeight.w600),
|
||||
),
|
||||
if (toast.message.isNotEmpty)
|
||||
Text(toast.message, maxLines: 4, overflow: TextOverflow.ellipsis),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
action: SnackBarAction(label: 'Open', onPressed: toast.open),
|
||||
);
|
||||
|
||||
/// Shows [toast] through [messenger], after any toast already showing.
|
||||
void showAgentNoticeToast(ScaffoldMessengerState? messenger, AgentToast toast) {
|
||||
messenger?.showSnackBar(agentNoticeSnackBar(toast));
|
||||
}
|
||||
Reference in New Issue
Block a user