import 'dart:async'; import 'package:flutter_singbox_proxy/src/singbox_proxy_api.g.dart'; export 'src/singbox_proxy_api.g.dart' show SingboxProxyConfigResult, SingboxProxyDnsConfig, SingboxProxyDnsServerConfig, SingboxProxyLogMessage, SingboxProxyProfile, SingboxProxyProfileType, SingboxProxyRuntimeEndpoint, SingboxProxyRuntimeOptions, SingboxProxyRuntimeState, SingboxProxyRuntimeStatus; class FlutterSingboxProxy implements SingboxProxyEventsApi { FlutterSingboxProxy({SingboxProxyApi? api}) : _api = api ?? SingboxProxyApi() { SingboxProxyEventsApi.setUp(this); } final SingboxProxyApi _api; final _stateController = StreamController.broadcast(); final _logController = StreamController.broadcast(); Stream get stateStream => _stateController.stream; Stream get logStream => _logController.stream; Future validateProfile(SingboxProxyProfile profile) { return _api.validateProfile(profile); } Future buildConfig( List profiles, { SingboxProxyRuntimeOptions? options, }) { return _api.buildConfig(profiles, options ?? SingboxProxyRuntimeOptions()); } Future start( List profiles, { SingboxProxyRuntimeOptions? options, }) { return _api.start(profiles, options ?? SingboxProxyRuntimeOptions()); } Future stop(List profileIds) => _api.stop(profileIds); Future stopAll() => _api.stopAll(); Future getState() => _api.getState(); @override void onStateChanged(SingboxProxyRuntimeState state) { _stateController.add(state); } @override void onLogMessage(SingboxProxyLogMessage message) { _logController.add(message); } Future dispose() async { SingboxProxyEventsApi.setUp(null); await _stateController.close(); await _logController.close(); } }