|
| 1 | +import Foundation |
| 2 | + |
| 3 | +enum GatewayConnectionTone: Equatable { |
| 4 | + case healthy |
| 5 | + case transient |
| 6 | + case attention |
| 7 | +} |
| 8 | + |
| 9 | +struct GatewayConnectionPresentation: Equatable { |
| 10 | + let statusLine: String |
| 11 | + let generalTitle: String |
| 12 | + let generalSubtitle: String |
| 13 | + let symbolName: String |
| 14 | + let tone: GatewayConnectionTone |
| 15 | + let showsConnectionAction: Bool |
| 16 | + let needsAttention: Bool |
| 17 | + |
| 18 | + init(state: ControlChannel.ConnectionState) { |
| 19 | + switch state { |
| 20 | + case .connected: |
| 21 | + self.statusLine = String(localized: "Connected") |
| 22 | + self.generalTitle = String(localized: "OpenClaw active") |
| 23 | + self.generalSubtitle = String(localized: "Connected to your remote Gateway.") |
| 24 | + self.symbolName = "checkmark" |
| 25 | + self.tone = .healthy |
| 26 | + self.showsConnectionAction = false |
| 27 | + self.needsAttention = false |
| 28 | + case .connecting: |
| 29 | + self.statusLine = String(localized: "Connecting…") |
| 30 | + self.generalTitle = String(localized: "OpenClaw connecting") |
| 31 | + self.generalSubtitle = String(localized: "Connecting to your remote Gateway…") |
| 32 | + self.symbolName = "arrow.trianglehead.2.clockwise.rotate.90" |
| 33 | + self.tone = .transient |
| 34 | + self.showsConnectionAction = false |
| 35 | + self.needsAttention = false |
| 36 | + case .disconnected: |
| 37 | + self.statusLine = String(localized: "Disconnected") |
| 38 | + self.generalTitle = String(localized: "OpenClaw needs attention") |
| 39 | + self |
| 40 | + .generalSubtitle = |
| 41 | + String(localized: "Disconnected from your remote Gateway. Open Connection settings to fix it.") |
| 42 | + self.symbolName = "exclamationmark.triangle.fill" |
| 43 | + self.tone = .attention |
| 44 | + self.showsConnectionAction = true |
| 45 | + self.needsAttention = false |
| 46 | + case let .degraded(message): |
| 47 | + let reason = message.trimmingCharacters(in: .whitespacesAndNewlines) |
| 48 | + self.statusLine = reason.isEmpty ? String(localized: "Gateway connection failed.") : reason |
| 49 | + self.generalTitle = String(localized: "OpenClaw needs attention") |
| 50 | + self.generalSubtitle = self.statusLine + " " + String(localized: "Open Connection settings to fix it.") |
| 51 | + self.symbolName = "exclamationmark.triangle.fill" |
| 52 | + self.tone = .attention |
| 53 | + self.showsConnectionAction = true |
| 54 | + self.needsAttention = true |
| 55 | + } |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +struct GeneralStatusPresentation: Equatable { |
| 60 | + let title: String |
| 61 | + let subtitle: String |
| 62 | + let symbolName: String |
| 63 | + let tone: GatewayConnectionTone |
| 64 | + let showsConnectionAction: Bool |
| 65 | + |
| 66 | + static func resolve( |
| 67 | + mode: AppState.ConnectionMode, |
| 68 | + isPaused: Bool, |
| 69 | + controlState: ControlChannel.ConnectionState) -> Self |
| 70 | + { |
| 71 | + if isPaused { |
| 72 | + return Self( |
| 73 | + title: String(localized: "OpenClaw paused"), |
| 74 | + subtitle: String(localized: "Gateway work is paused; incoming messages will wait."), |
| 75 | + symbolName: "pause.fill", |
| 76 | + tone: .transient, |
| 77 | + showsConnectionAction: false) |
| 78 | + } |
| 79 | + |
| 80 | + switch mode { |
| 81 | + case .local: |
| 82 | + return Self( |
| 83 | + title: String(localized: "OpenClaw active"), |
| 84 | + subtitle: String(localized: "Processing messages through the local Gateway on this Mac."), |
| 85 | + symbolName: "checkmark", |
| 86 | + tone: .healthy, |
| 87 | + showsConnectionAction: false) |
| 88 | + case .unconfigured: |
| 89 | + return Self( |
| 90 | + title: String(localized: "OpenClaw active"), |
| 91 | + subtitle: String(localized: "Ready to run after you choose a Gateway connection."), |
| 92 | + symbolName: "checkmark", |
| 93 | + tone: .healthy, |
| 94 | + showsConnectionAction: false) |
| 95 | + case .remote: |
| 96 | + let connection = GatewayConnectionPresentation(state: controlState) |
| 97 | + return Self( |
| 98 | + title: connection.generalTitle, |
| 99 | + subtitle: connection.generalSubtitle, |
| 100 | + symbolName: connection.symbolName, |
| 101 | + tone: connection.tone, |
| 102 | + showsConnectionAction: connection.showsConnectionAction) |
| 103 | + } |
| 104 | + } |
| 105 | +} |
0 commit comments