Add config options
This commit is contained in:
@@ -16,6 +16,10 @@ sealed class CoreServiceFailure with _$CoreServiceFailure, Failure {
|
||||
const factory CoreServiceFailure.serviceNotRunning([String? message]) =
|
||||
CoreServiceNotRunning;
|
||||
|
||||
const factory CoreServiceFailure.invalidConfigOptions([
|
||||
String? message,
|
||||
]) = InvalidConfigOptions;
|
||||
|
||||
const factory CoreServiceFailure.invalidConfig([
|
||||
String? message,
|
||||
]) = InvalidConfig;
|
||||
@@ -35,6 +39,7 @@ sealed class CoreServiceFailure with _$CoreServiceFailure, Failure {
|
||||
String? get msg => switch (this) {
|
||||
UnexpectedCoreServiceFailure() => null,
|
||||
CoreServiceNotRunning(:final message) => message,
|
||||
InvalidConfigOptions(:final message) => message,
|
||||
InvalidConfig(:final message) => message,
|
||||
CoreServiceCreateFailure(:final message) => message,
|
||||
CoreServiceStartFailure(:final message) => message,
|
||||
@@ -52,6 +57,10 @@ sealed class CoreServiceFailure with _$CoreServiceFailure, Failure {
|
||||
type: t.failure.singbox.serviceNotRunning,
|
||||
message: message
|
||||
),
|
||||
InvalidConfigOptions(:final message) => (
|
||||
type: t.failure.singbox.invalidConfigOptions,
|
||||
message: message
|
||||
),
|
||||
InvalidConfig(:final message) => (
|
||||
type: t.failure.singbox.invalidConfig,
|
||||
message: message
|
||||
|
||||
95
lib/domain/singbox/config_options.dart
Normal file
95
lib/domain/singbox/config_options.dart
Normal file
@@ -0,0 +1,95 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:hiddify/core/locale/locale.dart';
|
||||
import 'package:hiddify/utils/platform_utils.dart';
|
||||
|
||||
part 'config_options.freezed.dart';
|
||||
part 'config_options.g.dart';
|
||||
|
||||
@freezed
|
||||
class ConfigOptions with _$ConfigOptions {
|
||||
@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,
|
||||
@Default("https://8.8.8.8/dns-query") String remoteDnsAddress,
|
||||
@Default(DomainStrategy.auto) DomainStrategy remoteDnsDomainStrategy,
|
||||
@Default("https://235.5.5.5/dns-query") String directDnsAddress,
|
||||
@Default(DomainStrategy.auto) DomainStrategy directDnsDomainStrategy,
|
||||
@Default(2334) int mixedPort,
|
||||
@Default(6450) int localDnsPort,
|
||||
@Default(9000) int mtu,
|
||||
@Default("https://www.gstatic.com/generate_204") String connectionTestUrl,
|
||||
@IntervalConverter()
|
||||
@Default(Duration(minutes: 5))
|
||||
Duration urlTestInterval,
|
||||
@Default(true) bool enableClashApi,
|
||||
@Default(9090) int clashApiPort,
|
||||
@Default(false) bool enableTun,
|
||||
@Default(true) bool setSystemProxy,
|
||||
}) = _ConfigOptions;
|
||||
|
||||
static ConfigOptions initial = ConfigOptions(
|
||||
enableTun: !PlatformUtils.isDesktop,
|
||||
setSystemProxy: PlatformUtils.isDesktop,
|
||||
);
|
||||
|
||||
factory ConfigOptions.fromJson(Map<String, dynamic> json) =>
|
||||
_$ConfigOptionsFromJson(json);
|
||||
}
|
||||
|
||||
enum LogLevel {
|
||||
warn,
|
||||
info,
|
||||
debug,
|
||||
trace,
|
||||
}
|
||||
|
||||
@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,
|
||||
};
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export 'config_options.dart';
|
||||
export 'core_status.dart';
|
||||
export 'outbounds.dart';
|
||||
export 'proxy_type.dart';
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import 'package:fpdart/fpdart.dart';
|
||||
import 'package:hiddify/domain/core_service_failure.dart';
|
||||
import 'package:hiddify/domain/singbox/config_options.dart';
|
||||
import 'package:hiddify/domain/singbox/core_status.dart';
|
||||
import 'package:hiddify/domain/singbox/outbounds.dart';
|
||||
|
||||
@@ -8,6 +9,10 @@ abstract interface class SingboxFacade {
|
||||
|
||||
TaskEither<CoreServiceFailure, Unit> parseConfig(String path);
|
||||
|
||||
TaskEither<CoreServiceFailure, Unit> changeConfigOptions(
|
||||
ConfigOptions options,
|
||||
);
|
||||
|
||||
TaskEither<CoreServiceFailure, Unit> changeConfig(String fileName);
|
||||
|
||||
TaskEither<CoreServiceFailure, Unit> start();
|
||||
|
||||
Reference in New Issue
Block a user