add warp config, update to flutter 1.22
This commit is contained in:
@@ -48,6 +48,7 @@ class SingboxConfigOption with _$SingboxConfigOption {
|
||||
required SingboxMuxOption mux,
|
||||
required SingboxTlsTricks tlsTricks,
|
||||
required SingboxWarpOption warp,
|
||||
required SingboxWarpOption warp2,
|
||||
}) = _SingboxConfigOption;
|
||||
|
||||
String format() {
|
||||
@@ -55,8 +56,7 @@ class SingboxConfigOption with _$SingboxConfigOption {
|
||||
return encoder.convert(toJson());
|
||||
}
|
||||
|
||||
factory SingboxConfigOption.fromJson(Map<String, dynamic> json) =>
|
||||
_$SingboxConfigOptionFromJson(json);
|
||||
factory SingboxConfigOption.fromJson(Map<String, dynamic> json) => _$SingboxConfigOptionFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
@@ -75,8 +75,7 @@ class SingboxWarpOption with _$SingboxWarpOption {
|
||||
@OptionalRangeJsonConverter() required OptionalRange noiseDelay,
|
||||
}) = _SingboxWarpOption;
|
||||
|
||||
factory SingboxWarpOption.fromJson(Map<String, dynamic> json) =>
|
||||
_$SingboxWarpOptionFromJson(json);
|
||||
factory SingboxWarpOption.fromJson(Map<String, dynamic> json) => _$SingboxWarpOptionFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
@@ -89,8 +88,7 @@ class SingboxMuxOption with _$SingboxMuxOption {
|
||||
required MuxProtocol protocol,
|
||||
}) = _SingboxMuxOption;
|
||||
|
||||
factory SingboxMuxOption.fromJson(Map<String, dynamic> json) =>
|
||||
_$SingboxMuxOptionFromJson(json);
|
||||
factory SingboxMuxOption.fromJson(Map<String, dynamic> json) => _$SingboxMuxOptionFromJson(json);
|
||||
}
|
||||
|
||||
@freezed
|
||||
@@ -105,6 +103,5 @@ class SingboxTlsTricks with _$SingboxTlsTricks {
|
||||
@OptionalRangeJsonConverter() required OptionalRange paddingSize,
|
||||
}) = _SingboxTlsTricks;
|
||||
|
||||
factory SingboxTlsTricks.fromJson(Map<String, dynamic> json) =>
|
||||
_$SingboxTlsTricksFromJson(json);
|
||||
factory SingboxTlsTricks.fromJson(Map<String, dynamic> json) => _$SingboxTlsTricksFromJson(json);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:isolate';
|
||||
|
||||
import 'package:combine/combine.dart';
|
||||
import 'package:ffi/ffi.dart';
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:hiddify/core/model/directories.dart';
|
||||
@@ -52,10 +51,7 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
Future<void> init() async {
|
||||
loggy.debug("initializing");
|
||||
_statusReceiver = ReceivePort('service status receiver');
|
||||
final source = _statusReceiver
|
||||
.asBroadcastStream()
|
||||
.map((event) => jsonDecode(event as String))
|
||||
.map(SingboxStatus.fromEvent);
|
||||
final source = _statusReceiver.asBroadcastStream().map((event) => jsonDecode(event as String)).map(SingboxStatus.fromEvent);
|
||||
_status = ValueConnectableStream.seeded(
|
||||
source,
|
||||
const SingboxStopped(),
|
||||
@@ -69,8 +65,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
) {
|
||||
final port = _statusReceiver.sendPort.nativePort;
|
||||
return TaskEither(
|
||||
() => CombineWorker().execute(
|
||||
() {
|
||||
() => Future.microtask(
|
||||
() async {
|
||||
_box.setupOnce(NativeApi.initializeApiDLData);
|
||||
final err = _box
|
||||
.setup(
|
||||
@@ -98,8 +94,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
bool debug,
|
||||
) {
|
||||
return TaskEither(
|
||||
() => CombineWorker().execute(
|
||||
() {
|
||||
() => Future.microtask(
|
||||
() async {
|
||||
final err = _box
|
||||
.parse(
|
||||
path.toNativeUtf8().cast(),
|
||||
@@ -120,13 +116,10 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
@override
|
||||
TaskEither<String, Unit> changeOptions(SingboxConfigOption options) {
|
||||
return TaskEither(
|
||||
() => CombineWorker().execute(
|
||||
() {
|
||||
() => Future.microtask(
|
||||
() async {
|
||||
final json = jsonEncode(options.toJson());
|
||||
final err = _box
|
||||
.changeConfigOptions(json.toNativeUtf8().cast())
|
||||
.cast<Utf8>()
|
||||
.toDartString();
|
||||
final err = _box.changeConfigOptions(json.toNativeUtf8().cast()).cast<Utf8>().toDartString();
|
||||
if (err.isNotEmpty) {
|
||||
return left(err);
|
||||
}
|
||||
@@ -141,8 +134,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
String path,
|
||||
) {
|
||||
return TaskEither(
|
||||
() => CombineWorker().execute(
|
||||
() {
|
||||
() => Future.microtask(
|
||||
() async {
|
||||
final response = _box
|
||||
.generateConfig(
|
||||
path.toNativeUtf8().cast(),
|
||||
@@ -166,8 +159,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
) {
|
||||
loggy.debug("starting, memory limit: [${!disableMemoryLimit}]");
|
||||
return TaskEither(
|
||||
() => CombineWorker().execute(
|
||||
() {
|
||||
() => Future.microtask(
|
||||
() async {
|
||||
final err = _box
|
||||
.start(
|
||||
configPath.toNativeUtf8().cast(),
|
||||
@@ -187,8 +180,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
@override
|
||||
TaskEither<String, Unit> stop() {
|
||||
return TaskEither(
|
||||
() => CombineWorker().execute(
|
||||
() {
|
||||
() => Future.microtask(
|
||||
() async {
|
||||
final err = _box.stop().cast<Utf8>().toDartString();
|
||||
if (err.isNotEmpty) {
|
||||
return left(err);
|
||||
@@ -207,8 +200,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
) {
|
||||
loggy.debug("restarting, memory limit: [${!disableMemoryLimit}]");
|
||||
return TaskEither(
|
||||
() => CombineWorker().execute(
|
||||
() {
|
||||
() => Future.microtask(
|
||||
() async {
|
||||
final err = _box
|
||||
.restart(
|
||||
configPath.toNativeUtf8().cast(),
|
||||
@@ -265,10 +258,7 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
},
|
||||
);
|
||||
|
||||
final err = _box
|
||||
.startCommandClient(1, receiver.sendPort.nativePort)
|
||||
.cast<Utf8>()
|
||||
.toDartString();
|
||||
final err = _box.startCommandClient(1, receiver.sendPort.nativePort).cast<Utf8>().toDartString();
|
||||
if (err.isNotEmpty) {
|
||||
loggy.error("error starting status command: $err");
|
||||
throw err;
|
||||
@@ -310,10 +300,7 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
);
|
||||
|
||||
try {
|
||||
final err = _box
|
||||
.startCommandClient(5, receiver.sendPort.nativePort)
|
||||
.cast<Utf8>()
|
||||
.toDartString();
|
||||
final err = _box.startCommandClient(5, receiver.sendPort.nativePort).cast<Utf8>().toDartString();
|
||||
if (err.isNotEmpty) {
|
||||
logger.error("error starting group command: $err");
|
||||
throw err;
|
||||
@@ -357,10 +344,7 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
);
|
||||
|
||||
try {
|
||||
final err = _box
|
||||
.startCommandClient(13, receiver.sendPort.nativePort)
|
||||
.cast<Utf8>()
|
||||
.toDartString();
|
||||
final err = _box.startCommandClient(13, receiver.sendPort.nativePort).cast<Utf8>().toDartString();
|
||||
if (err.isNotEmpty) {
|
||||
logger.error("error starting: $err");
|
||||
throw err;
|
||||
@@ -376,8 +360,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
@override
|
||||
TaskEither<String, Unit> selectOutbound(String groupTag, String outboundTag) {
|
||||
return TaskEither(
|
||||
() => CombineWorker().execute(
|
||||
() {
|
||||
() => Future.microtask(
|
||||
() async {
|
||||
final err = _box
|
||||
.selectOutbound(
|
||||
groupTag.toNativeUtf8().cast(),
|
||||
@@ -397,12 +381,9 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
@override
|
||||
TaskEither<String, Unit> urlTest(String groupTag) {
|
||||
return TaskEither(
|
||||
() => CombineWorker().execute(
|
||||
() {
|
||||
final err = _box
|
||||
.urlTest(groupTag.toNativeUtf8().cast())
|
||||
.cast<Utf8>()
|
||||
.toDartString();
|
||||
() => Future.microtask(
|
||||
() async {
|
||||
final err = _box.urlTest(groupTag.toNativeUtf8().cast()).cast<Utf8>().toDartString();
|
||||
if (err.isNotEmpty) {
|
||||
return left(err);
|
||||
}
|
||||
@@ -418,9 +399,7 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
@override
|
||||
Stream<List<String>> watchLogs(String path) async* {
|
||||
yield await _readLogFile(File(path));
|
||||
yield* Watcher(path, pollingDelay: const Duration(seconds: 1))
|
||||
.events
|
||||
.asyncMap((event) async {
|
||||
yield* Watcher(path, pollingDelay: const Duration(seconds: 1)).events.asyncMap((event) async {
|
||||
if (event.type == ChangeType.MODIFY) {
|
||||
await _readLogFile(File(path));
|
||||
}
|
||||
@@ -431,17 +410,18 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
@override
|
||||
TaskEither<String, Unit> clearLogs() {
|
||||
return TaskEither(
|
||||
() async {
|
||||
_logBuffer.clear();
|
||||
return right(unit);
|
||||
},
|
||||
() => Future.microtask(
|
||||
() async {
|
||||
_logBuffer.clear();
|
||||
return right(unit);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<List<String>> _readLogFile(File file) async {
|
||||
if (_logFilePosition == 0 && file.lengthSync() == 0) return [];
|
||||
final content =
|
||||
await file.openRead(_logFilePosition).transform(utf8.decoder).join();
|
||||
final content = await file.openRead(_logFilePosition).transform(utf8.decoder).join();
|
||||
_logFilePosition = file.lengthSync();
|
||||
final lines = const LineSplitter().convert(content);
|
||||
if (lines.length > 300) {
|
||||
@@ -464,8 +444,8 @@ class FFISingboxService with InfraLogger implements SingboxService {
|
||||
}) {
|
||||
loggy.debug("generating warp config");
|
||||
return TaskEither(
|
||||
() => CombineWorker().execute(
|
||||
() {
|
||||
() => Future.microtask(
|
||||
() async {
|
||||
final response = _box
|
||||
.generateWarpConfig(
|
||||
licenseKey.toNativeUtf8().cast(),
|
||||
|
||||
Reference in New Issue
Block a user