diff --git a/src/lib/notifications/soundPlayer.ts b/src/lib/notifications/soundPlayer.ts index 8157a80..455acca 100644 --- a/src/lib/notifications/soundPlayer.ts +++ b/src/lib/notifications/soundPlayer.ts @@ -2,7 +2,7 @@ import { NOTIFICATION_SOUNDS, type NotificationType } from "./types"; class SoundPlayer { private audioCache: Map = new Map(); - private enabled: boolean = true; + private enabled: boolean = false; // Start disabled until config loads private globalVolume: number = 1.0; constructor() { diff --git a/src/lib/stores/notifications.ts b/src/lib/stores/notifications.ts index c001417..64f3599 100644 --- a/src/lib/stores/notifications.ts +++ b/src/lib/stores/notifications.ts @@ -1,22 +1,23 @@ -import { derived } from "svelte/store"; import { configStore } from "./config"; import { soundPlayer } from "$lib/notifications"; -// Sync notification settings with config -export const notificationSettings = derived(configStore.config, ($config) => { - soundPlayer.setEnabled($config.notifications_enabled); - soundPlayer.setGlobalVolume($config.notification_volume); +let unsubscribe: (() => void) | null = null; - return { - enabled: $config.notifications_enabled, - volume: $config.notification_volume, - }; -}); +// Initialize notification settings sync - call this once on app startup +export function initNotificationSync() { + // Prevent duplicate subscriptions + if (unsubscribe) return; -// Helper to update notification settings -export async function updateNotificationSettings(enabled: boolean, volume: number) { - await configStore.updateConfig({ - notifications_enabled: enabled, - notification_volume: volume, + unsubscribe = configStore.config.subscribe(($config) => { + soundPlayer.setEnabled($config.notifications_enabled); + soundPlayer.setGlobalVolume($config.notification_volume); }); } + +// Cleanup function if needed +export function cleanupNotificationSync() { + if (unsubscribe) { + unsubscribe(); + unsubscribe = null; + } +} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index c9d47eb..195de40 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -2,6 +2,7 @@ import { onMount, onDestroy } from "svelte"; import { initializeTauriListeners, cleanupTauriListeners } from "$lib/tauri"; import { configStore, applyTheme } from "$lib/stores/config"; + import { initNotificationSync, cleanupNotificationSync } from "$lib/stores/notifications"; import { conversationsStore } from "$lib/stores/conversations"; import "$lib/notifications/testNotifications"; import Terminal from "$lib/components/Terminal.svelte"; @@ -29,12 +30,16 @@ // Apply saved theme on startup const config = configStore.getConfig(); applyTheme(config.theme); + + // Initialize notification settings sync + initNotificationSync(); } }); onDestroy(() => { if (initialized) { cleanupTauriListeners(); + cleanupNotificationSync(); initialized = false; } });