fix proxy auto start issue
This commit is contained in:
@@ -139,23 +139,6 @@ class SingboxProxyRuntimeRepository extends _$SingboxProxyRuntimeRepository {
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> ensureProxyConnectionAvailable(
|
||||
SingboxProxyConnectionId connectionId,
|
||||
) async {
|
||||
await _lock.synchronized(() async {
|
||||
final currentState = await _stateSnapshotUnlocked();
|
||||
final isRunning = currentState.endpoints.any(
|
||||
(endpoint) => endpoint.profileId == connectionId.encode(),
|
||||
);
|
||||
if (isRunning) return;
|
||||
|
||||
final activeProfileIds = _activeProfileIds(currentState);
|
||||
await _startProfilesUnlocked(
|
||||
{...activeProfileIds, connectionId.profileId}.toList(),
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Set<String> _activeProfileIds(SingboxProxyRuntimeState runtimeState) {
|
||||
return runtimeState.endpoints
|
||||
.map((endpoint) => ProxyConnectionId.decode(endpoint.profileId))
|
||||
|
||||
@@ -87,7 +87,7 @@ final class SingboxProxyRuntimeRepositoryProvider
|
||||
}
|
||||
|
||||
String _$singboxProxyRuntimeRepositoryHash() =>
|
||||
r'665908eaff34569f7a19dc5328a067711d1937f2';
|
||||
r'bb84ab57abd3b7261105da85d3e047cef1b31a44';
|
||||
|
||||
abstract class _$SingboxProxyRuntimeRepository
|
||||
extends $AsyncNotifier<SingboxProxyRuntimeState> {
|
||||
|
||||
@@ -42,7 +42,7 @@ final class ProxyInputConsumerProvider
|
||||
}
|
||||
|
||||
String _$proxyInputConsumerHash() =>
|
||||
r'fed529f253a9bdf72d0b1c23a298765b681d07b8';
|
||||
r'8958cb3ff089779c1991390a7d6062cef74b0588';
|
||||
|
||||
abstract class _$ProxyInputConsumer extends $Notifier<void> {
|
||||
void build();
|
||||
|
||||
@@ -81,7 +81,7 @@ final class SingboxProxyEndpointSyncProvider
|
||||
}
|
||||
|
||||
String _$singboxProxyEndpointSyncHash() =>
|
||||
r'2d6b0641db33638b0b339b510dd63cdddab7f7cf';
|
||||
r'8aeb4097d02c2f6ea37fdb2de26b399d2e6042c2';
|
||||
|
||||
/// Mirrors the sing-box runtime's active SOCKS endpoints into Gecko's
|
||||
/// container-proxy registry. Listens to [singboxProxyRuntimeRepositoryProvider]
|
||||
|
||||
+16
-10
@@ -37,7 +37,18 @@ Future<bool> ensureProxyStartedForContainer(
|
||||
WidgetRef ref,
|
||||
ContainerData container,
|
||||
) async {
|
||||
final proxyConnectionId = container.metadata.proxyConnectionId;
|
||||
return ensureProxyStartedForConnection(
|
||||
context,
|
||||
ref,
|
||||
container.metadata.proxyConnectionId,
|
||||
);
|
||||
}
|
||||
|
||||
Future<bool> ensureProxyStartedForConnection(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
ProxyConnectionId? proxyConnectionId,
|
||||
) async {
|
||||
if (proxyConnectionId == null) return true;
|
||||
|
||||
if (proxyConnectionId is TorProxyConnectionId) {
|
||||
@@ -45,7 +56,7 @@ Future<bool> ensureProxyStartedForContainer(
|
||||
}
|
||||
|
||||
if (proxyConnectionId is SingboxProxyConnectionId) {
|
||||
return await _maybeStartSingboxProxyForContainer(context, ref, container);
|
||||
return await _maybeStartSingboxProxy(context, ref, proxyConnectionId);
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -71,16 +82,11 @@ Future<bool> _ensureTorStarted(BuildContext context, WidgetRef ref) async {
|
||||
return false;
|
||||
}
|
||||
|
||||
Future<bool> _maybeStartSingboxProxyForContainer(
|
||||
Future<bool> _maybeStartSingboxProxy(
|
||||
BuildContext context,
|
||||
WidgetRef ref,
|
||||
ContainerData container,
|
||||
SingboxProxyConnectionId proxyConnectionId,
|
||||
) async {
|
||||
final proxyConnectionId = container.metadata.proxyConnectionId;
|
||||
if (proxyConnectionId == null) return true;
|
||||
|
||||
if (proxyConnectionId is! SingboxProxyConnectionId) return true;
|
||||
|
||||
// Await any start/stop in flight so we don't prompt the user a second time
|
||||
// while a start they already triggered is still resolving. If the runtime
|
||||
// provider is already in AsyncError, keep treating that as "not running" so
|
||||
@@ -116,7 +122,7 @@ Future<bool> _maybeStartSingboxProxyForContainer(
|
||||
icon: const Icon(Icons.route_outlined),
|
||||
title: const Text('Start Proxy Connection?'),
|
||||
content: Text(
|
||||
'This container uses $proxyTitle, but that connection is not running. Start it now?',
|
||||
'This tab needs $proxyTitle, but that connection is not running. Start it now?',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
|
||||
Reference in New Issue
Block a user