Timothy Jaeryang Baek 3 月之前
父节点
当前提交
c0b93791dc
共有 2 个文件被更改,包括 13 次插入3 次删除
  1. 10 3
      src/lib/components/NotificationToast.svelte
  2. 3 0
      src/lib/stores/index.ts

+ 10 - 3
src/lib/components/NotificationToast.svelte

@@ -1,5 +1,5 @@
 <script lang="ts">
 <script lang="ts">
-	import { settings } from '$lib/stores';
+	import { settings, playingNotificationSound } from '$lib/stores';
 	import DOMPurify from 'dompurify';
 	import DOMPurify from 'dompurify';
 
 
 	import { marked } from 'marked';
 	import { marked } from 'marked';
@@ -17,8 +17,15 @@
 		}
 		}
 
 
 		if ($settings?.notificationSound ?? true) {
 		if ($settings?.notificationSound ?? true) {
-			const audio = new Audio(`/audio/notification.mp3`);
-			audio.play();
+			if (!$playingNotificationSound) {
+				playingNotificationSound.set(true);
+
+				const audio = new Audio(`/audio/notification.mp3`);
+				audio.play().finally(() => {
+					// Ensure the global state is reset after the sound finishes
+					playingNotificationSound.set(false);
+				});
+			}
 		}
 		}
 	});
 	});
 </script>
 </script>

+ 3 - 0
src/lib/stores/index.ts

@@ -69,6 +69,9 @@ export const temporaryChatEnabled = writable(false);
 export const scrollPaginationEnabled = writable(false);
 export const scrollPaginationEnabled = writable(false);
 export const currentChatPage = writable(1);
 export const currentChatPage = writable(1);
 
 
+
+export const playingNotificationSound = writable(false);
+
 export type Model = OpenAIModel | OllamaModel;
 export type Model = OpenAIModel | OllamaModel;
 
 
 type BaseModel = {
 type BaseModel = {