Files
ShadowsocksX-NG/ShadowsocksX-NG2/App/StatusMenuModel.swift
T
Qiu Yuzhou a8cd6262c2 feat(proxy): remove PAC and accept ACL system proxy path
Remove the PAC product feature entirely: PAC HTTP service, port, health
probe, runtime extension, PAC URL system proxy projection, PAC rule
editing, and GFWList URL settings. The product now exposes rule / global /
direct modes only, all projected as a local SOCKS system-proxy target.

First-run defaults are rule + proxyWhenUnmatched, agent on, system proxy
off. Homepage and status menu share one ProxyControlSnapshot showing the
three modes and rule sub-options. Manual servers, subscriptions, Legacy
import, and independent SOCKS/HTTP inbounds are retained.

Fix: include verbose in SslocalListenFingerprint so a verbose-only
contract change restarts sslocal instead of leaving RUST_LOG stale.

Revise CONTEXT.md vocabulary, ADR-0007, and ADR-0009. Record GFWList
exception shadowing, IPv6 system-exception, DNS, and traffic-coverage
boundaries. Add host acceptance evidence document.

Closes #67
2026-09-26 21:58:12 +08:00

95 lines
3.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import Foundation
/// 状态菜单的呈现模型(spec #21 D11,issue #31/#47/#60):从代理控制工作流
/// 的整体 snapshot 派生菜单数据。agent 与系统代理是两个独立状态面;不持有
/// AppKit 类型,纯逻辑可测;视觉与交互细节(勾选标记、禁用态)在
/// ProxyStatusMenu 呈现,不建自动测试。
enum StatusMenuModel {
/// 头部状态摘要:agent 运行状态、当前模式、活动目标(含点名失败细节)与
/// 系统代理实际应用状态。
struct Summary: Equatable {
/// Agent 开关意图(开关勾选态的绑定来源)。
let agentIntentEnabled: Bool
/// Agent 运行状态的「在跑」投影。
let isOn: Bool
/// Agent 运行状态文本。
let status: String
/// Agent 侧点名原因:运行失败或激活拒绝/目标清除(独立于运行状态)。
let detail: String?
/// 系统代理开关意图(开关勾选态的绑定来源)。
let systemProxyIntentEnabled: Bool
/// 系统代理实际应用状态文本(与 agent 运行状态分开呈现)。
let systemProxyStatus: String
/// 同上但不带「系统代理:」前缀(首页等已有上下文的呈现面用)。
let systemProxyStateLabel: String
/// 系统代理写入/恢复失败的点名原因;非失败态为 nil。
let systemProxyDetail: String?
let modeLabel: String
/// 活动目标从根到节点的显示名路径;未激活为 nil。
let targetPath: String?
}
/// 运行状态 → 摘要映射(与主窗口诊断区口径一致):输入是代理控制工作流
/// 的整体 snapshot(issue #47/#60),菜单不再拆装控制器或运行时字段。
static func summary(from snapshot: ProxyControlSnapshot) -> Summary {
let agentDetail =
snapshot.runtime.failure.map { AppPresentation.message(for: $0) }
?? snapshot.activationFailure.map { AppPresentation.message(for: $0) }
let systemProxy = systemProxyPresentation(for: snapshot.systemProxyApplication)
return Summary(
agentIntentEnabled: snapshot.agentIntentEnabled,
isOn: snapshot.runtime.isOn,
status: statusText(for: snapshot.runtime.status),
detail: agentDetail,
systemProxyIntentEnabled: snapshot.systemProxyIntentEnabled,
systemProxyStatus: "系统代理:\(systemProxy.label)",
systemProxyStateLabel: systemProxy.label,
systemProxyDetail: systemProxy.detail,
modeLabel: modeLabel(for: snapshot),
targetPath: snapshot.activeTarget?.pathSummary)
}
/// 模式标签与首页徽标同口径(issue #67 AC2):规则模式带上子选项。
private static func modeLabel(for snapshot: ProxyControlSnapshot) -> String {
let mode = snapshot.proxyMode
if mode == .rule {
return "\(mode.label) · \(snapshot.ruleDefaultAction.label)"
}
return mode.label
}
private static func statusText(for status: ProxyRuntimeStatus) -> String {
switch status {
case .off:
return "代理未运行"
case .starting:
return "正在启动代理…"
case .running:
return "代理运行中"
case .firewallBlocked:
return "代理运行中(局域网受阻)"
case .launchFailed:
return "启动失败"
case .requiresApproval:
return "等待允许后台代理"
case .serviceFailed:
return "服务管理失败"
}
}
private static func systemProxyPresentation(
for application: SystemProxyApplicationFacts
) -> (label: String, detail: String?) {
switch application {
case .idle:
return ("未接管", nil)
case .pending:
return ("待应用", nil)
case .applied:
return ("已应用", nil)
case .failed(let facts):
return ("应用失败", AppPresentation.message(for: RuntimeFailureFacts.systemProxy(facts)))
}
}
}