diff --git a/lib/data/data_providers.dart b/lib/data/data_providers.dart index 233777e6..0cf378dd 100644 --- a/lib/data/data_providers.dart +++ b/lib/data/data_providers.dart @@ -1,5 +1,6 @@ import 'package:dio/dio.dart'; import 'package:hiddify/core/core_providers.dart'; +import 'package:hiddify/core/prefs/general_prefs.dart'; import 'package:hiddify/data/api/clash_api.dart'; import 'package:hiddify/data/local/dao/dao.dart'; import 'package:hiddify/data/local/database.dart'; @@ -61,5 +62,6 @@ CoreFacade coreFacade(CoreFacadeRef ref) => CoreFacadeImpl( ref.watch(singboxServiceProvider), ref.watch(filesEditorServiceProvider), ref.watch(clashApiProvider), + ref.read(debugModeNotifierProvider), () => ref.read(configOptionsProvider), ); diff --git a/lib/data/repository/core_facade_impl.dart b/lib/data/repository/core_facade_impl.dart index 909b2676..f0214194 100644 --- a/lib/data/repository/core_facade_impl.dart +++ b/lib/data/repository/core_facade_impl.dart @@ -18,12 +18,14 @@ class CoreFacadeImpl with ExceptionHandler, InfraLogger implements CoreFacade { this.singbox, this.filesEditor, this.clash, + this.debug, this.configOptions, ); final SingboxService singbox; final FilesEditorService filesEditor; final ClashApi clash; + final bool debug; final ConfigOptions Function() configOptions; bool _initialized = false; @@ -39,6 +41,7 @@ class CoreFacadeImpl with ExceptionHandler, InfraLogger implements CoreFacade { filesEditor.dirs.baseDir.path, filesEditor.dirs.workingDir.path, filesEditor.dirs.tempDir.path, + debug, ) .map((r) { loggy.debug("setup complete"); diff --git a/lib/gen/singbox_generated_bindings.dart b/lib/gen/singbox_generated_bindings.dart index 25628fac..25279a7c 100644 --- a/lib/gen/singbox_generated_bindings.dart +++ b/lib/gen/singbox_generated_bindings.dart @@ -871,27 +871,33 @@ class SingboxNativeLibrary { late final _setupOnce = _setupOncePtr.asFunction)>(); - void setup( + ffi.Pointer setup( ffi.Pointer baseDir, ffi.Pointer workingDir, ffi.Pointer tempDir, int statusPort, + int debug, ) { return _setup( baseDir, workingDir, tempDir, statusPort, + debug, ); } late final _setupPtr = _lookup< ffi.NativeFunction< - ffi.Void Function(ffi.Pointer, ffi.Pointer, - ffi.Pointer, ffi.LongLong)>>('setup'); + ffi.Pointer Function( + ffi.Pointer, + ffi.Pointer, + ffi.Pointer, + ffi.LongLong, + GoUint8)>>('setup'); late final _setup = _setupPtr.asFunction< - void Function(ffi.Pointer, ffi.Pointer, - ffi.Pointer, int)>(); + ffi.Pointer Function(ffi.Pointer, + ffi.Pointer, ffi.Pointer, int, int)>(); ffi.Pointer parse( ffi.Pointer path, diff --git a/lib/services/singbox/ffi_singbox_service.dart b/lib/services/singbox/ffi_singbox_service.dart index 4f9de414..5d9aa308 100644 --- a/lib/services/singbox/ffi_singbox_service.dart +++ b/lib/services/singbox/ffi_singbox_service.dart @@ -66,18 +66,26 @@ class FFISingboxService String baseDir, String workingDir, String tempDir, + bool debug, ) { final port = _connectionStatusReceiver.sendPort.nativePort; return TaskEither( () => CombineWorker().execute( () { _box.setupOnce(NativeApi.initializeApiDLData); - _box.setup( - baseDir.toNativeUtf8().cast(), - workingDir.toNativeUtf8().cast(), - tempDir.toNativeUtf8().cast(), - port, - ); + final err = _box + .setup( + baseDir.toNativeUtf8().cast(), + workingDir.toNativeUtf8().cast(), + tempDir.toNativeUtf8().cast(), + port, + debug ? 1 : 0, + ) + .cast() + .toDartString(); + if (err.isNotEmpty) { + return left(err); + } return right(unit); }, ), diff --git a/lib/services/singbox/mobile_singbox_service.dart b/lib/services/singbox/mobile_singbox_service.dart index 95b6bc27..08887bcf 100644 --- a/lib/services/singbox/mobile_singbox_service.dart +++ b/lib/services/singbox/mobile_singbox_service.dart @@ -38,6 +38,7 @@ class MobileSingboxService String baseDir, String workingDir, String tempDir, + bool debug, ) => TaskEither.of(unit); diff --git a/lib/services/singbox/singbox_service.dart b/lib/services/singbox/singbox_service.dart index 8f92afe4..0d89ab88 100644 --- a/lib/services/singbox/singbox_service.dart +++ b/lib/services/singbox/singbox_service.dart @@ -22,6 +22,7 @@ abstract interface class SingboxService { String baseDir, String workingDir, String tempDir, + bool debug, ); TaskEither parseConfig(