2024-04-30 23:38:49 +08:00
|
|
|
// ignore_for_file: constant_identifier_names
|
|
|
|
|
|
2024-12-09 01:40:39 +08:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
2026-02-02 10:14:13 +08:00
|
|
|
import 'package:fl_clash/common/context.dart';
|
2025-06-07 01:48:34 +08:00
|
|
|
import 'package:fl_clash/common/system.dart';
|
2026-09-05 20:09:39 +08:00
|
|
|
import 'package:material_ui/material_ui.dart';
|
2024-09-08 21:21:21 +08:00
|
|
|
import 'package:flutter/services.dart';
|
2024-08-26 20:44:30 +08:00
|
|
|
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
|
|
|
|
2024-12-09 01:40:39 +08:00
|
|
|
enum SupportPlatform {
|
|
|
|
|
Windows,
|
|
|
|
|
MacOS,
|
|
|
|
|
Linux,
|
|
|
|
|
Android;
|
|
|
|
|
|
|
|
|
|
static SupportPlatform get currentPlatform {
|
2025-06-07 01:48:34 +08:00
|
|
|
if (system.isWindows) {
|
2024-12-09 01:40:39 +08:00
|
|
|
return SupportPlatform.Windows;
|
2025-06-07 01:48:34 +08:00
|
|
|
} else if (system.isMacOS) {
|
2024-12-09 01:40:39 +08:00
|
|
|
return SupportPlatform.MacOS;
|
|
|
|
|
} else if (Platform.isLinux) {
|
|
|
|
|
return SupportPlatform.Linux;
|
2025-06-07 01:48:34 +08:00
|
|
|
} else if (system.isAndroid) {
|
2024-12-09 01:40:39 +08:00
|
|
|
return SupportPlatform.Android;
|
|
|
|
|
}
|
2026-09-05 20:09:39 +08:00
|
|
|
throw UnsupportedError('Unsupported platform: ${Platform.operatingSystem}');
|
2024-12-09 01:40:39 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const desktopPlatforms = [
|
|
|
|
|
SupportPlatform.Linux,
|
|
|
|
|
SupportPlatform.MacOS,
|
|
|
|
|
SupportPlatform.Windows,
|
|
|
|
|
];
|
|
|
|
|
|
2026-02-02 10:14:13 +08:00
|
|
|
enum GroupName { GLOBAL }
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
enum GroupType {
|
2026-02-02 10:14:13 +08:00
|
|
|
@JsonValue('select')
|
|
|
|
|
Selector('select'),
|
|
|
|
|
@JsonValue('url-test')
|
|
|
|
|
URLTest('url-test'),
|
|
|
|
|
@JsonValue('fallback')
|
|
|
|
|
Fallback('fallback'),
|
|
|
|
|
@JsonValue('load-balance')
|
|
|
|
|
LoadBalance('load-balance'),
|
|
|
|
|
@JsonValue('relay')
|
|
|
|
|
Relay('relay');
|
|
|
|
|
|
|
|
|
|
final String value;
|
|
|
|
|
|
|
|
|
|
const GroupType(this.value);
|
|
|
|
|
|
|
|
|
|
static GroupType parse(String type) {
|
|
|
|
|
return switch (type.toLowerCase()) {
|
|
|
|
|
'url-test' || 'urltest' => URLTest,
|
|
|
|
|
'select' || 'selector' => Selector,
|
2025-06-07 01:48:34 +08:00
|
|
|
'fallback' => Fallback,
|
2026-02-02 10:14:13 +08:00
|
|
|
'load-balance' || 'loadbalance' => LoadBalance,
|
2025-06-07 01:48:34 +08:00
|
|
|
'relay' => Relay,
|
2025-02-09 18:39:38 +08:00
|
|
|
String() => throw UnimplementedError(),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-30 23:38:49 +08:00
|
|
|
|
|
|
|
|
extension GroupTypeExtension on GroupType {
|
2025-07-31 17:09:18 +08:00
|
|
|
static List<String> get valueList =>
|
|
|
|
|
GroupType.values.map((e) => e.toString().split('.').last).toList();
|
2024-04-30 23:38:49 +08:00
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
bool get isComputedSelected {
|
2024-09-20 14:32:57 +08:00
|
|
|
return [GroupType.URLTest, GroupType.Fallback].contains(this);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-03 14:31:10 +08:00
|
|
|
static GroupType? getGroupType(String value) {
|
2024-04-30 23:38:49 +08:00
|
|
|
final index = GroupTypeExtension.valueList.indexOf(value);
|
|
|
|
|
if (index == -1) return null;
|
|
|
|
|
return GroupType.values[index];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum UsedProxy { GLOBAL, DIRECT, REJECT }
|
|
|
|
|
|
|
|
|
|
extension UsedProxyExtension on UsedProxy {
|
2025-07-31 17:09:18 +08:00
|
|
|
static List<String> get valueList =>
|
|
|
|
|
UsedProxy.values.map((e) => e.toString().split('.').last).toList();
|
2024-04-30 23:38:49 +08:00
|
|
|
|
|
|
|
|
String get value => UsedProxyExtension.valueList[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum Mode { rule, global, direct }
|
|
|
|
|
|
2024-05-20 15:15:09 +08:00
|
|
|
enum ViewMode { mobile, laptop, desktop }
|
|
|
|
|
|
2025-07-31 17:09:18 +08:00
|
|
|
enum LogLevel { debug, info, warning, error, silent }
|
2025-06-07 01:48:34 +08:00
|
|
|
|
|
|
|
|
extension LogLevelExt on LogLevel {
|
2026-02-02 10:14:13 +08:00
|
|
|
Color? color(BuildContext context) {
|
|
|
|
|
final colorScheme = Theme.of(context).colorScheme;
|
2025-06-07 01:48:34 +08:00
|
|
|
return switch (this) {
|
2026-02-02 10:14:13 +08:00
|
|
|
LogLevel.silent => colorScheme.outline,
|
|
|
|
|
LogLevel.debug => colorScheme.onSurfaceVariant,
|
2025-06-07 01:48:34 +08:00
|
|
|
LogLevel.info => null,
|
2026-02-02 10:14:13 +08:00
|
|
|
LogLevel.warning => colorScheme.tertiary,
|
|
|
|
|
LogLevel.error => colorScheme.error,
|
2025-06-07 01:48:34 +08:00
|
|
|
};
|
|
|
|
|
}
|
2025-04-18 17:50:46 +08:00
|
|
|
}
|
2024-04-30 23:38:49 +08:00
|
|
|
|
2026-09-05 20:09:39 +08:00
|
|
|
enum MessageLevel { info, success, warning, error }
|
|
|
|
|
|
|
|
|
|
extension MessageLevelExt on MessageLevel {
|
|
|
|
|
IconData? get icon {
|
|
|
|
|
return switch (this) {
|
|
|
|
|
MessageLevel.info => null,
|
|
|
|
|
MessageLevel.success => Icons.check_circle_outline,
|
|
|
|
|
MessageLevel.warning => Icons.warning_amber_outlined,
|
|
|
|
|
MessageLevel.error => Icons.error_outline,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Color containerColor(BuildContext context) {
|
|
|
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
|
|
|
return switch (this) {
|
|
|
|
|
MessageLevel.error => colorScheme.errorContainer,
|
|
|
|
|
_ => colorScheme.surfaceContainerHigh,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Color contentColor(BuildContext context) {
|
|
|
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
|
|
|
return switch (this) {
|
|
|
|
|
MessageLevel.error => colorScheme.onErrorContainer,
|
|
|
|
|
_ => colorScheme.onSurfaceVariant,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Color iconColor(BuildContext context) {
|
|
|
|
|
final colorScheme = Theme.of(context).colorScheme;
|
|
|
|
|
return switch (this) {
|
|
|
|
|
MessageLevel.info => colorScheme.onSurfaceVariant,
|
|
|
|
|
MessageLevel.success => colorScheme.primary,
|
|
|
|
|
MessageLevel.warning => colorScheme.tertiary,
|
|
|
|
|
MessageLevel.error => colorScheme.onErrorContainer,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Duration get duration {
|
|
|
|
|
return switch (this) {
|
|
|
|
|
MessageLevel.info || MessageLevel.success => const Duration(seconds: 3),
|
|
|
|
|
MessageLevel.warning => const Duration(seconds: 5),
|
|
|
|
|
MessageLevel.error => const Duration(seconds: 6),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-04-30 23:38:49 +08:00
|
|
|
|
|
|
|
|
enum TrafficUnit { B, KB, MB, GB, TB }
|
|
|
|
|
|
|
|
|
|
enum NavigationItemMode { mobile, desktop, more }
|
|
|
|
|
|
|
|
|
|
enum Network { tcp, udp }
|
|
|
|
|
|
|
|
|
|
enum ProxiesSortType { none, delay, name }
|
|
|
|
|
|
|
|
|
|
enum TunStack { gvisor, system, mixed }
|
|
|
|
|
|
|
|
|
|
enum AccessControlMode { acceptSelected, rejectSelected }
|
|
|
|
|
|
2024-08-05 19:25:35 +08:00
|
|
|
enum AccessSortType { none, name, time }
|
|
|
|
|
|
2024-04-30 23:38:49 +08:00
|
|
|
enum ProfileType { file, url }
|
|
|
|
|
|
2025-05-02 02:24:12 +08:00
|
|
|
enum ResultType {
|
|
|
|
|
@JsonValue(0)
|
|
|
|
|
success,
|
|
|
|
|
@JsonValue(-1)
|
|
|
|
|
error,
|
|
|
|
|
}
|
2024-04-30 23:38:49 +08:00
|
|
|
|
2026-05-27 15:16:51 +08:00
|
|
|
enum CoreEventType { log, delay, request, loaded, crash, geoUpdate }
|
2024-07-13 16:36:08 +08:00
|
|
|
|
2025-07-31 17:09:18 +08:00
|
|
|
enum InvokeMessageType { protect, process }
|
2024-06-13 23:43:42 +08:00
|
|
|
|
|
|
|
|
enum FindProcessMode { always, off }
|
2024-05-20 15:15:09 +08:00
|
|
|
|
2026-09-05 20:09:39 +08:00
|
|
|
enum InterfaceNameMode { clear, follow, custom }
|
2024-06-19 13:13:31 +08:00
|
|
|
|
2026-09-05 20:09:39 +08:00
|
|
|
enum RestoreOption { all, onlyProfiles }
|
2024-06-23 00:26:24 +08:00
|
|
|
|
|
|
|
|
enum CommonCardType { plain, filled }
|
|
|
|
|
|
2024-07-15 22:06:09 +08:00
|
|
|
enum ProxiesType { tab, list }
|
2024-06-23 00:26:24 +08:00
|
|
|
|
2024-08-26 20:44:30 +08:00
|
|
|
enum ProxiesLayout { loose, standard, tight }
|
2024-08-13 21:42:23 +08:00
|
|
|
|
2024-07-15 22:06:09 +08:00
|
|
|
enum ProxyCardType { expand, shrink, min }
|
2024-08-26 20:44:30 +08:00
|
|
|
|
|
|
|
|
enum DnsMode {
|
|
|
|
|
normal,
|
2025-06-07 01:48:34 +08:00
|
|
|
@JsonValue('fake-ip')
|
2024-08-26 20:44:30 +08:00
|
|
|
fakeIp,
|
2025-06-07 01:48:34 +08:00
|
|
|
@JsonValue('redir-host')
|
2024-08-26 20:44:30 +08:00
|
|
|
redirHost,
|
2025-07-31 17:09:18 +08:00
|
|
|
hosts,
|
2024-08-26 20:44:30 +08:00
|
|
|
}
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
enum ExternalControllerStatus {
|
2025-06-07 01:48:34 +08:00
|
|
|
@JsonValue('')
|
|
|
|
|
close(''),
|
|
|
|
|
@JsonValue('127.0.0.1:9090')
|
|
|
|
|
open('127.0.0.1:9090');
|
2025-05-02 02:24:12 +08:00
|
|
|
|
|
|
|
|
final String value;
|
|
|
|
|
|
|
|
|
|
const ExternalControllerStatus(this.value);
|
2025-02-09 18:39:38 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-08 21:21:21 +08:00
|
|
|
enum KeyboardModifier {
|
2025-07-31 17:09:18 +08:00
|
|
|
alt([PhysicalKeyboardKey.altLeft, PhysicalKeyboardKey.altRight]),
|
|
|
|
|
capsLock([PhysicalKeyboardKey.capsLock]),
|
|
|
|
|
control([PhysicalKeyboardKey.controlLeft, PhysicalKeyboardKey.controlRight]),
|
|
|
|
|
fn([PhysicalKeyboardKey.fn]),
|
|
|
|
|
meta([PhysicalKeyboardKey.metaLeft, PhysicalKeyboardKey.metaRight]),
|
|
|
|
|
shift([PhysicalKeyboardKey.shiftLeft, PhysicalKeyboardKey.shiftRight]);
|
2024-09-08 21:21:21 +08:00
|
|
|
|
|
|
|
|
final List<PhysicalKeyboardKey> physicalKeys;
|
|
|
|
|
|
|
|
|
|
const KeyboardModifier(this.physicalKeys);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-31 17:09:18 +08:00
|
|
|
enum HotAction { start, view, mode, proxy, tun }
|
2024-09-26 14:29:04 +08:00
|
|
|
|
2025-10-14 15:13:52 +08:00
|
|
|
enum ProxiesIconStyle { none, standard, icon }
|
2024-10-26 16:52:10 +08:00
|
|
|
|
|
|
|
|
enum FontFamily {
|
2025-06-07 01:48:34 +08:00
|
|
|
twEmoji('Twemoji'),
|
|
|
|
|
jetBrainsMono('JetBrainsMono'),
|
|
|
|
|
icon('Icons');
|
2024-10-26 16:52:10 +08:00
|
|
|
|
2025-03-12 17:15:31 +08:00
|
|
|
final String value;
|
2024-10-26 16:52:10 +08:00
|
|
|
|
2025-03-12 17:15:31 +08:00
|
|
|
const FontFamily(this.value);
|
2024-10-26 16:52:10 +08:00
|
|
|
}
|
2024-11-09 20:17:57 +08:00
|
|
|
|
2025-07-31 17:09:18 +08:00
|
|
|
enum RouteMode { bypassPrivate, config }
|
2024-12-03 21:47:12 +08:00
|
|
|
|
|
|
|
|
enum AuthorizeCode { none, success, error }
|
|
|
|
|
|
2026-08-05 10:57:40 +08:00
|
|
|
enum TunAuthorizationState { none, authorized, unauthorized }
|
2024-12-09 01:40:39 +08:00
|
|
|
|
2025-05-02 02:24:12 +08:00
|
|
|
enum FunctionTag {
|
2025-12-16 11:23:09 +08:00
|
|
|
updateConfig,
|
|
|
|
|
setupConfig,
|
2024-12-09 01:40:39 +08:00
|
|
|
updateGroups,
|
|
|
|
|
addCheckIpNum,
|
|
|
|
|
applyProfile,
|
|
|
|
|
savePreferences,
|
|
|
|
|
changeProxy,
|
|
|
|
|
checkIp,
|
|
|
|
|
handleWill,
|
|
|
|
|
updateDelay,
|
|
|
|
|
vpnTip,
|
2025-02-09 18:39:38 +08:00
|
|
|
autoLaunch,
|
|
|
|
|
updatePageIndex,
|
|
|
|
|
pageChange,
|
|
|
|
|
proxiesTabChange,
|
2025-05-02 02:24:12 +08:00
|
|
|
logs,
|
|
|
|
|
requests,
|
2025-06-07 01:48:34 +08:00
|
|
|
autoScrollToEnd,
|
2025-10-14 15:13:52 +08:00
|
|
|
loadedProvider,
|
2025-12-16 11:23:09 +08:00
|
|
|
saveSharedFile,
|
2026-02-02 10:14:13 +08:00
|
|
|
removeProxy,
|
|
|
|
|
suspend,
|
2026-09-05 20:09:39 +08:00
|
|
|
coreErrorNotifier,
|
2024-12-09 01:40:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum DashboardWidget {
|
2026-09-05 20:09:39 +08:00
|
|
|
networkSpeed,
|
|
|
|
|
outboundModeV2,
|
|
|
|
|
outboundMode,
|
|
|
|
|
trafficUsage,
|
|
|
|
|
networkDetection,
|
|
|
|
|
tunButton(platforms: desktopPlatforms),
|
|
|
|
|
vpnButton(platforms: [SupportPlatform.Android]),
|
|
|
|
|
systemProxyButton(platforms: desktopPlatforms),
|
|
|
|
|
intranetIp,
|
|
|
|
|
memoryInfo;
|
2024-12-09 01:40:39 +08:00
|
|
|
|
2026-09-05 20:09:39 +08:00
|
|
|
final List<SupportPlatform> platforms;
|
2024-12-09 01:40:39 +08:00
|
|
|
|
2026-09-05 20:09:39 +08:00
|
|
|
const DashboardWidget({this.platforms = SupportPlatform.values});
|
2024-12-09 01:40:39 +08:00
|
|
|
}
|
2025-02-09 18:39:38 +08:00
|
|
|
|
2025-07-31 17:09:18 +08:00
|
|
|
enum GeodataLoader { standard, memconservative }
|
2025-02-09 18:39:38 +08:00
|
|
|
|
2026-05-27 15:16:51 +08:00
|
|
|
enum GeoResource {
|
|
|
|
|
@JsonValue('mmdb')
|
|
|
|
|
MMDB,
|
|
|
|
|
@JsonValue('asn')
|
|
|
|
|
ASN,
|
2026-08-05 10:57:40 +08:00
|
|
|
@JsonValue('geoip')
|
2026-05-27 15:16:51 +08:00
|
|
|
GEOIP,
|
2026-08-05 10:57:40 +08:00
|
|
|
@JsonValue('geosite')
|
2026-05-27 15:16:51 +08:00
|
|
|
GEOSITE;
|
|
|
|
|
|
|
|
|
|
static GeoResource fromJson(String value) {
|
|
|
|
|
return switch (value) {
|
|
|
|
|
'mmdb' => GeoResource.MMDB,
|
|
|
|
|
'asn' => GeoResource.ASN,
|
|
|
|
|
'geo-ip' || 'geoip' => GeoResource.GEOIP,
|
|
|
|
|
'geo-site' || 'geosite' => GeoResource.GEOSITE,
|
|
|
|
|
_ => throw ArgumentError.value(value, 'value', 'Invalid geo resource'),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension GeoResourceExt on GeoResource {
|
2026-08-05 10:57:40 +08:00
|
|
|
String get configKey {
|
2026-05-27 15:16:51 +08:00
|
|
|
return switch (this) {
|
|
|
|
|
GeoResource.MMDB => 'mmdb',
|
|
|
|
|
GeoResource.ASN => 'asn',
|
2026-08-05 10:57:40 +08:00
|
|
|
GeoResource.GEOIP => 'geoip',
|
|
|
|
|
GeoResource.GEOSITE => 'geosite',
|
2026-05-27 15:16:51 +08:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String get updatingKey => 'geo_resource_$name';
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-09 18:39:38 +08:00
|
|
|
enum PageLabel {
|
|
|
|
|
dashboard,
|
|
|
|
|
proxies,
|
|
|
|
|
profiles,
|
|
|
|
|
tools,
|
|
|
|
|
logs,
|
|
|
|
|
requests,
|
|
|
|
|
resources,
|
|
|
|
|
connections,
|
|
|
|
|
}
|
2025-03-12 17:15:31 +08:00
|
|
|
|
|
|
|
|
enum RuleAction {
|
2025-06-07 01:48:34 +08:00
|
|
|
DOMAIN('DOMAIN'),
|
|
|
|
|
DOMAIN_SUFFIX('DOMAIN-SUFFIX'),
|
|
|
|
|
DOMAIN_KEYWORD('DOMAIN-KEYWORD'),
|
|
|
|
|
DOMAIN_REGEX('DOMAIN-REGEX'),
|
2026-09-05 20:09:39 +08:00
|
|
|
DOMAIN_WILDCARD('DOMAIN-WILDCARD'),
|
2025-06-07 01:48:34 +08:00
|
|
|
GEOSITE('GEOSITE'),
|
|
|
|
|
IP_CIDR('IP-CIDR'),
|
|
|
|
|
IP_CIDR6('IP-CIDR6'),
|
|
|
|
|
IP_SUFFIX('IP-SUFFIX'),
|
|
|
|
|
IP_ASN('IP-ASN'),
|
|
|
|
|
GEOIP('GEOIP'),
|
|
|
|
|
SRC_GEOIP('SRC-GEOIP'),
|
|
|
|
|
SRC_IP_ASN('SRC-IP-ASN'),
|
|
|
|
|
SRC_IP_CIDR('SRC-IP-CIDR'),
|
|
|
|
|
SRC_IP_SUFFIX('SRC-IP-SUFFIX'),
|
|
|
|
|
DST_PORT('DST-PORT'),
|
|
|
|
|
SRC_PORT('SRC-PORT'),
|
|
|
|
|
IN_PORT('IN-PORT'),
|
|
|
|
|
IN_TYPE('IN-TYPE'),
|
|
|
|
|
IN_USER('IN-USER'),
|
|
|
|
|
IN_NAME('IN-NAME'),
|
2026-09-05 20:09:39 +08:00
|
|
|
REMATCH_NAME('REMATCH-NAME'),
|
2025-06-07 01:48:34 +08:00
|
|
|
PROCESS_PATH('PROCESS-PATH'),
|
|
|
|
|
PROCESS_PATH_REGEX('PROCESS-PATH-REGEX'),
|
2026-09-05 20:09:39 +08:00
|
|
|
PROCESS_PATH_WILDCARD('PROCESS-PATH-WILDCARD'),
|
2025-06-07 01:48:34 +08:00
|
|
|
PROCESS_NAME('PROCESS-NAME'),
|
|
|
|
|
PROCESS_NAME_REGEX('PROCESS-NAME-REGEX'),
|
2026-09-05 20:09:39 +08:00
|
|
|
PROCESS_NAME_WILDCARD('PROCESS-NAME-WILDCARD'),
|
2025-06-07 01:48:34 +08:00
|
|
|
UID('UID'),
|
|
|
|
|
NETWORK('NETWORK'),
|
|
|
|
|
DSCP('DSCP'),
|
|
|
|
|
RULE_SET('RULE-SET'),
|
|
|
|
|
AND('AND'),
|
|
|
|
|
OR('OR'),
|
|
|
|
|
NOT('NOT'),
|
|
|
|
|
SUB_RULE('SUB-RULE'),
|
|
|
|
|
MATCH('MATCH');
|
2025-03-12 17:15:31 +08:00
|
|
|
|
|
|
|
|
final String value;
|
|
|
|
|
|
|
|
|
|
const RuleAction(this.value);
|
2025-10-14 15:13:52 +08:00
|
|
|
|
|
|
|
|
static List<RuleAction> get addedRuleActions {
|
|
|
|
|
return RuleAction.values
|
|
|
|
|
.where(
|
|
|
|
|
(item) => ![
|
|
|
|
|
RuleAction.MATCH,
|
|
|
|
|
RuleAction.RULE_SET,
|
|
|
|
|
RuleAction.SUB_RULE,
|
|
|
|
|
].contains(item),
|
|
|
|
|
)
|
|
|
|
|
.toList();
|
|
|
|
|
}
|
2025-03-12 17:15:31 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension RuleActionExt on RuleAction {
|
|
|
|
|
bool get hasParams => [
|
2025-07-31 17:09:18 +08:00
|
|
|
RuleAction.GEOIP,
|
|
|
|
|
RuleAction.IP_ASN,
|
|
|
|
|
RuleAction.IP_CIDR,
|
|
|
|
|
RuleAction.IP_CIDR6,
|
|
|
|
|
RuleAction.IP_SUFFIX,
|
|
|
|
|
RuleAction.RULE_SET,
|
|
|
|
|
].contains(this);
|
2026-02-02 10:14:13 +08:00
|
|
|
|
2026-09-05 20:09:39 +08:00
|
|
|
bool get hasCommaPayload => [
|
|
|
|
|
RuleAction.AND,
|
|
|
|
|
RuleAction.OR,
|
|
|
|
|
RuleAction.NOT,
|
|
|
|
|
RuleAction.SUB_RULE,
|
|
|
|
|
RuleAction.DOMAIN_REGEX,
|
|
|
|
|
RuleAction.PROCESS_NAME_REGEX,
|
|
|
|
|
RuleAction.PROCESS_PATH_REGEX,
|
|
|
|
|
].contains(this);
|
|
|
|
|
|
2026-02-02 10:14:13 +08:00
|
|
|
String getDesc(BuildContext context) {
|
|
|
|
|
final appLocalizations = context.appLocalizations;
|
|
|
|
|
return switch (this) {
|
|
|
|
|
RuleAction.DOMAIN => appLocalizations.ruleActionDomainDesc,
|
|
|
|
|
RuleAction.DOMAIN_SUFFIX => appLocalizations.ruleActionDomainSuffixDesc,
|
|
|
|
|
RuleAction.DOMAIN_KEYWORD => appLocalizations.ruleActionDomainKeywordDesc,
|
|
|
|
|
RuleAction.DOMAIN_REGEX => appLocalizations.ruleActionDomainRegexDesc,
|
2026-09-05 20:09:39 +08:00
|
|
|
RuleAction.DOMAIN_WILDCARD =>
|
|
|
|
|
appLocalizations.ruleActionDomainWildcardDesc,
|
2026-02-02 10:14:13 +08:00
|
|
|
RuleAction.GEOSITE => appLocalizations.ruleActionGeositeDesc,
|
|
|
|
|
RuleAction.IP_CIDR => appLocalizations.ruleActionIpCidrDesc,
|
|
|
|
|
RuleAction.IP_CIDR6 => appLocalizations.ruleActionIpCidr6Desc,
|
|
|
|
|
RuleAction.IP_SUFFIX => appLocalizations.ruleActionIpSuffixDesc,
|
|
|
|
|
RuleAction.IP_ASN => appLocalizations.ruleActionIpAsnDesc,
|
|
|
|
|
RuleAction.GEOIP => appLocalizations.ruleActionGeoipDesc,
|
|
|
|
|
RuleAction.SRC_GEOIP => appLocalizations.ruleActionSrcGeoipDesc,
|
|
|
|
|
RuleAction.SRC_IP_ASN => appLocalizations.ruleActionSrcIpAsnDesc,
|
|
|
|
|
RuleAction.SRC_IP_CIDR => appLocalizations.ruleActionSrcIpCidrDesc,
|
|
|
|
|
RuleAction.SRC_IP_SUFFIX => appLocalizations.ruleActionSrcIpSuffixDesc,
|
|
|
|
|
RuleAction.DST_PORT => appLocalizations.ruleActionDstPortDesc,
|
|
|
|
|
RuleAction.SRC_PORT => appLocalizations.ruleActionSrcPortDesc,
|
|
|
|
|
RuleAction.IN_PORT => appLocalizations.ruleActionInPortDesc,
|
|
|
|
|
RuleAction.IN_TYPE => appLocalizations.ruleActionInTypeDesc,
|
|
|
|
|
RuleAction.IN_USER => appLocalizations.ruleActionInUserDesc,
|
|
|
|
|
RuleAction.IN_NAME => appLocalizations.ruleActionInNameDesc,
|
2026-09-05 20:09:39 +08:00
|
|
|
RuleAction.REMATCH_NAME => appLocalizations.ruleActionRematchNameDesc,
|
2026-02-02 10:14:13 +08:00
|
|
|
RuleAction.PROCESS_PATH => appLocalizations.ruleActionProcessPathDesc,
|
|
|
|
|
RuleAction.PROCESS_PATH_REGEX =>
|
|
|
|
|
appLocalizations.ruleActionProcessPathRegexDesc,
|
2026-09-05 20:09:39 +08:00
|
|
|
RuleAction.PROCESS_PATH_WILDCARD =>
|
|
|
|
|
appLocalizations.ruleActionProcessPathWildcardDesc,
|
2026-02-02 10:14:13 +08:00
|
|
|
RuleAction.PROCESS_NAME => appLocalizations.ruleActionProcessNameDesc,
|
|
|
|
|
RuleAction.PROCESS_NAME_REGEX =>
|
|
|
|
|
appLocalizations.ruleActionProcessNameRegexDesc,
|
2026-09-05 20:09:39 +08:00
|
|
|
RuleAction.PROCESS_NAME_WILDCARD =>
|
|
|
|
|
appLocalizations.ruleActionProcessNameWildcardDesc,
|
2026-02-02 10:14:13 +08:00
|
|
|
RuleAction.UID => appLocalizations.ruleActionUidDesc,
|
|
|
|
|
RuleAction.NETWORK => appLocalizations.ruleActionNetworkDesc,
|
|
|
|
|
RuleAction.DSCP => appLocalizations.ruleActionDscpDesc,
|
|
|
|
|
RuleAction.RULE_SET => appLocalizations.ruleActionRuleSetDesc,
|
|
|
|
|
RuleAction.AND => appLocalizations.ruleActionAndDesc,
|
|
|
|
|
RuleAction.OR => appLocalizations.ruleActionOrDesc,
|
|
|
|
|
RuleAction.NOT => appLocalizations.ruleActionNotDesc,
|
|
|
|
|
RuleAction.SUB_RULE => appLocalizations.ruleActionSubRuleDesc,
|
|
|
|
|
RuleAction.MATCH => appLocalizations.ruleActionMatchDesc,
|
|
|
|
|
};
|
|
|
|
|
}
|
2025-03-12 17:15:31 +08:00
|
|
|
}
|
|
|
|
|
|
2026-08-15 17:47:08 +08:00
|
|
|
enum OverwriteType { standard, script, custom }
|
2025-10-14 15:13:52 +08:00
|
|
|
|
2026-02-02 10:14:13 +08:00
|
|
|
enum RuleTarget {
|
|
|
|
|
DIRECT,
|
|
|
|
|
REJECT;
|
|
|
|
|
|
2026-09-05 20:09:39 +08:00
|
|
|
static final List<String> baseTargetNames = List.unmodifiable(
|
|
|
|
|
RuleTarget.values.map((item) => item.name),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
static final Set<String> baseTargets = Set.unmodifiable(baseTargetNames);
|
2026-02-02 10:14:13 +08:00
|
|
|
}
|
2025-04-18 17:50:46 +08:00
|
|
|
|
2025-12-16 11:23:09 +08:00
|
|
|
enum RestoreStrategy { compatible, override }
|
2025-04-18 17:50:46 +08:00
|
|
|
|
2025-10-14 15:13:52 +08:00
|
|
|
enum Language { yaml, javaScript, json }
|
2025-05-02 02:24:12 +08:00
|
|
|
|
2025-07-31 17:09:18 +08:00
|
|
|
enum ScrollPositionCacheKey { tools, profiles, proxiesList, proxiesTabList }
|
|
|
|
|
|
2025-10-14 15:13:52 +08:00
|
|
|
enum QueryTag { proxies, access }
|
2025-07-31 17:09:18 +08:00
|
|
|
|
2026-02-02 10:14:13 +08:00
|
|
|
enum LoadingTag {
|
|
|
|
|
profiles,
|
|
|
|
|
backup_restore,
|
|
|
|
|
access,
|
|
|
|
|
proxies,
|
|
|
|
|
batteryOptimization,
|
|
|
|
|
}
|
2025-12-16 11:23:09 +08:00
|
|
|
|
2025-07-31 17:09:18 +08:00
|
|
|
enum CoreStatus { connecting, connected, disconnected }
|
2025-12-16 11:23:09 +08:00
|
|
|
|
2026-09-05 20:09:39 +08:00
|
|
|
enum UpdatingScope { core, local }
|
|
|
|
|
|
2025-12-16 11:23:09 +08:00
|
|
|
enum RuleScene { added, disabled, custom }
|
2026-02-02 10:14:13 +08:00
|
|
|
|
|
|
|
|
enum ItemPosition {
|
|
|
|
|
start,
|
|
|
|
|
middle,
|
|
|
|
|
end,
|
|
|
|
|
startAndEnd;
|
|
|
|
|
|
|
|
|
|
static ItemPosition get(int index, int length) {
|
|
|
|
|
ItemPosition position = ItemPosition.middle;
|
|
|
|
|
if (length == 1) {
|
|
|
|
|
position = ItemPosition.startAndEnd;
|
|
|
|
|
} else if (index == length - 1) {
|
|
|
|
|
position = ItemPosition.end;
|
|
|
|
|
} else if (index == 0) {
|
|
|
|
|
position = ItemPosition.start;
|
|
|
|
|
}
|
|
|
|
|
return position;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static ItemPosition calculateVisualPosition<T>(
|
|
|
|
|
int currentIndex,
|
|
|
|
|
List<T> items,
|
|
|
|
|
Set<T> deletedItems,
|
|
|
|
|
) {
|
2026-09-05 20:09:39 +08:00
|
|
|
if (deletedItems.isEmpty) {
|
|
|
|
|
return ItemPosition.get(currentIndex, items.length);
|
|
|
|
|
}
|
2026-02-02 10:14:13 +08:00
|
|
|
final currentItem = items[currentIndex];
|
|
|
|
|
if (deletedItems.contains(currentItem)) {
|
|
|
|
|
return ItemPosition.middle;
|
|
|
|
|
}
|
|
|
|
|
final int visualLength = items.length - deletedItems.length;
|
|
|
|
|
if (visualLength <= 0) return ItemPosition.middle;
|
|
|
|
|
int deletedCountBeforeMe = 0;
|
|
|
|
|
for (int i = 0; i < currentIndex; i++) {
|
|
|
|
|
if (deletedItems.contains(items[i])) {
|
|
|
|
|
deletedCountBeforeMe++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
final int visualIndex = currentIndex - deletedCountBeforeMe;
|
|
|
|
|
return ItemPosition.get(visualIndex, visualLength);
|
|
|
|
|
}
|
|
|
|
|
}
|