Refactor
This commit is contained in:
37
lib/features/proxy/model/proxy_entity.dart
Normal file
37
lib/features/proxy/model/proxy_entity.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:hiddify/singbox/model/singbox_proxy_type.dart';
|
||||
|
||||
part 'proxy_entity.freezed.dart';
|
||||
|
||||
@freezed
|
||||
class ProxyGroupEntity with _$ProxyGroupEntity {
|
||||
const ProxyGroupEntity._();
|
||||
|
||||
const factory ProxyGroupEntity({
|
||||
required String tag,
|
||||
required ProxyType type,
|
||||
required String selected,
|
||||
@Default([]) List<ProxyItemEntity> items,
|
||||
}) = _ProxyGroupEntity;
|
||||
|
||||
String get name => _sanitizedTag(tag);
|
||||
}
|
||||
|
||||
@freezed
|
||||
class ProxyItemEntity with _$ProxyItemEntity {
|
||||
const ProxyItemEntity._();
|
||||
|
||||
const factory ProxyItemEntity({
|
||||
required String tag,
|
||||
required ProxyType type,
|
||||
required int urlTestDelay,
|
||||
String? selectedTag,
|
||||
}) = _ProxyItemEntity;
|
||||
|
||||
String get name => _sanitizedTag(tag);
|
||||
String? get selectedName =>
|
||||
selectedTag == null ? null : _sanitizedTag(selectedTag!);
|
||||
}
|
||||
|
||||
String _sanitizedTag(String tag) =>
|
||||
tag.replaceFirst(RegExp(r"\§[^]*"), "").trimRight();
|
||||
33
lib/features/proxy/model/proxy_failure.dart
Normal file
33
lib/features/proxy/model/proxy_failure.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:hiddify/core/localization/translations.dart';
|
||||
import 'package:hiddify/core/model/failures.dart';
|
||||
|
||||
part 'proxy_failure.freezed.dart';
|
||||
|
||||
@freezed
|
||||
sealed class ProxyFailure with _$ProxyFailure, Failure {
|
||||
const ProxyFailure._();
|
||||
|
||||
@With<UnexpectedFailure>()
|
||||
const factory ProxyFailure.unexpected([
|
||||
Object? error,
|
||||
StackTrace? stackTrace,
|
||||
]) = ProxyUnexpectedFailure;
|
||||
|
||||
@With<ExpectedFailure>()
|
||||
const factory ProxyFailure.serviceNotRunning() = ServiceNotRunning;
|
||||
|
||||
@override
|
||||
({String type, String? message}) present(TranslationsEn t) {
|
||||
return switch (this) {
|
||||
ProxyUnexpectedFailure() => (
|
||||
type: t.failure.unexpected,
|
||||
message: null,
|
||||
),
|
||||
ServiceNotRunning() => (
|
||||
type: t.failure.singbox.serviceNotRunning,
|
||||
message: null,
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user