Skip to content

notification

Install the required plugin:

Terminal window
tynd add notification
import { notification } from "@tynd/plugin-notification/client";

Show a native notification. Resolves with its id, which every event of that notification carries.

const id = await notification.send("Build Complete", { body: "0 errors." });
Option Type Default Description
body string "" Body text (up to 4096 chars, like title).
icon string app icon Absolute path to a PNG / ICO shown as the app logo.
image string — Absolute path to a larger image.
sound string system default Sound name: default, Mail, Glass, … (letters, digits, ., _, -).
silent boolean false Play no sound.
urgency "low" | "normal" | "critical" "normal" Linux sets the D-Bus urgency; Windows shows critical as an urgent toast.
timeout "default" | "never" | number "default" Time on screen in ms, or until dismissed. Windows maps a number to a short (up to 7 s) or long toast.
actions { id, label }[] — Up to 5 buttons. id: 1–64 letters, digits, _, -.
category string — Use the buttons registered with registerActions. Exclusive with actions.
reply { placeholder?, buttonLabel? } — Inline reply field; the text arrives in onReply.

icon and image paths go through the fs scope of the security policy.

await notification.registerActions("invite", [
{ id: "accept", label: "Accept" },
{ id: "decline", label: "Decline" },
]);
await notification.send("Meeting at 3 pm", { category: "invite" });
notification.onAction(({ id, action }) => {
if (action === "accept") acceptInvite(id);
});

registerActions(category, actions) registers or replaces the set (up to 64 categories). On macOS a single action is a button; two or more become a dropdown.

Method Payload Fires when
onClick(handler) { id } The user clicks the notification body.
onAction(handler) { id, action } The user clicks an action button.
onReply(handler) { id, text } The user sends an inline reply.
onClose(handler) { id, reason } The notification closes: reason is "user", "timeout", "app" or "unknown".

Each returns an unsubscribe function. Events reach the webview that sent the notification (or the backend once that webview is gone).

schedule(title, delayMs, opts?): Promise<number>

Section titled “schedule(title, delayMs, opts?): Promise<number>”

Fire after delayMs ms, with the same options as send. Returns an id that cancel() aborts while pending; once shown, events and remove() use the same id.

const id = await notification.schedule("Reminder", 60_000, { body: "Stand up!" });
// later
await notification.cancel(id); // true if the timer was still pending

A scheduled notification belongs to the webview that scheduled it: another webview cannot cancel it (the call returns false). When that webview reloads, navigates or closes the notification still fires and is handed to the backend, so only the backend and app-local webviews can cancel it. A notification scheduled by a call that finishes after that is owned by the backend from the start.

const shown = await notification.getDelivered(); // { id, title, body }[]
await notification.remove(shown[0].id); // false for an unknown id
const count = await notification.removeAll();

getDelivered lists the notifications still on screen or in the notification center (at most the 256 latest). All three only see notifications owned by the calling webview; the backend and app-local webviews see the ones handed over by closed webviews.

checkPermission() / requestPermission(): Promise<NotificationPermission>

Section titled “checkPermission() / requestPermission(): Promise<NotificationPermission>”

Resolves "denied" when notifications are turned off for the app in Windows settings, "granted" otherwise. Desktop OSes show no permission prompt, so requestPermission returns the current state; both exist for web-API parity.

if ((await notification.checkPermission()) === "granted") {
await notification.send("hi");
}
Feature Windows macOS Linux
Title, body, icon, image, sound, silent ✓ ✓ (icon and image share one slot) ✓
urgency ✓ (critical only) ignored ✓
timeout ✓ (short / long / until dismissed) ignored ✓ (server-dependent)
Actions and categories ✓ ✓ ✓
Inline reply ✓ ✓ (not with actions) rejects (“not supported on linux”)
onClick, onAction, onClose ✓ ✓ (onClose on the close button) ✓
getDelivered, remove, removeAll ✓ rejects (“not supported on macos”) ✓
Permission state ✓ always "granted" always "granted"
  • tray — persistent tray icon + menu.