跳到内容
Tauri

@tauri-apps/plugin-notification

向用户发送 Toast 通知(短暂的自动过期的操作系统窗口元素)。也可以与 Notification Web API 一起使用。

枚举

重要性

枚举成员

Default
Default: 3;

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L287

High
High: 4;

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L288

Low
Low: 2;

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L286

Min
Min: 1;

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L285

None
None: 0;

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L284


ScheduleEvery

枚举成员

Day
Day: "day";

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L159

Hour
Hour: "hour";

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L160

Minute
Minute: "minute";

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L161

Month
Month: "month";

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L156

Second
Second: "second";

iOS 不支持。

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L165

TwoWeeks
TwoWeeks: "twoWeeks";

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L157

Week
Week: "week";

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L158

Year
Year: "year";

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L155


Visibility

枚举成员

Private
Private: 0;

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L293

Public
Public: 1;

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L294

Secret
Secret: -1;

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L292

Schedule

构造函数

new Schedule()
new Schedule(): Schedule
返回值

Schedule

属性

属性类型定义于
atundefined | object来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L169
everyundefined | object来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L184
intervalundefined | object来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L177

方法

at()
static at(
date,
repeating,
allowWhileIdle): Schedule
参数
参数类型默认值
dateDateundefined
repeatingbooleanfalse
allowWhileIdlebooleanfalse
返回值

Schedule

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L192

every()
static every(
kind,
count,
allowWhileIdle): Schedule
参数
参数类型默认值
kindScheduleEveryundefined
countnumberundefined
allowWhileIdlebooleanfalse
返回值

Schedule

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L211

interval()
static interval(interval, allowWhileIdle): Schedule
参数
参数类型默认值
intervalScheduleIntervalundefined
allowWhileIdlebooleanfalse
返回值

Schedule

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L200

接口

Action

属性

属性类型定义于
destructive?boolean来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L239
foreground?boolean来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L238
idstring来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L235
input?boolean来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L240
inputButtonTitle?string来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L241
inputPlaceholder?string来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L242
requiresAuthentication?boolean来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L237
titlestring来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L236

ActionType

属性

属性类型描述定义于
actionsAction[]关联操作的列表来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L253
allowInCarPlay?boolean-来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L256
customDismissAction?boolean-来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L255
hiddenPreviewsBodyPlaceholder?string-来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L254
hiddenPreviewsShowSubtitle?boolean-来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L258
hiddenPreviewsShowTitle?boolean-来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L257
idstring此操作类型的标识符来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L249

ActiveNotification

属性

属性类型定义于
actionTypeId?string来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L278
attachmentsAttachment[]来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L277
body?string来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L272
dataRecord<string, string>来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L275
extraRecord<string, unknown>来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L276
group?string来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L273
groupSummaryboolean来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L274
idnumber来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L269
schedule?Schedule来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L279
sound?string来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L280
tag?string来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L270
title?string来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L271

Attachment

通知的附件。

属性

属性类型描述定义于
idstring附件标识符。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L229
urlstring附件 URL。接受 assetfile 协议。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L231

Channel

属性

属性类型定义于
description?string来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L300
idstring来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L298
importance?重要性来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L305
lightColor?string来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L303
lights?boolean来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L302
namestring来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L299
sound?string来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L301
vibration?boolean来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L304
visibility?Visibility来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L306

Options

发送通知的选项。

Since

2.0.0

属性

属性类型描述定义于
actionTypeId?string为此通知定义操作类型。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L62
attachments?Attachment[]通知附件。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L104
autoCancel?boolean当用户点击通知时自动取消通知。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L120
body?string可选的通知正文。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L44
channelId?stringChannel 的标识符,用于传递此通知。如果通道不存在,则通知不会触发。请使用 listChannels 和 createChannel 确保通道存在。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L36
extra?Record<string, unknown>要存储在通知中的额外有效负载。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L108
group?string用于对多个通知进行分组的标识符。 https://developer.apple.com/documentation/usernotifications/unmutablenotificationcontent/1649872-threadidentifier来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L68
groupSummary?boolean指示系统此通知是 Android 上某个组的摘要。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L72
icon?string通知图标。在 Android 上,图标必须放置在应用程序的 res/drawable 文件夹中。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L90
iconColor?stringAndroid 上的图标颜色。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L100
id?number通知标识符,用于稍后引用此对象。必须是 32 位整数。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L29
inboxLines?string[]要添加到通知的行列表。将通知样式更改为收件箱。不能与 largeBody 一起使用。仅支持最多 5 行。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L84
largeBody?string多行文本。将通知样式更改为大文本。不能与 inboxLines 一起使用。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L54
largeIcon?string通知大图标 (Android)。图标必须放置在应用程序的 res/drawable 文件夹中。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L96
number?number设置此通知在 Android 上代表的项目数。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L132
ongoing?boolean如果为 true,则用户无法在 Android 上关闭该通知。应用程序服务必须管理通知的关闭。它通常用于指示正在进行的后台任务(例如文件下载)或用户正在参与的任务(例如播放音乐)。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L116
schedule?Schedule计划此通知在稍后的时间或固定间隔触发。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L48
silent?boolean更改通知在 iOS 上的呈现方式为静默模式(无徽章、无声音、不列出)。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L124
sound?string声音资源名称。仅在移动设备上可用。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L76
summary?string带有 largeBodyinboxLinesgroupSummary 的通知的详细文本。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L58
titlestring通知标题。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L40
visibility?Visibility通知可见性。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L128

PendingNotification

属性

属性类型定义于
body?string来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L264
idnumber来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L262
scheduleSchedule来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L265
title?string来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L263

ScheduleInterval

属性

属性类型描述定义于
day?number-来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L138
hour?number-来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L149
minute?number-来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L150
month?number-来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L137
second?number-来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L151
weekday?number1 - 星期日 2 - 星期一 3 - 星期二 4 - 星期三 5 - 星期四 6 - 星期五 7 - 星期六来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L148
year?number-来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L136

类型别名

PermissionState

type PermissionState: "granted" | "denied" | "prompt" | "prompt-with-rationale";

来源: undefined

函数

active()

function active(): Promise<ActiveNotification[]>

检索活动通知的列表。

返回值

Promise<ActiveNotification[]>

一个 Promise,解析为活动通知的列表。

示例

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

Since

2.0.0

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L459


cancel()

function cancel(notifications): Promise<void>

使用给定的标识符列表取消待处理的通知。

参数

参数类型
notificationsnumber[]

返回值

Promise<void>

一个 Promise,指示操作的成功或失败。

示例

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

Since

2.0.0

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L425


cancelAll()

function cancelAll(): Promise<void>

取消所有待处理的通知。

返回值

Promise<void>

一个 Promise,指示操作的成功或失败。

示例

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

Since

2.0.0

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L442


channels()

function channels(): Promise<Channel[]>

检索通知渠道的列表。

返回值

Promise<Channel[]>

一个 Promise,解析为通知渠道的列表。

示例

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

Since

2.0.0

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L553


createChannel()

function createChannel(channel): Promise<void>

创建一个通知渠道。

参数

参数类型
channelChannel

返回值

Promise<void>

一个 Promise,指示操作的成功或失败。

示例

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

Since

2.0.0

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L519


isPermissionGranted()

function isPermissionGranted(): Promise<boolean>

检查是否已授予发送通知的权限。

返回值

Promise<boolean>

示例

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

Since

2.0.0

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L319


onAction()

function onAction(cb): Promise<PluginListener>

参数

参数类型
cb(notification) => void

返回值

Promise<PluginListener>

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L563


onNotificationReceived()

function onNotificationReceived(cb): Promise<PluginListener>

参数

参数类型
cb(notification) => void

返回值

Promise<PluginListener>

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L557


pending()

function pending(): Promise<PendingNotification[]>

检索待处理通知的列表。

返回值

Promise<PendingNotification[]>

一个 Promise,解析为待处理通知的列表。

示例

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

Since

2.0.0

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L408


registerActionTypes()

function registerActionTypes(types): Promise<void>

注册用户单击通知时执行的操作。

参数

参数类型
typesActionType[]

返回值

Promise<void>

一个 Promise,指示操作的成功或失败。

示例

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

Since

2.0.0

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L391


removeActive()

function removeActive(notifications): Promise<void>

使用给定的标识符列表移除活动通知。

参数

参数类型
notificationsobject[]

返回值

Promise<void>

一个 Promise,指示操作的成功或失败。

示例

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

Since

2.0.0

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L476


removeAllActive()

function removeAllActive(): Promise<void>

移除所有活动通知。

返回值

Promise<void>

一个 Promise,指示操作的成功或失败。

示例

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

Since

2.0.0

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L495


removeChannel()

function removeChannel(id): Promise<void>

移除具有给定标识符的渠道。

参数

参数类型
idstring

返回值

Promise<void>

一个 Promise,指示操作的成功或失败。

示例

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

Since

2.0.0

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L536


requestPermission()

function requestPermission(): Promise<NotificationPermission>

请求发送通知的权限。

返回值

Promise<NotificationPermission>

一个 Promise,解析为用户是否授予权限。

示例

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

Since

2.0.0

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L342


sendNotification()

function sendNotification(options): void

向用户发送通知。

参数

参数类型
optionsstring | Options

返回值

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

Since

2.0.0

来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L364


© 2025 Tauri Contributors. CC-BY / MIT