This commit is contained in:
problematicconsumer
2023-07-06 17:18:41 +03:30
commit b617c95f62
352 changed files with 21017 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
import 'dart:convert';
import 'dart:ffi';
import 'dart:isolate';
import 'package:hiddify/services/clash/async_ffi_response.dart';
import 'package:hiddify/utils/utils.dart';
// TODO: add timeout
// TODO: test and improve
mixin AsyncFFI implements LoggerMixin {
Future<AsyncFfiResponse> runAsync(void Function(int port) run) async {
final receivePort = ReceivePort();
final responseFuture = receivePort.map(
(event) {
if (event is String) {
receivePort.close();
return AsyncFfiResponse.fromJson(
jsonDecode(event) as Map<String, dynamic>,
);
}
receivePort.close();
throw Exception("unexpected data type[${event.runtimeType}]");
},
).first;
run(receivePort.sendPort.nativePort);
return responseFuture;
}
}