150481b57b
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>
47 lines
1.2 KiB
Dart
47 lines
1.2 KiB
Dart
import 'dart:async';
|
|
|
|
import 'package:flutter/widgets.dart';
|
|
|
|
import 'agent_notice.dart';
|
|
import 'page_signals.dart';
|
|
|
|
/// Presence from the app lifecycle: resumed is focused, inactive is visible
|
|
/// without focus, anything else is hidden. There is no tab title to badge and
|
|
/// no chime; the toast and the system notification carry the notice.
|
|
class LifecyclePageSignals with WidgetsBindingObserver implements PageSignals {
|
|
LifecyclePageSignals() {
|
|
WidgetsBinding.instance.addObserver(this);
|
|
}
|
|
|
|
final _focused = StreamController<void>.broadcast();
|
|
|
|
@override
|
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
|
if (state == AppLifecycleState.resumed) _focused.add(null);
|
|
}
|
|
|
|
@override
|
|
PagePresence get presence => switch (WidgetsBinding.instance.lifecycleState) {
|
|
null || AppLifecycleState.resumed => PagePresence.focused,
|
|
AppLifecycleState.inactive => PagePresence.visible,
|
|
_ => PagePresence.hidden,
|
|
};
|
|
|
|
@override
|
|
Stream<void> get focused => _focused.stream;
|
|
|
|
@override
|
|
void setBadge(int count) {}
|
|
|
|
@override
|
|
void chime() {}
|
|
|
|
@override
|
|
void dispose() {
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
unawaited(_focused.close());
|
|
}
|
|
}
|
|
|
|
PageSignals createPageSignals() => LifecyclePageSignals();
|