防止被多次初始化

(cherry picked from commit 77f1a8b30d2c30c03f0ec45fc32fe8eef9d2b4c7)
This commit is contained in:
2025-10-29 15:14:16 +08:00
committed by speakeloudest
parent 4250f61345
commit fbdf4a2337
2 changed files with 23 additions and 0 deletions
@@ -31,6 +31,9 @@ class FFISingboxService with InfraLogger implements SingboxService {
late final ReceivePort _statusReceiver;
Stream<SingboxStats>? _serviceStatsStream;
Stream<List<SingboxOutboundGroup>>? _outboundsStream;
/// 初始化标志,防止重复初始化
bool _isInitialized = false;
static SingboxNativeLibrary _gen() {
String fullPath = "";
@@ -52,6 +55,12 @@ class FFISingboxService with InfraLogger implements SingboxService {
@override
Future<void> init() async {
// 防止重复初始化
if (_isInitialized) {
loggy.debug("already initialized, skipping");
return;
}
loggy.debug("initializing");
_statusReceiver = ReceivePort('service status receiver');
final source = _statusReceiver
@@ -62,6 +71,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
source,
const SingboxStopped(),
).autoConnect();
_isInitialized = true;
}
@override