DEV Community

Cover image for Create a desktop app in Rust using Tauri and Yew

Create a desktop app in Rust using Tauri and Yew

Steve Pryde on January 16, 2022

I recently created a complete desktop app in Rust using Tauri and Yew. A few people expressed interest in how I did this, so here is a tutorial to ...
Collapse
 
sshine profile image
Simon Shine

Thanks for the great tutorial.

For those who try this tutorial with yew 0.20.0 and not 0.19.3 as the tutorial was made for, it seems that yew::start_app::<App>(); is no longer available. Instead, taken from the Yew 0.20 starter template:

fn main() {
    yew::Renderer::<App>::new().render();
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
papa_robot_mdm profile image
Marciano Marxiano

tower http was yanked from registry, had to use

cargo install trunk --locked

error: failed to compile `trunk v0.14.0`, intermediate artifacts can be found at `/tmp/cargo-installRrqVj8`

Caused by:
  failed to select a version for the requirement `tower-http = "^0.1"`
  candidate versions found which didn't match: 0.2.1, 0.0.0
Enter fullscreen mode Exit fullscreen mode
Collapse
 
tobiaskluth profile image
tobiaskluth

Hi!
Thanks for the great writeup! Excited to dip further into the topic.
As i followed along your tutorial i encountered a problem in src-tauri/src/main.rs. Defining the hello function public throws compilation error[E0255], removing the pub declaration fixes it. I'm not a 100% sure why though.

error[E0255]: the name `__cmd__hello` is defined multiple times
  --> src/main.rs:14:8
   |
13 | #[tauri::command]
   | ----------------- previous definition of the macro `__cmd__hello` here
14 | pub fn hello (name: &str) -> Result<String, String> {
   |        ^^^^^ `__cmd__hello` reimported here
   |
   = note: `__cmd__hello` must be defined only once in the macro namespace of this module
help: you can use `as` to change the binding name of the import
   |
14 | pub fn hello as other___cmd__hello (name: &str) -> Result<String, String> {
   |        ~~~~~~~~~~~~~~~~~~~~~~~~~~~

For more information about this error, try `rustc --explain E0255`.
error: could not compile `app` due to previous error
Enter fullscreen mode Exit fullscreen mode
Collapse
 
stevepryde profile image
Steve Pryde

I've removed the pub. Hopefully that solves the issue if anyone else is following along. I just have encountered the same thing on my travels and removed it. I guess there's no need for it to be public. It could be a bug with the proc macro or maybe it's intentional. I'm not sure.

Collapse
 
xelif profile image
FileX

So technically one would only need a ‚minimal’ API to the tauri backend,
like for storing to disk or attaching to different processes/ devices.. what else would be a requirement? Is there possibly a more developed approach already (being) build?

Collapse
 
xelif profile image
FileX

This repo looks promising to build on don’t you think?
github.com/JonasKruckenberg/tauri-sys

Collapse
 
opensourcecheemsburgers profile image
Stephen Power

Excellent guide!

For anyone who may be wondering about async Tauri commands, they work the exact same as regular Tauri commands.

I spent way too long trying different ways of getting async to work when I just forgot to add the following to my tauri.conf.json file:

"withGlobalTauri": true
Enter fullscreen mode Exit fullscreen mode
Collapse
 
lupyuen profile image
Lup Yuen Lee

Thanks for the awesome post! The demo works OK on PinePhone, here's what I did: gist.github.com/lupyuen/5566af817e...

Collapse
 
itflyingstart profile image
ItFlyingStart

Great tutorial. Thanks.

Dummy question: if I want to consume an external web service. Should I implement it in the frontend (Yew) or in the backend (Tauri)?

Collapse
 
stevepryde profile image
Steve Pryde

Apologies for the late reply but this is not a dummy question at all. I'll try to offer some info that might help you decide.

Firstly, it should be possible to do it in either. Browsers have the Fetch API available to them and you can use this within wasm: rustwasm.github.io/wasm-bindgen/ex...
From the backend you can use any HTTP client in Rust, for example reqwest.

If you do the web requests from wasm then any credentials etc will be visible via the built-in browser devtools (network tab) and depending on how much JS you have in your app it could also be vulnerable to XSS attacks.

Doing the requests from the backend in tauri should make this less visible and away from any XSS attacks. The backend would be my preference.

Collapse
 
estkae profile image
Karl Estermann

it's all far too elaborate. I'm thinking of Delphi. With pascal you can also build good applications and have everything on one IDE.
is there a what you see IDE for Rust gui.