import 'dart:async'; import 'package:nc_photos/exception_event.dart'; import 'package:nc_photos/mobile/self_signed_cert_manager.dart'; import 'package:nc_photos/rx_extension.dart'; import 'package:np_collection/np_collection.dart'; import 'package:rxdart/rxdart.dart'; class TrustedCertControllerRemoveError extends Error { TrustedCertControllerRemoveError(); } class TrustedCertController { TrustedCertController({ required this.manager, }) { _streamController.add(manager.whitelist); } ValueStream> get stream => _streamController.stream; ValueStream get errorStream => _errorStreamController.stream; Future whitelistLastBadCert() async { final cert = await manager.whitelistLastBadCert(); _streamController.addWithValue((value) => value.added(cert)); } Future remove(CertInfo cert) async { final result = await manager.removeFromWhitelist(cert); if (result) { _streamController.addWithValue((value) => value.removed(cert)); } else { _errorStreamController .add(ExceptionEvent(TrustedCertControllerRemoveError())); } } final SelfSignedCertManager manager; final _streamController = BehaviorSubject>(); final _errorStreamController = BehaviorSubject.seeded(null); }