Open wyhaya opened 1 year ago
I know @JonasKruckenberg and @oscartbeaumont have both had thoughts about this, with Jonas' approach using tauri-bindgen and Oscar's using Specta. Will leave it to them to go into detail about their approaches if they want.
Yeah, I really want raw byte-level IPC for some long-term plans on rspc. I am hoping to eventually be able to do file upload/download and have been eyeing potential formats so BigInt
-style numbers and Date
's are supported.
I am curious if a custom IPC hook @wyhaya proposes is actually required. Hopefully, Tauri will support async custom URI handlers in the near future, and in my limited knowledge of the IPC internals, they sound very similar but I could very much be wrong.
@Brendonovich and I have been discussing the idea of doing Specta serialisation/deserialisation to be able to deal with these similar issues for rspc (and potentially tauri-specta) and I would be curious if there is some room here for collaborating or creating a shared standard if there is not one out there that would work for our usecase.
@wyhaya we do have a way to implement a custom IPC: https://docs.rs/tauri/1.4.1/tauri/struct.Builder.html#method.invoke_system
and yes with the Response
struct you need to convert your data to Vecserde_json::to_vec
is the existing solution, though custom ones could be implemented. This is a limitation we have until RSON or something like that is implemented, for instance I had to split the command to read response body in order to take advantage of Response without serialization: https://github.com/tauri-apps/plugins-workspace/blob/903361100cd2dfe1cb5f4027c9a8b53f9d09a612/plugins/http/src/commands.rs#L167
It's also worth noting that tauri-bindgen
fully sidesteps tauris ipc in order to send binary data (using a custom encoding that can optimize more that the regular tauri ipc bc we have more type info available)
Other tools like specta
could theoretically use the same technique.
So in essence: The custom ipc method already exists it's called custom_uri_scheme_protocol
😉
custom_uri_scheme_protocol
hasn't really been able to satisfy the requirements for rspc and Spacedrive in its current form due to it being synchronous but it's awesome to see the Wry PR merge for async handler. Can't wait to have them in Tauri!
We recently had to move Spacedrive's media serving off of custom_uri_scheme_protocol
to a localhost Axum server because it was causing freezing within our inspector view as we execute asynchronous database queries and IO operations (potentially to really slow devices like NAS's) within it that ended up requiring a block_on
. I suspect it is blocking the main thread causing the UI to lock up and the app to sometimes crash which seems super logical but nonetheless was an issue.
Do you know if anyone has done benchmarking between tauri::ipc::Response::new
and the custom URI handlers? It seems very inefficient for tauri::ipc::Response
to serialize it to a serde_json::Value
which it looks like is what it does, but then again in practice I'm sure it's probably not that bad. I could conduct some benchmarks here if none exist because I would be really curious of the results.
Relying on custom URI protocols and leaving this to the ecosystem does seem like a pretty solid solution, especially given tauri-bindgen is an officially maintained solution.
Discussed in https://github.com/tauri-apps/tauri/discussions/7699