Merge branch 'main' of hiddify-github:hiddify/hiddify-next

This commit is contained in:
Hiddify
2023-10-24 11:26:57 +02:00
parent 45d3243d9e
commit aa946deebd
38 changed files with 668 additions and 1686 deletions

View File

@@ -0,0 +1,62 @@
import 'package:dartx/dartx.dart';
import 'package:flutter/material.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:tint/tint.dart';
part 'box_log.freezed.dart';
enum LogLevel {
trace,
debug,
info,
warn,
error,
fatal,
panic;
static List<LogLevel> get choices => values.takeFirst(4);
Color? get color => switch (this) {
trace => Colors.lightBlueAccent,
debug => Colors.grey,
info => Colors.lightGreen,
warn => Colors.orange,
error => Colors.redAccent,
fatal => Colors.red,
panic => Colors.red,
};
}
@freezed
class BoxLog with _$BoxLog {
const factory BoxLog({
LogLevel? level,
DateTime? time,
required String message,
}) = _BoxLog;
factory BoxLog.parse(String log) {
log = log.strip();
DateTime? time;
if (log.length > 25) {
time = DateTime.tryParse(log.substring(6, 25));
}
if (time != null) {
log = log.substring(26);
}
final level = LogLevel.values.firstOrNullWhere(
(e) {
if (log.startsWith(e.name.toUpperCase())) {
log = log.removePrefix(e.name.toUpperCase());
return true;
}
return false;
},
);
return BoxLog(
level: level,
time: time,
message: log.trim(),
);
}
}

View File

@@ -2,6 +2,8 @@ import 'dart:convert';
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hiddify/core/prefs/prefs.dart';
import 'package:hiddify/domain/singbox/box_log.dart';
import 'package:hiddify/domain/singbox/rules.dart';
import 'package:hiddify/utils/platform_utils.dart';
part 'config_options.freezed.dart';
@@ -19,13 +21,13 @@ class ConfigOptions with _$ConfigOptions {
@Default(IPv6Mode.disable) IPv6Mode ipv6Mode,
@Default("tcp://8.8.8.8") String remoteDnsAddress,
@Default(DomainStrategy.auto) DomainStrategy remoteDnsDomainStrategy,
@Default("8.8.8.8") String directDnsAddress,
@Default("local") String directDnsAddress,
@Default(DomainStrategy.auto) DomainStrategy directDnsDomainStrategy,
@Default(2334) int mixedPort,
@Default(6450) int localDnsPort,
@Default(TunImplementation.mixed) TunImplementation tunImplementation,
@Default(9000) int mtu,
@Default("https://www.gstatic.com/generate_204") String connectionTestUrl,
@Default("http://cp.cloudflare.com/") String connectionTestUrl,
@IntervalConverter()
@Default(Duration(minutes: 10))
Duration urlTestInterval,
@@ -33,6 +35,9 @@ class ConfigOptions with _$ConfigOptions {
@Default(6756) int clashApiPort,
@Default(false) bool enableTun,
@Default(true) bool setSystemProxy,
@Default(false) bool bypassLan,
@Default(false) bool enableFakeDns,
List<Rule>? rules,
}) = _ConfigOptions;
static ConfigOptions initial = ConfigOptions(
@@ -49,13 +54,6 @@ class ConfigOptions with _$ConfigOptions {
_$ConfigOptionsFromJson(json);
}
enum LogLevel {
warn,
info,
debug,
trace,
}
@JsonEnum(valueField: 'key')
enum IPv6Mode {
disable("ipv4_only"),

View File

@@ -1,5 +1,40 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hiddify/core/prefs/locale_prefs.dart';
part 'rules.freezed.dart';
part 'rules.g.dart';
@freezed
class Rule with _$Rule {
@JsonSerializable(fieldRename: FieldRename.kebab)
const factory Rule({
required String id,
required String name,
@Default(false) bool enabled,
String? domains,
String? ip,
String? port,
String? protocol,
@Default(RuleNetwork.tcpAndUdp) RuleNetwork network,
@Default(RuleOutbound.proxy) RuleOutbound outbound,
}) = _Rule;
factory Rule.fromJson(Map<String, dynamic> json) => _$RuleFromJson(json);
}
enum RuleOutbound { proxy, bypass, block }
@JsonEnum(valueField: 'key')
enum RuleNetwork {
tcpAndUdp(""),
tcp("tcp"),
udp("udp");
const RuleNetwork(this.key);
final String? key;
}
enum PerAppProxyMode {
off,
include,
@@ -26,11 +61,13 @@ enum PerAppProxyMode {
enum Region {
ir,
cn,
ru,
other;
String present(TranslationsEn t) => switch (this) {
ir => t.settings.general.regions.ir,
cn => t.settings.general.regions.cn,
ru => t.settings.general.regions.ru,
other => t.settings.general.regions.other,
};
}

View File

@@ -1,3 +1,4 @@
export 'box_log.dart';
export 'config_options.dart';
export 'core_status.dart';
export 'outbounds.dart';

View File

@@ -37,5 +37,7 @@ abstract interface class SingboxFacade {
Stream<Either<CoreServiceFailure, CoreStatus>> watchCoreStatus();
Stream<Either<CoreServiceFailure, String>> watchLogs();
Stream<Either<CoreServiceFailure, List<String>>> watchLogs();
TaskEither<CoreServiceFailure, Unit> clearLogs();
}