brows3r_lib/commands/notifications_cmd.rs
1//! Tauri commands for the in-app notification log.
2//!
3//! # Commands
4//!
5//! - `notifications_list` — return notifications, optionally filtered by timestamp.
6//! - `notification_dismiss` — remove a notification from the log by id.
7
8use tauri::State;
9
10use crate::{
11 error::AppError,
12 notifications::{Notification, NotificationLogHandle},
13};
14
15/// Return all notifications stored in the log.
16///
17/// When `since` is provided only notifications with
18/// `timestamp >= since` (unix milliseconds) are returned.
19#[tauri::command]
20pub async fn notifications_list(
21 since: Option<i64>,
22 log: State<'_, NotificationLogHandle>,
23) -> Result<Vec<Notification>, AppError> {
24 let guard = log.0.read().await;
25 Ok(guard.list(since))
26}
27
28/// Dismiss (remove) a notification by its `id`.
29///
30/// Returns `true` when the notification was found and removed,
31/// `false` when no notification with that id exists.
32#[tauri::command]
33pub async fn notification_dismiss(
34 id: String,
35 log: State<'_, NotificationLogHandle>,
36) -> Result<bool, AppError> {
37 let mut guard = log.0.write().await;
38 Ok(guard.dismiss(&id))
39}