fix(client): 自动连接竞态 + 版本 1.0.18+19
_maybeAutoConnect 启动瞬间同步读 settingsProvider.autoConnect,但其 _load 异步(SharedPreferences) 还没完成 → 读到默认 false 而永久跳过自动连接。改到「节点就绪」回调里再判 autoConnect(节点走网络 拉取,远慢于本地设置读取,届时设置必已加载到位)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -122,15 +122,16 @@ class _RootFlowState extends ConsumerState<RootFlow> {
|
|||||||
void _maybeAutoConnect() {
|
void _maybeAutoConnect() {
|
||||||
if (_autoConnectArmed) return;
|
if (_autoConnectArmed) return;
|
||||||
_autoConnectArmed = true;
|
_autoConnectArmed = true;
|
||||||
if (!ref.read(settingsProvider).autoConnect) return;
|
// 注意:不在此处早读 settingsProvider.autoConnect —— 其 _load 是异步(SharedPreferences),
|
||||||
if (ref.read(connectionProvider).phase != VpnPhase.off) return;
|
// 启动这一刻多半还没加载完,会读到默认 false 而永久跳过。改到「节点就绪」回调里再判:
|
||||||
// 节点列表异步加载,等出现可用(uuid 非空)节点再连,避免「节点未就绪」直接失败。
|
// 节点要走网络拉取,远慢于本地设置读取,那时 autoConnect 必已加载到位。
|
||||||
late final ProviderSubscription sub;
|
late final ProviderSubscription sub;
|
||||||
sub = ref.listenManual(nodesProvider, (prev, next) {
|
sub = ref.listenManual(nodesProvider, (prev, next) {
|
||||||
final ready = (next.valueOrNull ?? const []).any((n) => n.uuid.isNotEmpty);
|
final ready = (next.valueOrNull ?? const []).any((n) => n.uuid.isNotEmpty);
|
||||||
if (!ready) return;
|
if (!ready) return;
|
||||||
sub.close();
|
sub.close();
|
||||||
if (ref.read(connectionProvider).phase == VpnPhase.off) {
|
if (ref.read(settingsProvider).autoConnect &&
|
||||||
|
ref.read(connectionProvider).phase == VpnPhase.off) {
|
||||||
ref.read(connectionProvider.notifier).toggle();
|
ref.read(connectionProvider.notifier).toggle();
|
||||||
}
|
}
|
||||||
}, fireImmediately: true);
|
}, fireImmediately: true);
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
name: pangolin_vpn
|
name: pangolin_vpn
|
||||||
description: 穿山甲 · Pangolin — 极简、稳定、跨平台网络加速客户端。
|
description: 穿山甲 · Pangolin — 极简、稳定、跨平台网络加速客户端。
|
||||||
publish_to: "none"
|
publish_to: "none"
|
||||||
version: 1.0.17+18
|
version: 1.0.18+19
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ^3.5.0
|
sdk: ^3.5.0
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
; 前置: 先在 client/ 跑 `flutter build windows`(Release),产物在
|
; 前置: 先在 client/ 跑 `flutter build windows`(Release),产物在
|
||||||
; ..\..\build\windows\x64\runner\Release
|
; ..\..\build\windows\x64\runner\Release
|
||||||
#define MyAppName "穿山甲 Pangolin"
|
#define MyAppName "穿山甲 Pangolin"
|
||||||
#define MyAppVersion "1.0.17"
|
#define MyAppVersion "1.0.18"
|
||||||
#define MyAppPublisher "Pangolin"
|
#define MyAppPublisher "Pangolin"
|
||||||
#define MyAppExeName "pangolin_vpn.exe"
|
#define MyAppExeName "pangolin_vpn.exe"
|
||||||
#define BuildDir "..\..\build\windows\x64\runner\Release"
|
#define BuildDir "..\..\build\windows\x64\runner\Release"
|
||||||
|
|||||||
Reference in New Issue
Block a user