tauri-plugin-deeprespond-im 1.0.0-alpha

深应智能 IM 的 Tauri 插件:本地存储、安全存储、窗口间的锁与消息、系统事件、通知、角标、文件
//! 角标、引起注意、托盘闪烁的命令(引擎和界面窗口都可以调用:badge 为 auto 时由引擎设置,manual 时由 App 设置)。

use std::sync::Arc;

use tauri::{AppHandle, Runtime, State, Webview};

use super::TrayBlink;
use crate::commands::caller;
use crate::error::Result;
use crate::Shared;

/// 角标数;null 或 0 清除。
#[tauri::command(rename_all = "snake_case")]
pub async fn badge_set<R: Runtime>(app: AppHandle<R>, webview: Webview<R>, state: State<'_, Arc<Shared>>, count: Option<u64>) -> Result<()> {
    caller(&state, &webview)?;
    super::set(&app, &state, count).await;
    Ok(())
}

/// critical:Windows 持续闪烁、macOS 持续跳动,直到获得焦点;label 为空时选主窗口或任意可见的界面窗口。
#[tauri::command(rename_all = "snake_case")]
pub async fn attention_request<R: Runtime>(app: AppHandle<R>, webview: Webview<R>, state: State<'_, Arc<Shared>>, critical: bool, label: Option<String>) -> Result<()> {
    caller(&state, &webview)?;
    super::attention(&app, &state, critical, label.as_deref());
    Ok(())
}

/// 托盘图标闪烁:blink 为 null 时停止(Tauri 的命令不能直接以 null 为参数,所以包在 blink 中)。
#[tauri::command(rename_all = "snake_case")]
pub async fn tray_blink<R: Runtime>(app: AppHandle<R>, webview: Webview<R>, state: State<'_, Arc<Shared>>, blink: Option<TrayBlink>) -> Result<()> {
    caller(&state, &webview)?;
    super::tray_blink(&app, state.inner(), blink)
}