mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-11-24 23:03:46 +00:00
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
110 lines
3.0 KiB
Swift
110 lines
3.0 KiB
Swift
import Foundation
|
|
|
|
/// Persisted identity of a proxy mode. PAC is gone (issue #67): the product
|
|
/// exposes rule / global / direct only.
|
|
enum ProxyModeKind: String, Codable, CaseIterable, Equatable, Hashable, Sendable {
|
|
case rule
|
|
case global
|
|
case direct
|
|
}
|
|
|
|
/// The mutually exclusive ways in which 2.0 exposes the local proxy to macOS.
|
|
/// Hashable 供菜单栏模式选择的勾选态 Picker 使用(issue #31)。
|
|
/// 规则模式(issue #63)另持久化 `RuleDefaultAction` 子选项。
|
|
enum ProxyMode: Codable, Equatable, Hashable, Sendable {
|
|
case rule
|
|
case global
|
|
case direct
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
case kind
|
|
}
|
|
|
|
private enum Kind: String, Codable {
|
|
case rule
|
|
case global
|
|
case direct
|
|
}
|
|
|
|
init(from decoder: Decoder) throws {
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
switch try container.decode(Kind.self, forKey: .kind) {
|
|
case .rule:
|
|
self = .rule
|
|
case .global:
|
|
self = .global
|
|
case .direct:
|
|
self = .direct
|
|
}
|
|
}
|
|
|
|
func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
switch self {
|
|
case .rule:
|
|
try container.encode(Kind.rule, forKey: .kind)
|
|
case .global:
|
|
try container.encode(Kind.global, forKey: .kind)
|
|
case .direct:
|
|
try container.encode(Kind.direct, forKey: .kind)
|
|
}
|
|
}
|
|
|
|
var label: String {
|
|
switch self {
|
|
case .rule:
|
|
"规则"
|
|
case .global:
|
|
"全局"
|
|
case .direct:
|
|
"直连"
|
|
}
|
|
}
|
|
|
|
var kind: ProxyModeKind {
|
|
switch self {
|
|
case .rule: .rule
|
|
case .global: .global
|
|
case .direct: .direct
|
|
}
|
|
}
|
|
|
|
/// Returns every mode supported by the product in stable selector order.
|
|
static var availableModes: [ProxyMode] { [.rule, .global, .direct] }
|
|
|
|
/// Derives the only system-proxy state that this mode is allowed to own.
|
|
/// All three modes are projected as a local SOCKS target (issue #59/#67).
|
|
func systemProxyConfiguration(
|
|
for document: SslocalRuntimeDocument,
|
|
exceptions: [String]? = nil
|
|
) throws -> SystemProxyConfiguration {
|
|
guard (1...65535).contains(document.socksPort) else {
|
|
throw ProxyModeError.invalidSOCKSPort(document.socksPort)
|
|
}
|
|
return SystemProxyConfiguration(
|
|
target: .socks(host: "127.0.0.1", port: document.socksPort),
|
|
exceptions: FixedLocalProxyRanges.systemProxyExceptions(including: exceptions))
|
|
}
|
|
}
|
|
|
|
/// The part of the system proxy dictionary that 2.0 intentionally controls.
|
|
struct SystemProxyConfiguration: Equatable, Sendable {
|
|
enum Target: Equatable, Sendable {
|
|
case socks(host: String, port: Int)
|
|
}
|
|
|
|
let target: Target
|
|
/// `nil` preserves the user's original ExceptionsList. A non-nil value is
|
|
/// explicitly owned by the app and is projected on every activation.
|
|
let exceptions: [String]?
|
|
|
|
init(target: Target, exceptions: [String]? = nil) {
|
|
self.target = target
|
|
self.exceptions = exceptions
|
|
}
|
|
}
|
|
|
|
enum ProxyModeError: Error, Equatable, Sendable {
|
|
case invalidSOCKSPort(Int)
|
|
}
|