Remove legacy Commerce types, unused helpers, duplicate SFTP progress code, and 28 unreferenced strings. Drop fixture-only tests and arbitrary screenshot size assertions while retaining behavioral coverage. Validation: 2,592 macOS tests, 40 focused macOS tests, and 53 iOS tests passed. Swift formatting, AppStrings, and Chinese localization checks passed.
50 lines
1.6 KiB
Swift
50 lines
1.6 KiB
Swift
import Foundation
|
|
import TermindDomain
|
|
import TermindPresentation
|
|
|
|
nonisolated enum SerialPortError: LocalizedError, Sendable {
|
|
case invalidConfiguration(String)
|
|
case system(operation: String, code: Int32)
|
|
case closed
|
|
case openTimedOut
|
|
|
|
var errorDescription: String? {
|
|
switch self {
|
|
case .invalidConfiguration(let message): message
|
|
case .system(let operation, let code):
|
|
"\(operation): \(String(cString: strerror(code)))"
|
|
case .closed: String(localized: AppStrings.Terminal.theSerialPortIsClosed)
|
|
case .openTimedOut: String(localized: AppStrings.Terminal.openingTheSerialPortTimedOut)
|
|
}
|
|
}
|
|
}
|
|
|
|
nonisolated enum SerialPortOpenStage: Sendable {
|
|
case deviceOpened
|
|
case settingsApplied
|
|
case monitoringStarted
|
|
|
|
var message: String {
|
|
switch self {
|
|
case .deviceOpened: String(localized: AppStrings.Terminal.serialDeviceOpened)
|
|
case .settingsApplied: String(localized: AppStrings.Terminal.serialSettingsApplied)
|
|
case .monitoringStarted: String(localized: AppStrings.Terminal.serialInputMonitoringStarted)
|
|
}
|
|
}
|
|
}
|
|
|
|
protocol SerialPortConnection: Sendable {
|
|
func write(_ data: Data) async throws
|
|
func close() async
|
|
}
|
|
|
|
protocol SerialPortServing: Sendable {
|
|
func portUpdates() -> AsyncStream<[SerialPortDescriptor]>
|
|
func open(
|
|
_ configuration: SerialConnectionConfiguration,
|
|
receive: @escaping @Sendable (Data) -> Void,
|
|
disconnected: @escaping @Sendable (String) -> Void,
|
|
progress: @escaping @Sendable (SerialPortOpenStage) -> Void
|
|
) async throws -> any SerialPortConnection
|
|
}
|