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';
|
|
|
|
|
|
|
|
|
|
import 'package:fl_clash/fragments/dashboard/widgets/widgets.dart';
|
|
|
|
|
import 'package:fl_clash/widgets/widgets.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-09-08 21:21:21 +08:00
|
|
|
import 'package:hotkey_manager/hotkey_manager.dart';
|
2024-08-26 20:44:30 +08:00
|
|
|
|
2024-12-09 01:40:39 +08:00
|
|
|
enum SupportPlatform {
|
|
|
|
|
Windows,
|
|
|
|
|
MacOS,
|
|
|
|
|
Linux,
|
|
|
|
|
Android;
|
|
|
|
|
|
|
|
|
|
static SupportPlatform get currentPlatform {
|
|
|
|
|
if (Platform.isWindows) {
|
|
|
|
|
return SupportPlatform.Windows;
|
|
|
|
|
} else if (Platform.isMacOS) {
|
|
|
|
|
return SupportPlatform.MacOS;
|
|
|
|
|
} else if (Platform.isLinux) {
|
|
|
|
|
return SupportPlatform.Linux;
|
|
|
|
|
} else if (Platform.isAndroid) {
|
|
|
|
|
return SupportPlatform.Android;
|
|
|
|
|
}
|
|
|
|
|
throw "invalid platform";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const desktopPlatforms = [
|
|
|
|
|
SupportPlatform.Linux,
|
|
|
|
|
SupportPlatform.MacOS,
|
|
|
|
|
SupportPlatform.Windows,
|
|
|
|
|
];
|
|
|
|
|
|
2024-06-08 22:51:58 +08:00
|
|
|
enum GroupType { Selector, URLTest, Fallback, LoadBalance, Relay }
|
2024-04-30 23:38:49 +08:00
|
|
|
|
2024-05-07 13:50:00 +08:00
|
|
|
enum GroupName { GLOBAL, Proxy, Auto, Fallback }
|
|
|
|
|
|
2024-04-30 23:38:49 +08:00
|
|
|
extension GroupTypeExtension on GroupType {
|
|
|
|
|
static List<String> get valueList => GroupType.values
|
|
|
|
|
.map(
|
|
|
|
|
(e) => e.toString().split(".").last,
|
|
|
|
|
)
|
|
|
|
|
.toList();
|
|
|
|
|
|
2024-09-26 14:29:04 +08:00
|
|
|
bool get isURLTestOrFallback {
|
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];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String get value => GroupTypeExtension.valueList[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum UsedProxy { GLOBAL, DIRECT, REJECT }
|
|
|
|
|
|
|
|
|
|
extension UsedProxyExtension on UsedProxy {
|
|
|
|
|
static List<String> get valueList => UsedProxy.values
|
|
|
|
|
.map(
|
|
|
|
|
(e) => e.toString().split(".").last,
|
|
|
|
|
)
|
|
|
|
|
.toList();
|
|
|
|
|
|
|
|
|
|
String get value => UsedProxyExtension.valueList[index];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum Mode { rule, global, direct }
|
|
|
|
|
|
2024-05-20 15:15:09 +08:00
|
|
|
enum ViewMode { mobile, laptop, desktop }
|
|
|
|
|
|
2024-04-30 23:38:49 +08:00
|
|
|
enum LogLevel { debug, info, warning, error, silent }
|
|
|
|
|
|
|
|
|
|
enum TransportProtocol { udp, tcp }
|
|
|
|
|
|
|
|
|
|
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 }
|
|
|
|
|
|
|
|
|
|
enum ResultType { success, error }
|
|
|
|
|
|
2024-07-13 16:36:08 +08:00
|
|
|
enum AppMessageType {
|
2024-07-02 08:08:31 +08:00
|
|
|
log,
|
|
|
|
|
delay,
|
|
|
|
|
request,
|
2024-07-13 16:36:08 +08:00
|
|
|
loaded,
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-13 19:08:17 +08:00
|
|
|
enum InvokeMessageType {
|
2024-07-13 16:36:08 +08:00
|
|
|
protect,
|
|
|
|
|
process,
|
2024-07-02 08:08:31 +08:00
|
|
|
}
|
2024-06-13 23:43:42 +08:00
|
|
|
|
|
|
|
|
enum FindProcessMode { always, off }
|
2024-05-20 15:15:09 +08:00
|
|
|
|
|
|
|
|
enum RecoveryOption {
|
|
|
|
|
all,
|
|
|
|
|
onlyProfiles,
|
2024-06-08 22:51:58 +08:00
|
|
|
}
|
2024-06-19 13:13:31 +08:00
|
|
|
|
2024-06-23 00:26:24 +08:00
|
|
|
enum ChipType { action, delete }
|
|
|
|
|
|
|
|
|
|
enum CommonCardType { plain, filled }
|
2024-12-09 01:40:39 +08:00
|
|
|
//
|
|
|
|
|
// extension CommonCardTypeExt on CommonCardType {
|
|
|
|
|
// CommonCardType get variant => CommonCardType.plain;
|
|
|
|
|
// }
|
2024-06-23 00:26:24 +08:00
|
|
|
|
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,
|
|
|
|
|
@JsonValue("fake-ip")
|
|
|
|
|
fakeIp,
|
|
|
|
|
@JsonValue("redir-host")
|
|
|
|
|
redirHost,
|
|
|
|
|
hosts
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-08 21:21:21 +08:00
|
|
|
enum KeyboardModifier {
|
|
|
|
|
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,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
final List<PhysicalKeyboardKey> physicalKeys;
|
|
|
|
|
|
|
|
|
|
const KeyboardModifier(this.physicalKeys);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extension KeyboardModifierExt on KeyboardModifier {
|
|
|
|
|
HotKeyModifier toHotKeyModifier() {
|
|
|
|
|
return switch (this) {
|
|
|
|
|
KeyboardModifier.alt => HotKeyModifier.alt,
|
|
|
|
|
KeyboardModifier.capsLock => HotKeyModifier.capsLock,
|
|
|
|
|
KeyboardModifier.control => HotKeyModifier.control,
|
|
|
|
|
KeyboardModifier.fn => HotKeyModifier.fn,
|
|
|
|
|
KeyboardModifier.meta => HotKeyModifier.meta,
|
|
|
|
|
KeyboardModifier.shift => HotKeyModifier.shift,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum HotAction {
|
|
|
|
|
start,
|
|
|
|
|
view,
|
|
|
|
|
mode,
|
|
|
|
|
proxy,
|
|
|
|
|
tun,
|
|
|
|
|
}
|
2024-09-26 14:29:04 +08:00
|
|
|
|
|
|
|
|
enum ProxiesIconStyle {
|
|
|
|
|
standard,
|
|
|
|
|
none,
|
|
|
|
|
icon,
|
|
|
|
|
}
|
2024-10-26 16:52:10 +08:00
|
|
|
|
|
|
|
|
enum FontFamily {
|
|
|
|
|
system(),
|
|
|
|
|
miSans("MiSans"),
|
|
|
|
|
twEmoji("Twemoji"),
|
|
|
|
|
icon("Icons");
|
|
|
|
|
|
|
|
|
|
final String? value;
|
|
|
|
|
|
|
|
|
|
const FontFamily([this.value]);
|
|
|
|
|
}
|
2024-11-09 20:17:57 +08:00
|
|
|
|
|
|
|
|
enum RouteMode {
|
|
|
|
|
bypassPrivate,
|
|
|
|
|
config,
|
|
|
|
|
}
|
2024-12-03 21:47:12 +08:00
|
|
|
|
|
|
|
|
enum ActionMethod {
|
|
|
|
|
message,
|
|
|
|
|
initClash,
|
|
|
|
|
getIsInit,
|
|
|
|
|
forceGc,
|
|
|
|
|
shutdown,
|
|
|
|
|
validateConfig,
|
|
|
|
|
updateConfig,
|
|
|
|
|
getProxies,
|
|
|
|
|
changeProxy,
|
|
|
|
|
getTraffic,
|
|
|
|
|
getTotalTraffic,
|
|
|
|
|
resetTraffic,
|
|
|
|
|
asyncTestDelay,
|
|
|
|
|
getConnections,
|
|
|
|
|
closeConnections,
|
|
|
|
|
closeConnection,
|
|
|
|
|
getExternalProviders,
|
|
|
|
|
getExternalProvider,
|
|
|
|
|
updateGeoData,
|
|
|
|
|
updateExternalProvider,
|
|
|
|
|
sideLoadExternalProvider,
|
|
|
|
|
startLog,
|
|
|
|
|
stopLog,
|
|
|
|
|
startListener,
|
|
|
|
|
stopListener,
|
2024-12-09 01:40:39 +08:00
|
|
|
getCountryCode,
|
|
|
|
|
getMemory,
|
2025-01-13 19:08:17 +08:00
|
|
|
|
|
|
|
|
///Android,
|
|
|
|
|
setFdMap,
|
|
|
|
|
setProcessMap,
|
|
|
|
|
setState,
|
|
|
|
|
startTun,
|
|
|
|
|
stopTun,
|
|
|
|
|
getRunTime,
|
|
|
|
|
updateDns,
|
|
|
|
|
getAndroidVpnOptions,
|
|
|
|
|
getCurrentProfileName,
|
2024-12-03 21:47:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum AuthorizeCode { none, success, error }
|
|
|
|
|
|
|
|
|
|
enum WindowsHelperServiceStatus {
|
|
|
|
|
none,
|
|
|
|
|
presence,
|
|
|
|
|
running,
|
|
|
|
|
}
|
2024-12-09 01:40:39 +08:00
|
|
|
|
|
|
|
|
enum DebounceTag {
|
|
|
|
|
updateClashConfig,
|
|
|
|
|
updateGroups,
|
|
|
|
|
addCheckIpNum,
|
|
|
|
|
applyProfile,
|
|
|
|
|
savePreferences,
|
|
|
|
|
changeProxy,
|
|
|
|
|
checkIp,
|
|
|
|
|
handleWill,
|
|
|
|
|
updateDelay,
|
|
|
|
|
vpnTip,
|
|
|
|
|
autoLaunch
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
enum DashboardWidget {
|
|
|
|
|
networkSpeed(
|
|
|
|
|
GridItem(
|
|
|
|
|
crossAxisCellCount: 8,
|
|
|
|
|
child: NetworkSpeed(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
outboundMode(
|
|
|
|
|
GridItem(
|
|
|
|
|
crossAxisCellCount: 4,
|
|
|
|
|
child: OutboundMode(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
trafficUsage(
|
|
|
|
|
GridItem(
|
|
|
|
|
crossAxisCellCount: 4,
|
|
|
|
|
child: TrafficUsage(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
networkDetection(
|
|
|
|
|
GridItem(
|
|
|
|
|
crossAxisCellCount: 4,
|
|
|
|
|
child: NetworkDetection(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
tunButton(
|
|
|
|
|
GridItem(
|
|
|
|
|
crossAxisCellCount: 4,
|
|
|
|
|
child: TUNButton(),
|
|
|
|
|
),
|
|
|
|
|
platforms: desktopPlatforms,
|
|
|
|
|
),
|
|
|
|
|
systemProxyButton(
|
|
|
|
|
GridItem(
|
|
|
|
|
crossAxisCellCount: 4,
|
|
|
|
|
child: SystemProxyButton(),
|
|
|
|
|
),
|
|
|
|
|
platforms: desktopPlatforms,
|
|
|
|
|
),
|
|
|
|
|
intranetIp(
|
|
|
|
|
GridItem(
|
|
|
|
|
crossAxisCellCount: 4,
|
|
|
|
|
child: IntranetIP(),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
memoryInfo(
|
|
|
|
|
GridItem(
|
|
|
|
|
crossAxisCellCount: 4,
|
|
|
|
|
child: MemoryInfo(),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
final GridItem widget;
|
|
|
|
|
final List<SupportPlatform> platforms;
|
|
|
|
|
|
|
|
|
|
const DashboardWidget(
|
|
|
|
|
this.widget, {
|
|
|
|
|
this.platforms = SupportPlatform.values,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
static DashboardWidget getDashboardWidget(GridItem gridItem) {
|
|
|
|
|
final dashboardWidgets = DashboardWidget.values;
|
|
|
|
|
final index = dashboardWidgets.indexWhere(
|
|
|
|
|
(item) => item.widget == gridItem,
|
|
|
|
|
);
|
|
|
|
|
return dashboardWidgets[index];
|
|
|
|
|
}
|
|
|
|
|
}
|