New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement draft RPC API. #95
Conversation
Remove old Callback mechanism. * Remove obsolete Callback API * Remove FuncCall and RPC * Update README * Rename set_rpc_handler() to set_handler() * Use shared rpc_proxy() function for platform consistency * Improve handling of promise cleanup * Update README with RPC API info. * Panic if webview handler is set after window creation. * Improve rpc_proxy() logic, try to ensure any corresponding promise is always removed. * Remove FuncCall wrapper.
@wusyong, this version has a tidy history. Would appreciate it if we could get this merged 👍 I tried and failed to fix the MacOS issue and hope you have more success. I tried using
Which is all the stuff inside the |
We probably need to declare another objc class and it's full of hacks. I can take another day to work it. But for now that's just make it work on linux. |
Thanks @wusyong, it works on Linux do you have a Windows machine to test on? It might work there too! |
Sure. Do you mind I cherry pick this commit to |
Sure thing, let's put it in |
We can keep the discussion on #66. |
Oh no, we may have misunderstood each other. I have removed The benefit of the old callback model was that you could just call a vanilla Javascript function as I understood it. This can now be achieved like this: function someCallback() {
return window.rpc.call('someRpcMethod', Array.prototype.slice.call(arguments, 0));
}
someCallback("param").then((res) => console.log(res)); What is still not done is a function that would set these callback aliases automatically. That would be the |
I see. I do agree with this and it looks a lot cleaner. |
Hi @wusyong, sorry I didn't realize you have been working in the What I attempted to do was be fully backwards compatible with the first PR that you merged and then when you said that you liked the idea of cleaning up Is it possible for me to take any important changes from your Edit: would you like me to merge the |
Sorry I deleted the previous comment thinking it's not good for you to develop further. |
Sure @wusyong, I'll do the callback aliases stuff and hope that it works out. I looked at the tauri code that configures the Maybe we can get some people working on the main Tauri code to comment on how much this change will affect them? |
Yeah we'll have a discussion about this. |
Agreed @wusyong . I did add a So then we remove |
yeah, if that's possible. |
Use second argument to add_window_with_configs() to set an RpcHandler.
Sure thing @wusyong, that's done now and it feels more idiomatic 👍 However it does mean that for the aliases functionality that they would need to be passed in using the same mechanism so we probably want a wrapper type: pub struct RpcConfig {
handler: RpcHandler,
callbacks: Vec<String>
} Then we pass |
Current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great news! We could get rid of callbacks entirely! Just fix the following nits and I think it's good to go!
@@ -46,6 +46,46 @@ cargo run --example multiwindow | |||
|
|||
For more information, please read the documentation below. | |||
|
|||
## Rust <-> Javascript |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left a comment in #39 that wish we could add descriptions to examples. Maybe you could start a README.md
in examples/
Thanks @wusyong, excited to see this land! I have made those small changes you mentioned but I have a couple more points I would like to make:
I have a good idea how we can support async flows it it just a small bit of code and some documentation. I will do it now and ask you to take a look, thanks 👍 |
So that rust rpc handlers can perform asynchronous tasks and defer promise evaluation until later. If an rpc handler returns None then the handler takes responsibility for ensuring the corresponding promise is resolved or rejected. If the request contains an `id` then the handler *must* ensure it evaluates either `RpcResponse::into_result_script()` or `RpcResponse::into_error_script()`.
Update multiwindow example so it is slightly more illustrative of a real-world use case. Now it launches a window when a button is clicked in the main webview. Multiple windows can be launched and the URL for the new window is passed from the Javascript code.
Hi @wusyong, I think this can be merged if we can answer the following questions:
Hoping you are able to work out the MacOS issues! Cheers 👍 |
Thanks for all your help @wusyong, shall we get this merged and then over to you for the platform-specific stuff? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, really appreciate the help!
Remove old Callback mechanism.