/// 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'), signInRequired('sign_in_required'); 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.signInRequired => 'Sign in to Pipelines again to keep notifications', DeliveryState.unconfigured => 'Starts after the app connects to a server', DeliveryState.off => enabled ? 'Not running' : 'Off', }; }