From 1ba49b64f3e99d719896db76b40ca24fafc1abd3 Mon Sep 17 00:00:00 2001 From: mic Date: Mon, 29 Jul 2024 22:47:17 +0200 Subject: [PATCH] added error notification for empty model or apikey using the ChatGPT API --- _locales/en/messages.json | 12 ++++++++++++ mzta-background.js | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 8a1ae40d..26a5ee3c 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -418,5 +418,17 @@ "ChatGPT_Models_Loading": { "message": "Loading...", "description": "" + }, + "error": { + "message": "ThunderAI Error!", + "description": "" + }, + "chatgpt_empty_apikey": { + "message": "You've not added an API Key a model for the ChatGPT API. Please insert one in the options page.", + "description": "" + }, + "chatgpt_empty_model": { + "message": "You've not choosen a model for the ChatGPT API. Please choose one in the options page.", + "description": "" } } \ No newline at end of file diff --git a/mzta-background.js b/mzta-background.js index c0eeeaca..c090dd2b 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -149,6 +149,11 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_ // check if the API is present, otherwise open the web interface if (prefs.api_key_chatgpt == '') { + showNotification(browser.i18n.getMessage('error'),browser.i18n.getMessage('chatgpt_empty_apikey')); + prefs.connection_type = 'chatgpt_web'; + } + if (prefs.model_chatgpt == '') { + showNotification(browser.i18n.getMessage('error'),browser.i18n.getMessage('chatgpt_empty_model')); prefs.connection_type = 'chatgpt_web'; } @@ -255,6 +260,15 @@ function checkScreenDimensions(prefs){ return prefs; } +function showNotification(title, message) { + browser.notifications.create({ + "type": "basic", + "title": title, + "iconUrl": browser.extension.getURL("images/icon.png"), + "message": message + }); +} + // Menus handling const menus = new mzta_Menus(openChatGPT); menus.loadMenus(); \ No newline at end of file