mirror of
https://github.com/shadowsocks/ShadowsocksX-NG.git
synced 2026-10-28 05:03:49 +00:00
refactor(ui): 系统代理失败文案映射三份收成一份
This commit is contained in:
@@ -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 "系统网络配置正被其他设置操作占用"
|
||||
|
||||
@@ -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 "剪贴板写入失败,请重试"
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user