emitProxyState method
供 HelperHttpClient 调用,取代直接访问 controller。
连接成功(started)时顺带后台刷新代理模式——clash mode 的数据来源与推送 都内聚在本类,HelperHttpClient 只管 helper service 控制与状态转发。
Implementation
void emitProxyState(ProxyState state) {
_lastProxyState = state;
_controller.add(state);
if (state == ProxyState.started) {
unawaited(_refreshClashMode());
_startGroupRefresh();
_startLogSubscribe();
// 系统代理模式:sing-box 已起,设系统代理
if (CsSettingsStorage().proxyMode == ProxyMode.systemProxy) {
unawaited(SystemProxyService().enable());
}
} else if (state == ProxyState.stopped) {
_cancelGroupRefresh();
_cancelLogSubscribe();
// 只要标志位说系统代理还开着就清(覆盖断开/切换重启/崩溃后停止)
if (CsSettingsStorage().systemProxyActive) {
unawaited(SystemProxyService().disable());
}
}
}