Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions src-tauri/src/app/notification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ pub struct NotificationParams {
title: String,
body: String,
icon: String,
#[serde(default)]
#[cfg_attr(not(target_os = "windows"), allow(dead_code))]
silent: bool,
}

#[derive(serde::Serialize)]
Expand Down Expand Up @@ -166,11 +169,24 @@ pub fn send(
}

use tauri_plugin_notification::NotificationExt;
app.notification()
let notification = app
.notification()
.builder()
.title(&params.title)
.body(&params.body)
.icon(&params.icon)
.icon(&params.icon);

// On Windows, omitting sound makes notify-rust emit a silent toast.
// "Default" selects the OS notification sound while honoring Web
// Notification's silent option. Other platforms keep existing behavior.
#[cfg(target_os = "windows")]
let notification = if params.silent {
notification
} else {
notification.sound("Default")
};

notification
.show()
.map_err(|e| format!("Failed to show notification: {e}"))?;

Expand Down
8 changes: 7 additions & 1 deletion src-tauri/src/inject/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -1469,7 +1469,13 @@ document.addEventListener("DOMContentLoaded", () => {
pendingFocusClick = null;

invoke("send_notification", {
params: { id, title: this.title, body: this.body, icon: this.icon },
params: {
id,
title: this.title,
body: this.body,
icon: this.icon,
silent: this.silent,
},
})
.then((outcome) => {
if (liveNotifications.get(id) !== this) {
Expand Down
1 change: 1 addition & 0 deletions tests/unit/event-link-guard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@ describe("event link guard", () => {
title: "Hello",
body: "World",
icon: "https://example.com/icon.png",
silent: false,
},
},
],
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/notification-bridge.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,22 @@ function loadNotificationBridge({
}

describe("notification bridge", () => {
it("forwards silent true, false, and default false to the native command", async () => {
const bridge = loadNotificationBridge();
new bridge.Notification("Default");
new bridge.Notification("Audible", { silent: false });
new bridge.Notification("Quiet", { silent: true });
await bridge.settle();
const notifications = bridge.invokeCalls.filter(
(call) => call.command === "send_notification",
);
expect(notifications.map((call) => call.payload.params.silent)).toEqual([
false,
false,
true,
]);
});

it("preserves native event identity when EventTarget is not constructible", async () => {
const bridge = loadNotificationBridge({
nativeClick: true,
Expand Down
Loading