#tauri command calls in another file

4 messages · Page 1 of 1 (latest)

narrow flame
#

Hello all! I am new to Tauri and I have a question. Let's say that I had a data.rs which has a Data struct that includes an i32 value called value and a get_value function that returns said value.

Now let't say that in main.rs I have a struct DataWrapper(Mutex<Data>) and that I added it to tauri::Builder::default().manage().

So I am aware of how to call tauri commands and refer to the state DataWrapper(Mutex<Data>) . I was wondering if there's a way to set the state's instance of get_value() as a tauri command itself, as in if the state's Data instance has a value of 15 and I call get_value() from data.rs via tauri command the ideal result would be to get 15.

Is this even possible and, if so, what do I put in .invoke_handler(tauri::generate_handler![])? If not, I could technically make a get_value() from main.rs that calls the state's get_value(), it would just be cumbersome as the amount of functions to do this for increases. Thanks again everyone!

tall bolt
#

just include the data.rs as a module and scope the function in.

#

you can also include the tauri::manager namespace and label that function as a tauri command in the data.rs file - then just use that file as a crate or a module.

narrow flame
#

How would I implement the generate handler for the state instance, could you provide an example? It does have to be the state’s instance of Data being called specifically, not just Data in general. Thanks!