-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Show iOS terminal loading diagnostics #7198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5e8564a
Show iOS terminal loading diagnostics
lawrencecchen 8ed1357
Merge remote-tracking branch 'origin/main' into task-show-terminal-lo…
lawrencecchen 6c1f845
Address loading diagnostics review feedback
lawrencecchen 337c98e
Scope terminal loading network diagnostics
lawrencecchen 11a5c7f
Clarify empty terminal loading state
lawrencecchen 2858674
Add terminal loading retry state
lawrencecchen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
...ges/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/TerminalLoadingDiagnosticsModel.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #if os(iOS) | ||
| import CMUXMobileCore | ||
| import CmuxMobileShellModel | ||
|
|
||
| struct TerminalLoadingDiagnosticsModel: Equatable { | ||
| let title: String | ||
| let message: String | ||
| let rows: [TerminalLoadingDiagnosticsRow] | ||
| let isLoading: Bool | ||
|
|
||
| init( | ||
| workspaceName: String, | ||
| terminalCount: Int, | ||
| macName: String?, | ||
| connectionStatus: MobileMacConnectionStatus, | ||
| tailnetStatus: TailnetStatus?, | ||
| activeRoute: CmxAttachRoute?, | ||
| storedRouteDescription: String?, | ||
| connectionError: String?, | ||
| connectionErrorGuidance: String?, | ||
| loadingTimedOut: Bool = false | ||
| ) { | ||
| self = TerminalLoadingDiagnosticsModelBuilder( | ||
| workspaceName: workspaceName, | ||
| terminalCount: terminalCount, | ||
| macName: macName, | ||
| connectionStatus: connectionStatus, | ||
| tailnetStatus: tailnetStatus, | ||
| activeRoute: activeRoute, | ||
| storedRouteDescription: storedRouteDescription, | ||
| connectionError: connectionError, | ||
| connectionErrorGuidance: connectionErrorGuidance, | ||
| loadingTimedOut: loadingTimedOut | ||
| ).makeModel() | ||
| } | ||
|
|
||
| init(title: String, message: String, rows: [TerminalLoadingDiagnosticsRow], isLoading: Bool) { | ||
| self.title = title | ||
| self.message = message | ||
| self.rows = rows | ||
| self.isLoading = isLoading | ||
| } | ||
| } | ||
| #endif | ||
198 changes: 198 additions & 0 deletions
198
.../CmuxMobileShellUI/Sources/CmuxMobileShellUI/TerminalLoadingDiagnosticsModelBuilder.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| #if os(iOS) | ||
| import CMUXMobileCore | ||
| import CmuxMobileShellModel | ||
| import CmuxMobileSupport | ||
| import Foundation | ||
|
|
||
| struct TerminalLoadingDiagnosticsModelBuilder { | ||
| let workspaceName: String | ||
| let terminalCount: Int | ||
| let macName: String? | ||
| let connectionStatus: MobileMacConnectionStatus | ||
| let tailnetStatus: TailnetStatus? | ||
| let activeRoute: CmxAttachRoute? | ||
| let storedRouteDescription: String? | ||
| let connectionError: String? | ||
| let connectionErrorGuidance: String? | ||
| let loadingTimedOut: Bool | ||
|
|
||
| func makeModel() -> TerminalLoadingDiagnosticsModel { | ||
| let resolvedMacName = nonEmpty(macName) ?? nonEmpty(workspaceName) ?? L10n.string( | ||
| "mobile.terminal.loading.macFallback", | ||
| defaultValue: "Mac" | ||
| ) | ||
| var rows: [TerminalLoadingDiagnosticsRow] = [ | ||
| TerminalLoadingDiagnosticsRow( | ||
| id: "mac", | ||
| label: L10n.string("mobile.terminal.loading.mac", defaultValue: "Mac"), | ||
| value: String.localizedStringWithFormat( | ||
| L10n.string( | ||
| "mobile.terminal.loading.macStatusFormat", | ||
| defaultValue: "%@ · %@" | ||
| ), | ||
| resolvedMacName, | ||
| connectionStatus.label | ||
| ), | ||
| tone: tone(for: connectionStatus) | ||
| ), | ||
| TerminalLoadingDiagnosticsRow( | ||
| id: "terminals", | ||
| label: L10n.string("mobile.terminal.loading.terminals", defaultValue: "Terminals"), | ||
| value: terminalStatusText(count: terminalCount), | ||
| tone: terminalCount > 0 ? .good : .pending | ||
| ), | ||
| TerminalLoadingDiagnosticsRow( | ||
| id: "tailscale", | ||
| label: L10n.string("mobile.terminal.loading.tailscale", defaultValue: "Tailscale"), | ||
| value: tailnetStatusText(tailnetStatus), | ||
| tone: tone(for: tailnetStatus) | ||
| ), | ||
| TerminalLoadingDiagnosticsRow( | ||
| id: "route", | ||
| label: L10n.string("mobile.terminal.loading.route", defaultValue: "Route"), | ||
| value: routeText( | ||
| activeRoute: activeRoute, | ||
| storedRouteDescription: storedRouteDescription | ||
| ), | ||
| tone: activeRoute == nil && nonEmpty(storedRouteDescription) == nil ? .warning : .neutral | ||
| ), | ||
| ] | ||
|
|
||
| if let detail = nonEmpty(connectionErrorGuidance) ?? nonEmpty(connectionError) { | ||
| rows.append(TerminalLoadingDiagnosticsRow( | ||
| id: "network", | ||
| label: L10n.string("mobile.terminal.loading.network", defaultValue: "Network"), | ||
| value: detail, | ||
| tone: .warning | ||
| )) | ||
| } | ||
|
|
||
| let text = headerText(resolvedMacName: resolvedMacName) | ||
| return TerminalLoadingDiagnosticsModel( | ||
| title: text.title, | ||
| message: text.message, | ||
| rows: rows, | ||
| isLoading: connectionStatus == .connected && !loadingTimedOut | ||
| ) | ||
| } | ||
|
|
||
| private func nonEmpty(_ value: String?) -> String? { | ||
| let trimmed = value?.trimmingCharacters(in: .whitespacesAndNewlines) | ||
| return trimmed?.isEmpty == false ? trimmed : nil | ||
| } | ||
|
|
||
| private func terminalStatusText(count: Int) -> String { | ||
| guard count > 0 else { | ||
| return L10n.string("mobile.terminal.loading.terminalsWaiting", defaultValue: "No terminal list yet") | ||
| } | ||
| return L10n.terminalCount(count) | ||
| } | ||
|
|
||
| private func headerText(resolvedMacName: String) -> (title: String, message: String) { | ||
| if connectionStatus == .connected && terminalCount == 0 && loadingTimedOut { | ||
| return ( | ||
| L10n.string("mobile.terminal.loading.emptyTitle", defaultValue: "No terminals yet"), | ||
| String.localizedStringWithFormat( | ||
| L10n.string( | ||
| "mobile.terminal.loading.emptyMessageFormat", | ||
| defaultValue: "%@ is connected. Create a terminal, or tap Refresh to check again." | ||
| ), | ||
| resolvedMacName | ||
| ) | ||
| ) | ||
| } | ||
| return ( | ||
| L10n.string("mobile.terminal.loading.title", defaultValue: "Loading terminals"), | ||
| String.localizedStringWithFormat( | ||
| L10n.string( | ||
| "mobile.terminal.loading.messageFormat", | ||
| defaultValue: "Waiting for %@ to send terminal metadata for this workspace." | ||
| ), | ||
| resolvedMacName | ||
| ) | ||
| ) | ||
| } | ||
|
|
||
| private func tailnetStatusText(_ status: TailnetStatus?) -> String { | ||
| switch status { | ||
| case .active: | ||
| return L10n.string("mobile.terminal.loading.tailscale.active", defaultValue: "Active") | ||
| case .inactiveOrNotInstalled: | ||
| return L10n.string("mobile.terminal.loading.tailscale.inactive", defaultValue: "Off or not installed") | ||
| case .unknown: | ||
| return L10n.string("mobile.terminal.loading.tailscale.unknown", defaultValue: "Unknown") | ||
| case nil: | ||
| return L10n.string("mobile.terminal.loading.tailscale.notChecked", defaultValue: "Not checked") | ||
| } | ||
| } | ||
|
|
||
| private func routeText(activeRoute: CmxAttachRoute?, storedRouteDescription: String?) -> String { | ||
| if let activeRoute { | ||
| return String.localizedStringWithFormat( | ||
| L10n.string( | ||
| "mobile.terminal.loading.routeActiveFormat", | ||
| defaultValue: "%@ · %@" | ||
| ), | ||
| routeKindText(activeRoute.kind), | ||
| endpointText(activeRoute.endpoint) | ||
| ) | ||
| } | ||
| if let storedRouteDescription = nonEmpty(storedRouteDescription) { | ||
| return String.localizedStringWithFormat( | ||
| L10n.string( | ||
| "mobile.terminal.loading.routeStoredFormat", | ||
| defaultValue: "Saved route · %@" | ||
| ), | ||
| storedRouteDescription | ||
| ) | ||
| } | ||
| return L10n.string("mobile.terminal.loading.routeMissing", defaultValue: "No saved route") | ||
| } | ||
|
|
||
| private func routeKindText(_ kind: CmxAttachTransportKind) -> String { | ||
| switch kind { | ||
| case .tailscale: | ||
| return L10n.string("mobile.terminal.loading.route.tailscale", defaultValue: "Tailscale") | ||
| case .debugLoopback: | ||
| return L10n.string("mobile.terminal.loading.route.debugLoopback", defaultValue: "Debug loopback") | ||
| case .iroh: | ||
| return L10n.string("mobile.terminal.loading.route.iroh", defaultValue: "Iroh") | ||
| case .websocket: | ||
| return L10n.string("mobile.terminal.loading.route.websocket", defaultValue: "WebSocket") | ||
| } | ||
| } | ||
|
|
||
| private func endpointText(_ endpoint: CmxAttachEndpoint) -> String { | ||
| switch endpoint { | ||
| case let .hostPort(host, port): | ||
| return "\(host):\(port)" | ||
| case let .peer(id, _, directAddrs, _): | ||
| return directAddrs.first ?? id | ||
| case let .url(url): | ||
| return url | ||
| } | ||
| } | ||
|
|
||
| private func tone(for status: MobileMacConnectionStatus) -> TerminalLoadingDiagnosticsTone { | ||
| switch status { | ||
| case .connected: | ||
| return .good | ||
| case .reconnecting: | ||
| return .pending | ||
| case .unavailable: | ||
| return .warning | ||
| } | ||
| } | ||
|
|
||
| private func tone(for status: TailnetStatus?) -> TerminalLoadingDiagnosticsTone { | ||
| switch status { | ||
| case .active: | ||
| return .good | ||
| case .inactiveOrNotInstalled: | ||
| return .warning | ||
| case .unknown, nil: | ||
| return .neutral | ||
| } | ||
| } | ||
| } | ||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win
Consider marking this pure value struct
nonisolated.TerminalLoadingDiagnosticsModelis a plain data struct with no UI/actor-affinity, but under Swift 6 MainActor-by-default isolation it can implicitly inherit@MainActor, coupling a value-only type to the main actor unnecessarily and forcing hops when built off-main.♻️ Suggested fix
As per coding guidelines, "Report a failure when the diff introduces or materially expands ... pure value model structs that remain implicitly
@MainActorwhen they should be marked nonisolated."📝 Committable suggestion
🤖 Prompt for AI Agents
Source: Coding guidelines