From e34b4525094880332cb88e09da12d2054ef79cfa Mon Sep 17 00:00:00 2001 From: "Timothy J. Baek" Date: Thu, 14 Dec 2023 15:32:43 -0800 Subject: [PATCH] feat: response notification --- src/lib/components/chat/SettingsModal.svelte | 103 +++++++++++++------ src/routes/(app)/+page.svelte | 15 +++ src/routes/(app)/c/[id]/+page.svelte | 15 +++ 3 files changed, 100 insertions(+), 33 deletions(-) diff --git a/src/lib/components/chat/SettingsModal.svelte b/src/lib/components/chat/SettingsModal.svelte index fe17475e..fb1f49f6 100644 --- a/src/lib/components/chat/SettingsModal.svelte +++ b/src/lib/components/chat/SettingsModal.svelte @@ -49,8 +49,10 @@ let pullProgress = null; // Addons + let responseNotification = false; let titleAutoGenerate = true; let speechAutoSend = false; + let gravatarEmail = ''; let OPENAI_API_KEY = ''; @@ -108,6 +110,19 @@ saveSettings({ titleAutoGenerate: titleAutoGenerate }); }; + const toggleResponseNotification = async () => { + const permission = await Notification.requestPermission(); + + if (permission === 'granted') { + responseNotification = !responseNotification; + saveSettings({ responseNotification: responseNotification }); + } else { + toast.error( + 'Response notifications cannot be activated as the website permissions have been denied. Please visit your browser settings to grant the necessary access.' + ); + } + }; + const toggleAuthHeader = async () => { authEnabled = !authEnabled; }; @@ -802,44 +817,66 @@ >
-
-
Title Auto Generation
+
WebUI Add-ons
- +
+
+
Response Notification
+ + +
-
-
+
+
+
Title Auto Generation
-
-
-
Voice Input Auto-Send
+ +
+
- +
+
+
Voice Input Auto-Send
+ + +
diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index c82a26a5..5d4291d7 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -222,6 +222,21 @@ eval_duration: data.eval_duration }; messages = messages; + + if ($settings.responseNotification && !document.hasFocus()) { + const notification = new Notification( + selectedModelfile + ? `${ + selectedModelfile.title.charAt(0).toUpperCase() + + selectedModelfile.title.slice(1) + }` + : `Ollama - ${model}`, + { + body: responseMessage.content, + icon: selectedModelfile?.imageUrl ?? '/favicon.png' + } + ); + } } } } diff --git a/src/routes/(app)/c/[id]/+page.svelte b/src/routes/(app)/c/[id]/+page.svelte index f156ed99..b164a4b4 100644 --- a/src/routes/(app)/c/[id]/+page.svelte +++ b/src/routes/(app)/c/[id]/+page.svelte @@ -234,6 +234,21 @@ eval_duration: data.eval_duration }; messages = messages; + + if ($settings.responseNotification && !document.hasFocus()) { + const notification = new Notification( + selectedModelfile + ? `${ + selectedModelfile.title.charAt(0).toUpperCase() + + selectedModelfile.title.slice(1) + }` + : `Ollama - ${model}`, + { + body: responseMessage.content, + icon: selectedModelfile?.imageUrl ?? '/favicon.png' + } + ); + } } } }