Open AMythicDev opened 5 months ago
Would it be possible to turn those crates into tauri plugins? They have their own invoke_handler call which would work around this issue.
Actually i just remembered a discord discussion and it's actually possible. In that discussion the solution was to change this
use my_library::commands::greet;
.invoke_handler(generate_handler![greet])
to this
use my_library::commands;
.invoke_handler(generate_handler![commands::greet])
I have written the same in my code but I don't have an inner module like command
so essentially what I have is like this:
.invoke_handler(generate_handler![config::get_details])
And this too gave the same error message.
Ahh right, you can trigger that same error in your tauri-app's main.rs/lib.rs file by having the command pub
. I did not find a solution to this on our side (though i am not good with macros at all) so at least for now you must move them into a submodule (inside that seperate crate).
so at least for now you must move them into a submodule (inside that seperate crate).
From what I understand from this is that I should move all the functions into a commands
module. Am I getting that right?
Yes. The exact name of the module is up to you, but commands
is popular.
Thanks @FabianLars, that worked. However I am still keeping this open because for the tauri team to look into.
Describe the problem
It seems that right now I can only call the
#[tauri::command]
on the rootsrc/
folder of my project. Due to the size and complexity of the project that I am working on, I need to separate parts of the codebase into Cargo workspaces. I want to be able to call certain functions in these workspaces from the frontend so I have added these workspace as a dependency of the root package which is responsible for initialising my main app. However when I declare a function inside a workspace as a command throws an error like this:Describe the solution you'd like
I would like to be able to declare functions in workspaces as tauri commands just as easily as I can do it in my root package.
Alternatives considered
My current approach is to make wrappers for all the functions in my root package and declare then declare these wrappers as tauri commands. This is terrible in my eyes as it is very error-prone, adds a useless function call and requires me to use weird gimmicks to properly bubble up the errors in the wrapper function.
Additional context
Tauri version: v1.6.1 OS: Fedora Linux 39 webkitgtk6.0 version: 2.42.1