fix socks version issue
This commit is contained in:
@@ -26,6 +26,12 @@ enum SingboxFieldKind {
|
||||
port,
|
||||
boolean,
|
||||
stringList,
|
||||
|
||||
/// A value constrained to [SingboxProxyFormField.allowedValues] and always
|
||||
/// serialized as a JSON string. Use for sing-box string enums such as the
|
||||
/// SOCKS `version` field, whose accepted values ("4", "4a", "5") are
|
||||
/// string-typed even when numeric-looking.
|
||||
choice,
|
||||
}
|
||||
|
||||
class SingboxProxyFormField {
|
||||
@@ -39,6 +45,10 @@ class SingboxProxyFormField {
|
||||
final int? minValue;
|
||||
final int? maxValue;
|
||||
|
||||
/// Permitted values for a [SingboxFieldKind.choice] field, rendered as a
|
||||
/// dropdown and enforced during validation.
|
||||
final List<String>? allowedValues;
|
||||
|
||||
const SingboxProxyFormField({
|
||||
required this.key,
|
||||
required this.label,
|
||||
@@ -49,6 +59,7 @@ class SingboxProxyFormField {
|
||||
this.exactListLength,
|
||||
this.minValue,
|
||||
this.maxValue,
|
||||
this.allowedValues,
|
||||
});
|
||||
|
||||
bool get isSecret => kind == SingboxFieldKind.secret;
|
||||
@@ -58,6 +69,7 @@ class SingboxProxyFormField {
|
||||
bool get isPort => kind == SingboxFieldKind.port;
|
||||
bool get isBoolean => kind == SingboxFieldKind.boolean;
|
||||
bool get isStringList => kind == SingboxFieldKind.stringList;
|
||||
bool get isChoice => kind == SingboxFieldKind.choice;
|
||||
}
|
||||
|
||||
/// Shared parsing of boolean form values. Returns null when the text doesn't
|
||||
|
||||
@@ -72,6 +72,12 @@ class SingboxProxyFormSpec {
|
||||
if (field.isBoolean && value.isNotEmpty && parseFormBool(value) == null) {
|
||||
return '${field.label} must be true or false.';
|
||||
}
|
||||
if (field.isChoice && value.isNotEmpty) {
|
||||
final allowedValues = field.allowedValues;
|
||||
if (allowedValues != null && !allowedValues.contains(value)) {
|
||||
return '${field.label} must be one of: ${allowedValues.join(', ')}.';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -139,7 +139,9 @@ const singboxProxyFormSpecs = <SingboxProxyProfileType, SingboxProxyFormSpec>{
|
||||
key: 'version',
|
||||
label: 'SOCKS Version',
|
||||
defaultValue: '5',
|
||||
kind: SingboxFieldKind.integer,
|
||||
// sing-box expects this as a JSON string enum, not a number.
|
||||
kind: SingboxFieldKind.choice,
|
||||
allowedValues: ['5', '4a', '4'],
|
||||
),
|
||||
_usernameField,
|
||||
_optionalPasswordField,
|
||||
|
||||
Reference in New Issue
Block a user