First try with Tauri
Recently, I have been trying to learn Tauri, a framework for building desktop applications using web technologies. I decided to create a simple music player application called “rmusic” as my first project.
For back, I use Rust and choose crates like rodio
and tokio
to handle audio playback and asynchronous tasks, respectively. The application is designed to be lightweight and efficient, making it suitable for various platforms.
For front, I use Vue.js and Vite to build the user interface. The combination of Tauri, Vue.js, and Rust allows me to create a modern desktop application with a responsive design and smooth performance.
Here is the github link for the project: rmusic
Init with Tauri
1 | npm create tauri-app |
Dependencies
1 | # Cargo.toml |
1 | // package.json |
Permissions
For tauri, you need to set permissions in /capabilities/default.json
, which gives permissions to frontend.
1 | { |
Begin
Now everything is ready, and you can start building your Tauri application. You can run the application using the following command:
1 | npm run tauri dev |
Some details
The point of this project is the state sharing between the front and back. Tauri offers a way to share state between the front and back using the invoke
method. You can call Rust functions from JavaScript and vice versa.
Also, Tauri provides a way to manage global state using manage
.
1 | // src/lib.rs |
.invoke_handler
is used to register the Rust functions that can be called from JavaScript. The manage
method is used to share the state between the front and back. In this case, we are sharing the event_sender
and sink
objects.
1 | // src/music.rs |
Update
I add another service to rmusic to handle online music. This repo can help you to get the online music. I use reqwest
to get the data from the API. The API is a little bit slow, but it works.
So, before you use the new feature, you should run the server first.
1 | cd KuGouMusicApi |
Now localhost:3000
is the API server. You can use it to get the online music.
Conclusion
In conclusion, Tauri is a powerful framework for building desktop applications using web technologies. It allows you to create lightweight and efficient applications with a modern user interface. The combination of Rust and JavaScript provides a great development experience, and the ability to share state between the front and back makes it easy to manage application logic.
However, I find it difficult to search for the information I need. In my opinion, the documentation is very good. But nowadays, there are little examples for Tauri.