Files
umbrix/lib/domain/singbox/rules.dart

74 lines
1.8 KiB
Dart
Raw Normal View History

import 'package:freezed_annotation/freezed_annotation.dart';
2023-09-13 23:19:16 +03:30
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({
2023-11-19 12:29:30 +03:30
@JsonKey(includeToJson: false) required String id,
@JsonKey(includeToJson: false) required String name,
@JsonKey(includeToJson: false) @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;
}
2023-09-13 23:19:16 +03:30
enum PerAppProxyMode {
off,
include,
exclude;
bool get enabled => this != off;
({String title, String message}) present(TranslationsEn t) => switch (this) {
off => (
title: t.settings.network.perAppProxyModes.off,
message: t.settings.network.perAppProxyModes.offMsg,
),
include => (
title: t.settings.network.perAppProxyModes.include,
message: t.settings.network.perAppProxyModes.includeMsg,
),
exclude => (
title: t.settings.network.perAppProxyModes.exclude,
message: t.settings.network.perAppProxyModes.excludeMsg,
),
};
}
2023-09-17 14:55:46 +03:30
enum Region {
ir,
cn,
ru,
2023-09-17 14:55:46 +03:30
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,
2023-09-17 14:55:46 +03:30
other => t.settings.general.regions.other,
};
}