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 = [
|
2025-06-07 01:48:34 +08:00
|
|
|
'*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.*',
|
2025-07-31 17:09:18 +08:00
|
|
|
'192.168.*',
|
2025-02-09 18:39:38 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const defaultAppSettingProps = AppSettingProps();
|
|
|
|
|
const defaultVpnProps = VpnProps();
|
|
|
|
|
const defaultNetworkProps = NetworkProps();
|
2025-12-16 11:23:09 +08:00
|
|
|
const defaultProxiesStyleProps = ProxiesStyleProps();
|
2025-02-09 18:39:38 +08:00
|
|
|
const defaultWindowProps = WindowProps();
|
2025-12-16 11:23:09 +08:00
|
|
|
const defaultAccessControlProps = AccessControlProps();
|
2025-07-31 17:09:18 +08:00
|
|
|
final defaultThemeProps = ThemeProps(primaryColor: defaultPrimaryColor);
|
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-07-31 17:09:18 +08:00
|
|
|
abstract class AppSettingProps with _$AppSettingProps {
|
2025-02-09 18:39:38 +08:00
|
|
|
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,
|
2025-04-18 17:50:46 +08:00
|
|
|
@Default(false) bool openLogs,
|
2024-09-26 14:29:04 +08:00
|
|
|
@Default(true) bool closeConnections,
|
|
|
|
|
@Default(defaultTestUrl) String testUrl,
|
|
|
|
|
@Default(true) bool isAnimateToPage,
|
|
|
|
|
@Default(true) bool autoCheckUpdate,
|
|
|
|
|
@Default(false) bool showLabel,
|
|
|
|
|
@Default(false) bool disclaimerAccepted,
|
2025-07-31 17:09:18 +08:00
|
|
|
@Default(false) bool crashlyticsTip,
|
|
|
|
|
@Default(false) bool crashlytics,
|
2024-09-26 14:29:04 +08:00
|
|
|
@Default(true) bool minimizeOnExit,
|
|
|
|
|
@Default(false) bool hidden,
|
2025-04-18 17:50:46 +08:00
|
|
|
@Default(false) bool developerMode,
|
2025-12-16 11:23:09 +08:00
|
|
|
@Default(RestoreStrategy.compatible) RestoreStrategy restoreStrategy,
|
2025-10-14 15:13:52 +08:00
|
|
|
@Default(true) bool showTrayTitle,
|
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
|
2025-12-16 11:23:09 +08:00
|
|
|
abstract class AccessControlProps with _$AccessControlProps {
|
|
|
|
|
const factory AccessControlProps({
|
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,
|
2025-04-18 17:50:46 +08:00
|
|
|
@Default(true) bool isFilterNonInternetApp,
|
2025-12-16 11:23:09 +08:00
|
|
|
}) = _AccessControlProps;
|
2024-06-03 11:24:41 +08:00
|
|
|
|
2025-12-16 11:23:09 +08:00
|
|
|
factory AccessControlProps.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$AccessControlPropsFromJson(json);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
2025-12-16 11:23:09 +08:00
|
|
|
extension AccessControlPropsExt on AccessControlProps {
|
2024-08-05 19:25:35 +08:00
|
|
|
List<String> get currentList => switch (mode) {
|
2025-07-31 17:09:18 +08:00
|
|
|
AccessControlMode.acceptSelected => acceptList,
|
|
|
|
|
AccessControlMode.rejectSelected => rejectList,
|
|
|
|
|
};
|
2025-10-14 15:13:52 +08:00
|
|
|
|
2025-12-16 11:23:09 +08:00
|
|
|
AccessControlProps copyWithNewList(List<String> value) => switch (mode) {
|
2025-10-14 15:13:52 +08:00
|
|
|
AccessControlMode.acceptSelected => copyWith(acceptList: value),
|
|
|
|
|
AccessControlMode.rejectSelected => copyWith(rejectList: value),
|
|
|
|
|
};
|
2024-08-05 19:25:35 +08:00
|
|
|
}
|
|
|
|
|
|
2024-07-15 22:06:09 +08:00
|
|
|
@freezed
|
2025-07-31 17:09:18 +08:00
|
|
|
abstract class WindowProps with _$WindowProps {
|
2024-07-15 22:06:09 +08:00
|
|
|
const factory WindowProps({
|
2025-10-14 15:13:52 +08:00
|
|
|
@Default(0) double width,
|
|
|
|
|
@Default(0) double height,
|
2024-07-15 22:06:09 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
2025-10-14 15:13:52 +08:00
|
|
|
extension WindowPropsExt on WindowProps {
|
|
|
|
|
Size get _size => Size(width, height);
|
|
|
|
|
|
|
|
|
|
Size get size => _size.isEmpty ? Size(680, 580) : _size;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-15 16:18:00 +08:00
|
|
|
@freezed
|
2025-07-31 17:09:18 +08:00
|
|
|
abstract class VpnProps with _$VpnProps {
|
2024-08-15 16:18:00 +08:00
|
|
|
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-07-31 17:09:18 +08:00
|
|
|
@Default(false) bool dnsHijacking,
|
2025-12-16 11:23:09 +08:00
|
|
|
@Default(defaultAccessControlProps) AccessControlProps accessControlProps,
|
2024-08-15 16:18:00 +08:00
|
|
|
}) = _VpnProps;
|
|
|
|
|
|
|
|
|
|
factory VpnProps.fromJson(Map<String, Object?>? json) =>
|
2025-04-09 16:46:14 +08:00
|
|
|
json == null ? defaultVpnProps : _$VpnPropsFromJson(json);
|
2024-08-15 16:18:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@freezed
|
2025-07-31 17:09:18 +08:00
|
|
|
abstract class NetworkProps with _$NetworkProps {
|
2024-11-09 20:17:57 +08:00
|
|
|
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-05-02 02:24:12 +08:00
|
|
|
@Default(RouteMode.config) RouteMode routeMode,
|
|
|
|
|
@Default(true) bool autoSetSystemDns,
|
2025-09-27 23:39:20 +08:00
|
|
|
@Default(false) bool appendSystemDns,
|
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
|
2025-12-16 11:23:09 +08:00
|
|
|
abstract class ProxiesStyleProps with _$ProxiesStyleProps {
|
|
|
|
|
const factory ProxiesStyleProps({
|
2024-09-26 14:29:04 +08:00
|
|
|
@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,
|
2025-12-16 11:23:09 +08:00
|
|
|
}) = _ProxiesStyleProps;
|
2024-09-26 14:29:04 +08:00
|
|
|
|
2025-12-16 11:23:09 +08:00
|
|
|
factory ProxiesStyleProps.fromJson(Map<String, Object?>? json) => json == null
|
|
|
|
|
? defaultProxiesStyleProps
|
|
|
|
|
: _$ProxiesStylePropsFromJson(json);
|
2024-09-05 08:59:45 +08:00
|
|
|
}
|
|
|
|
|
|
2025-04-18 17:50:46 +08:00
|
|
|
@freezed
|
2025-07-31 17:09:18 +08:00
|
|
|
abstract class TextScale with _$TextScale {
|
2025-04-18 17:50:46 +08:00
|
|
|
const factory TextScale({
|
2025-06-07 01:48:34 +08:00
|
|
|
@Default(false) bool enable,
|
|
|
|
|
@Default(1.0) double scale,
|
2025-04-18 17:50:46 +08:00
|
|
|
}) = _TextScale;
|
|
|
|
|
|
|
|
|
|
factory TextScale.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$TextScaleFromJson(json);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-26 16:52:10 +08:00
|
|
|
@freezed
|
2025-07-31 17:09:18 +08:00
|
|
|
abstract class ThemeProps with _$ThemeProps {
|
2024-10-26 16:52:10 +08:00
|
|
|
const factory ThemeProps({
|
2025-04-18 17:50:46 +08:00
|
|
|
int? primaryColor,
|
2025-04-09 16:46:14 +08:00
|
|
|
@Default(defaultPrimaryColors) List<int> primaryColors,
|
|
|
|
|
@Default(ThemeMode.dark) ThemeMode themeMode,
|
2025-04-18 17:50:46 +08:00
|
|
|
@Default(DynamicSchemeVariant.content) DynamicSchemeVariant schemeVariant,
|
2025-03-05 16:08:50 +08:00
|
|
|
@Default(false) bool pureBlack,
|
2025-04-18 17:50:46 +08:00
|
|
|
@Default(TextScale()) TextScale textScale,
|
2024-10-26 16:52:10 +08:00
|
|
|
}) = _ThemeProps;
|
|
|
|
|
|
2025-04-18 17:50:46 +08:00
|
|
|
factory ThemeProps.fromJson(Map<String, Object?> json) =>
|
|
|
|
|
_$ThemePropsFromJson(json);
|
|
|
|
|
|
|
|
|
|
factory ThemeProps.safeFromJson(Map<String, Object?>? json) {
|
|
|
|
|
if (json == null) {
|
|
|
|
|
return defaultThemeProps;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
return ThemeProps.fromJson(json);
|
|
|
|
|
} catch (_) {
|
|
|
|
|
return defaultThemeProps;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-26 16:52:10 +08:00
|
|
|
}
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
@freezed
|
2025-07-31 17:09:18 +08:00
|
|
|
abstract class Config with _$Config {
|
2025-02-09 18:39:38 +08:00
|
|
|
const factory Config({
|
2025-12-16 11:23:09 +08:00
|
|
|
int? currentProfileId,
|
|
|
|
|
@Default(false) bool overrideDns,
|
|
|
|
|
@Default([]) List<HotKeyAction> hotKeyActions,
|
2025-02-09 18:39:38 +08:00
|
|
|
@JsonKey(fromJson: AppSettingProps.safeFromJson)
|
|
|
|
|
@Default(defaultAppSettingProps)
|
2025-12-16 11:23:09 +08:00
|
|
|
AppSettingProps appSettingProps,
|
|
|
|
|
DAVProps? davProps,
|
2025-02-09 18:39:38 +08:00
|
|
|
@Default(defaultNetworkProps) NetworkProps networkProps,
|
|
|
|
|
@Default(defaultVpnProps) VpnProps vpnProps,
|
2025-04-18 17:50:46 +08:00
|
|
|
@JsonKey(fromJson: ThemeProps.safeFromJson) required ThemeProps themeProps,
|
2025-12-16 11:23:09 +08:00
|
|
|
@Default(defaultProxiesStyleProps) ProxiesStyleProps proxiesStyleProps,
|
2025-02-09 18:39:38 +08:00
|
|
|
@Default(defaultWindowProps) WindowProps windowProps,
|
|
|
|
|
@Default(defaultClashConfig) ClashConfig patchClashConfig,
|
|
|
|
|
}) = _Config;
|
|
|
|
|
|
|
|
|
|
factory Config.fromJson(Map<String, Object?> json) => _$ConfigFromJson(json);
|
|
|
|
|
|
2025-12-16 11:23:09 +08:00
|
|
|
factory Config.realFromJson(Map<String, Object?>? json) {
|
|
|
|
|
if (json == null) {
|
|
|
|
|
return Config(themeProps: defaultThemeProps);
|
|
|
|
|
}
|
|
|
|
|
return _$ConfigFromJson(json);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
}
|