2025-09-24 17:32:55 +00:00
|
|
|
<script lang="ts">
|
|
|
|
|
import {onMount} from "svelte"
|
2026-09-02 22:59:56 +00:00
|
|
|
import {Capacitor} from "@capacitor/core"
|
2026-06-08 22:33:38 +00:00
|
|
|
import {notificationSettings} from "@app/settings"
|
2026-06-08 21:14:40 +00:00
|
|
|
import {onNotification} from "@app/push"
|
2025-09-24 17:32:55 +00:00
|
|
|
|
|
|
|
|
let audioElement: HTMLAudioElement
|
|
|
|
|
|
2025-09-26 15:31:04 +00:00
|
|
|
let enabled = $state(false)
|
|
|
|
|
|
2026-01-28 22:08:15 +00:00
|
|
|
const onVisibilityChange = () => {
|
2025-09-26 15:31:04 +00:00
|
|
|
if (document.hidden) {
|
|
|
|
|
enabled = true
|
|
|
|
|
} else {
|
|
|
|
|
enabled = false
|
|
|
|
|
}
|
2026-01-28 22:08:15 +00:00
|
|
|
}
|
2025-10-06 18:23:19 +00:00
|
|
|
|
2026-01-07 00:52:15 +00:00
|
|
|
onMount(() => {
|
2026-09-02 22:59:56 +00:00
|
|
|
if (Capacitor.isNativePlatform()) return
|
|
|
|
|
|
2026-01-07 00:52:15 +00:00
|
|
|
audioElement.load()
|
2026-01-22 22:23:46 +00:00
|
|
|
|
2026-01-28 22:08:15 +00:00
|
|
|
document.addEventListener("visibilitychange", onVisibilityChange)
|
|
|
|
|
|
2026-01-22 22:23:46 +00:00
|
|
|
const unsubscribe = onNotification(() => {
|
2026-01-28 22:08:15 +00:00
|
|
|
if (enabled && $notificationSettings.sound) {
|
2026-01-22 22:23:46 +00:00
|
|
|
audioElement?.play()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2026-01-28 22:08:15 +00:00
|
|
|
return () => {
|
|
|
|
|
unsubscribe()
|
|
|
|
|
document.removeEventListener("visibilitychange", onVisibilityChange)
|
|
|
|
|
}
|
2025-09-24 17:32:55 +00:00
|
|
|
})
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<audio bind:this={audioElement} src="/new-notification-3-398649.mp3"></audio>
|