Show a toast.
This lib requires a Rust version of at least 1.64
There are three general methods of installation that we can recommend.
- Use crates.io and npm (easiest, and requires you to trust that our publishing pipeline worked)
- Pull sources directly from Github using git tags / revision hashes (most secure)
- Git submodule install this repo in your tauri project and then use file protocol to ingest the source (most secure, but inconvenient to use)
Install the Core plugin by adding the following to your Cargo.toml
file:
src-tauri/Cargo.toml
[dependencies]
toast = { git = "https://github.com/ahkohd/tauri-toolkit", branch = "v2" }
use toast::{Toast, ToastExt};
fn main() {
// setup the toast with default configuration
app_handle.manage(Toast::default());
// show a toast
// `message` can be formatted in markdown
app_handle.toast("Hello, **World!** 🎉");
}
app_handle.toast(message: &str)
: Shows a toastmessage: &str
: The toast message. It supports markdown.
Configure the toast
font_size: f64
: The font size of the toast text labelpadding: (f64, f64)
: The padding of the toastposition: ToastPosition
: Where to place the toastoffset: f64
: Offset the toast positionduration: f64
: The duration of the toastfade_duration: f64
: The duration of the enter and exit fade animation
Top
: The toast will be position at the top center of the monitor with cursorBottom
: The toast will be position at the bottom center of the monitor with cursor
To configure your toast, use Toast::new(...)
instead of Toast::default()
. For example:
use toast::{Toast, ToastConfig, ToastPosition};
app_handle.manage(Toast::new(ToastConfig {
position: ToastPosition::Top,
offset: 20.0,
..Default::default()
}));
PRs accepted. Please make sure to read the Contributing Guide before making a pull request.
MIT or MIT/Apache 2.0 where applicable