parent
98e268a98f
commit
470f558ef7
@ -0,0 +1,115 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
|
<title>Tauri Notification Sound Test</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
||||||
|
padding: 20px;
|
||||||
|
max-width: 800px;
|
||||||
|
margin: 0 auto;
|
||||||
|
background-color: #f5f5f5;
|
||||||
|
}
|
||||||
|
.container {
|
||||||
|
background-color: white;
|
||||||
|
padding: 20px;
|
||||||
|
border-radius: 8px;
|
||||||
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||||
|
}
|
||||||
|
h1 {
|
||||||
|
color: #0066cc;
|
||||||
|
}
|
||||||
|
button {
|
||||||
|
background-color: #0066cc;
|
||||||
|
color: white;
|
||||||
|
border: none;
|
||||||
|
padding: 10px 15px;
|
||||||
|
border-radius: 4px;
|
||||||
|
margin: 5px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 0.2s;
|
||||||
|
}
|
||||||
|
button:hover {
|
||||||
|
background-color: #004999;
|
||||||
|
}
|
||||||
|
.info {
|
||||||
|
background-color: #e6f7ff;
|
||||||
|
border-left: 4px solid #0066cc;
|
||||||
|
padding: 10px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
pre {
|
||||||
|
background-color: #f1f1f1;
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 4px;
|
||||||
|
overflow-x: auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
<h1>Tauri Notifications with Sound</h1>
|
||||||
|
|
||||||
|
<div class="info">
|
||||||
|
<p>This demo shows how to use sound with Tauri notifications across different platforms.</p>
|
||||||
|
<p>Make sure you have the notification plugin installed and configured correctly.</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<h2>Test Notifications</h2>
|
||||||
|
<button id="systemSound">Show Notification with System Sound</button>
|
||||||
|
<button id="customSound">Show Notification with Custom Sound</button>
|
||||||
|
<button id="platformSpecific">Show Platform-Specific Sound Notification</button>
|
||||||
|
|
||||||
|
<h2>Example Code</h2>
|
||||||
|
<pre>
|
||||||
|
// Example with system sound (mainly for macOS)
|
||||||
|
await sendNotification({
|
||||||
|
title: 'Notification with System Sound',
|
||||||
|
body: 'This notification uses a system sound on macOS.',
|
||||||
|
sound: 'Ping' // macOS system sound
|
||||||
|
});
|
||||||
|
|
||||||
|
// Example with custom sound file
|
||||||
|
await sendNotification({
|
||||||
|
title: 'Notification with Custom Sound',
|
||||||
|
body: 'This notification uses a custom sound file.',
|
||||||
|
sound: 'notification.wav' // path to your sound file
|
||||||
|
});
|
||||||
|
|
||||||
|
// Example with different sounds based on platform
|
||||||
|
const platform = await import('@tauri-apps/api/os').then(os => os.platform());
|
||||||
|
|
||||||
|
let soundPath;
|
||||||
|
if (platform === 'darwin') {
|
||||||
|
soundPath = 'Blow'; // macOS system sound
|
||||||
|
} else if (platform === 'linux') {
|
||||||
|
soundPath = 'message-new-instant'; // XDG theme sound
|
||||||
|
} else {
|
||||||
|
soundPath = 'notification.wav'; // Custom sound file for Windows
|
||||||
|
}
|
||||||
|
|
||||||
|
await sendNotification({
|
||||||
|
title: 'Platform-specific Sound',
|
||||||
|
body: `This notification uses platform-specific sound settings for ${platform}.`,
|
||||||
|
sound: soundPath
|
||||||
|
});</pre>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script src="sound-notification.js"></script>
|
||||||
|
<script>
|
||||||
|
document.getElementById('systemSound').addEventListener('click', () => {
|
||||||
|
window.showNotificationWithSystemSound();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('customSound').addEventListener('click', () => {
|
||||||
|
window.showNotificationWithCustomSound();
|
||||||
|
});
|
||||||
|
|
||||||
|
document.getElementById('platformSpecific').addEventListener('click', () => {
|
||||||
|
window.showNotificationWithPlatformSpecificSound();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,64 @@
|
|||||||
|
// Copyright 2019-2023 Tauri Programme within The Commons Conservancy
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This file demonstrates how to use sound with notifications in Tauri v2.
|
||||||
|
*
|
||||||
|
* On macOS:
|
||||||
|
* - Sound file should be in your application bundle
|
||||||
|
* - Use the sound name without extension
|
||||||
|
* - Or use system sounds like "Ping", "Basso", "Blow", "Bottle", "Frog", "Funk", "Glass", etc.
|
||||||
|
*
|
||||||
|
* On Linux:
|
||||||
|
* - Use a file path to a sound file (e.g., .wav file)
|
||||||
|
* - Or use XDG theme sounds by name (e.g., "message-new-instant")
|
||||||
|
*
|
||||||
|
* On Windows:
|
||||||
|
* - Use a file path to a sound file (e.g., .wav file)
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { sendNotification } from '@tauri-apps/api/notification';
|
||||||
|
|
||||||
|
// Example with system sound (macOS)
|
||||||
|
async function showNotificationWithSystemSound() {
|
||||||
|
await sendNotification({
|
||||||
|
title: 'Notification with System Sound',
|
||||||
|
body: 'This notification uses a system sound on macOS.',
|
||||||
|
sound: 'Ping' // macOS system sound
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Example with custom sound file
|
||||||
|
async function showNotificationWithCustomSound() {
|
||||||
|
await sendNotification({
|
||||||
|
title: 'Notification with Custom Sound',
|
||||||
|
body: 'This notification uses a custom sound file.',
|
||||||
|
sound: 'notification.wav' // path to your sound file
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Example with different sounds based on platform
|
||||||
|
async function showNotificationWithPlatformSpecificSound() {
|
||||||
|
const platform = await import('@tauri-apps/api/os').then(os => os.platform());
|
||||||
|
|
||||||
|
let soundPath;
|
||||||
|
if (platform === 'darwin') {
|
||||||
|
soundPath = 'Blow'; // macOS system sound
|
||||||
|
} else if (platform === 'linux') {
|
||||||
|
soundPath = 'message-new-instant'; // XDG theme sound
|
||||||
|
} else {
|
||||||
|
soundPath = 'notification.wav'; // Custom sound file for Windows
|
||||||
|
}
|
||||||
|
|
||||||
|
await sendNotification({
|
||||||
|
title: 'Platform-specific Sound',
|
||||||
|
body: `This notification uses platform-specific sound settings for ${platform}.`,
|
||||||
|
sound: soundPath
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export functions to be called from HTML
|
||||||
|
window.showNotificationWithSystemSound = showNotificationWithSystemSound;
|
||||||
|
window.showNotificationWithCustomSound = showNotificationWithCustomSound;
|
||||||
|
window.showNotificationWithPlatformSpecificSound = showNotificationWithPlatformSpecificSound;
|
Loading…
Reference in new issue