feat: windows ico替换成圆角,macos增加tg代理
This commit is contained in:
@@ -3,6 +3,7 @@ import 'dart:convert';
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:kaer_with_panels/utils/isolate_worker.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
@@ -31,32 +32,80 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
Stream<List<SingboxOutboundGroup>>? _outboundsStream;
|
||||
|
||||
static SingboxNativeLibrary _gen() {
|
||||
String fullPath = "";
|
||||
if (Platform.environment.containsKey('FLUTTER_TEST')) {
|
||||
fullPath = "libcore";
|
||||
}
|
||||
if (Platform.isWindows) {
|
||||
fullPath = p.join(fullPath, "libcore.dll");
|
||||
} else if (Platform.isMacOS) {
|
||||
fullPath = p.join(fullPath, "libcore.dylib");
|
||||
} else {
|
||||
fullPath = p.join(fullPath, "libcore.so");
|
||||
}
|
||||
String fullPath = _getLibraryPath();
|
||||
_logger.debug('singbox native libs path: "$fullPath"');
|
||||
final lib = DynamicLibrary.open(fullPath);
|
||||
return SingboxNativeLibrary(lib);
|
||||
}
|
||||
|
||||
static String _getLibraryPath() {
|
||||
String libName;
|
||||
if (Platform.isWindows) {
|
||||
libName = "libcore.dll";
|
||||
} else if (Platform.isMacOS) {
|
||||
libName = "libcore.dylib";
|
||||
} else {
|
||||
libName = "libcore.so";
|
||||
}
|
||||
|
||||
// 测试环境
|
||||
if (Platform.environment.containsKey('FLUTTER_TEST')) {
|
||||
return p.join("libcore", libName);
|
||||
}
|
||||
|
||||
// 🔧 修复:开发环境使用绝对路径
|
||||
// 尝试开发环境路径(相对于当前工作目录)
|
||||
final devPath = p.join("libcore", "bin", libName);
|
||||
if (kDebugMode) {
|
||||
print('🔍 [FFI] 检查开发环境路径: $devPath');
|
||||
print('🔍 [FFI] 当前工作目录: ${Directory.current.path}');
|
||||
print('🔍 [FFI] 文件是否存在: ${File(devPath).existsSync()}');
|
||||
}
|
||||
|
||||
if (File(devPath).existsSync()) {
|
||||
if (kDebugMode) {
|
||||
print('✅ [FFI] 使用开发环境路径: $devPath');
|
||||
}
|
||||
return devPath;
|
||||
}
|
||||
|
||||
// 生产环境:使用相对路径(bundle中的路径)
|
||||
if (kDebugMode) {
|
||||
print('⚠️ [FFI] 开发环境路径不存在,使用生产环境路径: $libName');
|
||||
}
|
||||
return libName;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> init() async {
|
||||
if (kDebugMode) {
|
||||
print('🚀 [FFI] init() 开始');
|
||||
}
|
||||
loggy.debug("initializing");
|
||||
_box.setupOnce(NativeApi.initializeApiDLData);
|
||||
|
||||
// 注意:setupOnce 会在 worker isolate 中调用(见 _ffiLoadLibrary)
|
||||
// 在主 isolate 中调用会导致阻塞,因此这里跳过
|
||||
if (kDebugMode) {
|
||||
print('⏭️ [FFI] 跳过主 isolate 中的 setupOnce(将在 worker isolate 中执行)');
|
||||
}
|
||||
|
||||
if (kDebugMode) {
|
||||
print('📡 [FFI] 创建 ReceivePort');
|
||||
}
|
||||
_statusReceiver = ReceivePort('service status receiver');
|
||||
|
||||
if (kDebugMode) {
|
||||
print('🔄 [FFI] 设置状态流');
|
||||
}
|
||||
final source = _statusReceiver.asBroadcastStream().map((event) => jsonDecode(event as String)).map(SingboxStatus.fromEvent);
|
||||
_status = ValueConnectableStream.seeded(
|
||||
source,
|
||||
const SingboxStopped(),
|
||||
).autoConnect();
|
||||
|
||||
if (kDebugMode) {
|
||||
print('✅ [FFI] init() 完成');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -495,17 +544,7 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
}
|
||||
|
||||
SingboxNativeLibrary _ffiLoadLibrary() {
|
||||
String fullPath = "";
|
||||
if (Platform.environment.containsKey('FLUTTER_TEST')) {
|
||||
fullPath = "libcore";
|
||||
}
|
||||
if (Platform.isWindows) {
|
||||
fullPath = p.join(fullPath, "libcore.dll");
|
||||
} else if (Platform.isMacOS) {
|
||||
fullPath = p.join(fullPath, "libcore.dylib");
|
||||
} else {
|
||||
fullPath = p.join(fullPath, "libcore.so");
|
||||
}
|
||||
final fullPath = FFISingboxService._getLibraryPath();
|
||||
final lib = DynamicLibrary.open(fullPath);
|
||||
final box = SingboxNativeLibrary(lib);
|
||||
box.setupOnce(NativeApi.initializeApiDLData);
|
||||
|
||||
Reference in New Issue
Block a user