feat(notification): report actions on desktop (#3671)

* feat(notification): report actions on desktop

A click on a notification (tap) or on one of the actions of its action
type now reaches the JavaScript onAction listeners on desktop, and the
new Rust Notification::on_action on every platform. On Linux and the
BSDs the click comes from the notification server's ActionInvoked
signal; on Windows and macOS from notify-rust's wait_for_response,
which needs notify-rust 4.18.

register_action_types, remove_active (Linux and the BSDs) and the
listener commands are implemented for desktop, so they no longer fail
with "command not found".

The api example sends a notification with two actions and shows the
action it hears.

Closes #2150, closes #1903.

* fix(notification): complete desktop action API

* cleanup

---------

Co-authored-by: Haex <hexxx@ok.de>
Co-authored-by: Lucas Nogueira <lucas@tauri.app>
This commit is contained in:
authored and GitHub committed 2026-10-08 14:14:19 -03:00
1 parent 116f7f8239
commit 46381516b7
10 files changed
+868 -108

No files matched your search

+39 -1
View File
@@ -1,8 +1,43 @@
<script>
import { sendNotification } from '@tauri-apps/plugin-notification'
import { onDestroy, onMount } from 'svelte'
import {
onAction,
registerActionTypes,
sendNotification
} from '@tauri-apps/plugin-notification'
export let onMessage
let sound = ''
let actionListener
onMount(async () => {
await registerActionTypes([
{
id: 'api-example',
actions: [
{ id: 'open', title: 'Open' },
{ id: 'later', title: 'Later' }
]
}
]).catch(onMessage)
// a click on the notification arrives as `tap`, a button as its id
actionListener = await onAction((event) => {
onMessage(
`Action "${event.actionId}" on notification ${event.notification?.id}`
)
}).catch(onMessage)
})
onDestroy(() => actionListener?.unregister())
function sendActionNotification() {
sendNotification({
id: Math.floor(Math.random() * 100000),
title: 'Notification with actions',
body: 'Click it or one of its buttons',
actionTypeId: 'api-example'
})
}
// send the notification directly
// the backend is responsible for checking the permission
@@ -42,3 +77,6 @@
<button class="btn" id="notification" on:click={triggerNotification}>
Send test notification
</button>
<button class="btn" id="notification-actions" on:click={sendActionNotification}>
Send notification with actions
</button>