Files
ShadowsocksX-NG/ShadowsocksX-NG2/App/Presentation/ErrorPresentation+Runtime.swift
T
Qiu Yuzhou fb428f12bc refactor(app): 按分层重组 App/ 源码目录
App/ 根目录原有 73 个散落源文件,已无法从目录读出任何分组信息。

按「目录即分层」重组为 Composition / Application / Presentation / UI /
PlatformEffects / Resources 六个目录,UI 层再按子视图分目录(Workspace、
Home、Servers(含 Plugin)、Subscriptions、Rules、Settings、Diagnostics、
StatusMenu)。纯移动:类型名、模块名与 import 均未改动,App/ 根层不再有
散落文件。

配套改动:

- project.yml:Core 测试镜像的 excludes 由裸文件名改为 `**/` 递归形式。
  XcodeGen 的 exclude 不跨 `/`,裸名只匹配 App 根层;MainApp.swift 下移后
  旧写法会静默失效,把 @main 组合根编进测试镜像。info.path 与
  entitlements.path 指向 App/Resources/;并排除 `**/*.md`——App/ 下任何
  非源码文件都会被 XcodeGen 收进 Resources 阶段并封进签名后的 bundle。
- SkeletonTests 的架构守卫由「默认扫描全部 App/ + 7 个豁免文件 + 1 个豁免
  前缀 + 4 个豁免目录」改为正面圈定 App/UI/,豁免登记全部删除;新增运行时
  适配器放进 Application/ 即自动落在扫描范围外,无需再登记。
- README 工程结构说明同步;根 .gitignore 的生成物路径随 Resources/ 归位。

验证:clean build 0 error;task test 1022 用例全通过(含两个架构守卫);
task format 无改动(证明纯移动);task lint 与移动前同为 21 条内容型
warning;packaging-gate.sh ALL CHECKS PASSED,确认 plist/entitlements 归位
后签名与 entitlements 语义不变。

注意:迁移时须先删旧的生成物再 xcodegen generate,否则遗留的 App/Info.plist
会被当作普通资源扫进 Resources 阶段。
2026-10-05 19:56:18 +08:00

96 lines
4.4 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
// MARK: - 运行时失败事实的呈现(RuntimeFailureFacts / 系统代理应用态)
extension AppPresentation {
/// 系统代理暂停的统一文案:状态菜单、运行控制卡与错误呈现边三面共用。
static let systemProxyPausedNotice = "后台代理不可用,已清除系统代理配置。恢复后将自动应用。"
/// 系统代理配置不可读的统一前缀:状态菜单与运行控制卡差异区共用。
static let systemProxyUnreadablePrefix = "无法读取网络接口的代理配置:"
static func message(for failure: RuntimeFailureFacts) -> String {
switch failure {
case .firewallBlocked(let facts):
return
"macOS 防火墙已阻止 \(facts.executableName) 接受传入连接。请在系统设置中允许传入连接。"
case .launch(let facts): return launchFailure(facts)
case .service(let facts): return serviceFailure(facts)
case .activation(let error): return activation(error)
case .requiresApproval: return "请在系统设置的登录项中允许代理后台服务"
case .systemProxy(let facts): return systemProxyFailure(facts)
}
}
static func message(for application: SystemProxyApplicationFacts) -> String {
switch application {
case .idle: return "系统代理未应用"
case .pending: return "系统代理待应用:等待代理就绪或可用出口"
case .applied: return "系统代理已应用"
case .failed(let facts), .repairFailed(let facts), .clearFailed(let facts),
.unreadable(let facts):
return systemProxyFailure(facts)
case .changed: return "系统代理配置已改变"
case .applying: return "系统代理应用中"
case .repairing: return "系统代理修复中"
case .paused: return systemProxyPausedNotice
}
}
private static func launchFailure(_ facts: LaunchFailureFacts) -> String {
switch facts {
case .missingRuntimeDocument: return "缺少运行时文档"
case .localEndpoint(let endpoint, let host, let port, let cause):
return "本地代理 \(endpoint.uppercased()) 端点 \(host):\(port) 未就绪(\(endpointFailure(cause)))"
case .unreadableSettings: return "本地代理配置无法读取,已停止代理以避免静默改用出厂端口"
}
}
private static func serviceFailure(_ facts: ServiceFailureFacts) -> String {
switch facts {
case .runtimeFile: return "运行时文件读写失败"
case .agent: return "代理后台服务管理失败"
case .missingDocument: return "缺少运行时文档"
case .persistence: return "代理运行状态保存失败"
case .unknown: return unknownError
}
}
private static func systemProxyFailure(_ facts: SystemProxyFailureFacts) -> String {
switch facts {
case .operation(let failure): return systemProxy(failure)
case .mode(let error): return proxyMode(error)
case .unknown: return "系统代理未能应用"
}
}
// 系统代理操作失败的唯一文案映射(ErrorPresentation 的 SystemProxyError
// 分支经 SystemProxyOperationFailure(error) 桥接到这里)。
// swiftlint:disable:next cyclomatic_complexity
static func systemProxy(_ failure: SystemProxyOperationFailure) -> String {
switch failure {
case .preferencesUnavailable: return "系统网络配置不可用"
case .preferencesBusy: return "系统网络配置正被其他设置操作占用"
case .noCurrentNetworkSet: return "没有当前网络位置"
case .noNetworkLocations: return "没有可检查的网络位置"
case .noProxyServices: return "当前网络位置没有可写入的网络服务"
case .unreadableService: return "无法读取网络服务的代理配置"
case .invalidStoredConfiguration: return "保存的系统代理配置无效"
case .cannotWriteService: return "无法写入网络服务的代理配置"
case .commitFailed: return "系统代理提交失败"
case .applyFailed: return "系统代理应用失败"
case .invalidRequest: return "系统代理助手收到了无效请求"
case .helperUnavailable: return "系统代理助手不可用;请确认已在登录项中允许"
}
}
private static func endpointFailure(_ outcome: RuntimeEndpointFailure) -> String {
switch outcome {
case .refused: return "连接被拒绝"
case .timedOut: return "连接超时"
case .invalidResponse: return "响应无效"
case .unknown: return "状态无法确定"
}
}
}