generated from nhcarrigan/template
fix: live settings updates
This commit is contained in:
@@ -2,7 +2,7 @@ import { NOTIFICATION_SOUNDS, type NotificationType } from "./types";
|
|||||||
|
|
||||||
class SoundPlayer {
|
class SoundPlayer {
|
||||||
private audioCache: Map<NotificationType, HTMLAudioElement> = new Map();
|
private audioCache: Map<NotificationType, HTMLAudioElement> = new Map();
|
||||||
private enabled: boolean = true;
|
private enabled: boolean = false; // Start disabled until config loads
|
||||||
private globalVolume: number = 1.0;
|
private globalVolume: number = 1.0;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|||||||
@@ -1,22 +1,23 @@
|
|||||||
import { derived } from "svelte/store";
|
|
||||||
import { configStore } from "./config";
|
import { configStore } from "./config";
|
||||||
import { soundPlayer } from "$lib/notifications";
|
import { soundPlayer } from "$lib/notifications";
|
||||||
|
|
||||||
// Sync notification settings with config
|
let unsubscribe: (() => void) | null = null;
|
||||||
export const notificationSettings = derived(configStore.config, ($config) => {
|
|
||||||
soundPlayer.setEnabled($config.notifications_enabled);
|
|
||||||
soundPlayer.setGlobalVolume($config.notification_volume);
|
|
||||||
|
|
||||||
return {
|
// Initialize notification settings sync - call this once on app startup
|
||||||
enabled: $config.notifications_enabled,
|
export function initNotificationSync() {
|
||||||
volume: $config.notification_volume,
|
// Prevent duplicate subscriptions
|
||||||
};
|
if (unsubscribe) return;
|
||||||
});
|
|
||||||
|
|
||||||
// Helper to update notification settings
|
unsubscribe = configStore.config.subscribe(($config) => {
|
||||||
export async function updateNotificationSettings(enabled: boolean, volume: number) {
|
soundPlayer.setEnabled($config.notifications_enabled);
|
||||||
await configStore.updateConfig({
|
soundPlayer.setGlobalVolume($config.notification_volume);
|
||||||
notifications_enabled: enabled,
|
|
||||||
notification_volume: volume,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cleanup function if needed
|
||||||
|
export function cleanupNotificationSync() {
|
||||||
|
if (unsubscribe) {
|
||||||
|
unsubscribe();
|
||||||
|
unsubscribe = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
import { onMount, onDestroy } from "svelte";
|
import { onMount, onDestroy } from "svelte";
|
||||||
import { initializeTauriListeners, cleanupTauriListeners } from "$lib/tauri";
|
import { initializeTauriListeners, cleanupTauriListeners } from "$lib/tauri";
|
||||||
import { configStore, applyTheme } from "$lib/stores/config";
|
import { configStore, applyTheme } from "$lib/stores/config";
|
||||||
|
import { initNotificationSync, cleanupNotificationSync } from "$lib/stores/notifications";
|
||||||
import { conversationsStore } from "$lib/stores/conversations";
|
import { conversationsStore } from "$lib/stores/conversations";
|
||||||
import "$lib/notifications/testNotifications";
|
import "$lib/notifications/testNotifications";
|
||||||
import Terminal from "$lib/components/Terminal.svelte";
|
import Terminal from "$lib/components/Terminal.svelte";
|
||||||
@@ -29,12 +30,16 @@
|
|||||||
// Apply saved theme on startup
|
// Apply saved theme on startup
|
||||||
const config = configStore.getConfig();
|
const config = configStore.getConfig();
|
||||||
applyTheme(config.theme);
|
applyTheme(config.theme);
|
||||||
|
|
||||||
|
// Initialize notification settings sync
|
||||||
|
initNotificationSync();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onDestroy(() => {
|
onDestroy(() => {
|
||||||
if (initialized) {
|
if (initialized) {
|
||||||
cleanupTauriListeners();
|
cleanupTauriListeners();
|
||||||
|
cleanupNotificationSync();
|
||||||
initialized = false;
|
initialized = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user