diff --git a/src/content/docs/2/recipe/notifications.mdx b/src/content/docs/2/recipe/notifications.mdx new file mode 100644 index 00000000000..ef0fdd79d4d --- /dev/null +++ b/src/content/docs/2/recipe/notifications.mdx @@ -0,0 +1,112 @@ +--- +title: Notifications +--- + +import { Tabs, TabItem } from '@astrojs/starlight/components'; + +In this recipe we'll take a look at sending a native notification to your user. We'll do this by using the official notification plugin. + +## Setup + +First you have to install the notification plugin in your backend. + + + + ```toml + [dependencies] + tauri-plugin-notification = "2.0.0-alpha" + ``` + + + ```rust + #[cfg_attr(mobile, tauri::mobile_entry_point)] + pub fn run() { + tauri::Builder::default() + // Initialize the plugin + .plugin(tauri_plugin_notification::init()) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); + } + ``` + + + +## Usage + +Once you're done with the general setup you're free to use the notification plugin in either your frontend or straight from the backend. + +### Frontend + +Install the `@tauri-apps/plugin-notification` package using your favorite package manager. + + + + ```html + ``` + + + ```html + + + + ``` + + + +### Backend + +You can also create notifications straight from the backend. All you need to do is create an instance of `Notification` and `.show()` it. + + + + ```rust + use tauri_plugin_notification::Notification; + + #[tauri::command] + async fn notify(app: AppHandle) -> Result<(), ()> { + Notification::new(&app.config().tauri.bundle.identifier) + .title("New message") + .body("You've got a new message.") + .show() + } + ``` + + + ```rust + ``` + + + ```rust + ``` + + + +## Deep dive + +### How it works + +TODO: Write stuff + +### Security + +TODO: Write stuff