Compare commits

..

1 Commits

Author SHA1 Message Date
chen08209
578a3591ff Fix windows tun issues 2025-06-12 12:13:32 +08:00
8 changed files with 73 additions and 87 deletions

View File

@@ -104,7 +104,7 @@ fun ConnectivityManager.resolveDns(network: Network?): List<String> {
fun InetAddress.asSocketAddressText(port: Int): String {
return when (this) {
is Inet6Address ->
"[${numericToTextFormat(this)}]:$port"
"[${numericToTextFormat(this.address)}]:$port"
is Inet4Address ->
"${this.hostAddress}:$port"
@@ -141,8 +141,7 @@ fun Context.getActionPendingIntent(action: String): PendingIntent {
}
}
private fun numericToTextFormat(address: Inet6Address): String {
val src = address.address
private fun numericToTextFormat(src: ByteArray): String {
val sb = StringBuilder(39)
for (i in 0 until 8) {
sb.append(
@@ -155,10 +154,6 @@ private fun numericToTextFormat(address: Inet6Address): String {
sb.append(":")
}
}
if (address.scopeId > 0) {
sb.append("%")
sb.append(address.scopeId)
}
return sb.toString()
}

View File

@@ -100,7 +100,6 @@ data object VpnPlugin : FlutterPlugin, MethodChannel.MethodCallHandler {
}
fun handleStart(options: VpnOptions): Boolean {
onUpdateNetwork();
if (options.enable != this.options?.enable) {
this.flClashService = null
}

View File

@@ -1,4 +1,3 @@
import 'dart:async';
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
@@ -91,37 +90,37 @@ class Request {
"https://ipinfo.io/json/": IpInfo.fromIpInfoIoJson,
};
Future<Result<IpInfo?>> checkIp({CancelToken? cancelToken}) async {
var failureCount = 0;
final futures = _ipInfoSources.entries.map((source) async {
final Completer<Result<IpInfo?>> completer = Completer();
final future = Dio().get<Map<String, dynamic>>(
source.key,
cancelToken: cancelToken,
options: Options(
responseType: ResponseType.json,
),
);
future.then((res) {
if (res.statusCode == HttpStatus.ok && res.data != null) {
completer.complete(Result.success(source.value(res.data!)));
} else {
failureCount++;
if (failureCount == _ipInfoSources.length) {
completer.complete(Result.success(null));
}
Future<IpInfo?> checkIp({CancelToken? cancelToken}) async {
for (final source in _ipInfoSources.entries) {
try {
final response = await Dio()
.get<Map<String, dynamic>>(
source.key,
cancelToken: cancelToken,
options: Options(
responseType: ResponseType.json,
),
)
.timeout(
Duration(
seconds: 30,
),
);
if (response.statusCode != 200 || response.data == null) {
continue;
}
}).catchError((e) {
failureCount++;
if (e == DioExceptionType.cancel) {
completer.complete(Result.error("cancelled"));
if (response.data == null) {
continue;
}
});
return completer.future;
});
final res = await Future.any(futures);
cancelToken?.cancel();
return res;
return source.value(response.data!);
} catch (e) {
commonPrint.log("checkIp error ===> $e");
if (e is DioException && e.type == DioExceptionType.cancel) {
throw "cancelled";
}
}
}
return null;
}
Future<bool> pingHelper() async {

View File

@@ -62,7 +62,6 @@ Future<void> _service(List<String> flags) async {
vpn?.addListener(
_VpnListenerWithService(
onDnsChanged: (String dns) {
print("handle dns $dns");
clashLibHandler.updateDns(dns);
},
),

View File

@@ -126,7 +126,7 @@ final proxyStateProvider = AutoDisposeProvider<ProxyState>.internal(
@Deprecated('Will be removed in 3.0. Use Ref instead')
// ignore: unused_element
typedef ProxyStateRef = AutoDisposeProviderRef<ProxyState>;
String _$trayStateHash() => r'61c99bbae2cb7ed69dc9ee0f2149510eb6a87df4';
String _$trayStateHash() => r'39ff84c50ad9c9cc666fa2538fe13ec0d7236b2e';
/// See also [trayState].
@ProviderFor(trayState)

View File

@@ -158,11 +158,9 @@ TrayState trayState(Ref ref) {
final appSetting = ref.watch(
appSettingProvider,
);
final groups = ref
.watch(
currentGroupsStateProvider,
)
.value;
final groups = ref.watch(
groupsProvider,
);
final brightness = ref.watch(
appBrightnessProvider,
);

View File

@@ -401,23 +401,21 @@ class GlobalState {
for (final host in realPatchConfig.hosts.entries) {
rawConfig["hosts"][host.key] = host.value.splitByMultipleSeparators;
}
if (rawConfig["dns"] == null) {
rawConfig["dns"] = {};
}
final isEnableDns = rawConfig["dns"]["enable"] == true;
final overrideDns = globalState.config.overrideDns;
if (overrideDns || !isEnableDns) {
final dns = switch (!isEnableDns) {
true => realPatchConfig.dns.copyWith(
nameserver: [...realPatchConfig.dns.nameserver, "system://"]),
false => realPatchConfig.dns,
};
rawConfig["dns"] = dns.toJson();
if (overrideDns) {
rawConfig["dns"] = realPatchConfig.dns.toJson();
rawConfig["dns"]["nameserver-policy"] = {};
for (final entry in dns.nameserverPolicy.entries) {
for (final entry in realPatchConfig.dns.nameserverPolicy.entries) {
rawConfig["dns"]["nameserver-policy"][entry.key] =
entry.value.splitByMultipleSeparators;
}
} else {
if (rawConfig["dns"] == null) {
rawConfig["dns"] = {};
}
if (rawConfig["dns"]["enable"] != false) {
rawConfig["dns"]["enable"] = true;
}
}
var rules = [];
if (rawConfig["rules"] != null) {
@@ -501,9 +499,6 @@ class DetectionState {
debouncer.call(
FunctionTag.checkIp,
_checkIp,
duration: Duration(
milliseconds: 1200,
),
);
}
@@ -528,35 +523,36 @@ class DetectionState {
cancelToken = null;
}
cancelToken = CancelToken();
state.value = state.value.copyWith(
isTesting: true,
);
final res = await request.checkIp(cancelToken: cancelToken);
if (res.isError) {
try {
state.value = state.value.copyWith(
isLoading: true,
ipInfo: null,
isTesting: true,
);
return;
final ipInfo = await request.checkIp(cancelToken: cancelToken);
state.value = state.value.copyWith(
isTesting: false,
);
if (ipInfo != null) {
state.value = state.value.copyWith(
isLoading: false,
ipInfo: ipInfo,
);
return;
}
_clearSetTimeoutTimer();
_setTimeoutTimer = Timer(const Duration(milliseconds: 300), () {
state.value = state.value.copyWith(
isLoading: false,
ipInfo: null,
);
});
} catch (e) {
if (e.toString() == "cancelled") {
state.value = state.value.copyWith(
isLoading: true,
ipInfo: null,
);
}
}
final ipInfo = res.data;
state.value = state.value.copyWith(
isTesting: false,
);
if (ipInfo != null) {
state.value = state.value.copyWith(
isLoading: false,
ipInfo: ipInfo,
);
return;
}
_clearSetTimeoutTimer();
_setTimeoutTimer = Timer(const Duration(milliseconds: 300), () {
state.value = state.value.copyWith(
isLoading: false,
ipInfo: null,
);
});
}
_clearSetTimeoutTimer() {

View File

@@ -1,7 +1,7 @@
name: fl_clash
description: A multi-platform proxy client based on ClashMeta, simple and easy to use, open-source and ad-free.
publish_to: 'none'
version: 0.8.86+202506142
version: 0.8.86+202506121
environment:
sdk: '>=3.1.0 <4.0.0'