2024-04-30 23:38:49 +08:00
|
|
|
// ignore_for_file: invalid_annotation_target
|
|
|
|
|
|
2024-12-03 21:47:12 +08:00
|
|
|
import 'dart:convert';
|
|
|
|
|
|
2024-04-30 23:38:49 +08:00
|
|
|
import 'package:fl_clash/enum/enum.dart';
|
2024-07-02 08:08:31 +08:00
|
|
|
import 'package:fl_clash/models/models.dart';
|
2024-04-30 23:38:49 +08:00
|
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
|
|
2024-12-03 21:47:12 +08:00
|
|
|
part 'generated/core.freezed.dart';
|
|
|
|
|
part 'generated/core.g.dart';
|
|
|
|
|
|
|
|
|
|
abstract mixin class AppMessageListener {
|
|
|
|
|
void onLog(Log log) {}
|
|
|
|
|
|
|
|
|
|
void onDelay(Delay delay) {}
|
|
|
|
|
|
|
|
|
|
void onRequest(Connection connection) {}
|
|
|
|
|
|
|
|
|
|
void onStarted(String runTime) {}
|
|
|
|
|
|
|
|
|
|
void onLoaded(String providerName) {}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
abstract mixin class ServiceMessageListener {
|
|
|
|
|
onProtect(Fd fd) {}
|
|
|
|
|
|
|
|
|
|
onProcess(ProcessData process) {}
|
|
|
|
|
|
|
|
|
|
onStarted(String runTime) {}
|
|
|
|
|
|
|
|
|
|
onLoaded(String providerName) {}
|
|
|
|
|
}
|
2024-04-30 23:38:49 +08:00
|
|
|
|
2024-09-26 14:29:04 +08:00
|
|
|
@freezed
|
|
|
|
|
class CoreState with _$CoreState {
|
|
|
|
|
const factory CoreState({
|
|
|
|
|
required bool enable,
|
|
|
|
|
AccessControl? accessControl,
|
|
|
|
|
required String currentProfileName,
|
|
|
|
|
required bool allowBypass,
|
|
|
|
|
required bool systemProxy,
|
|
|
|
|
required List<String> bypassDomain,
|
2024-11-09 20:17:57 +08:00
|
|
|
required List<String> routeAddress,
|
2024-09-26 14:29:04 +08:00
|
|
|
required bool ipv6,
|
|
|
|
|
required bool onlyProxy,
|
|
|
|
|
}) = _CoreState;
|
|
|
|
|
|
|
|
|
|
factory CoreState.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$CoreStateFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@freezed
|
|
|
|
|
class AndroidVpnOptions with _$AndroidVpnOptions {
|
|
|
|
|
const factory AndroidVpnOptions({
|
|
|
|
|
required bool enable,
|
|
|
|
|
required int port,
|
|
|
|
|
required AccessControl? accessControl,
|
|
|
|
|
required bool allowBypass,
|
|
|
|
|
required bool systemProxy,
|
|
|
|
|
required List<String> bypassDomain,
|
|
|
|
|
required String ipv4Address,
|
|
|
|
|
required String ipv6Address,
|
2024-11-09 20:17:57 +08:00
|
|
|
required List<String> routeAddress,
|
2024-09-26 14:29:04 +08:00
|
|
|
required String dnsServerAddress,
|
|
|
|
|
}) = _AndroidVpnOptions;
|
|
|
|
|
|
|
|
|
|
factory AndroidVpnOptions.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$AndroidVpnOptionsFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-02 08:08:31 +08:00
|
|
|
@freezed
|
|
|
|
|
class ConfigExtendedParams with _$ConfigExtendedParams {
|
|
|
|
|
const factory ConfigExtendedParams({
|
|
|
|
|
@JsonKey(name: "is-patch") required bool isPatch,
|
|
|
|
|
@JsonKey(name: "is-compatible") required bool isCompatible,
|
|
|
|
|
@JsonKey(name: "selected-map") required SelectedMap selectedMap,
|
2024-08-26 20:44:30 +08:00
|
|
|
@JsonKey(name: "override-dns") required bool overrideDns,
|
2024-07-02 08:08:31 +08:00
|
|
|
@JsonKey(name: "test-url") required String testUrl,
|
|
|
|
|
}) = _ConfigExtendedParams;
|
|
|
|
|
|
|
|
|
|
factory ConfigExtendedParams.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$ConfigExtendedParamsFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-30 23:38:49 +08:00
|
|
|
@freezed
|
|
|
|
|
class UpdateConfigParams with _$UpdateConfigParams {
|
|
|
|
|
const factory UpdateConfigParams({
|
2024-08-04 08:21:14 +08:00
|
|
|
@JsonKey(name: "profile-id") required String profileId,
|
2024-04-30 23:38:49 +08:00
|
|
|
required ClashConfig config,
|
2024-07-02 08:08:31 +08:00
|
|
|
required ConfigExtendedParams params,
|
2024-04-30 23:38:49 +08:00
|
|
|
}) = _UpdateConfigParams;
|
|
|
|
|
|
|
|
|
|
factory UpdateConfigParams.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$UpdateConfigParamsFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@freezed
|
|
|
|
|
class ChangeProxyParams with _$ChangeProxyParams {
|
|
|
|
|
const factory ChangeProxyParams({
|
|
|
|
|
@JsonKey(name: "group-name") required String groupName,
|
|
|
|
|
@JsonKey(name: "proxy-name") required String proxyName,
|
|
|
|
|
}) = _ChangeProxyParams;
|
|
|
|
|
|
|
|
|
|
factory ChangeProxyParams.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$ChangeProxyParamsFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@freezed
|
2024-07-13 16:36:08 +08:00
|
|
|
class AppMessage with _$AppMessage {
|
|
|
|
|
const factory AppMessage({
|
|
|
|
|
required AppMessageType type,
|
2024-04-30 23:38:49 +08:00
|
|
|
dynamic data,
|
2024-07-13 16:36:08 +08:00
|
|
|
}) = _AppMessage;
|
2024-04-30 23:38:49 +08:00
|
|
|
|
2024-07-13 16:36:08 +08:00
|
|
|
factory AppMessage.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$AppMessageFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@freezed
|
|
|
|
|
class ServiceMessage with _$ServiceMessage {
|
|
|
|
|
const factory ServiceMessage({
|
|
|
|
|
required ServiceMessageType type,
|
|
|
|
|
dynamic data,
|
|
|
|
|
}) = _ServiceMessage;
|
|
|
|
|
|
|
|
|
|
factory ServiceMessage.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$ServiceMessageFromJson(json);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@freezed
|
|
|
|
|
class Delay with _$Delay {
|
|
|
|
|
const factory Delay({
|
|
|
|
|
required String name,
|
|
|
|
|
int? value,
|
|
|
|
|
}) = _Delay;
|
|
|
|
|
|
|
|
|
|
factory Delay.fromJson(Map<String, Object?> json) => _$DelayFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-05 21:40:12 +08:00
|
|
|
@freezed
|
|
|
|
|
class Now with _$Now {
|
|
|
|
|
const factory Now({
|
|
|
|
|
required String name,
|
|
|
|
|
required String value,
|
|
|
|
|
}) = _Now;
|
|
|
|
|
|
|
|
|
|
factory Now.fromJson(Map<String, Object?> json) => _$NowFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-30 23:38:49 +08:00
|
|
|
@freezed
|
2024-12-03 21:47:12 +08:00
|
|
|
class ProcessData with _$ProcessData {
|
|
|
|
|
const factory ProcessData({
|
2024-06-13 23:43:42 +08:00
|
|
|
required int id,
|
|
|
|
|
required Metadata metadata,
|
2024-12-03 21:47:12 +08:00
|
|
|
}) = _ProcessData;
|
2024-04-30 23:38:49 +08:00
|
|
|
|
2024-12-03 21:47:12 +08:00
|
|
|
factory ProcessData.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$ProcessDataFromJson(json);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
2024-06-03 18:02:05 +08:00
|
|
|
|
2024-07-02 08:08:31 +08:00
|
|
|
@freezed
|
|
|
|
|
class Fd with _$Fd {
|
|
|
|
|
const factory Fd({
|
|
|
|
|
required int id,
|
|
|
|
|
required int value,
|
|
|
|
|
}) = _Fd;
|
|
|
|
|
|
|
|
|
|
factory Fd.fromJson(Map<String, Object?> json) => _$FdFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-13 23:43:42 +08:00
|
|
|
@freezed
|
|
|
|
|
class ProcessMapItem with _$ProcessMapItem {
|
|
|
|
|
const factory ProcessMapItem({
|
|
|
|
|
required int id,
|
2024-06-16 19:04:33 +08:00
|
|
|
required String value,
|
2024-06-13 23:43:42 +08:00
|
|
|
}) = _ProcessMapItem;
|
|
|
|
|
|
|
|
|
|
factory ProcessMapItem.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$ProcessMapItemFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-09 20:17:57 +08:00
|
|
|
@freezed
|
|
|
|
|
class ProviderSubscriptionInfo with _$ProviderSubscriptionInfo {
|
|
|
|
|
const factory ProviderSubscriptionInfo({
|
|
|
|
|
@JsonKey(name: "UPLOAD") @Default(0) int upload,
|
|
|
|
|
@JsonKey(name: "DOWNLOAD") @Default(0) int download,
|
|
|
|
|
@JsonKey(name: "TOTAL") @Default(0) int total,
|
|
|
|
|
@JsonKey(name: "EXPIRE") @Default(0) int expire,
|
|
|
|
|
}) = _ProviderSubscriptionInfo;
|
|
|
|
|
|
|
|
|
|
factory ProviderSubscriptionInfo.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$ProviderSubscriptionInfoFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SubscriptionInfo? subscriptionInfoFormCore(Map<String, Object?>? json) {
|
|
|
|
|
if (json == null) return null;
|
|
|
|
|
return SubscriptionInfo(
|
|
|
|
|
upload: (json['Upload'] as num?)?.toInt() ?? 0,
|
|
|
|
|
download: (json['Download'] as num?)?.toInt() ?? 0,
|
|
|
|
|
total: (json['Total'] as num?)?.toInt() ?? 0,
|
|
|
|
|
expire: (json['Expire'] as num?)?.toInt() ?? 0,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-03 18:02:05 +08:00
|
|
|
@freezed
|
|
|
|
|
class ExternalProvider with _$ExternalProvider {
|
|
|
|
|
const factory ExternalProvider({
|
|
|
|
|
required String name,
|
|
|
|
|
required String type,
|
2024-11-09 20:17:57 +08:00
|
|
|
String? path,
|
2024-08-04 08:21:14 +08:00
|
|
|
required int count,
|
2024-11-09 20:17:57 +08:00
|
|
|
@JsonKey(name: "subscription-info", fromJson: subscriptionInfoFormCore)
|
|
|
|
|
SubscriptionInfo? subscriptionInfo,
|
2024-08-04 08:21:14 +08:00
|
|
|
@Default(false) bool isUpdating,
|
2024-06-03 18:02:05 +08:00
|
|
|
@JsonKey(name: "vehicle-type") required String vehicleType,
|
|
|
|
|
@JsonKey(name: "update-at") required DateTime updateAt,
|
|
|
|
|
}) = _ExternalProvider;
|
|
|
|
|
|
|
|
|
|
factory ExternalProvider.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$ExternalProviderFromJson(json);
|
|
|
|
|
}
|
2024-07-13 16:36:08 +08:00
|
|
|
|
2024-09-08 21:21:21 +08:00
|
|
|
@freezed
|
|
|
|
|
class TunProps with _$TunProps {
|
|
|
|
|
const factory TunProps({
|
|
|
|
|
required int fd,
|
|
|
|
|
required String gateway,
|
|
|
|
|
required String gateway6,
|
|
|
|
|
required String portal,
|
|
|
|
|
required String portal6,
|
|
|
|
|
required String dns,
|
|
|
|
|
required String dns6,
|
|
|
|
|
}) = _TunProps;
|
|
|
|
|
|
|
|
|
|
factory TunProps.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$TunPropsFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-03 21:47:12 +08:00
|
|
|
@freezed
|
|
|
|
|
class Action with _$Action {
|
|
|
|
|
const factory Action({
|
|
|
|
|
required ActionMethod method,
|
|
|
|
|
required dynamic data,
|
|
|
|
|
required String id,
|
|
|
|
|
}) = _Action;
|
2024-07-13 16:36:08 +08:00
|
|
|
|
2024-12-03 21:47:12 +08:00
|
|
|
factory Action.fromJson(Map<String, Object?> json) => _$ActionFromJson(json);
|
2024-07-13 16:36:08 +08:00
|
|
|
}
|
|
|
|
|
|
2024-12-03 21:47:12 +08:00
|
|
|
extension ActionExt on Action {
|
|
|
|
|
String get toJson {
|
|
|
|
|
return json.encode(this);
|
|
|
|
|
}
|
2024-07-13 16:36:08 +08:00
|
|
|
}
|