mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-02-06 13:57:16 +00:00
feat(ios): support async Swift plugin methods (completionHandler:) in PluginManager (#14148)
* Added selector with completionHandler handling * Added .changes file * fix change file --------- Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
parent
6bbb530fd5
commit
2e089f6acb
5
.changes/ios-async-support.md
Normal file
5
.changes/ios-async-support.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"tauri": minor:feat
|
||||
---
|
||||
|
||||
Support async Swift plugin methods (`completionHandler:`) in PluginManager
|
||||
@ -59,8 +59,23 @@ public class PluginManager {
|
||||
func invoke(name: String, invoke: Invoke) {
|
||||
if let plugin = plugins[name] {
|
||||
ipcDispatchQueue.async {
|
||||
let selectorWithCompletionHandler = Selector(("\(invoke.command):completionHandler:"))
|
||||
let selectorWithThrows = Selector(("\(invoke.command):error:"))
|
||||
if plugin.instance.responds(to: selectorWithThrows) {
|
||||
|
||||
if plugin.instance.responds(to: selectorWithCompletionHandler) {
|
||||
let completion: @convention(block) (NSError?) -> Void = { error in
|
||||
if let error = error {
|
||||
invoke.reject("\(error)")
|
||||
}
|
||||
}
|
||||
|
||||
let blockObj: AnyObject = unsafeBitCast(completion, to: AnyObject.self)
|
||||
let imp = plugin.instance.method(for: selectorWithCompletionHandler)
|
||||
|
||||
typealias Fn = @convention(c) (AnyObject, Selector, Invoke, AnyObject) -> Void
|
||||
let fn = unsafeBitCast(imp, to: Fn.self)
|
||||
fn(plugin.instance, selectorWithCompletionHandler, invoke, blockObj)
|
||||
} else if plugin.instance.responds(to: selectorWithThrows) {
|
||||
var error: NSError? = nil
|
||||
withUnsafeMutablePointer(to: &error) {
|
||||
let methodIMP: IMP! = plugin.instance.method(for: selectorWithThrows)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user