iOS: update onboarding and gateway UI

This commit is contained in:
Mariano Belinky
2026-02-02 12:58:09 +00:00
parent 532b9653be
commit ff6114599e
9 changed files with 725 additions and 58 deletions

View File

@@ -62,7 +62,7 @@ final class NodeAppModel {
private var gatewayTask: Task<Void, Never>?
private var voiceWakeSyncTask: Task<Void, Never>?
@ObservationIgnored private var cameraHUDDismissTask: Task<Void, Never>?
@ObservationIgnored private var capabilityRouter: NodeCapabilityRouter
@ObservationIgnored private lazy var capabilityRouter: NodeCapabilityRouter = self.buildCapabilityRouter()
private let gatewayHealthMonitor = GatewayHealthMonitor()
private let notificationCenter: NotificationCentering
let voiceWake = VoiceWakeManager()
@@ -111,8 +111,6 @@ final class NodeAppModel {
self.remindersService = remindersService
self.motionService = motionService
self.talkMode = talkMode
self.capabilityRouter = NodeCapabilityRouter(handlers: [:])
self.capabilityRouter = self.buildCapabilityRouter()
self.voiceWake.configure { [weak self] cmd in
guard let self else { return }
@@ -298,6 +296,9 @@ final class NodeAppModel {
self.gatewayTask = Task {
var attempt = 0
var currentOptions = connectOptions
var didFallbackClientId = false
let trimmedStableID = gatewayStableID.trimmingCharacters(in: .whitespacesAndNewlines)
while !Task.isCancelled {
await MainActor.run {
if attempt == 0 {
@@ -314,7 +315,7 @@ final class NodeAppModel {
url: url,
token: token,
password: password,
connectOptions: connectOptions,
connectOptions: currentOptions,
sessionBox: sessionBox,
onConnected: { [weak self] in
guard let self else { return }
@@ -363,6 +364,23 @@ final class NodeAppModel {
try? await Task.sleep(nanoseconds: 1_000_000_000)
} catch {
if Task.isCancelled { break }
if !didFallbackClientId,
let fallbackClientId = self.legacyClientIdFallback(
currentClientId: currentOptions.clientId,
error: error)
{
didFallbackClientId = true
currentOptions.clientId = fallbackClientId
if !trimmedStableID.isEmpty {
GatewaySettingsStore.saveGatewayClientIdOverride(
stableID: trimmedStableID,
clientId: fallbackClientId)
}
await MainActor.run {
self.gatewayStatusText = "Gateway rejected client id. Retrying…"
}
continue
}
attempt += 1
await MainActor.run {
self.gatewayStatusText = "Gateway error: \(error.localizedDescription)"
@@ -394,6 +412,16 @@ final class NodeAppModel {
}
}
private func legacyClientIdFallback(currentClientId: String, error: Error) -> String? {
let normalizedClientId = currentClientId.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
guard normalizedClientId == "openclaw-ios" else { return nil }
let message = error.localizedDescription.lowercased()
guard message.contains("invalid connect params"), message.contains("/client/id") else {
return nil
}
return "moltbot-ios"
}
func disconnectGateway() {
self.gatewayTask?.cancel()
self.gatewayTask = nil
@@ -507,7 +535,10 @@ final class NodeAppModel {
guard let self else { return false }
do {
let data = try await self.gateway.request(method: "health", paramsJSON: nil, timeoutSeconds: 6)
return (try? JSONDecoder().decode(OpenClawGatewayHealthOK.self, from: data))?.ok ?? true
guard let decoded = try? JSONDecoder().decode(OpenClawGatewayHealthOK.self, from: data) else {
return false
}
return decoded.ok ?? false
} catch {
return false
}