mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-25 19:01:14 +00:00
* feat: add native inline widget support * refactor: simplify plugin surface refresh * fix: preserve plugin surface refresh API * fix: reload widgets after WebKit termination * fix: harden native widget refresh * fix: bound native widget recovery * docs: defer native widget release note * chore: refresh native i18n inventory * fix: harden native widget delivery * refactor: simplify native widget API surface * fix: serialize native widget capability refresh * fix: harden native widget recovery * fix: recover native widget capabilities * style: format widget refresh role selection * fix: correct widget refresh formatting * fix: harden cross-platform widget recovery * fix: bind widget trust and recovery to routes * chore: refresh native i18n inventory * chore: regenerate Android gateway protocol * test: remove unused release workflow read
45 lines
1.9 KiB
Swift
45 lines
1.9 KiB
Swift
import Foundation
|
|
|
|
struct MacNodeCanvasHostedSurfaceResolver: Sendable {
|
|
private let currentSurfaceURL: @Sendable () async -> String?
|
|
private let refreshSurfaceURL: @Sendable (String?) async -> String?
|
|
|
|
init(
|
|
currentSurfaceURL: @escaping @Sendable () async -> String?,
|
|
refreshSurfaceURL: @escaping @Sendable (String?) async -> String?)
|
|
{
|
|
self.currentSurfaceURL = currentSurfaceURL
|
|
self.refreshSurfaceURL = refreshSurfaceURL
|
|
}
|
|
|
|
func resolveA2UIURL(forceRefresh: Bool = false) async -> String? {
|
|
let observedSurface = await currentSurfaceURL()
|
|
if !forceRefresh,
|
|
let current = CanvasHostedURLResolver.resolveA2UIURL(surfaceURL: observedSurface)
|
|
{
|
|
return current
|
|
}
|
|
let refreshedSurface = await refreshSurfaceURL(observedSurface)
|
|
return CanvasHostedURLResolver.resolveA2UIURL(surfaceURL: refreshedSurface)
|
|
}
|
|
|
|
func resolveTarget(_ target: String?) async throws -> CanvasHostedTarget? {
|
|
guard let target, CanvasHostedURLResolver.isHostedTarget(target) else { return nil }
|
|
let observedSurface = await currentSurfaceURL()
|
|
if let refreshedSurface = await refreshSurfaceURL(observedSurface),
|
|
let resolved = CanvasHostedURLResolver.resolve(surfaceURL: refreshedSurface, target: target)
|
|
{
|
|
return resolved
|
|
}
|
|
// A failed refresh can mean the route changed while it was in flight.
|
|
// Re-read so the replacement gateway's capability wins over the stale observation.
|
|
let currentSurface = await currentSurfaceURL()
|
|
if let resolved = CanvasHostedURLResolver.resolve(surfaceURL: currentSurface, target: target) {
|
|
return resolved
|
|
}
|
|
throw NSError(domain: "Canvas", code: 32, userInfo: [
|
|
NSLocalizedDescriptionKey: "CANVAS_HOST_NOT_CONFIGURED: gateway did not advertise canvas host",
|
|
])
|
|
}
|
|
}
|