@@ -21,36 +21,44 @@ class DictionarySettings {
2121 /// 查词面板打开或切换到新词时是否自动播放发音
2222 final bool autoSpeakOnLookup;
2323
24+ /// 是否在网页词典中启用通用广告过滤
25+ final bool adFilteringEnabled;
26+
2427 /// 默认源 id 缺省值
2528 static const defaultId = 'local' ;
2629
2730 DictionarySettings ({
2831 this .defaultSourceId = defaultId,
2932 Set <String > disabledIds = const {},
3033 this .autoSpeakOnLookup = true ,
34+ this .adFilteringEnabled = false ,
3135 }) : disabledIds = UnmodifiableSetView (Set .of (disabledIds));
3236
3337 DictionarySettings copyWith ({
3438 String ? defaultSourceId,
3539 Set <String >? disabledIds,
3640 bool ? autoSpeakOnLookup,
41+ bool ? adFilteringEnabled,
3742 }) => DictionarySettings (
3843 defaultSourceId: defaultSourceId ?? this .defaultSourceId,
3944 disabledIds: disabledIds ?? this .disabledIds,
4045 autoSpeakOnLookup: autoSpeakOnLookup ?? this .autoSpeakOnLookup,
46+ adFilteringEnabled: adFilteringEnabled ?? this .adFilteringEnabled,
4147 );
4248
4349 Map <String , dynamic > toJson () => {
4450 'defaultSourceId' : defaultSourceId,
4551 'disabledIds' : disabledIds.toList (),
4652 'autoSpeakOnLookup' : autoSpeakOnLookup,
53+ 'adFilteringEnabled' : adFilteringEnabled,
4754 };
4855
4956 /// 防御性解析:字段缺失/类型不符回退缺省
5057 factory DictionarySettings .fromJson (Map <String , dynamic > json) {
5158 final rawDefault = json['defaultSourceId' ];
5259 final rawDisabled = json['disabledIds' ];
5360 final rawAutoSpeak = json['autoSpeakOnLookup' ];
61+ final rawAdFilteringEnabled = json['adFilteringEnabled' ];
5462 return DictionarySettings (
5563 defaultSourceId: rawDefault is String && rawDefault.isNotEmpty
5664 ? rawDefault
@@ -59,6 +67,9 @@ class DictionarySettings {
5967 ? rawDisabled.whereType <String >().toSet ()
6068 : const {},
6169 autoSpeakOnLookup: rawAutoSpeak is bool ? rawAutoSpeak : true ,
70+ adFilteringEnabled: rawAdFilteringEnabled is bool
71+ ? rawAdFilteringEnabled
72+ : false ,
6273 );
6374 }
6475
@@ -69,13 +80,15 @@ class DictionarySettings {
6980 runtimeType == other.runtimeType &&
7081 defaultSourceId == other.defaultSourceId &&
7182 _setEquals (disabledIds, other.disabledIds) &&
72- autoSpeakOnLookup == other.autoSpeakOnLookup;
83+ autoSpeakOnLookup == other.autoSpeakOnLookup &&
84+ adFilteringEnabled == other.adFilteringEnabled;
7385
7486 @override
7587 int get hashCode => Object .hash (
7688 defaultSourceId,
7789 Object .hashAllUnordered (disabledIds),
7890 autoSpeakOnLookup,
91+ adFilteringEnabled,
7992 );
8093
8194 static bool _setEquals (Set <String > a, Set <String > b) =>
0 commit comments