Optimize DNS strategy

Fix the problem that the tray is not displayed in some cases

Optimize tray

Update core

Fix some error
This commit is contained in:
chen08209
2024-09-05 08:59:45 +08:00
parent 6e5f1b8e5f
commit 846ec9728f
54 changed files with 903 additions and 391 deletions

View File

@@ -111,6 +111,9 @@ typedef GeoXMap = Map<String, String>;
typedef HostsMap = Map<String, String>;
const defaultMixedPort = 7890;
const defaultKeepAliveInterval = 30;
@JsonSerializable()
class ClashConfig extends ChangeNotifier {
int _mixedPort;
@@ -132,7 +135,7 @@ class ClashConfig extends ChangeNotifier {
HostsMap _hosts;
ClashConfig()
: _mixedPort = 7890,
: _mixedPort = defaultMixedPort,
_mode = Mode.rule,
_ipv6 = false,
_findProcessMode = FindProcessMode.off,
@@ -143,13 +146,13 @@ class ClashConfig extends ChangeNotifier {
_unifiedDelay = false,
_geodataLoader = geodataLoaderMemconservative,
_externalController = '',
_keepAliveInterval = 30,
_keepAliveInterval = defaultKeepAliveInterval,
_dns = const Dns(),
_geoXUrl = defaultGeoXMap,
_rules = [],
_hosts = {};
@JsonKey(name: "mixed-port", defaultValue: 7890)
@JsonKey(name: "mixed-port", defaultValue: defaultMixedPort)
int get mixedPort => _mixedPort;
set mixedPort(int value) {
@@ -209,7 +212,7 @@ class ClashConfig extends ChangeNotifier {
}
}
@JsonKey(name: "keep-alive-interval", defaultValue: 30)
@JsonKey(name: "keep-alive-interval", defaultValue: defaultKeepAliveInterval)
int get keepAliveInterval => _keepAliveInterval;
set keepAliveInterval(int value) {

View File

@@ -95,6 +95,21 @@ class DesktopProps with _$DesktopProps {
json == null ? const DesktopProps() : _$DesktopPropsFromJson(json);
}
const defaultCustomFontSizeScale = 1.0;
const defaultScaleProps = ScaleProps();
@freezed
class ScaleProps with _$ScaleProps {
const factory ScaleProps({
@Default(false) bool custom,
@Default(defaultCustomFontSizeScale) double scale,
}) = _ScaleProps;
factory ScaleProps.fromJson(Map<String, Object?>? json) =>
json == null ? defaultScaleProps : _$ScalePropsFromJson(json);
}
@JsonSerializable()
class Config extends ChangeNotifier {
List<Profile> _profiles;
@@ -124,6 +139,7 @@ class Config extends ChangeNotifier {
bool _onlyProxy;
bool _prueBlack;
VpnProps _vpnProps;
ScaleProps _scaleProps;
DesktopProps _desktopProps;
bool _showLabel;
bool _overrideDns;
@@ -155,7 +171,8 @@ class Config extends ChangeNotifier {
_vpnProps = const VpnProps(),
_desktopProps = const DesktopProps(),
_showLabel = false,
_overrideDns = false;
_overrideDns = false,
_scaleProps = const ScaleProps();
deleteProfileById(String id) {
_profiles = profiles.where((element) => element.id != id).toList();
@@ -551,6 +568,15 @@ class Config extends ChangeNotifier {
}
}
ScaleProps get scaleProps => _scaleProps;
set scaleProps(ScaleProps value) {
if (_scaleProps != value) {
_scaleProps = value;
notifyListeners();
}
}
@JsonKey(defaultValue: false)
bool get showLabel => _showLabel;
@@ -589,6 +615,7 @@ class Config extends ChangeNotifier {
_isCloseConnections = config._isCloseConnections;
_isCompatible = config._isCompatible;
_autoLaunch = config._autoLaunch;
_dav = config._dav;
_silentLaunch = config._silentLaunch;
_autoRun = config._autoRun;
_proxiesType = config._proxiesType;

View File

@@ -4,14 +4,16 @@ part 'generated/dav.g.dart';
part 'generated/dav.freezed.dart';
const defaultDavFileName = "backup.zip";
@freezed
class DAV with _$DAV{
class DAV with _$DAV {
const factory DAV({
required String uri,
required String user,
required String password,
@Default(defaultDavFileName) String fileName,
}) = _DAV;
factory DAV.fromJson(Map<String, Object?> json) =>
_$DAVFromJson(json);
}
factory DAV.fromJson(Map<String, Object?> json) => _$DAVFromJson(json);
}

View File

@@ -1240,3 +1240,159 @@ abstract class _DesktopProps implements DesktopProps {
_$$DesktopPropsImplCopyWith<_$DesktopPropsImpl> get copyWith =>
throw _privateConstructorUsedError;
}
ScaleProps _$ScalePropsFromJson(Map<String, dynamic> json) {
return _ScaleProps.fromJson(json);
}
/// @nodoc
mixin _$ScaleProps {
bool get custom => throw _privateConstructorUsedError;
double get scale => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
$ScalePropsCopyWith<ScaleProps> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $ScalePropsCopyWith<$Res> {
factory $ScalePropsCopyWith(
ScaleProps value, $Res Function(ScaleProps) then) =
_$ScalePropsCopyWithImpl<$Res, ScaleProps>;
@useResult
$Res call({bool custom, double scale});
}
/// @nodoc
class _$ScalePropsCopyWithImpl<$Res, $Val extends ScaleProps>
implements $ScalePropsCopyWith<$Res> {
_$ScalePropsCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
@pragma('vm:prefer-inline')
@override
$Res call({
Object? custom = null,
Object? scale = null,
}) {
return _then(_value.copyWith(
custom: null == custom
? _value.custom
: custom // ignore: cast_nullable_to_non_nullable
as bool,
scale: null == scale
? _value.scale
: scale // ignore: cast_nullable_to_non_nullable
as double,
) as $Val);
}
}
/// @nodoc
abstract class _$$ScalePropsImplCopyWith<$Res>
implements $ScalePropsCopyWith<$Res> {
factory _$$ScalePropsImplCopyWith(
_$ScalePropsImpl value, $Res Function(_$ScalePropsImpl) then) =
__$$ScalePropsImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({bool custom, double scale});
}
/// @nodoc
class __$$ScalePropsImplCopyWithImpl<$Res>
extends _$ScalePropsCopyWithImpl<$Res, _$ScalePropsImpl>
implements _$$ScalePropsImplCopyWith<$Res> {
__$$ScalePropsImplCopyWithImpl(
_$ScalePropsImpl _value, $Res Function(_$ScalePropsImpl) _then)
: super(_value, _then);
@pragma('vm:prefer-inline')
@override
$Res call({
Object? custom = null,
Object? scale = null,
}) {
return _then(_$ScalePropsImpl(
custom: null == custom
? _value.custom
: custom // ignore: cast_nullable_to_non_nullable
as bool,
scale: null == scale
? _value.scale
: scale // ignore: cast_nullable_to_non_nullable
as double,
));
}
}
/// @nodoc
@JsonSerializable()
class _$ScalePropsImpl implements _ScaleProps {
const _$ScalePropsImpl(
{this.custom = false, this.scale = defaultCustomFontSizeScale});
factory _$ScalePropsImpl.fromJson(Map<String, dynamic> json) =>
_$$ScalePropsImplFromJson(json);
@override
@JsonKey()
final bool custom;
@override
@JsonKey()
final double scale;
@override
String toString() {
return 'ScaleProps(custom: $custom, scale: $scale)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$ScalePropsImpl &&
(identical(other.custom, custom) || other.custom == custom) &&
(identical(other.scale, scale) || other.scale == scale));
}
@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, custom, scale);
@JsonKey(ignore: true)
@override
@pragma('vm:prefer-inline')
_$$ScalePropsImplCopyWith<_$ScalePropsImpl> get copyWith =>
__$$ScalePropsImplCopyWithImpl<_$ScalePropsImpl>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$$ScalePropsImplToJson(
this,
);
}
}
abstract class _ScaleProps implements ScaleProps {
const factory _ScaleProps({final bool custom, final double scale}) =
_$ScalePropsImpl;
factory _ScaleProps.fromJson(Map<String, dynamic> json) =
_$ScalePropsImpl.fromJson;
@override
bool get custom;
@override
double get scale;
@override
@JsonKey(ignore: true)
_$$ScalePropsImplCopyWith<_$ScalePropsImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -53,6 +53,8 @@ Config _$ConfigFromJson(Map<String, dynamic> json) => Config()
..vpnProps = VpnProps.fromJson(json['vpnProps'] as Map<String, dynamic>?)
..desktopProps =
DesktopProps.fromJson(json['desktopProps'] as Map<String, dynamic>?)
..scaleProps =
ScaleProps.fromJson(json['scaleProps'] as Map<String, dynamic>?)
..showLabel = json['showLabel'] as bool? ?? false
..overrideDns = json['overrideDns'] as bool? ?? false;
@@ -85,6 +87,7 @@ Map<String, dynamic> _$ConfigToJson(Config instance) => <String, dynamic>{
'windowProps': instance.windowProps,
'vpnProps': instance.vpnProps,
'desktopProps': instance.desktopProps,
'scaleProps': instance.scaleProps,
'showLabel': instance.showLabel,
'overrideDns': instance.overrideDns,
};
@@ -234,3 +237,15 @@ Map<String, dynamic> _$$DesktopPropsImplToJson(_$DesktopPropsImpl instance) =>
<String, dynamic>{
'systemProxy': instance.systemProxy,
};
_$ScalePropsImpl _$$ScalePropsImplFromJson(Map<String, dynamic> json) =>
_$ScalePropsImpl(
custom: json['custom'] as bool? ?? false,
scale: (json['scale'] as num?)?.toDouble() ?? defaultCustomFontSizeScale,
);
Map<String, dynamic> _$$ScalePropsImplToJson(_$ScalePropsImpl instance) =>
<String, dynamic>{
'custom': instance.custom,
'scale': instance.scale,
};

View File

@@ -23,6 +23,7 @@ mixin _$DAV {
String get uri => throw _privateConstructorUsedError;
String get user => throw _privateConstructorUsedError;
String get password => throw _privateConstructorUsedError;
String get fileName => throw _privateConstructorUsedError;
Map<String, dynamic> toJson() => throw _privateConstructorUsedError;
@JsonKey(ignore: true)
@@ -34,7 +35,7 @@ abstract class $DAVCopyWith<$Res> {
factory $DAVCopyWith(DAV value, $Res Function(DAV) then) =
_$DAVCopyWithImpl<$Res, DAV>;
@useResult
$Res call({String uri, String user, String password});
$Res call({String uri, String user, String password, String fileName});
}
/// @nodoc
@@ -52,6 +53,7 @@ class _$DAVCopyWithImpl<$Res, $Val extends DAV> implements $DAVCopyWith<$Res> {
Object? uri = null,
Object? user = null,
Object? password = null,
Object? fileName = null,
}) {
return _then(_value.copyWith(
uri: null == uri
@@ -66,6 +68,10 @@ class _$DAVCopyWithImpl<$Res, $Val extends DAV> implements $DAVCopyWith<$Res> {
? _value.password
: password // ignore: cast_nullable_to_non_nullable
as String,
fileName: null == fileName
? _value.fileName
: fileName // ignore: cast_nullable_to_non_nullable
as String,
) as $Val);
}
}
@@ -76,7 +82,7 @@ abstract class _$$DAVImplCopyWith<$Res> implements $DAVCopyWith<$Res> {
__$$DAVImplCopyWithImpl<$Res>;
@override
@useResult
$Res call({String uri, String user, String password});
$Res call({String uri, String user, String password, String fileName});
}
/// @nodoc
@@ -91,6 +97,7 @@ class __$$DAVImplCopyWithImpl<$Res> extends _$DAVCopyWithImpl<$Res, _$DAVImpl>
Object? uri = null,
Object? user = null,
Object? password = null,
Object? fileName = null,
}) {
return _then(_$DAVImpl(
uri: null == uri
@@ -105,6 +112,10 @@ class __$$DAVImplCopyWithImpl<$Res> extends _$DAVCopyWithImpl<$Res, _$DAVImpl>
? _value.password
: password // ignore: cast_nullable_to_non_nullable
as String,
fileName: null == fileName
? _value.fileName
: fileName // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
@@ -113,7 +124,10 @@ class __$$DAVImplCopyWithImpl<$Res> extends _$DAVCopyWithImpl<$Res, _$DAVImpl>
@JsonSerializable()
class _$DAVImpl implements _DAV {
const _$DAVImpl(
{required this.uri, required this.user, required this.password});
{required this.uri,
required this.user,
required this.password,
this.fileName = defaultDavFileName});
factory _$DAVImpl.fromJson(Map<String, dynamic> json) =>
_$$DAVImplFromJson(json);
@@ -124,10 +138,13 @@ class _$DAVImpl implements _DAV {
final String user;
@override
final String password;
@override
@JsonKey()
final String fileName;
@override
String toString() {
return 'DAV(uri: $uri, user: $user, password: $password)';
return 'DAV(uri: $uri, user: $user, password: $password, fileName: $fileName)';
}
@override
@@ -138,12 +155,14 @@ class _$DAVImpl implements _DAV {
(identical(other.uri, uri) || other.uri == uri) &&
(identical(other.user, user) || other.user == user) &&
(identical(other.password, password) ||
other.password == password));
other.password == password) &&
(identical(other.fileName, fileName) ||
other.fileName == fileName));
}
@JsonKey(ignore: true)
@override
int get hashCode => Object.hash(runtimeType, uri, user, password);
int get hashCode => Object.hash(runtimeType, uri, user, password, fileName);
@JsonKey(ignore: true)
@override
@@ -163,7 +182,8 @@ abstract class _DAV implements DAV {
const factory _DAV(
{required final String uri,
required final String user,
required final String password}) = _$DAVImpl;
required final String password,
final String fileName}) = _$DAVImpl;
factory _DAV.fromJson(Map<String, dynamic> json) = _$DAVImpl.fromJson;
@@ -174,6 +194,8 @@ abstract class _DAV implements DAV {
@override
String get password;
@override
String get fileName;
@override
@JsonKey(ignore: true)
_$$DAVImplCopyWith<_$DAVImpl> get copyWith =>
throw _privateConstructorUsedError;

View File

@@ -10,10 +10,12 @@ _$DAVImpl _$$DAVImplFromJson(Map<String, dynamic> json) => _$DAVImpl(
uri: json['uri'] as String,
user: json['user'] as String,
password: json['password'] as String,
fileName: json['fileName'] as String? ?? defaultDavFileName,
);
Map<String, dynamic> _$$DAVImplToJson(_$DAVImpl instance) => <String, dynamic>{
'uri': instance.uri,
'user': instance.user,
'password': instance.password,
'fileName': instance.fileName,
};

View File

@@ -3472,6 +3472,7 @@ mixin _$ClashConfigState {
int get mixedPort => throw _privateConstructorUsedError;
bool get allowLan => throw _privateConstructorUsedError;
bool get ipv6 => throw _privateConstructorUsedError;
bool get overrideDns => throw _privateConstructorUsedError;
String get geodataLoader => throw _privateConstructorUsedError;
LogLevel get logLevel => throw _privateConstructorUsedError;
String get externalController => throw _privateConstructorUsedError;
@@ -3502,6 +3503,7 @@ abstract class $ClashConfigStateCopyWith<$Res> {
{int mixedPort,
bool allowLan,
bool ipv6,
bool overrideDns,
String geodataLoader,
LogLevel logLevel,
String externalController,
@@ -3537,6 +3539,7 @@ class _$ClashConfigStateCopyWithImpl<$Res, $Val extends ClashConfigState>
Object? mixedPort = null,
Object? allowLan = null,
Object? ipv6 = null,
Object? overrideDns = null,
Object? geodataLoader = null,
Object? logLevel = null,
Object? externalController = null,
@@ -3565,6 +3568,10 @@ class _$ClashConfigStateCopyWithImpl<$Res, $Val extends ClashConfigState>
? _value.ipv6
: ipv6 // ignore: cast_nullable_to_non_nullable
as bool,
overrideDns: null == overrideDns
? _value.overrideDns
: overrideDns // ignore: cast_nullable_to_non_nullable
as bool,
geodataLoader: null == geodataLoader
? _value.geodataLoader
: geodataLoader // ignore: cast_nullable_to_non_nullable
@@ -3653,6 +3660,7 @@ abstract class _$$ClashConfigStateImplCopyWith<$Res>
{int mixedPort,
bool allowLan,
bool ipv6,
bool overrideDns,
String geodataLoader,
LogLevel logLevel,
String externalController,
@@ -3688,6 +3696,7 @@ class __$$ClashConfigStateImplCopyWithImpl<$Res>
Object? mixedPort = null,
Object? allowLan = null,
Object? ipv6 = null,
Object? overrideDns = null,
Object? geodataLoader = null,
Object? logLevel = null,
Object? externalController = null,
@@ -3716,6 +3725,10 @@ class __$$ClashConfigStateImplCopyWithImpl<$Res>
? _value.ipv6
: ipv6 // ignore: cast_nullable_to_non_nullable
as bool,
overrideDns: null == overrideDns
? _value.overrideDns
: overrideDns // ignore: cast_nullable_to_non_nullable
as bool,
geodataLoader: null == geodataLoader
? _value.geodataLoader
: geodataLoader // ignore: cast_nullable_to_non_nullable
@@ -3783,6 +3796,7 @@ class _$ClashConfigStateImpl implements _ClashConfigState {
{required this.mixedPort,
required this.allowLan,
required this.ipv6,
required this.overrideDns,
required this.geodataLoader,
required this.logLevel,
required this.externalController,
@@ -3808,6 +3822,8 @@ class _$ClashConfigStateImpl implements _ClashConfigState {
@override
final bool ipv6;
@override
final bool overrideDns;
@override
final String geodataLoader;
@override
final LogLevel logLevel;
@@ -3856,7 +3872,7 @@ class _$ClashConfigStateImpl implements _ClashConfigState {
@override
String toString() {
return 'ClashConfigState(mixedPort: $mixedPort, allowLan: $allowLan, ipv6: $ipv6, geodataLoader: $geodataLoader, logLevel: $logLevel, externalController: $externalController, mode: $mode, findProcessMode: $findProcessMode, keepAliveInterval: $keepAliveInterval, unifiedDelay: $unifiedDelay, tcpConcurrent: $tcpConcurrent, hosts: $hosts, tun: $tun, dns: $dns, geoXUrl: $geoXUrl, rules: $rules, globalRealUa: $globalRealUa)';
return 'ClashConfigState(mixedPort: $mixedPort, allowLan: $allowLan, ipv6: $ipv6, overrideDns: $overrideDns, geodataLoader: $geodataLoader, logLevel: $logLevel, externalController: $externalController, mode: $mode, findProcessMode: $findProcessMode, keepAliveInterval: $keepAliveInterval, unifiedDelay: $unifiedDelay, tcpConcurrent: $tcpConcurrent, hosts: $hosts, tun: $tun, dns: $dns, geoXUrl: $geoXUrl, rules: $rules, globalRealUa: $globalRealUa)';
}
@override
@@ -3869,6 +3885,8 @@ class _$ClashConfigStateImpl implements _ClashConfigState {
(identical(other.allowLan, allowLan) ||
other.allowLan == allowLan) &&
(identical(other.ipv6, ipv6) || other.ipv6 == ipv6) &&
(identical(other.overrideDns, overrideDns) ||
other.overrideDns == overrideDns) &&
(identical(other.geodataLoader, geodataLoader) ||
other.geodataLoader == geodataLoader) &&
(identical(other.logLevel, logLevel) ||
@@ -3899,6 +3917,7 @@ class _$ClashConfigStateImpl implements _ClashConfigState {
mixedPort,
allowLan,
ipv6,
overrideDns,
geodataLoader,
logLevel,
externalController,
@@ -3927,6 +3946,7 @@ abstract class _ClashConfigState implements ClashConfigState {
{required final int mixedPort,
required final bool allowLan,
required final bool ipv6,
required final bool overrideDns,
required final String geodataLoader,
required final LogLevel logLevel,
required final String externalController,
@@ -3949,6 +3969,8 @@ abstract class _ClashConfigState implements ClashConfigState {
@override
bool get ipv6;
@override
bool get overrideDns;
@override
String get geodataLoader;
@override
LogLevel get logLevel;

View File

@@ -228,6 +228,7 @@ class ClashConfigState with _$ClashConfigState {
required int mixedPort,
required bool allowLan,
required bool ipv6,
required bool overrideDns,
required String geodataLoader,
required LogLevel logLevel,
required String externalController,