mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-09 03:44:51 +00:00
Separate Agent supervision from sslocal input and preserve the latest intent after deployment failure. Persist failure barriers, serialize publication and retirement, and verify reload and single-instance behavior with real processes. Refs #83
33 lines
1.2 KiB
Swift
33 lines
1.2 KiB
Swift
import Foundation
|
|
|
|
extension ProxyRuntimeController {
|
|
/// The choice persists with the settings snapshot. 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, ruleDefaultAction: settings.ruleDefaultAction)
|
|
}
|
|
|
|
/// 规则模式子选项:切换「未匹配时代理/直连」并重部署 ACL。
|
|
/// 失败保留最新模式与子选项,发布后失败停止服务并暂停系统代理。
|
|
func setRuleDefaultAction(_ action: RuleDefaultAction) async {
|
|
guard action != settings.ruleDefaultAction else { return }
|
|
await transitionMode(proxyMode, ruleDefaultAction: action)
|
|
}
|
|
|
|
private func transitionMode(
|
|
_ mode: ProxyMode,
|
|
ruleDefaultAction: RuleDefaultAction
|
|
) async {
|
|
var next = settings
|
|
next.preferredMode = mode.kind
|
|
next.ruleDefaultAction = ruleDefaultAction
|
|
guard persistSettings(next) else { return }
|
|
settings = next
|
|
proxyMode = mode
|
|
modeChangeGeneration += 1
|
|
await convergeRuntime(.modeTransition)
|
|
}
|
|
}
|