跳转到内容
Tauri

@tauri-apps/plugin-notification

向用户发送 toast 通知(简短的自操作系统窗口元素)。

枚举

重要性

枚举成员

默认
Default: 3;

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

High: 4;

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

Low: 2;

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

最小
Min: 1;

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

None: 0;

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


按计划执行

枚举成员

每天
Day: "day";

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

每小时
Hour: "hour";

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

每分钟
Minute: "minute";

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

每月
Month: "month";

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

每秒
Second: "second";

在 iOS 上不受支持。

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

两周
TwoWeeks: "twoWeeks";

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

每周
Week: "week";

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

每年
Year: "year";

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


可见性

枚举成员

私有
Private: 0;

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

公共
Public: 1;

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

保密
Secret: -1;

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

计划

构造函数

new Schedule()
new 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
参数
参数类型默认值
date日期undefined
重复布尔型false
allowWhileIdle布尔型false
返回

计划

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

every()
static every(
kind,
count,
allowWhileIdle): Schedule
参数
参数类型默认值
kind按计划执行undefined
count数字undefined
allowWhileIdle布尔型false
返回

计划

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

interval()
static interval(interval, allowWhileIdle): Schedule
参数
参数类型默认值
interval计划间隔undefined
allowWhileIdle布尔型false
返回

计划

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

接口

动作

属性

属性类型定义于
destructive?布尔型来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L239
foreground?布尔型来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L238
id字符串来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L235
input?布尔型来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L240
inputButtonTitle?字符串来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L241
inputPlaceholder?字符串来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L242
requiresAuthentication?布尔型来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L237
title字符串来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L236

动作类型

属性

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

活动通知

属性

属性类型定义于
actionTypeId?字符串来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L278
attachments附件[]来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L277
body?字符串来源: 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?字符串来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L273
groupSummary布尔型来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L274
id数字来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L269
schedule?计划来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L279
sound?字符串来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L280
tag?字符串来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L270
title?字符串来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L271

附件

通知的附件。

属性

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

频道

属性

属性类型定义于
description?字符串来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L300
id字符串来源: 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?字符串来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L303
lights?布尔型来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L302
name字符串来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L299
sound?字符串来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L301
vibration?布尔型来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L304
visibility?可见性来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L306

选项

发送通知的选项。

自从

2.0.0

属性

属性类型描述定义于
actionTypeId?字符串为该通知定义操作类型。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L62
attachments?附件[]通知附件。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L104
autoCancel?布尔型当用户点击时,自动取消通知。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L120
body?字符串可选的通知内容。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L44
channelId?字符串传送该通知的渠道标识符。如果渠道不存在,通知将不会触发。请确保渠道存在,可以使用listChannelscreateChannel来创建。来源: 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?字符串用于将多个通知分组使用的标识符。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?布尔型指示系统,此通知是Android上某一组的摘要。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L72
icon?字符串通知图标。在Android中,图标必须放置在应用的res/drawable文件夹中。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L90
iconColor?字符串Android上的图标颜色。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L100
id?数字此通知标识符供以后引用该对象使用。必须是32位整数。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L29
inboxLines?字符串[]要添加到通知中的行列表。更改通知样式为收件箱样式。不能与largeBody一起使用。仅支持最多5行。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L84
largeBody?字符串多行文本。更改通知样式为大字体。不能与inboxLines一起使用。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L54
largeIcon?字符串通知大图标(Android)。图标必须放置在应用的res/drawable文件夹中。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L96
number?数字为Android上此通知所表示的项目数量设置。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L132
ongoing?布尔型如果为真,用户无法在Android上取消此通知。应用服务必须管理通知的取消。通常用于指示挂起的后台任务(例如文件下载)或用户正在参与的任务(例如播放音乐)。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L116
schedule?计划安排此通知在稍后时间或固定间隔触发。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L48
silent?布尔型将iOS的通知呈现方式更改为静音(无徽章,无声音,未列出)。来源: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L124
sound?字符串声音资源名称。仅在移动设备上可用。来源https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L76
summary?字符串带有 largeBodyinboxLinesgroupSummary 的通知的详细文本。来源https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L58
title字符串通知标题。来源https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L40
visibility?可见性通知可见性。来源https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L128

挂起通知

属性

属性类型定义于
body?字符串来源https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L264
id数字来源https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L262
schedule计划来源https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L265
title?字符串来源https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L263

计划间隔

属性

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

类型别名

权限状态

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

来源: undefined

函数

活跃状态()

function active(): Promise<ActiveNotification[]>

检索活动通知的列表。

返回

Promise<ActiveNotification[]>

一个解析为活动通知列表的承诺。

示例

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

自从

2.0.0

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


取消()

function cancel(notifications): Promise<void>

取消具有给定标识符列表的挂起通知。

参数

参数类型
notifications数字[]

返回

Promise<void>

一个承诺,表示操作的成功或失败。

示例

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

自从

2.0.0

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


取消全部()

function cancelAll(): Promise<void>

取消所有挂起的通知。

返回

Promise<void>

一个承诺,表示操作的成功或失败。

示例

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

自从

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[]>

一个解析为通知通道列表的承诺。

示例

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

自从

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>

创建一个通知通道。

参数

参数类型
通道频道

返回

Promise<void>

一个承诺,表示操作的成功或失败。

示例

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

来源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();

自从

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[]>

一个解析为挂起通知列表的承诺。

示例

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

自从

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>

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

参数

参数类型
types动作类型[]

返回

Promise<void>

一个承诺,表示操作的成功或失败。

示例

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

自从

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>

一个承诺,表示操作的成功或失败。

示例

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

自从

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>

一个承诺,表示操作的成功或失败。

示例

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

自从

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>

移除给定标识符的通道。

参数

参数类型
id字符串

返回

Promise<void>

一个承诺,表示操作的成功或失败。

示例

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

自从

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>

一个解析为用户是否授予了权限的承诺。

示例

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

自从

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

自从

2.0.0

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


© 2025 Tauri 贡献者. CC-BY / MIT