feat(routing): 存档案后连接态自动重连使新规则生效
Task 9: RoutingProfileNotifier._persist() 保存成功后,若 connectionProvider.phase == on,触发 ConnectionController.reapplyRoutingProfile()(disconnect→connect, 不改选中节点)重连,让服务端按新档案渲染的规则生效;off 态不触发。 新增 l10n 键 routingRulesReconnecting(单源 design/i18n/strings.json → codegen), 「规则已更新,正在重连…」区别于既有 nodeReconnecting(弱网抖动语义)。 reapplyRoutingProfile 内先置 _userDisconnect=true 再 disconnect,避免其触发的 kernel off 事件被 _onKernelStatus 误判「意外掉线」、再抢跑一次 watchdog 自动重连。
This commit is contained in:
@@ -10,11 +10,14 @@
|
||||
// **当前已存的 state**(此时已是乐观更新后的 next)重新 copyWithPrevious 一次,
|
||||
// 会把我们想还原的旧值又覆盖回 next,达不到「回退」效果。故失败时直接整体
|
||||
// `state = AsyncData(previous)`(纯回退,无错误标记)+ rethrow 传递异常。
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../models/routing_profile.dart';
|
||||
import 'account_providers.dart';
|
||||
import 'auth_provider.dart';
|
||||
import 'connection_provider.dart';
|
||||
|
||||
/// 当前账户的分流档案。未登录返回默认档案(不打后端)。
|
||||
class RoutingProfileNotifier extends AsyncNotifier<RoutingProfile> {
|
||||
@@ -81,6 +84,18 @@ class RoutingProfileNotifier extends AsyncNotifier<RoutingProfile> {
|
||||
state = AsyncData(previous);
|
||||
rethrow;
|
||||
}
|
||||
_reconnectIfConnected(); // Task 9:保存成功且已连接 → 重连使新规则生效
|
||||
}
|
||||
|
||||
/// 用 ref.read(非 watch)单向读取 connectionProvider:仅本 notifier 在保存成功后
|
||||
/// 顺带触发一次重连,不建立「connectionProvider 依赖 routingProfileProvider」的反向
|
||||
/// 引用,provider 依赖图仍是单向(routing → connection),不成环。off 态不触发——
|
||||
/// 下次连接本就会按最新档案渲染配置。重连失败由 connection_provider 自身状态承接
|
||||
/// (沿用其既有错误提示),不 rethrow 到这里,不影响「保存」这个操作本身的成败。
|
||||
void _reconnectIfConnected() {
|
||||
if (ref.read(connectionProvider).phase == VpnPhase.on) {
|
||||
unawaited(ref.read(connectionProvider.notifier).reapplyRoutingProfile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user