跳到內容
Tauri

@tauri-apps/plugin-notification

向您的使用者發送 Toast 通知(簡短的自動過期作業系統視窗元素)。也可以與 Notification Web API 一起使用。

列舉

重要性

列舉成員

預設
Default: 3;

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

High: 4;

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

Low: 2;

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

最小
Min: 1;

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

None: 0;

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


ScheduleEvery

列舉成員

Day: "day";

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

Hour: "hour";

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

Minute: "minute";

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

Month: "month";

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

Second: "second";

iOS 不支援。

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

TwoWeeks
TwoWeeks: "twoWeeks";

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

Week: "week";

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

Year: "year";

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


可見性

列舉成員

私有
Private: 0;

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

公開
Public: 1;

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

秘密
Secret: -1;

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

類別

Schedule

建構函式

new Schedule()
new Schedule(): Schedule
回傳

Schedule

屬性

屬性類型定義於
atundefined | objectSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L169
everyundefined | objectSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L184
intervalundefined | objectSource: 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

Source: 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

Source: 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

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

介面

Action

屬性

屬性類型定義於
destructive?booleanSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L239
foreground?booleanSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L238
idstringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L235
input?booleanSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L240
inputButtonTitle?stringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L241
inputPlaceholder?stringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L242
requiresAuthentication?booleanSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L237
titlestringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L236

ActionType

屬性

屬性類型描述定義於
actionsAction[]關聯動作的列表Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L253
allowInCarPlay?boolean-Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L256
customDismissAction?boolean-Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L255
hiddenPreviewsBodyPlaceholder?string-Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L254
hiddenPreviewsShowSubtitle?boolean-Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L258
hiddenPreviewsShowTitle?boolean-Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L257
idstring此動作類型的識別符Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L249

ActiveNotification

屬性

屬性類型定義於
actionTypeId?stringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L278
attachmentsAttachment[]Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L277
body?stringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L272
dataRecord<string, string>Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L275
extraRecord<string, unknown>Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L276
group?stringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L273
groupSummarybooleanSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L274
idnumberSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L269
schedule?ScheduleSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L279
sound?stringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L280
tag?stringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L270
title?stringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L271

Attachment

通知的附件。

屬性

屬性類型描述定義於
idstring附件識別符。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L229
urlstring附件 URL。接受 assetfile 協定。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L231

Channel

屬性

屬性類型定義於
description?stringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L300
idstringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L298
importance?重要性Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L305
lightColor?stringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L303
lights?booleanSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L302
namestringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L299
sound?stringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L301
vibration?booleanSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L304
visibility?可見性Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L306

Options

發送通知的選項。

Since

2.0.0

屬性

屬性類型描述定義於
actionTypeId?string為此通知定義動作類型。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L62
attachments?Attachment[]通知附件。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L104
autoCancel?boolean當使用者點擊通知時自動取消通知。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L120
body?string可選的通知內文。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L44
channelId?string傳遞此通知的 頻道 識別符。如果頻道不存在,則通知將不會觸發。請使用 listChannels 和 createChannel 確保頻道存在。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L36
extra?Record<string, unknown>要儲存在通知中的額外 payload。Source: 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-threadidentifierSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L68
groupSummary?boolean指示系統此通知是 Android 上群組的摘要。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L72
icon?string通知圖示。在 Android 上,圖示必須放置在應用程式的 res/drawable 資料夾中。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L90
iconColor?stringAndroid 上的圖示顏色。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L100
id?number稍後引用此物件的通知識別符。必須是 32 位元整數。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L29
inboxLines?string[]要新增至通知的行清單。將通知樣式變更為 inbox。不能與 largeBody 一起使用。僅支援最多 5 行。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L84
largeBody?string多行文字。將通知樣式變更為大文字。不能與 inboxLines 一起使用。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L54
largeIcon?string通知大圖示 (Android)。圖示必須放置在應用程式的 res/drawable 資料夾中。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L96
number?number設定此通知在 Android 上代表的項目數量。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L132
ongoing?boolean如果為 true,則使用者無法在 Android 上關閉通知。應用程式服務必須管理通知的關閉。它通常用於指示待處理的背景工作 (例如,檔案下載) 或使用者正在參與的工作 (例如,播放音樂)。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L116
schedule?Schedule排程此通知在稍後時間或固定間隔觸發。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L48
silent?boolean變更通知呈現方式,使其在 iOS 上靜音 (無徽章、無聲音、未列出)。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L124
sound?string聲音資源名稱。僅適用於行動裝置。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L76
summary?string具有 largeBodyinboxLinesgroupSummary 的通知詳細文字。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L58
titlestring通知標題。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L40
visibility?可見性通知可見性。Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L128

PendingNotification

屬性

屬性類型定義於
body?stringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L264
idnumberSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L262
scheduleScheduleSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L265
title?stringSource: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L263

ScheduleInterval

屬性

屬性類型描述定義於
day?number-Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L138
hour?number-Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L149
minute?number-Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L150
month?number-Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L137
second?number-Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L151
weekday?number1 - 星期日 2 - 星期一 3 - 星期二 4 - 星期三 5 - 星期四 6 - 星期五 7 - 星期六Source: https://github.com/tauri-apps/plugins-workspace/blob/v2/plugins/notification/guest-js/index.ts#L148
year?number-Source: 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";

Source: undefined

函式

active()

function active(): Promise<ActiveNotification[]>

取回使用中通知的清單。

回傳

Promise<ActiveNotification[]>

解析為使用中通知清單的 Promise。

範例

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

Since

2.0.0

Source: 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

Source: 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

Source: 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

Source: 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

Source: 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

Source: 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>

Source: 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>

Source: 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

Source: 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

Source: 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

Source: 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

Source: 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

Source: 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

Source: 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

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


© 2025 Tauri Contributors. CC-BY / MIT