// Copyright 2019-2023 Tauri Programme within The Commons Conservancy // SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: MIT use serde::Deserialize; use tauri::{command, AppHandle, Runtime, State}; use crate::{Notification, PermissionState, Result}; /// The options for the notification API. #[derive(Debug, Clone, Deserialize)] pub struct NotificationOptions { /// The notification title. pub title: String, /// The notification body. pub body: Option, /// The notification icon. pub icon: Option, } #[command] pub(crate) async fn is_permission_granted( _app: AppHandle, notification: State<'_, Notification>, ) -> Result { notification .permission_state() .map(|s| s == PermissionState::Granted) } #[command] pub(crate) async fn request_permission( _app: AppHandle, notification: State<'_, Notification>, ) -> Result { notification.request_permission() } #[command] pub(crate) async fn notify( _app: AppHandle, notification: State<'_, Notification>, options: NotificationOptions, ) -> Result<()> { let mut builder = notification.builder().title(options.title); if let Some(body) = options.body { builder = builder.body(body); } if let Some(icon) = options.icon { builder = builder.icon(icon); } builder.show() }