Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Comment on lines +5 to +43

Copy link
Copy Markdown

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.

TerminalLoadingDiagnosticsModel is 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
-struct TerminalLoadingDiagnosticsModel: Equatable {
+nonisolated struct TerminalLoadingDiagnosticsModel: Equatable {

As per coding guidelines, "Report a failure when the diff introduces or materially expands ... pure value model structs that remain implicitly @MainActor when they should be marked nonisolated."

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
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
}
}
nonisolated 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
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/TerminalLoadingDiagnosticsModel.swift`
around lines 5 - 43, Mark TerminalLoadingDiagnosticsModel as nonisolated because
it is a pure value type and should not implicitly inherit MainActor isolation
under Swift 6. Update the struct declaration itself, and keep both initializers
in place while ensuring the TerminalLoadingDiagnosticsModelBuilder path and the
direct property initializer remain free of actor affinity so the model can be
constructed off-main without unnecessary hops.

Source: Coding guidelines

#endif
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
Loading
Loading