Saltearse al contenido
Tauri

Notificaciones

Envía notificaciones nativas al usuario utilizando el plugin de notificaciones.

Plataformas soportadas

This plugin requires a Rust version of at least 1.77.2

Platform Level Notes
windows

Only works for installed apps. Shows powershell name & icon in development.

linux
macos
android
ios

Configuración

Instala el plugin de notificaciones para comenzar.

Utiliza el gestor de paquetes de tu proyecto para añadir la dependencia:

npm run tauri add notification

Uso

Aquí hay algunos ejemplos de cómo usar el plugin de notificaciones:

El plugin de notificaciones está disponible tanto en JavaScript como en Rust.

Enviar notificación

Sigue estos pasos para enviar una notificación:

  1. Comprueba si se ha concedido el permiso

  2. Solicita permiso si no se ha concedido

  3. Envía la notificación

import {
isPermissionGranted,
requestPermission,
sendNotification,
} from '@tauri-apps/plugin-notification';
// si se usa `"withGlobalTauri": true`, puedes hacer
// const { isPermissionGranted, requestPermission, sendNotification, } = window.__TAURI__.notification;
// Tienes permiso para enviar una notificación?
let permissionGranted = await isPermissionGranted();
// Si no es así, necesitamos solicitarlo
if (!permissionGranted) {
const permission = await requestPermission();
permissionGranted = permission === 'granted';
}
// Una vez que se concede el permiso, envía la notificación
if (permissionGranted) {
sendNotification({ title: 'Tauri', body: 'Tauri is awesome!' });
}

Actions

Las acciones añaden botones e inputs interactivos a las notificaciones. Úsalas para crear una experiencia interactiva para tus usuarios.

Registrar tipos de acciones

Registra tipos de acciones para definir elementos interactivos:

import { registerActionTypes } from '@tauri-apps/plugin-notification';
await registerActionTypes([
{
id: 'messages',
actions: [
{
id: 'reply',
title: 'Responder',
input: true,
inputButtonTitle: 'Enviar',
inputPlaceholder: 'Escribe tu respuesta...',
},
{
id: 'mark-read',
title: 'Marcar como leído',
foreground: false,
},
],
},
]);

Propiedades de las acciones

PropiedadDescripción
idIdentificador único de la acción
titleTexto a mostrar en la acción del botón
requiresAuthenticationRequiere autenticación en el dispositivo
foregroundPone la aplicación en primer plano cuando es accionada
destructiveMuestra la acción en rojo en iOS
inputHabilita el campo de texto
inputButtonTitleTexto para el botón para enviar el input
inputPlaceholderTexto de ejemplo en el campo de texto

Suscribirse a acciones

Suscribirse a notificaciones con acciones:

import { onAction } from '@tauri-apps/plugin-notification';
await onAction((notification) => {
console.log('Acción realizada:', notification);
});

Adjuntos

Los adjuntos añaden contenido multimedia a las notificaciones. El soporte varía según la plataforma.

import { sendNotification } from '@tauri-apps/plugin-notification';
sendNotification({
title: 'Nueva imagen',
body: 'Mira esta imagen',
attachments: [
{
id: 'image-1',
url: 'asset:///notification-image.jpg',
},
],
});

Propiedades de los adjuntos

PropiedadDescripción
idIdentificador único
urlURL del contenido usando los protocolos asset:// o file://

Nota: Prueba los adjuntos en tus plataformas que quieras soportar para asegurarte de su compatibilidad.

Canales

Los canales organizan las notificaciones en categorías con diferentes comportamientos. Aunque se usan principalmente en Android, proporcionan una API consistente en todas las plataformas.

Crear un canal

import {
createChannel,
Importance,
Visibility,
} from '@tauri-apps/plugin-notification';
await createChannel({
id: 'messages',
name: 'Mensajes',
description: 'Notificaciones para nuevos mensajes',
importance: Importance.High,
visibility: Visibility.Private,
lights: true,
lightColor: '#ff0000',
vibration: true,
sound: 'notification_sound',
});

Propiedades de los canales

PropiedadDescripción
idIdentificador único
nameNombre a mostrar
descriptionPropósito del canal
importanceNivel de prioridad (None, Min, Low, Default, High)
visibilityNivel de privacidad (Secret, Private, Public)
lightsHabilitar indicador LED (Android)
lightColorColor del indicador LED (Android)
vibrationHabilitar vibraciones
soundNombre del fichero para sonido personalizado

Gestionar canales

Listar canales existentes:

import { channels } from '@tauri-apps/plugin-notification';
const existingChannels = await channels();

Eliminar un canal:

import { removeChannel } from '@tauri-apps/plugin-notification';
await removeChannel('messages');

Usando canales

Enviar una notificación usando un canal:

import { sendNotification } from '@tauri-apps/plugin-notification';
sendNotification({
title: 'Nuevo mensaje',
body: 'Tienes un nuevo mensaje',
channelId: 'messages',
});

Nota: Crea canales antes de enviar notificaciones que los referencien. Los identificadores de canal inválidos impiden que las notificaciones se muestren.

Consideraciones de seguridad

Aparte de los procedimientos normales de sanitización de la entrada del usuario, actualmente no hay consideraciones de seguridad conocidas.

Default Permission

This permission set configures which notification features are by default exposed.

Granted Permissions

It allows all notification related features.

  • allow-is-permission-granted
  • allow-request-permission
  • allow-notify
  • allow-register-action-types
  • allow-register-listener
  • allow-cancel
  • allow-get-pending
  • allow-remove-active
  • allow-get-active
  • allow-check-permissions
  • allow-show
  • allow-batch
  • allow-list-channels
  • allow-delete-channel
  • allow-create-channel
  • allow-permission-state

Permission Table

Identifier Description

notification:allow-batch

Enables the batch command without any pre-configured scope.

notification:deny-batch

Denies the batch command without any pre-configured scope.

notification:allow-cancel

Enables the cancel command without any pre-configured scope.

notification:deny-cancel

Denies the cancel command without any pre-configured scope.

notification:allow-check-permissions

Enables the check_permissions command without any pre-configured scope.

notification:deny-check-permissions

Denies the check_permissions command without any pre-configured scope.

notification:allow-create-channel

Enables the create_channel command without any pre-configured scope.

notification:deny-create-channel

Denies the create_channel command without any pre-configured scope.

notification:allow-delete-channel

Enables the delete_channel command without any pre-configured scope.

notification:deny-delete-channel

Denies the delete_channel command without any pre-configured scope.

notification:allow-get-active

Enables the get_active command without any pre-configured scope.

notification:deny-get-active

Denies the get_active command without any pre-configured scope.

notification:allow-get-pending

Enables the get_pending command without any pre-configured scope.

notification:deny-get-pending

Denies the get_pending command without any pre-configured scope.

notification:allow-is-permission-granted

Enables the is_permission_granted command without any pre-configured scope.

notification:deny-is-permission-granted

Denies the is_permission_granted command without any pre-configured scope.

notification:allow-list-channels

Enables the list_channels command without any pre-configured scope.

notification:deny-list-channels

Denies the list_channels command without any pre-configured scope.

notification:allow-notify

Enables the notify command without any pre-configured scope.

notification:deny-notify

Denies the notify command without any pre-configured scope.

notification:allow-permission-state

Enables the permission_state command without any pre-configured scope.

notification:deny-permission-state

Denies the permission_state command without any pre-configured scope.

notification:allow-register-action-types

Enables the register_action_types command without any pre-configured scope.

notification:deny-register-action-types

Denies the register_action_types command without any pre-configured scope.

notification:allow-register-listener

Enables the register_listener command without any pre-configured scope.

notification:deny-register-listener

Denies the register_listener command without any pre-configured scope.

notification:allow-remove-active

Enables the remove_active command without any pre-configured scope.

notification:deny-remove-active

Denies the remove_active command without any pre-configured scope.

notification:allow-request-permission

Enables the request_permission command without any pre-configured scope.

notification:deny-request-permission

Denies the request_permission command without any pre-configured scope.

notification:allow-show

Enables the show command without any pre-configured scope.

notification:deny-show

Denies the show command without any pre-configured scope.


© 2025 Tauri Contributors. CC-BY / MIT