mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-24 06:48:14 +00:00
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 阶段。
75 lines
2.6 KiB
Swift
75 lines
2.6 KiB
Swift
import Foundation
|
|
|
|
/// 写入侧窄 seam(issue #48):设置工作流只依赖已提交快照、当前 runtime 的
|
|
/// typed listener facts 与提交入口。生产实现是 `ProxyRuntimeController`
|
|
/// 的薄扩展;测试注入 fake。Domain 快照类型只出现在本缝与 adapter。读取侧是
|
|
/// 运行时控制器的主 actor 状态,本缝随之主 actor 绑定。
|
|
@MainActor
|
|
protocol SettingsCommitting: AnyObject {
|
|
var committedSettings: ProxySettings { get }
|
|
var runtimeListenFacts: RuntimeListenFacts? { get }
|
|
var runtimeListenerProcessID: Int32? { get }
|
|
func updateSettings(_ proposed: ProxySettings) async throws
|
|
func updateListenerMode(_ mode: ListenerMode) async throws
|
|
}
|
|
|
|
extension ProxyRuntimeController: SettingsCommitting {
|
|
var committedSettings: ProxySettings { settings }
|
|
var runtimeListenFacts: RuntimeListenFacts? { effectiveRuntimeListenFacts }
|
|
var runtimeListenerProcessID: Int32? { effectiveRuntimeListenerProcessID }
|
|
|
|
func updateListenerMode(_ mode: ListenerMode) async throws {
|
|
var proposed = settings
|
|
proposed.listen.listenerMode = mode
|
|
try await updateSettings(proposed)
|
|
}
|
|
}
|
|
|
|
/// Settings field adapters keep port IDs, endpoints, and validation facts aligned.
|
|
enum SettingsPortAdapter {
|
|
/// UI 形状端口标识 → 端点类型(module 内部复用 Domain 端口语义)。
|
|
static func endpoint(for id: SettingsPortID) -> ProxyEndpointKind {
|
|
switch id {
|
|
case .socks: .socks
|
|
case .http: .http
|
|
}
|
|
}
|
|
|
|
/// Domain 点名校验错误 → 按字段归位的问题;点名文案沿用既有错误属性。
|
|
/// 端口互异涉及两个端点,两侧端口各归位一条,用户只改有错的那个输入。
|
|
static func fieldIssues(from errors: [ProxySettingsValidationError]) -> [SettingsFieldIssue] {
|
|
errors.flatMap { error -> [SettingsFieldIssue] in
|
|
switch error {
|
|
case .portOutOfRange(let endpoint, _):
|
|
return [.port(portID(for: endpoint), error: error)]
|
|
case .duplicatePort(let endpoint, let otherEndpoint, _):
|
|
return [
|
|
.port(portID(for: endpoint), error: error),
|
|
.port(portID(for: otherEndpoint), error: error),
|
|
]
|
|
}
|
|
}
|
|
}
|
|
|
|
private static func portID(for endpoint: ProxyEndpointKind) -> SettingsPortID {
|
|
switch endpoint {
|
|
case .socks: .socks
|
|
case .http: .http
|
|
}
|
|
}
|
|
}
|
|
|
|
extension SettingsPortOccupancy {
|
|
/// 探测层判定 → UI 形状事实。
|
|
init(_ occupancy: PortOccupancy) {
|
|
switch occupancy {
|
|
case .free:
|
|
self = .free
|
|
case .occupied(let facts):
|
|
self = .occupied(occupier: facts.occupier)
|
|
case .unknown(let detail):
|
|
self = .unknown(detail: detail)
|
|
}
|
|
}
|
|
}
|