fix(mac): re-ensure remote gateway tunnel
parent
ef20053e72
commit
62f624b66b
|
|
@ -109,11 +109,15 @@ actor GatewayConnection {
|
||||||
do {
|
do {
|
||||||
return try await client.request(method: method, params: params, timeoutMs: timeoutMs)
|
return try await client.request(method: method, params: params, timeoutMs: timeoutMs)
|
||||||
} catch {
|
} catch {
|
||||||
|
if error is GatewayResponseError || error is GatewayDecodingError {
|
||||||
|
throw error
|
||||||
|
}
|
||||||
|
|
||||||
// Auto-recover in local mode by spawning/attaching a gateway and retrying a few times.
|
// Auto-recover in local mode by spawning/attaching a gateway and retrying a few times.
|
||||||
// Canvas interactions should "just work" even if the local gateway isn't running yet.
|
// Canvas interactions should "just work" even if the local gateway isn't running yet.
|
||||||
let isLocal = await MainActor.run { AppStateStore.shared.connectionMode == .local }
|
let mode = await MainActor.run { AppStateStore.shared.connectionMode }
|
||||||
guard isLocal else { throw error }
|
switch mode {
|
||||||
|
case .local:
|
||||||
await MainActor.run { GatewayProcessManager.shared.setActive(true) }
|
await MainActor.run { GatewayProcessManager.shared.setActive(true) }
|
||||||
|
|
||||||
var lastError: Error = error
|
var lastError: Error = error
|
||||||
|
|
@ -127,6 +131,39 @@ actor GatewayConnection {
|
||||||
}
|
}
|
||||||
|
|
||||||
throw lastError
|
throw lastError
|
||||||
|
case .remote:
|
||||||
|
let nsError = error as NSError
|
||||||
|
guard nsError.domain == URLError.errorDomain else { throw error }
|
||||||
|
|
||||||
|
var lastError: Error = error
|
||||||
|
await RemoteTunnelManager.shared.stopAll()
|
||||||
|
do {
|
||||||
|
_ = try await GatewayEndpointStore.shared.ensureRemoteControlTunnel()
|
||||||
|
} catch {
|
||||||
|
lastError = error
|
||||||
|
}
|
||||||
|
|
||||||
|
for delayMs in [150, 400, 900] {
|
||||||
|
try await Task.sleep(nanoseconds: UInt64(delayMs) * 1_000_000)
|
||||||
|
do {
|
||||||
|
let cfg = try await self.configProvider()
|
||||||
|
await self.configure(url: cfg.url, token: cfg.token)
|
||||||
|
guard let client = self.client else {
|
||||||
|
throw NSError(
|
||||||
|
domain: "Gateway",
|
||||||
|
code: 0,
|
||||||
|
userInfo: [NSLocalizedDescriptionKey: "gateway not configured"])
|
||||||
|
}
|
||||||
|
return try await client.request(method: method, params: params, timeoutMs: timeoutMs)
|
||||||
|
} catch {
|
||||||
|
lastError = error
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw lastError
|
||||||
|
case .unconfigured:
|
||||||
|
throw error
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue