From b00e14eb3f009e2445b04dbabb02716cb474bba6 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sun, 23 Feb 2025 20:27:55 +0100 Subject: [PATCH] Handle no location permission --- .../chat/MessageInput/Commands/Prompts.svelte | 8 +++++++- src/lib/utils/index.ts | 17 ++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/lib/components/chat/MessageInput/Commands/Prompts.svelte b/src/lib/components/chat/MessageInput/Commands/Prompts.svelte index 76809e6d1..bb91e00a8 100644 --- a/src/lib/components/chat/MessageInput/Commands/Prompts.svelte +++ b/src/lib/components/chat/MessageInput/Commands/Prompts.svelte @@ -74,7 +74,13 @@ } if (command.content.includes('{{USER_LOCATION}}')) { - const location = await getUserPosition(); + let location; + try { + location = await getUserPosition(); + } catch (error) { + toast.error($i18n.t('Location access not allowed')); + location = 'LOCATION_UNKNOWN'; + } text = text.replaceAll('{{USER_LOCATION}}', String(location)); } diff --git a/src/lib/utils/index.ts b/src/lib/utils/index.ts index 0ce738762..ef8681003 100644 --- a/src/lib/utils/index.ts +++ b/src/lib/utils/index.ts @@ -279,9 +279,9 @@ export const generateInitialsImage = (name) => { const initials = sanitizedName.length > 0 ? sanitizedName[0] + - (sanitizedName.split(' ').length > 1 - ? sanitizedName[sanitizedName.lastIndexOf(' ') + 1] - : '') + (sanitizedName.split(' ').length > 1 + ? sanitizedName[sanitizedName.lastIndexOf(' ') + 1] + : '') : ''; ctx.fillText(initials.toUpperCase(), canvas.width / 2, canvas.height / 2); @@ -348,10 +348,10 @@ export const compareVersion = (latest, current) => { return current === '0.0.0' ? false : current.localeCompare(latest, undefined, { - numeric: true, - sensitivity: 'case', - caseFirst: 'upper' - }) < 0; + numeric: true, + sensitivity: 'case', + caseFirst: 'upper' + }) < 0; }; export const findWordIndices = (text) => { @@ -846,6 +846,9 @@ export const promptTemplate = ( if (user_location) { // Replace {{USER_LOCATION}} in the template with the current location template = template.replace('{{USER_LOCATION}}', user_location); + } else { + // Replace {{USER_LOCATION}} in the template with 'Unknown' if no location is provided + template = template.replace('{{USER_LOCATION}}', 'LOCATION_UNKNOWN'); } return template;