Skip to content

Commit

Permalink
Merge branch 'develop' into 'master'
Browse files Browse the repository at this point in the history
3.32.5 release

See merge request papers/airgap/airgap-vault!521
  • Loading branch information
isordo committed Oct 21, 2024
2 parents a5eba41 + a071018 commit 091fff8
Show file tree
Hide file tree
Showing 4 changed files with 394 additions and 393 deletions.
19 changes: 10 additions & 9 deletions ios/App/App/Helpers/JS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ protocol JSONConvertible {

class JSAsyncResult: NSObject, Identifiable, WKScriptMessageHandler {
private typealias Listener = (Result<Any, Error>) -> ()

private static let defaultName: String = "jsAsyncResult"

private static let fieldID: String = "id"
Expand All @@ -49,34 +49,35 @@ class JSAsyncResult: NSObject, Identifiable, WKScriptMessageHandler {
await selfWeak?.resultManager.setResult(result, forID: id)
}
}

return id
}

func awaitResultWithID(_ id: String) async throws -> Any {
if let result = await resultManager.result[id] {
return try result.get()
}

return try await withCheckedThrowingContinuation { continuation in
Task {
await listenerRegistry.add(forID: id) { result in
if let result = await resultManager.result[id] {
continuation.resume(with: result)
} else {
await listenerRegistry.add(forID: id) { result in
continuation.resume(with: result)
}
}
}
}
}


func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
guard message.name == id, let body = message.body as? [String: Any] else { return }

Task {
guard let id = body[Self.fieldID] as? String else { return }

do {
let result = body[Self.fieldResult]
let error = body[Self.fieldError]

if let result = result, error == nil {
await listenerRegistry.notifyAllWithID(id, with: .success(result))
} else if let error = error {
Expand Down
Loading

0 comments on commit 091fff8

Please sign in to comment.