Move notification sound and badge settings to settings store

This commit is contained in:
Matthew Remmel
2025-09-24 13:50:01 -04:00
committed by hodlbod
parent e48d1e0e59
commit c6641dba31
4 changed files with 14 additions and 23 deletions
+6 -7
View File
@@ -16,8 +16,7 @@
deriveAlertStatus, deriveAlertStatus,
userInboxRelays, userInboxRelays,
getAlertFeed, getAlertFeed,
showUnreadBadge, userSettingsValues,
playAlertSound,
} from "@app/core/state" } from "@app/core/state"
import {deleteAlert, createDmAlert} from "@app/core/commands" import {deleteAlert, createDmAlert} from "@app/core/commands"
import {clearBadges} from "../util/notifications" import {clearBadges} from "../util/notifications"
@@ -74,15 +73,15 @@
} }
const onShowBadgeOnUnreadToggle = async () => { const onShowBadgeOnUnreadToggle = async () => {
$showUnreadBadge = !$showUnreadBadge $userSettingsValues.show_notifications_badge = !$userSettingsValues.show_notifications_badge
if (!$showUnreadBadge) { if (!$userSettingsValues.show_notifications_badge) {
await clearBadges() await clearBadges()
} }
} }
const onDirectMessagesNotificationSoundToggle = async () => { const onDirectMessagesNotificationSoundToggle = async () => {
$playAlertSound = !$playAlertSound $userSettingsValues.play_notification_sound = !$userSettingsValues.play_notification_sound
} }
let directMessagesNotificationToggle: HTMLInputElement let directMessagesNotificationToggle: HTMLInputElement
@@ -123,7 +122,7 @@
<input <input
type="checkbox" type="checkbox"
class="toggle toggle-primary" class="toggle toggle-primary"
checked={Boolean($showUnreadBadge)} checked={Boolean($userSettingsValues.show_notifications_badge)}
oninput={onShowBadgeOnUnreadToggle} /> oninput={onShowBadgeOnUnreadToggle} />
</div> </div>
<div class="flex justify-between"> <div class="flex justify-between">
@@ -131,7 +130,7 @@
<input <input
type="checkbox" type="checkbox"
class="toggle toggle-primary" class="toggle toggle-primary"
checked={Boolean($playAlertSound)} checked={Boolean($userSettingsValues.play_notification_sound)}
oninput={onDirectMessagesNotificationSoundToggle} /> oninput={onDirectMessagesNotificationSoundToggle} />
</div> </div>
{#if $dmStatus} {#if $dmStatus}
@@ -1,6 +1,6 @@
<script lang="ts"> <script lang="ts">
import {onMount} from "svelte" import {onMount} from "svelte"
import {playAlertSound} from "@app/core/state" import {userSettingsValues} from "@app/core/state"
import {notifications} from "../util/notifications" import {notifications} from "../util/notifications"
let audioElement: HTMLAudioElement let audioElement: HTMLAudioElement
@@ -8,7 +8,7 @@
let notificationCount = $state($notifications.size) let notificationCount = $state($notifications.size)
const playSound = () => { const playSound = () => {
if ($playAlertSound) { if ($userSettingsValues.play_notification_sound) {
audioElement.play() audioElement.play()
} }
} }
+4 -12
View File
@@ -338,6 +338,8 @@ export type SettingsValues = {
report_errors: boolean report_errors: boolean
send_delay: number send_delay: number
font_size: number font_size: number
play_notification_sound: boolean
show_notifications_badge: boolean
} }
export type Settings = { export type Settings = {
@@ -353,6 +355,8 @@ export const defaultSettings = {
report_errors: true, report_errors: true,
send_delay: 0, send_delay: 0,
font_size: 1, font_size: 1,
play_notification_sound: true,
show_notifications_badge: true,
} }
export const settings = deriveEventsMapped<Settings>(repository, { export const settings = deriveEventsMapped<Settings>(repository, {
@@ -425,18 +429,6 @@ export const dmAlert = derived(alerts, $alerts =>
}), }),
) )
export const showUnreadBadge = synced({
key: "showUnreadBadge",
defaultValue: true,
storage: preferencesStorageProvider,
})
export const playAlertSound = synced({
key: "playAlertSound",
defaultValue: true,
storage: preferencesStorageProvider,
})
// Alert Statuses // Alert Statuses
export type AlertStatus = { export type AlertStatus = {
+2 -2
View File
@@ -18,7 +18,7 @@ import {
getUrlsForEvent, getUrlsForEvent,
userRoomsByUrl, userRoomsByUrl,
repositoryStore, repositoryStore,
showUnreadBadge, userSettingsValues,
} from "@app/core/state" } from "@app/core/state"
import {preferencesStorageProvider} from "@src/lib/storage" import {preferencesStorageProvider} from "@src/lib/storage"
import {Badge} from "@capawesome/capacitor-badge" import {Badge} from "@capawesome/capacitor-badge"
@@ -168,7 +168,7 @@ export const badgeCount = derived(notifications, notifications => {
}) })
export const handleBadgeCountChanges = async (count: number) => { export const handleBadgeCountChanges = async (count: number) => {
if (get(showUnreadBadge)) { if (get(userSettingsValues).show_notifications_badge) {
await Badge.set({count}) await Badge.set({count})
} else { } else {
await clearBadges() await clearBadges()