2023-10-06 23:42:06 +03:30
|
|
|
import 'dart:convert';
|
|
|
|
|
|
2023-09-01 15:00:41 +03:30
|
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
2023-09-06 12:56:30 +03:30
|
|
|
import 'package:hiddify/core/prefs/prefs.dart';
|
2023-10-24 11:26:57 +02:00
|
|
|
import 'package:hiddify/domain/singbox/box_log.dart';
|
|
|
|
|
import 'package:hiddify/domain/singbox/rules.dart';
|
2023-09-01 15:00:41 +03:30
|
|
|
|
|
|
|
|
part 'config_options.freezed.dart';
|
|
|
|
|
part 'config_options.g.dart';
|
|
|
|
|
|
|
|
|
|
@freezed
|
|
|
|
|
class ConfigOptions with _$ConfigOptions {
|
2023-10-06 23:42:06 +03:30
|
|
|
const ConfigOptions._();
|
|
|
|
|
|
2023-09-01 15:00:41 +03:30
|
|
|
@JsonSerializable(fieldRename: FieldRename.kebab)
|
|
|
|
|
const factory ConfigOptions({
|
|
|
|
|
@Default(false) bool executeConfigAsIs,
|
|
|
|
|
@Default(LogLevel.warn) LogLevel logLevel,
|
|
|
|
|
@Default(false) bool resolveDestination,
|
|
|
|
|
@Default(IPv6Mode.disable) IPv6Mode ipv6Mode,
|
2023-09-07 13:42:44 +03:30
|
|
|
@Default("tcp://8.8.8.8") String remoteDnsAddress,
|
2023-09-01 15:00:41 +03:30
|
|
|
@Default(DomainStrategy.auto) DomainStrategy remoteDnsDomainStrategy,
|
2023-10-24 11:26:57 +02:00
|
|
|
@Default("local") String directDnsAddress,
|
2023-09-01 15:00:41 +03:30
|
|
|
@Default(DomainStrategy.auto) DomainStrategy directDnsDomainStrategy,
|
|
|
|
|
@Default(2334) int mixedPort,
|
|
|
|
|
@Default(6450) int localDnsPort,
|
2023-09-05 19:04:46 +03:30
|
|
|
@Default(TunImplementation.mixed) TunImplementation tunImplementation,
|
2023-09-01 15:00:41 +03:30
|
|
|
@Default(9000) int mtu,
|
2023-11-11 23:10:58 +03:30
|
|
|
@Default(true) bool strictRoute,
|
2023-10-24 11:26:57 +02:00
|
|
|
@Default("http://cp.cloudflare.com/") String connectionTestUrl,
|
2023-09-01 15:00:41 +03:30
|
|
|
@IntervalConverter()
|
2023-09-05 19:04:46 +03:30
|
|
|
@Default(Duration(minutes: 10))
|
2023-09-01 15:00:41 +03:30
|
|
|
Duration urlTestInterval,
|
|
|
|
|
@Default(true) bool enableClashApi,
|
2023-09-07 13:42:44 +03:30
|
|
|
@Default(6756) int clashApiPort,
|
2023-09-01 15:00:41 +03:30
|
|
|
@Default(false) bool enableTun,
|
2023-11-01 22:01:43 +03:30
|
|
|
@Default(false) bool setSystemProxy,
|
2023-10-24 11:26:57 +02:00
|
|
|
@Default(false) bool bypassLan,
|
|
|
|
|
@Default(false) bool enableFakeDns,
|
2023-11-14 19:16:14 +03:30
|
|
|
@Default(true) bool independentDnsCache,
|
2023-11-17 21:30:09 +03:30
|
|
|
@Default("geoip.db") String geoipPath,
|
|
|
|
|
@Default("geosite.db") String geositePath,
|
2023-10-24 11:26:57 +02:00
|
|
|
List<Rule>? rules,
|
2023-09-01 15:00:41 +03:30
|
|
|
}) = _ConfigOptions;
|
|
|
|
|
|
2023-11-01 22:01:43 +03:30
|
|
|
static ConfigOptions initial = const ConfigOptions();
|
2023-09-01 15:00:41 +03:30
|
|
|
|
2023-10-06 23:42:06 +03:30
|
|
|
String format() {
|
|
|
|
|
const encoder = JsonEncoder.withIndent(' ');
|
|
|
|
|
return encoder.convert(toJson());
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-01 15:00:41 +03:30
|
|
|
factory ConfigOptions.fromJson(Map<String, dynamic> json) =>
|
|
|
|
|
_$ConfigOptionsFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JsonEnum(valueField: 'key')
|
|
|
|
|
enum IPv6Mode {
|
|
|
|
|
disable("ipv4_only"),
|
|
|
|
|
enable("prefer_ipv4"),
|
|
|
|
|
prefer("prefer_ipv6"),
|
|
|
|
|
only("ipv6_only");
|
|
|
|
|
|
|
|
|
|
const IPv6Mode(this.key);
|
|
|
|
|
|
|
|
|
|
final String key;
|
|
|
|
|
|
|
|
|
|
String present(TranslationsEn t) => switch (this) {
|
|
|
|
|
disable => t.settings.config.ipv6Modes.disable,
|
|
|
|
|
enable => t.settings.config.ipv6Modes.enable,
|
|
|
|
|
prefer => t.settings.config.ipv6Modes.prefer,
|
|
|
|
|
only => t.settings.config.ipv6Modes.only,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@JsonEnum(valueField: 'key')
|
|
|
|
|
enum DomainStrategy {
|
|
|
|
|
auto(""),
|
|
|
|
|
preferIpv6("prefer_ipv6"),
|
|
|
|
|
preferIpv4("prefer_ipv4"),
|
|
|
|
|
ipv4Only("ipv4_only"),
|
|
|
|
|
ipv6Only("ipv6_only");
|
|
|
|
|
|
|
|
|
|
const DomainStrategy(this.key);
|
|
|
|
|
|
|
|
|
|
final String key;
|
|
|
|
|
|
|
|
|
|
String get displayName => switch (this) {
|
|
|
|
|
auto => "auto",
|
|
|
|
|
_ => key,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-05 19:04:46 +03:30
|
|
|
enum TunImplementation {
|
|
|
|
|
mixed,
|
|
|
|
|
system,
|
|
|
|
|
gVisor;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-01 15:00:41 +03:30
|
|
|
class IntervalConverter implements JsonConverter<Duration, String> {
|
|
|
|
|
const IntervalConverter();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Duration fromJson(String json) =>
|
|
|
|
|
Duration(minutes: int.parse(json.replaceAll("m", "")));
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
String toJson(Duration object) => "${object.inMinutes}m";
|
|
|
|
|
}
|