From ae62457d8ced0f67b72fe4f6a2acbe4943fb6d20 Mon Sep 17 00:00:00 2001 From: Rust Date: Fri, 24 Oct 2025 21:03:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A5=E5=BF=97=20?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/hiddify/hiddify/MethodHandler.kt | 24 +++++++++++++++ .../services/singbox_imp/kr_sing_box_imp.dart | 30 ++----------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/android/app/src/main/kotlin/com/hiddify/hiddify/MethodHandler.kt b/android/app/src/main/kotlin/com/hiddify/hiddify/MethodHandler.kt index c9d1655..be9c994 100755 --- a/android/app/src/main/kotlin/com/hiddify/hiddify/MethodHandler.kt +++ b/android/app/src/main/kotlin/com/hiddify/hiddify/MethodHandler.kt @@ -90,7 +90,18 @@ class MethodHandler(private val scope: CoroutineScope) : FlutterPlugin, scope.launch { result.runCatching { val args = call.arguments as String + + // ✅ 添加日志 + Log.d(TAG, "📍 changeHiddifyOptions 被调用") + Log.d(TAG, "⚙️ 接收到的配置长度: ${args.length}") + Log.d(TAG, "⚙️ 接收到的配置前500字符: ${args.substring(0, minOf(500, args.length))}") + Settings.configOptions = args + + // 验证保存 + val saved = Settings.configOptions + Log.d(TAG, "✅ 配置已保存,验证长度: ${saved.length}") + success(true) } } @@ -102,10 +113,23 @@ class MethodHandler(private val scope: CoroutineScope) : FlutterPlugin, val args = call.arguments as Map<*, *> val path = args["path"] as String val options = Settings.configOptions + + // ✅ 添加详细日志 + Log.d(TAG, "📍 GenerateConfig 被调用") + Log.d(TAG, "📁 配置文件路径: $path") + Log.d(TAG, "⚙️ configOptions 长度: ${options.length}") + Log.d(TAG, "⚙️ configOptions 内容: $options") + if (options.isBlank() || path.isBlank()) { + Log.e(TAG, "❌ 配置选项或路径为空!options.isBlank=${options.isBlank()}, path.isBlank=${path.isBlank()}") error("blank properties") } + + Log.d(TAG, "🔧 开始调用 Mobile.buildConfig...") val config = BoxService.buildConfig(path, options) + Log.d(TAG, "✅ buildConfig 完成,配置长度: ${config.length}") + Log.d(TAG, "📄 生成的配置前500字符: ${config.substring(0, minOf(500, config.length))}") + success(config) } } diff --git a/lib/app/services/singbox_imp/kr_sing_box_imp.dart b/lib/app/services/singbox_imp/kr_sing_box_imp.dart index 502130c..759c025 100755 --- a/lib/app/services/singbox_imp/kr_sing_box_imp.dart +++ b/lib/app/services/singbox_imp/kr_sing_box_imp.dart @@ -462,37 +462,13 @@ class KRSingBoxImp { final configFile = File(_cutPath); if (await configFile.exists()) { final configContent = await configFile.readAsString(); - KRLogUtil.kr_i('📄 基础配置文件内容长度: ${configContent.length}', tag: 'SingBox'); - KRLogUtil.kr_i('📄 基础配置文件前500字符: ${configContent.substring(0, configContent.length > 500 ? 500 : configContent.length)}', tag: 'SingBox'); + KRLogUtil.kr_i('📄 配置文件内容长度: ${configContent.length}', tag: 'SingBox'); + KRLogUtil.kr_i('📄 配置文件前500字符: ${configContent.substring(0, configContent.length > 500 ? 500 : configContent.length)}', tag: 'SingBox'); } else { KRLogUtil.kr_w('⚠️ 配置文件不存在: $_cutPath', tag: 'SingBox'); } - // ✅ 关键修复:生成完整的 sing-box 配置 - KRLogUtil.kr_i('🔧 开始生成完整配置...', tag: 'SingBox'); - - final fullConfigResult = await kr_singBox.generateFullConfigByPath(_cutPath).run(); - - final String fullConfigJson = fullConfigResult.fold( - (error) { - KRLogUtil.kr_e('❌ 生成完整配置失败: $error', tag: 'SingBox'); - throw Exception('生成完整配置失败: $error'); - }, - (config) { - KRLogUtil.kr_i('✅ 完整配置生成成功', tag: 'SingBox'); - KRLogUtil.kr_i('📄 完整配置长度: ${config.length}', tag: 'SingBox'); - KRLogUtil.kr_i('📄 完整配置前500字符: ${config.substring(0, config.length > 500 ? 500 : config.length)}', tag: 'SingBox'); - return config; - }, - ); - - // 保存完整配置到临时文件 - final fullConfigFile = File('${_cutPath}.full'); - await fullConfigFile.writeAsString(fullConfigJson); - KRLogUtil.kr_i('💾 完整配置已保存到: ${fullConfigFile.path}', tag: 'SingBox'); - - // 使用完整配置文件启动服务 - await kr_singBox.start(fullConfigFile.path, kr_configName, false).map( + await kr_singBox.start(_cutPath, kr_configName, false).map( (r) { KRLogUtil.kr_i('✅ SingBox 启动成功', tag: 'SingBox'); },