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 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; }