Interface INotification

interface INotification {
    active: () => Promise<ActiveNotification[]>;
    cancel: (notifications: number[]) => Promise<void>;
    cancelAll: () => Promise<void>;
    channels: () => Promise<Channel[]>;
    createChannel: (channel: Channel) => Promise<void>;
    isPermissionGranted: () => Promise<boolean>;
    onAction: (cb: (notification: Options) => void) => Promise<PluginListener>;
    onNotificationReceived: (
        cb: (notification: Options) => void,
    ) => Promise<PluginListener>;
    pending: () => Promise<PendingNotification[]>;
    registerActionTypes: (types: ActionType[]) => Promise<void>;
    removeActive: (
        notifications: { id: number; tag?: string }[],
    ) => Promise<void>;
    removeAllActive: () => Promise<void>;
    removeChannel: (id: string) => Promise<void>;
    requestPermission: () => Promise<NotificationPermission>;
    sendNotification: (options: string | Options) => void;
}

Properties

active: () => Promise<ActiveNotification[]>

Type declaration

    • (): Promise<ActiveNotification[]>
    • Retrieves the list of active notifications.

      Returns Promise<ActiveNotification[]>

      A promise resolving to the list of active notifications.

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

      2.0.0

cancel: (notifications: number[]) => Promise<void>

Type declaration

    • (notifications: number[]): Promise<void>
    • Cancels the pending notifications with the given list of identifiers.

      Parameters

      • notifications: number[]

      Returns Promise<void>

      A promise indicating the success or failure of the operation.

      import { cancel } from '@tauri-apps/plugin-notification';
      await cancel([-34234, 23432, 4311]);

      2.0.0

cancelAll: () => Promise<void>

Type declaration

    • (): Promise<void>
    • Cancels all pending notifications.

      Returns Promise<void>

      A promise indicating the success or failure of the operation.

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

      2.0.0

channels: () => Promise<Channel[]>

Type declaration

    • (): Promise<Channel[]>
    • Retrieves the list of notification channels.

      Returns Promise<Channel[]>

      A promise resolving to the list of notification channels.

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

      2.0.0

createChannel: (channel: Channel) => Promise<void>

Type declaration

    • (channel: Channel): Promise<void>
    • Creates a notification channel.

      Parameters

      • channel: Channel

      Returns Promise<void>

      A promise indicating the success or failure of the operation.

      import { createChannel, Importance, Visibility } from '@tauri-apps/plugin-notification';
      await createChannel({
      id: 'new-messages',
      name: 'New Messages',
      lights: true,
      vibration: true,
      importance: Importance.Default,
      visibility: Visibility.Private
      });

      2.0.0

isPermissionGranted: () => Promise<boolean>

Type declaration

    • (): Promise<boolean>
    • Checks if the permission to send notifications is granted.

      Returns Promise<boolean>

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

      2.0.0

onAction: (cb: (notification: Options) => void) => Promise<PluginListener>
onNotificationReceived: (
    cb: (notification: Options) => void,
) => Promise<PluginListener>
pending: () => Promise<PendingNotification[]>

Type declaration

    • (): Promise<PendingNotification[]>
    • Retrieves the list of pending notifications.

      Returns Promise<PendingNotification[]>

      A promise resolving to the list of pending notifications.

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

      2.0.0

registerActionTypes: (types: ActionType[]) => Promise<void>

Type declaration

    • (types: ActionType[]): Promise<void>
    • Register actions that are performed when the user clicks on the notification.

      Parameters

      • types: ActionType[]

      Returns Promise<void>

      A promise indicating the success or failure of the operation.

      import { registerActionTypes } from '@tauri-apps/plugin-notification';
      await registerActionTypes([{
      id: 'tauri',
      actions: [{
      id: 'my-action',
      title: 'Settings'
      }]
      }])

      2.0.0

removeActive: (notifications: { id: number; tag?: string }[]) => Promise<void>

Type declaration

    • (notifications: { id: number; tag?: string }[]): Promise<void>
    • Removes the active notifications with the given list of identifiers.

      Parameters

      • notifications: { id: number; tag?: string }[]

      Returns Promise<void>

      A promise indicating the success or failure of the operation.

      import { cancel } from '@tauri-apps/plugin-notification';
      await cancel([-34234, 23432, 4311])

      2.0.0

removeAllActive: () => Promise<void>

Type declaration

    • (): Promise<void>
    • Removes all active notifications.

      Returns Promise<void>

      A promise indicating the success or failure of the operation.

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

      2.0.0

removeChannel: (id: string) => Promise<void>

Type declaration

    • (id: string): Promise<void>
    • Removes the channel with the given identifier.

      Parameters

      • id: string

      Returns Promise<void>

      A promise indicating the success or failure of the operation.

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

      2.0.0

requestPermission: () => Promise<NotificationPermission>

Type declaration

    • (): Promise<NotificationPermission>
    • Requests the permission to send notifications.

      Returns Promise<NotificationPermission>

      A promise resolving to whether the user granted the permission or not.

      import { isPermissionGranted, requestPermission } from '@tauri-apps/plugin-notification';
      let permissionGranted = await isPermissionGranted();
      if (!permissionGranted) {
      const permission = await requestPermission();
      permissionGranted = permission === 'granted';
      }

      2.0.0

sendNotification: (options: string | Options) => void

Type declaration

    • (options: string | Options): void
    • Sends a notification to the user.

      Parameters

      • options: string | Options

      Returns void

      import { isPermissionGranted, requestPermission, sendNotification } from '@tauri-apps/plugin-notification';
      let permissionGranted = await isPermissionGranted();
      if (!permissionGranted) {
      const permission = await requestPermission();
      permissionGranted = permission === 'granted';
      }
      if (permissionGranted) {
      sendNotification('Tauri is awesome!');
      sendNotification({ title: 'TAURI', body: 'Tauri is awesome!' });
      }

      2.0.0