Files
pipelines/app/test/features/notification_service/fake_notification_service.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

89 lines
2.4 KiB
Dart

import 'dart:async';
import 'package:pipelines_app/features/notification_service/notification_service_bridge.dart';
/// A scripted background service: records calls and reports [current].
class FakeNotificationService implements NotificationServiceBridge {
FakeNotificationService({NotificationServiceStatus? status})
: current =
status ??
const NotificationServiceStatus(
enabled: true,
configured: true,
state: DeliveryState.connected,
notificationsAllowed: true,
batteryExempt: false,
);
NotificationServiceStatus current;
final calls = <(String, Map<String, Object?>)>[];
final _changes = StreamController<NotificationServiceStatus>.broadcast();
bool batteryGranted = true;
void push(NotificationServiceStatus status) {
current = status;
_changes.add(status);
}
NotificationServiceStatus copy({
bool? enabled,
DeliveryState? state,
bool? notificationsAllowed,
bool? batteryExempt,
}) => NotificationServiceStatus(
enabled: enabled ?? current.enabled,
configured: current.configured,
state: state ?? current.state,
notificationsAllowed: notificationsAllowed ?? current.notificationsAllowed,
batteryExempt: batteryExempt ?? current.batteryExempt,
);
@override
bool get supported => true;
@override
Stream<NotificationServiceStatus> get changes => _changes.stream;
@override
Future<NotificationServiceStatus> status() async {
calls.add(('status', const {}));
return current;
}
@override
Future<NotificationServiceStatus> start() async {
calls.add(('start', const {}));
return current;
}
@override
Future<NotificationServiceStatus> configure({
required String serverId,
required List<String> endpoints,
required String cookie,
}) async {
calls.add((
'configure',
{'serverId': serverId, 'endpoints': endpoints, 'cookie': cookie},
));
return current;
}
@override
Future<NotificationServiceStatus> setEnabled(bool enabled) async {
calls.add(('setEnabled', {'enabled': enabled}));
current = copy(
enabled: enabled,
state: enabled ? DeliveryState.connecting : DeliveryState.off,
);
return current;
}
@override
Future<bool> requestBatteryExemption() async {
calls.add(('requestBatteryExemption', const {}));
if (batteryGranted) current = copy(batteryExempt: true);
return true;
}
}