From 0a44e638d77d1bfae8054063dc3100c9bd07308a Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Mon, 13 Nov 2023 15:02:38 +0330 Subject: [PATCH] Fix code typo --- lib/services/singbox/ffi_singbox_service.dart | 31 +++++++++---------- .../singbox/mobile_singbox_service.dart | 4 +-- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib/services/singbox/ffi_singbox_service.dart b/lib/services/singbox/ffi_singbox_service.dart index 87124e55..62bcf6b7 100644 --- a/lib/services/singbox/ffi_singbox_service.dart +++ b/lib/services/singbox/ffi_singbox_service.dart @@ -5,7 +5,6 @@ import 'dart:io'; import 'dart:isolate'; import 'package:combine/combine.dart'; -import 'package:dartx/dartx.dart'; import 'package:ffi/ffi.dart'; import 'package:fpdart/fpdart.dart'; import 'package:hiddify/domain/connectivity/connectivity.dart'; @@ -28,8 +27,8 @@ class FFISingboxService late final ValueStream _connectionStatus; late final ReceivePort _connectionStatusReceiver; - Stream? _statusStream; - Stream? _groupsStream; + Stream? _serviceStatsStream; + Stream? _outboundsStream; static SingboxNativeLibrary _gen() { String fullPath = ""; @@ -152,7 +151,7 @@ class FFISingboxService .cast() .toDartString(); if (response.startsWith("error")) { - return left(response.removePrefix("error")); + return left(response.replaceFirst("error", "")); } return right(response); }, @@ -224,28 +223,28 @@ class FFISingboxService @override Stream watchStats() { - if (_statusStream != null) return _statusStream!; - final receiver = ReceivePort('status receiver'); + if (_serviceStatsStream != null) return _serviceStatsStream!; + final receiver = ReceivePort('service stats receiver'); final statusStream = receiver.asBroadcastStream( onCancel: (_) { - _logger.debug("stopping status command client"); + _logger.debug("stopping stats command client"); final err = _box.stopCommandClient(1).cast().toDartString(); if (err.isNotEmpty) { - _logger.error("error stopping status client"); + _logger.error("error stopping stats client"); } receiver.close(); - _statusStream = null; + _serviceStatsStream = null; }, ).map( (event) { if (event case String _) { if (event.startsWith('error:')) { - loggy.error("[status client] error received: $event"); + loggy.error("[service stats client] error received: $event"); throw event.replaceFirst('error:', ""); } return event; } - loggy.error("[status client] unexpected type, msg: $event"); + loggy.error("[service status client] unexpected type, msg: $event"); throw "invalid type"; }, ); @@ -259,14 +258,14 @@ class FFISingboxService throw err; } - return _statusStream = statusStream; + return _serviceStatsStream = statusStream; } @override Stream watchOutbounds() { - if (_groupsStream != null) return _groupsStream!; + if (_outboundsStream != null) return _outboundsStream!; final receiver = ReceivePort('outbounds receiver'); - final groupsStream = receiver.asBroadcastStream( + final outboundsStream = receiver.asBroadcastStream( onCancel: (_) { _logger.debug("stopping group command client"); final err = _box.stopCommandClient(4).cast().toDartString(); @@ -274,7 +273,7 @@ class FFISingboxService _logger.error("error stopping group client"); } receiver.close(); - _groupsStream = null; + _outboundsStream = null; }, ).map( (event) { @@ -299,7 +298,7 @@ class FFISingboxService throw err; } - return _groupsStream = groupsStream; + return _outboundsStream = outboundsStream; } @override diff --git a/lib/services/singbox/mobile_singbox_service.dart b/lib/services/singbox/mobile_singbox_service.dart index b27ec2ab..f4440772 100644 --- a/lib/services/singbox/mobile_singbox_service.dart +++ b/lib/services/singbox/mobile_singbox_service.dart @@ -13,7 +13,7 @@ class MobileSingboxService with ServiceStatus, InfraLogger implements SingboxService { late final _methodChannel = const MethodChannel("com.hiddify.app/method"); - late final _statusChannel = + late final _connectionStatusChannel = const EventChannel("com.hiddify.app/service.status"); late final _alertsChannel = const EventChannel("com.hiddify.app/service.alerts"); @@ -25,7 +25,7 @@ class MobileSingboxService Future init() async { loggy.debug("initializing"); final status = - _statusChannel.receiveBroadcastStream().map(mapEventToStatus); + _connectionStatusChannel.receiveBroadcastStream().map(mapEventToStatus); final alerts = _alertsChannel.receiveBroadcastStream().map(mapEventToStatus); _connectionStatus =