Add status command receiver

This commit is contained in:
problematicconsumer
2023-08-28 13:15:57 +03:30
parent 4f5c6c12a5
commit 01980ba28d
9 changed files with 147 additions and 6 deletions

View File

@@ -17,12 +17,16 @@ class TrafficNotifier extends _$TrafficNotifier with AppLogger {
Stream<List<Traffic>> build() async* {
final serviceRunning = await ref.watch(serviceRunningProvider.future);
if (serviceRunning) {
yield* ref.watch(coreFacadeProvider).watchTraffic().map(
(event) => _mapToState(
event
.getOrElse((_) => const ClashTraffic(upload: 0, download: 0)),
),
);
// TODO: temporary!
yield* ref.watch(coreFacadeProvider).watchCoreStatus().map((event) {
return event.map(
(a) => ClashTraffic(upload: a.uplink, download: a.downlink),
);
}).map(
(event) => _mapToState(
event.getOrElse((_) => const ClashTraffic(upload: 0, download: 0)),
),
);
} else {
yield* Stream.periodic(const Duration(seconds: 1)).asyncMap(
(_) async {