forked from coracle/flotilla
Fix async bug and add sound component for notification sound
This commit is contained in:
@@ -77,7 +77,7 @@
|
|||||||
$showUnreadBadge = !$showUnreadBadge
|
$showUnreadBadge = !$showUnreadBadge
|
||||||
|
|
||||||
if (!$showUnreadBadge) {
|
if (!$showUnreadBadge) {
|
||||||
clearBadges()
|
await clearBadges()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import {onMount} from "svelte"
|
||||||
|
import {playAlertSound} from "@app/core/state"
|
||||||
|
import {notifications} from "../util/notifications"
|
||||||
|
|
||||||
|
let audioElement: HTMLAudioElement
|
||||||
|
|
||||||
|
let notificationCount = $state($notifications.size)
|
||||||
|
|
||||||
|
const playSound = () => {
|
||||||
|
if ($playAlertSound) {
|
||||||
|
audioElement.play()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
audioElement.load()
|
||||||
|
|
||||||
|
notifications.subscribe(notifications => {
|
||||||
|
if (notifications.size > notificationCount) {
|
||||||
|
playSound()
|
||||||
|
}
|
||||||
|
|
||||||
|
notificationCount = notifications.size
|
||||||
|
})
|
||||||
|
})
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<audio bind:this={audioElement} src="/new-notification-3-398649.mp3"></audio>
|
||||||
@@ -156,6 +156,8 @@ export const notifications = derived(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
paths.add("pls")
|
||||||
|
|
||||||
return paths
|
return paths
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@@ -165,14 +167,14 @@ export const badgeCount = derived(notifications, notifications => {
|
|||||||
return notifications.size
|
return notifications.size
|
||||||
})
|
})
|
||||||
|
|
||||||
export const handleBadgeCountChanges = (count: number) => {
|
export const handleBadgeCountChanges = async (count: number) => {
|
||||||
if (get(showUnreadBadge)) {
|
if (get(showUnreadBadge)) {
|
||||||
Badge.set({count})
|
await Badge.set({count})
|
||||||
} else {
|
} else {
|
||||||
clearBadges()
|
await clearBadges()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const clearBadges = () => {
|
export const clearBadges = async () => {
|
||||||
Badge.clear()
|
await Badge.clear()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -110,6 +110,7 @@
|
|||||||
import * as notifications from "@app/util/notifications"
|
import * as notifications from "@app/util/notifications"
|
||||||
import * as appState from "@app/core/state"
|
import * as appState from "@app/core/state"
|
||||||
import {badgeCount, handleBadgeCountChanges} from "@app/util/notifications"
|
import {badgeCount, handleBadgeCountChanges} from "@app/util/notifications"
|
||||||
|
import NewNotificationSound from "@src/app/components/NewNotificationSound.svelte"
|
||||||
|
|
||||||
// Migration: old nostrtalk instance used different sessions
|
// Migration: old nostrtalk instance used different sessions
|
||||||
if ($session && !$signer) {
|
if ($session && !$signer) {
|
||||||
@@ -508,5 +509,6 @@
|
|||||||
</AppContainer>
|
</AppContainer>
|
||||||
<ModalContainer />
|
<ModalContainer />
|
||||||
<div class="tippy-target"></div>
|
<div class="tippy-target"></div>
|
||||||
|
<NewNotificationSound />
|
||||||
</div>
|
</div>
|
||||||
{/await}
|
{/await}
|
||||||
|
|||||||
Reference in New Issue
Block a user