Ir al contenido

Notificaciones

GitHubnpmcrates.io
API Reference

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

This plugin requires a Rust version of at least 1.77.2

PlatformLevelNotes
windows

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

linux
macos
android
ios

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

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

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

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!' });
}

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

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,
},
],
},
]);
Propiedad Descripción
id Identificador único de la acción
title Texto a mostrar en la acción del botón
requiresAuthentication Requiere autenticación en el dispositivo
foreground Pone la aplicación en primer plano cuando es accionada
destructive Muestra la acción en rojo en iOS
input Habilita el campo de texto
inputButtonTitle Texto para el botón para enviar el input
inputPlaceholder Texto de ejemplo en el campo de texto

Suscribirse a notificaciones con acciones:

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

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',
},
],
});
Propiedad Descripción
id Identificador único
url URL del contenido usando los protocolos asset:// o file://

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

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.

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',
});
Propiedad Descripción
id Identificador único
name Nombre a mostrar
description Propósito del canal
importance Nivel de prioridad (None, Min, Low, Default, High)
visibility Nivel de privacidad (Secret, Private, Public)
lights Habilitar indicador LED (Android)
lightColor Color del indicador LED (Android)
vibration Habilitar vibraciones
sound Nombre del fichero para sonido personalizado

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');

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.

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.

This default permission set includes the following:

  • 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.


© 2026 Tauri Contributors. CC-BY / MIT