Fix code typo

This commit is contained in:
problematicconsumer
2023-11-13 15:02:38 +03:30
parent 14ff634038
commit 0a44e638d7
2 changed files with 17 additions and 18 deletions

View File

@@ -5,7 +5,6 @@ import 'dart:io';
import 'dart:isolate'; import 'dart:isolate';
import 'package:combine/combine.dart'; import 'package:combine/combine.dart';
import 'package:dartx/dartx.dart';
import 'package:ffi/ffi.dart'; import 'package:ffi/ffi.dart';
import 'package:fpdart/fpdart.dart'; import 'package:fpdart/fpdart.dart';
import 'package:hiddify/domain/connectivity/connectivity.dart'; import 'package:hiddify/domain/connectivity/connectivity.dart';
@@ -28,8 +27,8 @@ class FFISingboxService
late final ValueStream<ConnectionStatus> _connectionStatus; late final ValueStream<ConnectionStatus> _connectionStatus;
late final ReceivePort _connectionStatusReceiver; late final ReceivePort _connectionStatusReceiver;
Stream<String>? _statusStream; Stream<String>? _serviceStatsStream;
Stream<String>? _groupsStream; Stream<String>? _outboundsStream;
static SingboxNativeLibrary _gen() { static SingboxNativeLibrary _gen() {
String fullPath = ""; String fullPath = "";
@@ -152,7 +151,7 @@ class FFISingboxService
.cast<Utf8>() .cast<Utf8>()
.toDartString(); .toDartString();
if (response.startsWith("error")) { if (response.startsWith("error")) {
return left(response.removePrefix("error")); return left(response.replaceFirst("error", ""));
} }
return right(response); return right(response);
}, },
@@ -224,28 +223,28 @@ class FFISingboxService
@override @override
Stream<String> watchStats() { Stream<String> watchStats() {
if (_statusStream != null) return _statusStream!; if (_serviceStatsStream != null) return _serviceStatsStream!;
final receiver = ReceivePort('status receiver'); final receiver = ReceivePort('service stats receiver');
final statusStream = receiver.asBroadcastStream( final statusStream = receiver.asBroadcastStream(
onCancel: (_) { onCancel: (_) {
_logger.debug("stopping status command client"); _logger.debug("stopping stats command client");
final err = _box.stopCommandClient(1).cast<Utf8>().toDartString(); final err = _box.stopCommandClient(1).cast<Utf8>().toDartString();
if (err.isNotEmpty) { if (err.isNotEmpty) {
_logger.error("error stopping status client"); _logger.error("error stopping stats client");
} }
receiver.close(); receiver.close();
_statusStream = null; _serviceStatsStream = null;
}, },
).map( ).map(
(event) { (event) {
if (event case String _) { if (event case String _) {
if (event.startsWith('error:')) { if (event.startsWith('error:')) {
loggy.error("[status client] error received: $event"); loggy.error("[service stats client] error received: $event");
throw event.replaceFirst('error:', ""); throw event.replaceFirst('error:', "");
} }
return event; return event;
} }
loggy.error("[status client] unexpected type, msg: $event"); loggy.error("[service status client] unexpected type, msg: $event");
throw "invalid type"; throw "invalid type";
}, },
); );
@@ -259,14 +258,14 @@ class FFISingboxService
throw err; throw err;
} }
return _statusStream = statusStream; return _serviceStatsStream = statusStream;
} }
@override @override
Stream<String> watchOutbounds() { Stream<String> watchOutbounds() {
if (_groupsStream != null) return _groupsStream!; if (_outboundsStream != null) return _outboundsStream!;
final receiver = ReceivePort('outbounds receiver'); final receiver = ReceivePort('outbounds receiver');
final groupsStream = receiver.asBroadcastStream( final outboundsStream = receiver.asBroadcastStream(
onCancel: (_) { onCancel: (_) {
_logger.debug("stopping group command client"); _logger.debug("stopping group command client");
final err = _box.stopCommandClient(4).cast<Utf8>().toDartString(); final err = _box.stopCommandClient(4).cast<Utf8>().toDartString();
@@ -274,7 +273,7 @@ class FFISingboxService
_logger.error("error stopping group client"); _logger.error("error stopping group client");
} }
receiver.close(); receiver.close();
_groupsStream = null; _outboundsStream = null;
}, },
).map( ).map(
(event) { (event) {
@@ -299,7 +298,7 @@ class FFISingboxService
throw err; throw err;
} }
return _groupsStream = groupsStream; return _outboundsStream = outboundsStream;
} }
@override @override

View File

@@ -13,7 +13,7 @@ class MobileSingboxService
with ServiceStatus, InfraLogger with ServiceStatus, InfraLogger
implements SingboxService { implements SingboxService {
late final _methodChannel = const MethodChannel("com.hiddify.app/method"); late final _methodChannel = const MethodChannel("com.hiddify.app/method");
late final _statusChannel = late final _connectionStatusChannel =
const EventChannel("com.hiddify.app/service.status"); const EventChannel("com.hiddify.app/service.status");
late final _alertsChannel = late final _alertsChannel =
const EventChannel("com.hiddify.app/service.alerts"); const EventChannel("com.hiddify.app/service.alerts");
@@ -25,7 +25,7 @@ class MobileSingboxService
Future<void> init() async { Future<void> init() async {
loggy.debug("initializing"); loggy.debug("initializing");
final status = final status =
_statusChannel.receiveBroadcastStream().map(mapEventToStatus); _connectionStatusChannel.receiveBroadcastStream().map(mapEventToStatus);
final alerts = final alerts =
_alertsChannel.receiveBroadcastStream().map(mapEventToStatus); _alertsChannel.receiveBroadcastStream().map(mapEventToStatus);
_connectionStatus = _connectionStatus =