2024-12-09 01:40:39 +08:00
|
|
|
// ignore_for_file: invalid_annotation_target
|
|
|
|
|
|
2024-09-26 14:29:04 +08:00
|
|
|
import 'package:fl_clash/common/common.dart';
|
|
|
|
|
import 'package:fl_clash/enum/enum.dart';
|
2024-04-30 23:38:49 +08:00
|
|
|
import 'package:flutter/material.dart';
|
2024-06-03 11:24:41 +08:00
|
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
2024-04-30 23:38:49 +08:00
|
|
|
|
|
|
|
|
import 'models.dart';
|
|
|
|
|
|
2024-06-03 11:24:41 +08:00
|
|
|
part 'generated/config.freezed.dart';
|
2024-11-09 20:17:57 +08:00
|
|
|
part 'generated/config.g.dart';
|
2024-06-03 11:24:41 +08:00
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
const defaultBypassDomain = [
|
|
|
|
|
"*zhihu.com",
|
|
|
|
|
"*zhimg.com",
|
|
|
|
|
"*jd.com",
|
|
|
|
|
"100ime-iat-api.xfyun.cn",
|
|
|
|
|
"*360buyimg.com",
|
|
|
|
|
"localhost",
|
|
|
|
|
"*.local",
|
|
|
|
|
"127.*",
|
|
|
|
|
"10.*",
|
|
|
|
|
"172.16.*",
|
|
|
|
|
"172.17.*",
|
|
|
|
|
"172.18.*",
|
|
|
|
|
"172.19.*",
|
|
|
|
|
"172.2*",
|
|
|
|
|
"172.30.*",
|
|
|
|
|
"172.31.*",
|
|
|
|
|
"192.168.*"
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const defaultAppSettingProps = AppSettingProps();
|
|
|
|
|
const defaultVpnProps = VpnProps();
|
|
|
|
|
const defaultNetworkProps = NetworkProps();
|
|
|
|
|
const defaultProxiesStyle = ProxiesStyle();
|
|
|
|
|
const defaultWindowProps = WindowProps();
|
|
|
|
|
const defaultAccessControl = AccessControl();
|
2025-03-05 16:08:50 +08:00
|
|
|
final defaultThemeProps = ThemeProps().copyWith(
|
|
|
|
|
primaryColor: defaultPrimaryColor.value,
|
|
|
|
|
themeMode: ThemeMode.dark,
|
|
|
|
|
);
|
2024-09-26 14:29:04 +08:00
|
|
|
|
2024-12-09 01:40:39 +08:00
|
|
|
const List<DashboardWidget> defaultDashboardWidgets = [
|
|
|
|
|
DashboardWidget.networkSpeed,
|
|
|
|
|
DashboardWidget.systemProxyButton,
|
|
|
|
|
DashboardWidget.tunButton,
|
|
|
|
|
DashboardWidget.outboundMode,
|
|
|
|
|
DashboardWidget.networkDetection,
|
|
|
|
|
DashboardWidget.trafficUsage,
|
|
|
|
|
DashboardWidget.intranetIp,
|
|
|
|
|
];
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
List<DashboardWidget> dashboardWidgetsSafeFormJson(
|
|
|
|
|
List<dynamic>? dashboardWidgets,
|
|
|
|
|
) {
|
2024-12-09 01:40:39 +08:00
|
|
|
try {
|
|
|
|
|
return dashboardWidgets
|
|
|
|
|
?.map((e) => $enumDecode(_$DashboardWidgetEnumMap, e))
|
|
|
|
|
.toList() ??
|
|
|
|
|
defaultDashboardWidgets;
|
|
|
|
|
} catch (_) {
|
|
|
|
|
return defaultDashboardWidgets;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-26 14:29:04 +08:00
|
|
|
@freezed
|
2025-02-09 18:39:38 +08:00
|
|
|
class AppSettingProps with _$AppSettingProps {
|
|
|
|
|
const factory AppSettingProps({
|
2024-09-26 14:29:04 +08:00
|
|
|
String? locale,
|
2024-12-09 01:40:39 +08:00
|
|
|
@Default(defaultDashboardWidgets)
|
2025-02-09 18:39:38 +08:00
|
|
|
@JsonKey(fromJson: dashboardWidgetsSafeFormJson)
|
2024-12-09 01:40:39 +08:00
|
|
|
List<DashboardWidget> dashboardWidgets,
|
2025-01-13 19:08:17 +08:00
|
|
|
@Default(false) bool onlyStatisticsProxy,
|
2024-09-26 14:29:04 +08:00
|
|
|
@Default(false) bool autoLaunch,
|
|
|
|
|
@Default(false) bool silentLaunch,
|
|
|
|
|
@Default(false) bool autoRun,
|
|
|
|
|
@Default(false) bool openLogs,
|
|
|
|
|
@Default(true) bool closeConnections,
|
|
|
|
|
@Default(defaultTestUrl) String testUrl,
|
|
|
|
|
@Default(true) bool isAnimateToPage,
|
|
|
|
|
@Default(true) bool autoCheckUpdate,
|
|
|
|
|
@Default(false) bool showLabel,
|
|
|
|
|
@Default(false) bool disclaimerAccepted,
|
|
|
|
|
@Default(true) bool minimizeOnExit,
|
|
|
|
|
@Default(false) bool hidden,
|
2025-02-09 18:39:38 +08:00
|
|
|
}) = _AppSettingProps;
|
2024-09-26 14:29:04 +08:00
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
factory AppSettingProps.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$AppSettingPropsFromJson(json);
|
2024-09-26 14:29:04 +08:00
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
factory AppSettingProps.safeFromJson(Map<String, Object?>? json) {
|
|
|
|
|
return json == null
|
|
|
|
|
? defaultAppSettingProps
|
|
|
|
|
: AppSettingProps.fromJson(json);
|
2024-09-26 14:29:04 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-03 11:24:41 +08:00
|
|
|
@freezed
|
|
|
|
|
class AccessControl with _$AccessControl {
|
|
|
|
|
const factory AccessControl({
|
2025-02-09 18:39:38 +08:00
|
|
|
@Default(false) bool enable,
|
2024-06-03 11:24:41 +08:00
|
|
|
@Default(AccessControlMode.rejectSelected) AccessControlMode mode,
|
|
|
|
|
@Default([]) List<String> acceptList,
|
|
|
|
|
@Default([]) List<String> rejectList,
|
2024-08-05 19:25:35 +08:00
|
|
|
@Default(AccessSortType.none) AccessSortType sort,
|
2024-06-03 11:24:41 +08:00
|
|
|
@Default(true) bool isFilterSystemApp,
|
|
|
|
|
}) = _AccessControl;
|
|
|
|
|
|
|
|
|
|
factory AccessControl.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$AccessControlFromJson(json);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
2024-08-05 19:25:35 +08:00
|
|
|
extension AccessControlExt on AccessControl {
|
|
|
|
|
List<String> get currentList => switch (mode) {
|
2024-08-13 21:42:23 +08:00
|
|
|
AccessControlMode.acceptSelected => acceptList,
|
|
|
|
|
AccessControlMode.rejectSelected => rejectList,
|
|
|
|
|
};
|
2024-08-05 19:25:35 +08:00
|
|
|
}
|
|
|
|
|
|
2024-07-15 22:06:09 +08:00
|
|
|
@freezed
|
|
|
|
|
class WindowProps with _$WindowProps {
|
|
|
|
|
const factory WindowProps({
|
2024-10-27 16:59:23 +08:00
|
|
|
@Default(900) double width,
|
2024-07-15 22:06:09 +08:00
|
|
|
@Default(600) double height,
|
|
|
|
|
double? top,
|
|
|
|
|
double? left,
|
|
|
|
|
}) = _WindowProps;
|
|
|
|
|
|
|
|
|
|
factory WindowProps.fromJson(Map<String, Object?>? json) =>
|
2024-08-15 16:18:00 +08:00
|
|
|
json == null ? const WindowProps() : _$WindowPropsFromJson(json);
|
2024-07-15 22:06:09 +08:00
|
|
|
}
|
|
|
|
|
|
2024-08-15 16:18:00 +08:00
|
|
|
@freezed
|
|
|
|
|
class VpnProps with _$VpnProps {
|
|
|
|
|
const factory VpnProps({
|
|
|
|
|
@Default(true) bool enable,
|
2024-09-20 14:32:57 +08:00
|
|
|
@Default(true) bool systemProxy,
|
|
|
|
|
@Default(false) bool ipv6,
|
2024-08-15 16:18:00 +08:00
|
|
|
@Default(true) bool allowBypass,
|
2025-02-09 18:39:38 +08:00
|
|
|
@Default(defaultAccessControl) AccessControl accessControl,
|
2024-08-15 16:18:00 +08:00
|
|
|
}) = _VpnProps;
|
|
|
|
|
|
|
|
|
|
factory VpnProps.fromJson(Map<String, Object?>? json) =>
|
|
|
|
|
json == null ? const VpnProps() : _$VpnPropsFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@freezed
|
2024-11-09 20:17:57 +08:00
|
|
|
class NetworkProps with _$NetworkProps {
|
|
|
|
|
const factory NetworkProps({
|
2024-08-15 16:18:00 +08:00
|
|
|
@Default(true) bool systemProxy,
|
2024-11-09 20:17:57 +08:00
|
|
|
@Default(defaultBypassDomain) List<String> bypassDomain,
|
2025-02-09 18:39:38 +08:00
|
|
|
@Default(RouteMode.bypassPrivate) RouteMode routeMode,
|
2024-11-09 20:17:57 +08:00
|
|
|
}) = _NetworkProps;
|
2024-08-15 16:18:00 +08:00
|
|
|
|
2024-11-09 20:17:57 +08:00
|
|
|
factory NetworkProps.fromJson(Map<String, Object?>? json) =>
|
|
|
|
|
json == null ? const NetworkProps() : _$NetworkPropsFromJson(json);
|
2024-08-15 16:18:00 +08:00
|
|
|
}
|
2024-07-15 22:06:09 +08:00
|
|
|
|
2024-09-05 08:59:45 +08:00
|
|
|
@freezed
|
2024-09-26 14:29:04 +08:00
|
|
|
class ProxiesStyle with _$ProxiesStyle {
|
|
|
|
|
const factory ProxiesStyle({
|
|
|
|
|
@Default(ProxiesType.tab) ProxiesType type,
|
|
|
|
|
@Default(ProxiesSortType.none) ProxiesSortType sortType,
|
|
|
|
|
@Default(ProxiesLayout.standard) ProxiesLayout layout,
|
|
|
|
|
@Default(ProxiesIconStyle.standard) ProxiesIconStyle iconStyle,
|
|
|
|
|
@Default(ProxyCardType.expand) ProxyCardType cardType,
|
|
|
|
|
@Default({}) Map<String, String> iconMap,
|
|
|
|
|
}) = _ProxiesStyle;
|
|
|
|
|
|
|
|
|
|
factory ProxiesStyle.fromJson(Map<String, Object?>? json) =>
|
|
|
|
|
json == null ? defaultProxiesStyle : _$ProxiesStyleFromJson(json);
|
2024-09-05 08:59:45 +08:00
|
|
|
}
|
|
|
|
|
|
2024-10-26 16:52:10 +08:00
|
|
|
@freezed
|
|
|
|
|
class ThemeProps with _$ThemeProps {
|
|
|
|
|
const factory ThemeProps({
|
2024-10-27 16:59:23 +08:00
|
|
|
int? primaryColor,
|
2024-10-26 16:52:10 +08:00
|
|
|
@Default(ThemeMode.system) ThemeMode themeMode,
|
2025-03-05 16:08:50 +08:00
|
|
|
@Default(false) bool pureBlack,
|
2024-10-26 16:52:10 +08:00
|
|
|
}) = _ThemeProps;
|
|
|
|
|
|
2024-10-27 16:59:23 +08:00
|
|
|
factory ThemeProps.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$ThemePropsFromJson(json);
|
2024-10-26 16:52:10 +08:00
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
factory ThemeProps.safeFromJson(Map<String, Object?>? json) {
|
2024-10-26 16:52:10 +08:00
|
|
|
if (json == null) {
|
2024-10-27 16:59:23 +08:00
|
|
|
return defaultThemeProps;
|
2024-10-26 16:52:10 +08:00
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
return ThemeProps.fromJson(json);
|
|
|
|
|
} catch (_) {
|
2024-10-27 16:59:23 +08:00
|
|
|
return defaultThemeProps;
|
2024-10-26 16:52:10 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
@freezed
|
|
|
|
|
class Config with _$Config {
|
|
|
|
|
const factory Config({
|
|
|
|
|
@JsonKey(fromJson: AppSettingProps.safeFromJson)
|
|
|
|
|
@Default(defaultAppSettingProps)
|
|
|
|
|
AppSettingProps appSetting,
|
|
|
|
|
@Default([]) List<Profile> profiles,
|
|
|
|
|
@Default([]) List<HotKeyAction> hotKeyActions,
|
|
|
|
|
String? currentProfileId,
|
|
|
|
|
@Default(false) bool overrideDns,
|
|
|
|
|
DAV? dav,
|
|
|
|
|
@Default(defaultNetworkProps) NetworkProps networkProps,
|
|
|
|
|
@Default(defaultVpnProps) VpnProps vpnProps,
|
|
|
|
|
@JsonKey(fromJson: ThemeProps.safeFromJson) required ThemeProps themeProps,
|
|
|
|
|
@Default(defaultProxiesStyle) ProxiesStyle proxiesStyle,
|
|
|
|
|
@Default(defaultWindowProps) WindowProps windowProps,
|
|
|
|
|
@Default(defaultClashConfig) ClashConfig patchClashConfig,
|
|
|
|
|
}) = _Config;
|
|
|
|
|
|
|
|
|
|
factory Config.fromJson(Map<String, Object?> json) => _$ConfigFromJson(json);
|
|
|
|
|
|
|
|
|
|
factory Config.compatibleFromJson(Map<String, Object?> json) {
|
|
|
|
|
try {
|
|
|
|
|
final accessControlMap = json["accessControl"];
|
|
|
|
|
final isAccessControl = json["isAccessControl"];
|
|
|
|
|
if (accessControlMap != null) {
|
|
|
|
|
(accessControlMap as Map)["enable"] = isAccessControl;
|
|
|
|
|
if (json["vpnProps"] != null) {
|
|
|
|
|
(json["vpnProps"] as Map)["accessControl"] = accessControlMap;
|
|
|
|
|
}
|
2024-05-20 15:15:09 +08:00
|
|
|
}
|
2025-02-09 18:39:38 +08:00
|
|
|
} catch (_) {}
|
|
|
|
|
return Config.fromJson(json);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
2024-04-30 23:38:49 +08:00
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
extension ConfigExt on Config {
|
|
|
|
|
Profile? get currentProfile {
|
|
|
|
|
return profiles.getProfile(currentProfileId);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
}
|