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:
@@ -71,6 +71,11 @@ class NotificationController extends ChangeNotifier {
|
||||
/// True once the persisted ledger and the platform facts have been read.
|
||||
bool get loaded => _loaded;
|
||||
|
||||
/// Completes once [load] has read the ledger, so a caller can claim agent
|
||||
/// notices against the persisted record rather than an empty one.
|
||||
Future<void> get ready => _ready.future;
|
||||
final Completer<void> _ready = Completer<void>();
|
||||
|
||||
/// Whether the operator has ever been asked for permission.
|
||||
bool get asked => _ledger.asked;
|
||||
|
||||
@@ -102,6 +107,7 @@ class NotificationController extends ChangeNotifier {
|
||||
_announced.clear();
|
||||
_permission = notificationStateOf(bridge.environment());
|
||||
_loaded = true;
|
||||
if (!_ready.isCompleted) _ready.complete();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
@@ -254,6 +260,17 @@ class NotificationController extends ChangeNotifier {
|
||||
return posted;
|
||||
}
|
||||
|
||||
/// Records agent notification [id] as shown on this device and reports
|
||||
/// whether it is new. Only the first claim of an id, in this session or any
|
||||
/// earlier one (the ledger persists), returns true, so a replay after a
|
||||
/// reload or reconnect is shown once. Call it after [load] has completed.
|
||||
bool claimAgentNotice(String id, DateTime now) {
|
||||
if (_disposed || id.isEmpty || _ledger.hasShownAgent(id)) return false;
|
||||
_ledger = _ledger.recordingAgent(id, now);
|
||||
unawaited(_persist(_ledger));
|
||||
return true;
|
||||
}
|
||||
|
||||
/// Writes the ledger without ever throwing into the caller's frame, one write
|
||||
/// at a time so their order matches the calls.
|
||||
Future<void> _persist(NotificationLedger ledger) {
|
||||
|
||||
Reference in New Issue
Block a user