Files
pipelines/app/lib/features/attention/notify/page_signals.dart
T
alan 150481b57b 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>
2026-12-02 16:02:47 +00:00

39 lines
1.3 KiB
Dart

import 'page_signals_stub.dart'
if (dart.library.js_interop) 'page_signals_web.dart'
as impl;
import 'agent_notice.dart';
/// The page-level signals agent notices use besides system notifications:
/// whether the operator is looking, a count in the tab title, and a chime.
///
/// On the web these are the document's own visibility and focus, its title,
/// and a Web Audio tone; elsewhere presence follows the app lifecycle and the
/// title count and chime are absent (a native app has no tab title).
abstract interface class PageSignals {
/// Whether the operator is looking at the app right now.
PagePresence get presence;
/// Fires each time the page becomes visible and focused again.
Stream<void> get focused;
/// Shows [count] in the tab title ("(2) Pipelines"); 0 removes it.
void setBadge(int count);
/// Plays a short, quiet tone when the platform allows it.
void chime();
void dispose();
}
PageSignals createPageSignals() => impl.createPageSignals();
/// The title with a leading "(n) " count removed.
String unbadgedTitle(String title) =>
title.replaceFirst(RegExp(r'^\(\d+\) '), '');
/// [title] showing [count]; 0 shows the bare title.
String badgedTitle(String title, int count) {
final base = unbadgedTitle(title);
return count > 0 ? '($count) $base' : base;
}