Files
pipelines/app/lib/features/notification_service/notification_service_status.dart
T
alan 826e420423 Deliver server notifications from the Android app itself
A native foreground service keeps an authenticated websocket to the
connected server (handed over by the app on every connect), subscribes with
a replay cursor, shows each notification with kind-based channels and
grouping, opens pipelines:// links on tap, and clears taps, dismissals and
cross-device clears. It starts at boot and app launch, backs off and follows
network changes. Settings gains the delivery switch, status, notification
and battery-exemption actions, and the server's optional ntfy_enabled
toggle.
2026-11-01 02:21:22 +00:00

66 lines
2.0 KiB
Dart

/// The background connection's state, in the service's wire words.
enum DeliveryState {
off('off'),
unconfigured('unconfigured'),
connecting('connecting'),
connected('connected'),
reconnecting('reconnecting'),
waitingForNetwork('waiting_for_network');
const DeliveryState(this.wire);
final String wire;
static DeliveryState parse(Object? value) => DeliveryState.values.firstWhere(
(state) => state.wire == value,
orElse: () => DeliveryState.off,
);
}
/// What the native service reports: the switch, whether a server was handed
/// over, the connection, and the two Android permissions delivery relies on.
class NotificationServiceStatus {
const NotificationServiceStatus({
required this.enabled,
required this.configured,
required this.state,
required this.notificationsAllowed,
required this.batteryExempt,
});
static const unsupported = NotificationServiceStatus(
enabled: false,
configured: false,
state: DeliveryState.off,
notificationsAllowed: false,
batteryExempt: false,
);
final bool enabled;
final bool configured;
final DeliveryState state;
final bool notificationsAllowed;
final bool batteryExempt;
factory NotificationServiceStatus.fromMap(Object? raw) {
final map = raw is Map ? raw : const {};
return NotificationServiceStatus(
enabled: map['enabled'] == true,
configured: map['configured'] == true,
state: DeliveryState.parse(map['status']),
notificationsAllowed: map['notificationsAllowed'] == true,
batteryExempt: map['batteryExempt'] == true,
);
}
/// One short line for Settings.
String get label => switch (state) {
DeliveryState.connected => 'Connected',
DeliveryState.connecting => 'Connecting…',
DeliveryState.reconnecting => 'Reconnecting…',
DeliveryState.waitingForNetwork => 'Waiting for a network',
DeliveryState.unconfigured => 'Starts after the app connects to a server',
DeliveryState.off => enabled ? 'Not running' : 'Off',
};
}