feat(app): deliver live attention notifications and show permission in Settings

This commit is contained in:
2026-10-22 02:33:12 +01:00
parent e68d598a41
commit e7165f7722
8 changed files with 216 additions and 1 deletions
@@ -4,6 +4,8 @@ import 'package:flutter/widgets.dart';
import '../../../core/api_gateway.dart';
import '../domain/attention_models.dart';
import '../notify/notification_controller.dart';
import '../notify/notification_ledger.dart';
import '../runtime/attention_controller.dart';
import '../runtime/attention_store.dart';
import 'needs_you_bell.dart';
@@ -25,6 +27,7 @@ class NeedsYouRunsHeading extends StatefulWidget {
this.store = const SharedPreferencesAttentionStore(),
this.now,
this.cupertino,
this.notifications,
});
/// The run summaries the Runs destination already holds.
@@ -48,6 +51,10 @@ class NeedsYouRunsHeading extends StatefulWidget {
/// Forces the native host in tests and fixtures.
final bool? cupertino;
/// The app-level notification capability. Absent in fixtures that only draw
/// the bell, so no store or platform bridge is touched there.
final NotificationController? notifications;
@override
State<NeedsYouRunsHeading> createState() => _NeedsYouRunsHeadingState();
}
@@ -65,12 +72,44 @@ class _NeedsYouRunsHeadingState extends State<NeedsYouRunsHeading> {
_attention.seedRows(widget.rows);
unawaited(_attention.load());
_listen();
final notifications = widget.notifications;
if (notifications != null) {
notifications.onOpenRun = _openRunById;
unawaited(notifications.load().then((_) => _publish()));
}
}
/// A notification names only the run id; opening it follows the same route
/// rule as a bell row. Dismissal is not implied by a notice tap.
void _openRunById(int id) {
for (final entry in _attention.entries) {
if (entry.runId == id) {
widget.onOpen(entry);
return;
}
}
}
/// Publishes the transitions the model accumulated against the rows and the
/// dismissals that are in force right now. Idempotent, so the whole list is
/// safe to pass after every read or pushed frame.
void _publish() {
final notifications = widget.notifications;
if (notifications == null) return;
notifications.publishTransitions(
_attention.transitions,
qualifying: notificationQualifyingKeys(_attention.rows),
dismissed: _attention.dismissed,
);
}
void _listen() {
_frames = widget.frames
.where((frame) => frame['type'] == 'run_event')
.listen(_attention.observeFrame);
.listen((frame) {
_attention.observeFrame(frame);
_publish();
});
}
@override
@@ -84,10 +123,12 @@ class _NeedsYouRunsHeadingState extends State<NeedsYouRunsHeading> {
if (oldWidget.syncToken != widget.syncToken) {
_attention.resetForReconnect();
_attention.seedRows(widget.rows, reconnect: true);
_publish();
return;
}
if (!identical(oldWidget.rows, widget.rows)) {
_attention.seedRows(widget.rows);
_publish();
}
}
+6
View File
@@ -1,6 +1,7 @@
import 'package:flutter/widgets.dart';
import '../../core/api_gateway.dart';
import '../attention/notify/notification_controller.dart';
import '../attention/runtime/attention_store.dart';
import 'data/runs_repository.dart';
import 'ui/run_detail_view.dart';
@@ -24,6 +25,7 @@ class RunsScreen extends StatefulWidget {
this.onBack,
this.attentionStore = const SharedPreferencesAttentionStore(),
this.attentionNow,
this.notifications,
});
final ApiGateway gateway;
@@ -47,6 +49,9 @@ class RunsScreen extends StatefulWidget {
final AttentionStore attentionStore;
final DateTime Function()? attentionNow;
/// App-level notification delivery for live attention transitions.
final NotificationController? notifications;
@override
State<RunsScreen> createState() => _RunsScreenState();
}
@@ -128,6 +133,7 @@ class _RunsScreenState extends State<RunsScreen> {
syncToken: widget.syncToken,
attentionStore: widget.attentionStore,
attentionNow: widget.attentionNow,
notifications: widget.notifications,
),
),
),
+6
View File
@@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import '../../../core/api_gateway.dart';
import '../../../ui/adaptive/host.dart';
import '../../attention/notify/notification_controller.dart';
import '../../attention/runtime/attention_store.dart';
import '../../attention/ui/needs_you_runs_heading.dart';
import '../domain/run_models.dart';
@@ -17,6 +18,7 @@ class RunsList extends StatelessWidget {
this.syncToken = 0,
this.attentionStore = const SharedPreferencesAttentionStore(),
this.attentionNow,
this.notifications,
});
final RunsController controller;
@@ -32,6 +34,9 @@ class RunsList extends StatelessWidget {
/// Deterministic local-day clock for the attention window.
final DateTime Function()? attentionNow;
/// App-level notification delivery; absent in list-only fixtures.
final NotificationController? notifications;
@override
Widget build(BuildContext context) {
if (controller.loading && controller.runs.isEmpty) {
@@ -58,6 +63,7 @@ class RunsList extends StatelessWidget {
syncToken: syncToken,
store: attentionStore,
now: attentionNow,
notifications: notifications,
),
),
),
@@ -0,0 +1,33 @@
import 'package:flutter/widgets.dart';
import '../attention/notify/notification_controller.dart';
import '../attention/ui/notification_permission_tile.dart';
/// The Settings entry for the browser notification permission.
///
/// It reads the platform's own state from the app-level
/// [NotificationController] and asks only when the operator presses the tile's
/// Enable action. The controller is shared with the Runs attention surface, so
/// the permission shown here is the one that gates the live notices.
class SettingsNotificationsSection extends StatelessWidget {
const SettingsNotificationsSection({
super.key,
required this.controller,
});
final NotificationController controller;
@override
Widget build(BuildContext context) => AnimatedBuilder(
animation: controller,
builder: (context, _) => NotificationPermissionTile(
state: controller.permission,
asked: controller.asked,
onRequest: () {
// The platform answer updates the controller; the AnimationBuilder above
// redraws the tile with its own words.
controller.requestPermission();
},
),
);
}
@@ -4,10 +4,12 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import '../../core/transport/pipelines_client.dart' as transport;
import '../attention/notify/notification_controller.dart';
import 'default_endpoint.dart';
import 'settings_controller.dart';
import 'settings_controls.dart';
import 'settings_layout.dart';
import 'settings_notifications_section.dart';
import 'settings_sections.dart';
import 'settings_store.dart';
import 'settings_templates_section.dart';
@@ -29,6 +31,7 @@ class SettingsScreen extends StatefulWidget {
this.ping,
this.embedded = false,
this.onOpenTemplates,
this.notifications,
});
final transport.PipelinesClient client;
@@ -50,6 +53,9 @@ class SettingsScreen extends StatefulWidget {
/// without a dead row that would go nowhere.
final VoidCallback? onOpenTemplates;
/// The app-level notification capability; absent in connection-only fixtures.
final NotificationController? notifications;
@override
State<SettingsScreen> createState() => _SettingsScreenState();
}
@@ -127,6 +133,14 @@ class _SettingsScreenState extends State<SettingsScreen> {
controller: _controller,
workspaceField: _workspaceField,
),
if (widget.notifications != null) ...<Widget>[
const SizedBox(height: settingsSectionGap),
const _SectionTitle('Notifications'),
const SizedBox(height: settingsTitleGap),
SettingsNotificationsSection(
controller: widget.notifications!,
),
],
if (widget.onOpenTemplates != null) ...<Widget>[
const SizedBox(height: settingsSectionGap),
const _SectionTitle('Templates'),