Files
umbrix/lib/singbox/model/singbox_config_enum.dart

118 lines
2.8 KiB
Dart
Raw Normal View History

2024-02-15 12:24:42 +03:30
import 'dart:io';
2024-02-17 11:58:34 +03:30
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:umbrix/core/localization/translations.dart';
import 'package:umbrix/utils/platform_utils.dart';
2023-12-01 12:56:24 +03:30
2024-02-17 11:58:34 +03:30
@JsonEnum(valueField: 'key')
2023-12-01 12:56:24 +03:30
enum ServiceMode {
2024-02-17 11:58:34 +03:30
proxy("proxy"),
systemProxy("system-proxy"),
tun("vpn"),
tunService("vpn-service");
2023-12-14 15:46:15 +03:30
2024-02-17 11:58:34 +03:30
const ServiceMode(this.key);
2024-02-15 19:39:35 +03:30
2024-02-17 11:58:34 +03:30
final String key;
2023-12-01 12:56:24 +03:30
static ServiceMode get defaultMode =>
PlatformUtils.isDesktop ? systemProxy : tun;
2024-02-15 12:24:42 +03:30
/// supported service mode based on platform, use this instead of [values] in UI
2023-12-01 12:56:24 +03:30
static List<ServiceMode> get choices {
2024-02-15 12:24:42 +03:30
if (Platform.isWindows || Platform.isLinux) {
2023-12-01 12:56:24 +03:30
return values;
2024-02-15 12:24:42 +03:30
} else if (Platform.isMacOS) {
return [proxy, systemProxy, tun];
2023-12-01 12:56:24 +03:30
}
2024-02-15 12:24:42 +03:30
// mobile
2023-12-01 12:56:24 +03:30
return [proxy, tun];
}
2024-03-07 17:04:32 +03:30
bool get isExperimental => switch (this) {
tun => PlatformUtils.isDesktop,
tunService => PlatformUtils.isDesktop,
_ => false,
};
2023-12-01 12:56:24 +03:30
String present(TranslationsEn t) => switch (this) {
2024-03-08 17:24:43 +03:30
proxy => t.config.serviceModes.proxy,
systemProxy => t.config.serviceModes.systemProxy,
2023-12-29 15:35:01 +03:30
tun =>
2024-03-08 17:24:43 +03:30
"${t.config.serviceModes.tun}${isExperimental ? " (${t.settings.experimental})" : ""}",
2024-02-14 15:51:58 +01:00
tunService =>
2024-03-08 17:24:43 +03:30
"${t.config.serviceModes.tunService}${isExperimental ? " (${t.settings.experimental})" : ""}",
2024-03-07 17:04:32 +03:30
};
String presentShort(TranslationsEn t) => switch (this) {
2024-03-08 17:24:43 +03:30
proxy => t.config.shortServiceModes.proxy,
systemProxy => t.config.shortServiceModes.systemProxy,
tun => t.config.shortServiceModes.tun,
tunService => t.config.shortServiceModes.tunService,
2023-12-01 12:56:24 +03:30
};
}
2024-02-17 11:58:34 +03:30
@JsonEnum(valueField: 'key')
2023-12-01 12:56:24 +03:30
enum IPv6Mode {
2024-02-17 11:58:34 +03:30
disable("ipv4_only"),
enable("prefer_ipv4"),
prefer("prefer_ipv6"),
only("ipv6_only");
2023-12-01 12:56:24 +03:30
2024-02-17 11:58:34 +03:30
const IPv6Mode(this.key);
2023-12-01 12:56:24 +03:30
2024-02-17 11:58:34 +03:30
final String key;
2023-12-01 12:56:24 +03:30
String present(TranslationsEn t) => switch (this) {
2024-03-08 17:24:43 +03:30
disable => t.config.ipv6Modes.disable,
enable => t.config.ipv6Modes.enable,
prefer => t.config.ipv6Modes.prefer,
only => t.config.ipv6Modes.only,
2023-12-01 12:56:24 +03:30
};
}
2024-02-17 11:58:34 +03:30
@JsonEnum(valueField: 'key')
2023-12-01 12:56:24 +03:30
enum DomainStrategy {
auto(""),
preferIpv6("prefer_ipv6"),
preferIpv4("prefer_ipv4"),
ipv4Only("ipv4_only"),
ipv6Only("ipv6_only");
const DomainStrategy(this.key);
final String key;
String get displayName => switch (this) {
auto => "auto",
_ => key,
};
}
enum TunImplementation {
mixed,
system,
2024-03-19 12:45:49 +01:00
gvisor;
2023-12-01 12:56:24 +03:30
}
2024-01-19 22:26:23 +03:30
enum MuxProtocol {
h2mux,
smux,
yamux;
}
2024-02-03 12:36:27 +03:30
2024-03-07 20:21:25 +03:30
@JsonEnum(valueField: 'key')
2024-02-03 12:36:27 +03:30
enum WarpDetourMode {
2024-03-07 20:21:25 +03:30
proxyOverWarp("proxy_over_warp"),
warpOverProxy("warp_over_proxy");
const WarpDetourMode(this.key);
final String key;
2024-02-03 12:36:27 +03:30
String present(TranslationsEn t) => switch (this) {
2024-03-08 17:24:43 +03:30
proxyOverWarp => t.config.warpDetourModes.proxyOverWarp,
warpOverProxy => t.config.warpDetourModes.warpOverProxy,
2024-02-03 12:36:27 +03:30
};
}