Files
Qiu Yuzhou 32709333f5 refactor(rules): require explicit preset selection
Remove lossy default-action writes that can replace china-proxy
with gfwlist. Preserve legacy preference reads and derive the
default action from the selected preset.

Update tests to use explicit presets and verify identity,
legacy compatibility, and no-op reselection.
2026-10-25 14:32:12 +08:00

31 lines
1.1 KiB
Swift

import Foundation
extension ProxyRuntimeController {
/// The choice persists in UserDefaults independently of listening configuration. ACL-backed modes (direct
/// and global) also deploy and verify the ACL runtime even when system proxy
/// is off, because manually connected SOCKS and HTTP clients use the same ACL.
func setProxyMode(_ mode: ProxyMode) async {
guard mode != proxyMode else { return }
await transitionMode(mode, preset: settings.rulePreset)
}
/// 切换规则预设;失败保留最新意图,发布后失败停止服务并暂停系统代理。
func setRulePreset(_ preset: RulePreset) async {
guard preset != settings.rulePreset else { return }
await transitionMode(proxyMode, preset: preset)
}
private func transitionMode(
_ mode: ProxyMode,
preset: RulePreset
) async {
controlPreferences.preferredMode = mode.kind
controlPreferences.rulePreset = preset
settings.preferredMode = mode.kind
settings.rulePreset = preset
proxyMode = mode
modeChangeGeneration += 1
await convergeRuntime(.modeTransition)
}
}