Fix profile update bug
This commit is contained in:
@@ -50,8 +50,10 @@ class MethodHandler : FlutterPlugin, MethodChannel.MethodCallHandler {
|
||||
GlobalScope.launch {
|
||||
result.runCatching {
|
||||
val args = call.arguments as Map<*, *>
|
||||
val path = args["path"] as String? ?: ""
|
||||
val msg = BoxService.parseConfig(path)
|
||||
val path = args["path"] as String
|
||||
val tempPath = args["tempPath"] as String
|
||||
val debug = args["debug"] as Boolean
|
||||
val msg = BoxService.parseConfig(path, tempPath, debug)
|
||||
success(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,9 +61,9 @@ class BoxService(
|
||||
return
|
||||
}
|
||||
|
||||
fun parseConfig(path: String): String {
|
||||
fun parseConfig(path: String, tempPath: String, debug: Boolean): String {
|
||||
return try {
|
||||
Mobile.parse(path)
|
||||
Mobile.parse(path, tempPath, debug)
|
||||
""
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, e)
|
||||
@@ -157,7 +157,7 @@ class BoxService(
|
||||
return
|
||||
}
|
||||
|
||||
if(Settings.debugMode) {
|
||||
if (Settings.debugMode) {
|
||||
File(workingDir, "current-config.json").writeText(content)
|
||||
}
|
||||
|
||||
|
||||
@@ -24,10 +24,12 @@ AppDatabase appDatabase(AppDatabaseRef ref) => AppDatabase.connect();
|
||||
SharedPreferences sharedPreferences(SharedPreferencesRef ref) =>
|
||||
throw UnimplementedError('sharedPreferences must be overridden');
|
||||
|
||||
// TODO: set options for dio
|
||||
@Riverpod(keepAlive: true)
|
||||
Dio dio(DioRef ref) => Dio(
|
||||
BaseOptions(
|
||||
connectTimeout: const Duration(seconds: 15),
|
||||
sendTimeout: const Duration(seconds: 15),
|
||||
receiveTimeout: const Duration(seconds: 15),
|
||||
headers: {
|
||||
"User-Agent": ref.watch(appInfoProvider).userAgent,
|
||||
},
|
||||
|
||||
@@ -57,11 +57,15 @@ class CoreFacadeImpl with ExceptionHandler, InfraLogger implements CoreFacade {
|
||||
}
|
||||
|
||||
@override
|
||||
TaskEither<CoreServiceFailure, Unit> parseConfig(String path) {
|
||||
TaskEither<CoreServiceFailure, Unit> parseConfig(
|
||||
String path,
|
||||
String tempPath,
|
||||
bool debug,
|
||||
) {
|
||||
return exceptionHandler(
|
||||
() {
|
||||
return singbox
|
||||
.parseConfig(path)
|
||||
.parseConfig(path, tempPath, debug)
|
||||
.mapLeft(CoreServiceFailure.invalidConfig)
|
||||
.run();
|
||||
},
|
||||
|
||||
@@ -198,21 +198,27 @@ class ProfilesRepositoryImpl
|
||||
) {
|
||||
return TaskEither(
|
||||
() async {
|
||||
final tempPath = filesEditor.configPath("temp_$fileName");
|
||||
final path = filesEditor.configPath(fileName);
|
||||
final response = await dio.download(url.trim(), path);
|
||||
final headers = await _populateHeaders(response.headers.map, path);
|
||||
final parseResult = await singbox.parseConfig(path).run();
|
||||
return parseResult.fold(
|
||||
(l) async {
|
||||
await File(path).delete();
|
||||
loggy.warning("error parsing config: $l");
|
||||
return left(ProfileFailure.invalidConfig(l.msg));
|
||||
},
|
||||
(_) async {
|
||||
final profile = Profile.fromResponse(url, headers);
|
||||
return right(profile);
|
||||
},
|
||||
);
|
||||
try {
|
||||
final response = await dio.download(url.trim(), tempPath);
|
||||
final headers =
|
||||
await _populateHeaders(response.headers.map, tempPath);
|
||||
final parseResult =
|
||||
await singbox.parseConfig(path, tempPath, false).run();
|
||||
return parseResult.fold(
|
||||
(l) async {
|
||||
loggy.warning("error parsing config: $l");
|
||||
return left(ProfileFailure.invalidConfig(l.msg));
|
||||
},
|
||||
(_) async {
|
||||
final profile = Profile.fromResponse(url, headers);
|
||||
return right(profile);
|
||||
},
|
||||
);
|
||||
} finally {
|
||||
if (await File(tempPath).exists()) await File(tempPath).delete();
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,11 @@ import 'package:hiddify/domain/singbox/outbounds.dart';
|
||||
abstract interface class SingboxFacade {
|
||||
TaskEither<CoreServiceFailure, Unit> setup();
|
||||
|
||||
TaskEither<CoreServiceFailure, Unit> parseConfig(String path);
|
||||
TaskEither<CoreServiceFailure, Unit> parseConfig(
|
||||
String path,
|
||||
String tempPath,
|
||||
bool debug,
|
||||
);
|
||||
|
||||
TaskEither<CoreServiceFailure, Unit> changeConfigOptions(
|
||||
ConfigOptions options,
|
||||
|
||||
@@ -895,17 +895,23 @@ class SingboxNativeLibrary {
|
||||
|
||||
ffi.Pointer<ffi.Char> parse(
|
||||
ffi.Pointer<ffi.Char> path,
|
||||
ffi.Pointer<ffi.Char> tempPath,
|
||||
int debug,
|
||||
) {
|
||||
return _parse(
|
||||
path,
|
||||
tempPath,
|
||||
debug,
|
||||
);
|
||||
}
|
||||
|
||||
late final _parsePtr = _lookup<
|
||||
ffi.NativeFunction<
|
||||
ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.Char>)>>('parse');
|
||||
late final _parse = _parsePtr
|
||||
.asFunction<ffi.Pointer<ffi.Char> Function(ffi.Pointer<ffi.Char>)>();
|
||||
ffi.Pointer<ffi.Char> Function(
|
||||
ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Char>, GoUint8)>>('parse');
|
||||
late final _parse = _parsePtr.asFunction<
|
||||
ffi.Pointer<ffi.Char> Function(
|
||||
ffi.Pointer<ffi.Char>, ffi.Pointer<ffi.Char>, int)>();
|
||||
|
||||
ffi.Pointer<ffi.Char> changeConfigOptions(
|
||||
ffi.Pointer<ffi.Char> configOptionsJson,
|
||||
@@ -1099,6 +1105,7 @@ final class GoSlice extends ffi.Struct {
|
||||
|
||||
typedef GoInt = GoInt64;
|
||||
typedef GoInt64 = ffi.LongLong;
|
||||
typedef GoUint8 = ffi.UnsignedChar;
|
||||
|
||||
const int _VCRT_COMPILER_PREPROCESSOR = 1;
|
||||
|
||||
|
||||
@@ -84,12 +84,20 @@ class FFISingboxService
|
||||
}
|
||||
|
||||
@override
|
||||
TaskEither<String, Unit> parseConfig(String path) {
|
||||
TaskEither<String, Unit> parseConfig(
|
||||
String path,
|
||||
String tempPath,
|
||||
bool debug,
|
||||
) {
|
||||
return TaskEither(
|
||||
() => CombineWorker().execute(
|
||||
() {
|
||||
final err = _box
|
||||
.parse(path.toNativeUtf8().cast())
|
||||
.parse(
|
||||
path.toNativeUtf8().cast(),
|
||||
tempPath.toNativeUtf8().cast(),
|
||||
debug ? 1 : 0,
|
||||
)
|
||||
.cast<Utf8>()
|
||||
.toDartString();
|
||||
if (err.isNotEmpty) {
|
||||
|
||||
@@ -42,12 +42,16 @@ class MobileSingboxService
|
||||
TaskEither.of(unit);
|
||||
|
||||
@override
|
||||
TaskEither<String, Unit> parseConfig(String path) {
|
||||
TaskEither<String, Unit> parseConfig(
|
||||
String path,
|
||||
String tempPath,
|
||||
bool debug,
|
||||
) {
|
||||
return TaskEither(
|
||||
() async {
|
||||
final message = await _methodChannel.invokeMethod<String>(
|
||||
"parse_config",
|
||||
{"path": path},
|
||||
{"path": path, "tempPath": tempPath, "debug": debug},
|
||||
);
|
||||
if (message == null || message.isEmpty) return right(unit);
|
||||
return left(message);
|
||||
|
||||
@@ -24,7 +24,11 @@ abstract interface class SingboxService {
|
||||
String tempDir,
|
||||
);
|
||||
|
||||
TaskEither<String, Unit> parseConfig(String path);
|
||||
TaskEither<String, Unit> parseConfig(
|
||||
String path,
|
||||
String tempPath,
|
||||
bool debug,
|
||||
);
|
||||
|
||||
TaskEither<String, Unit> changeConfigOptions(ConfigOptions options);
|
||||
|
||||
|
||||
2
libcore
2
libcore
Submodule libcore updated: 00bc20b86a...75e342b6ba
Reference in New Issue
Block a user