From f39e32ecd714e8ba718b41d3eded1b7704c46d7c Mon Sep 17 00:00:00 2001 From: Qiu Yuzhou Date: Sat, 3 Oct 2026 19:53:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor(ui):=20=E7=B3=BB=E7=BB=9F=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E5=A4=B1=E8=B4=A5=E6=96=87=E6=A1=88=E6=98=A0=E5=B0=84?= =?UTF-8?q?=E4=B8=89=E4=BB=BD=E6=94=B6=E6=88=90=E4=B8=80=E4=BB=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../App/ErrorPresentation+Runtime.swift | 4 +++- ShadowsocksX-NG2/App/ErrorPresentation.swift | 20 +--------------- ShadowsocksX-NG2/App/ProxyRuntimeFacts.swift | 21 +++++++++++++++++ .../App/SystemProxyObserver.swift | 23 +------------------ 4 files changed, 26 insertions(+), 42 deletions(-) diff --git a/ShadowsocksX-NG2/App/ErrorPresentation+Runtime.swift b/ShadowsocksX-NG2/App/ErrorPresentation+Runtime.swift index 13beb5eb..1ef91fc8 100644 --- a/ShadowsocksX-NG2/App/ErrorPresentation+Runtime.swift +++ b/ShadowsocksX-NG2/App/ErrorPresentation+Runtime.swift @@ -58,8 +58,10 @@ extension AppPresentation { } } + // 系统代理操作失败的唯一文案映射(ErrorPresentation 的 SystemProxyError + // 分支经 SystemProxyOperationFailure(error) 桥接到这里)。 // swiftlint:disable:next cyclomatic_complexity - private static func systemProxy(_ failure: SystemProxyOperationFailure) -> String { + static func systemProxy(_ failure: SystemProxyOperationFailure) -> String { switch failure { case .preferencesUnavailable: return "系统网络配置不可用" case .preferencesBusy: return "系统网络配置正被其他设置操作占用" diff --git a/ShadowsocksX-NG2/App/ErrorPresentation.swift b/ShadowsocksX-NG2/App/ErrorPresentation.swift index cf717a1a..d7317fa8 100644 --- a/ShadowsocksX-NG2/App/ErrorPresentation.swift +++ b/ShadowsocksX-NG2/App/ErrorPresentation.swift @@ -60,7 +60,7 @@ extension AppPresentation { case let error as LegacyImportError: return legacyImport(error) case let error as SystemProxyError: - return systemProxy(error) + return systemProxy(SystemProxyOperationFailure(error)) case let error as TextClipboardFailure: return textClipboard(error) case let error as DiagnosticReportFailure: @@ -305,24 +305,6 @@ extension AppPresentation { } } - // swiftlint:disable:next cyclomatic_complexity - private static func systemProxy(_ error: SystemProxyError) -> String { - switch error { - 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 textClipboard(_ error: TextClipboardFailure) -> String { switch error { case .writeFailed: return "剪贴板写入失败,请重试" diff --git a/ShadowsocksX-NG2/App/ProxyRuntimeFacts.swift b/ShadowsocksX-NG2/App/ProxyRuntimeFacts.swift index 039c9910..0ecc7d2f 100644 --- a/ShadowsocksX-NG2/App/ProxyRuntimeFacts.swift +++ b/ShadowsocksX-NG2/App/ProxyRuntimeFacts.swift @@ -111,6 +111,27 @@ enum SystemProxyOperationFailure: Equatable, Sendable { case helperUnavailable } +extension SystemProxyOperationFailure { + /// `SystemProxyError` 的呈现类别投影:稳定事实只保留操作类别;Domain 错误 + /// 的关联值(排查细节)不出现在运行时事实里。 + init(_ error: SystemProxyError) { + switch error { + case .preferencesUnavailable: self = .preferencesUnavailable + case .preferencesBusy: self = .preferencesBusy + case .noCurrentNetworkSet: self = .noCurrentNetworkSet + case .noNetworkLocations: self = .noNetworkLocations + case .noProxyServices: self = .noProxyServices + case .unreadableService: self = .unreadableService + case .invalidStoredConfiguration: self = .invalidStoredConfiguration + case .cannotWriteService: self = .cannotWriteService + case .commitFailed: self = .commitFailed + case .applyFailed: self = .applyFailed + case .invalidRequest: self = .invalidRequest + case .helperUnavailable: self = .helperUnavailable + } + } +} + enum SystemProxyFailureFacts: Equatable, Sendable { case operation(SystemProxyOperationFailure) case mode(ProxyModeError) diff --git a/ShadowsocksX-NG2/App/SystemProxyObserver.swift b/ShadowsocksX-NG2/App/SystemProxyObserver.swift index 7caa191a..adb61662 100644 --- a/ShadowsocksX-NG2/App/SystemProxyObserver.swift +++ b/ShadowsocksX-NG2/App/SystemProxyObserver.swift @@ -472,32 +472,11 @@ extension SystemProxyObserver { extension SystemProxyObserver { private func systemProxyFacts(for error: Error) -> SystemProxyFailureFacts { if let error = error as? SystemProxyError { - return Self.systemProxyFacts(for: error) + return .operation(SystemProxyOperationFailure(error)) } if let error = error as? ProxyModeError { return .mode(error) } return .unknown } - - // 显式映射保持与错误族一一对应;错误带关联值,无法用字典键穷举。 - // swiftlint:disable:next cyclomatic_complexity - private static func systemProxyFacts( - for error: SystemProxyError - ) -> SystemProxyFailureFacts { - switch error { - case .preferencesUnavailable: return .operation(.preferencesUnavailable) - case .preferencesBusy: return .operation(.preferencesBusy) - case .noCurrentNetworkSet: return .operation(.noCurrentNetworkSet) - case .noProxyServices: return .operation(.noProxyServices) - case .unreadableService: return .operation(.unreadableService) - case .invalidStoredConfiguration: return .operation(.invalidStoredConfiguration) - case .cannotWriteService: return .operation(.cannotWriteService) - case .commitFailed: return .operation(.commitFailed) - case .applyFailed: return .operation(.applyFailed) - case .noNetworkLocations: return .operation(.noNetworkLocations) - case .invalidRequest: return .operation(.invalidRequest) - case .helperUnavailable: return .operation(.helperUnavailable) - } - } }