diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c3608fd..3aeffd18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@
  • Added the {%mail_folder_path%} placeholder to get the mail folder path [#253].
  • Added the {%account_email_address%} placeholder to get the current account mail address [#272].
  • Added a context menu to manually add tags and run the spam filter on selected messages. [#262].
  • +
  • The button icon now shows a loading indicator when ThunderAI is performing an operation [#295].
  • Improved the handling of null or undefined placeholders [#288].
  • Czech (cs) translation added, thanks to Jaroslav Staněk and Fjuro.
  • Simplified Chinese (zh_Hans) translation added, thanks to jeklau.
  • diff --git a/images/icon-loading.svg b/images/icon-loading.svg new file mode 100644 index 00000000..8a95de1a --- /dev/null +++ b/images/icon-loading.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/js/mzta-menus.js b/js/mzta-menus.js index 9c7fb255..9d50a38d 100644 --- a/js/mzta-menus.js +++ b/js/mzta-menus.js @@ -24,6 +24,7 @@ import { taPromptUtils } from './mzta-utils-prompt.js'; import { taLogger } from './mzta-logger.js'; import { placeholdersUtils } from './mzta-placeholders.js'; import { mzta_specialCommand } from './mzta-special-commands.js'; +import { taWorkingStatus } from './mzta-working-status.js'; export class mzta_Menus { @@ -88,6 +89,7 @@ export class mzta_Menus { }; curr_menu_entry.act = async () => { + taWorkingStatus.startWorking(); const tabs = await browser.tabs.query({ active: true, currentWindow: true }); const msg_text = await getMailBody(tabs, placeholdersUtils.hasPlaceholder(curr_prompt.text,'mail_typed_text')); @@ -156,6 +158,7 @@ export class mzta_Menus { let prefs_at = await browser.storage.sync.get({add_tags_maxnum: 3, connection_type: '', add_tags_force_lang: true, default_chatgpt_lang: '', do_debug: false}); if((prefs_at.connection_type === '')||(prefs_at.connection_type === null)||(prefs_at.connection_type === undefined)||(prefs_at.connection_type === 'chatgpt_web')){ console.error("[ThunderAI | AddTags] Invalid connection type: " + prefs_at.connection_type); + taWorkingStatus.stopWorking(); return {ok:'0'}; } fullPrompt = taPromptUtils.finalizePrompt_add_tags(fullPrompt, prefs_at.add_tags_maxnum, prefs_at.add_tags_force_lang, prefs_at.default_chatgpt_lang); @@ -171,11 +174,13 @@ export class mzta_Menus { }catch(err){ console.error("[ThunderAI] Error getting tags: ", err); browser.tabs.sendMessage(tabs[0].id, { command: "sendAlert", curr_tab_type: tabs[0].type, message: "Error getting tags: " + err }); + taWorkingStatus.stopWorking(); return {ok:'0'}; } this.logger.log("tags_current_email: " + tags_current_email); this.logger.log("tags_full_list: " + JSON.stringify(tags_full_list)); browser.tabs.sendMessage(tabs[0].id, {command: "getTags", tags: tags_current_email, messageId: curr_message.id}); + taWorkingStatus.stopWorking(); return {ok:'1'}; break; // Add tags to the email - END } @@ -184,6 +189,7 @@ export class mzta_Menus { let prefs_at = await browser.storage.sync.get({connection_type: ''}); if((prefs_at.connection_type === '')||(prefs_at.connection_type === null)||(prefs_at.connection_type === undefined)||(prefs_at.connection_type === 'chatgpt_web')){ console.error("[ThunderAI | GetCalendarEvent] Invalid connection type: " + prefs_at.connection_type); + taWorkingStatus.stopWorking(); return {ok:'0'}; } /* We expect to receive from the AI a JSON object like this: @@ -203,30 +209,37 @@ export class mzta_Menus { }catch(err){ console.error("[ThunderAI] Error getting calendar event data: ", JSON.stringify(err)); browser.tabs.sendMessage(tabs[0].id, { command: "sendAlert", curr_tab_type: tabs[0].type, message: browser.i18n.getMessage("calendar_getting_data_error") + ": " + JSON.stringify(err) }); + taWorkingStatus.stopWorking(); return {ok:'0'}; } this.logger.log("calendar_event_data: " + calendar_event_data); try{ let result_openCalendarEventDialog = await browser.runtime.sendMessage('thunderai-sparks@micz.it',{action: "openCalendarEventDialog", calendar_event_data: calendar_event_data}) if(result_openCalendarEventDialog == 'ok'){ + taWorkingStatus.stopWorking(); return {ok:'1'}; } else { browser.tabs.sendMessage(tabs[0].id, { command: "sendAlert", curr_tab_type: tabs[0].type, message: browser.i18n.getMessage("calendar_opening_dialog_error") + ": " + result_openCalendarEventDialog.error }); + taWorkingStatus.stopWorking(); return {ok:'0'}; } }catch(err){ console.error("[ThunderAI] Error opening calendar event dialog: ", JSON.stringify(err)); browser.tabs.sendMessage(tabs[0].id, { command: "sendAlert", curr_tab_type: tabs[0].type, message: browser.i18n.getMessage("calendar_opening_dialog_error") + ": " + browser.i18n.getMessage("sparks_not_installed") }); + taWorkingStatus.stopWorking(); return {ok:'0'}; } break; // Get a calendar event info - END } default: console.error("[ThunderAI] Unknown special prompt id: " + curr_prompt.id); + taWorkingStatus.stopWorking(); + return {ok:'0'}; break; } }else{ // Classic prompts for the API webchat this.openChatGPT(fullPrompt, curr_prompt.action, tabs[0].id, curr_prompt.name, curr_prompt.need_custom_text); + taWorkingStatus.stopWorking(); return {ok:'1'}; } }; diff --git a/js/mzta-working-status.js b/js/mzta-working-status.js new file mode 100644 index 00000000..9f220d0f --- /dev/null +++ b/js/mzta-working-status.js @@ -0,0 +1,41 @@ +/* + * ThunderAI [https://micz.it/thunderbird-addon-thunderai/] + * Copyright (C) 2024 - 2025 Mic (m@micz.it) + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + + +export const taWorkingStatus = { + + WorkingLevel: 0, + taLog: console, + + startWorking(){ + this.WorkingLevel++; + this.taLog.log("[startWorking] WorkingLevel: " + this.WorkingLevel); + browser.messageDisplayAction.setIcon({path: "/images/icon-loading.svg"}); + browser.composeAction.setIcon({path: "/images/icon-loading.svg"}); + }, + + stopWorking(){ + this.WorkingLevel--; + this.taLog.log("[stopWorking] WorkingLevel: " + this.WorkingLevel); + if(this.WorkingLevel<=0){ + this.WorkingLevel = 0; + browser.messageDisplayAction.setIcon({path: "/images/icon-32px.png"}); + browser.composeAction.setIcon({path: "/images/icon-32px.png"}); + } + } +}; \ No newline at end of file diff --git a/mzta-background.js b/mzta-background.js index 87385ccf..e51417fe 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -25,6 +25,7 @@ import { taPromptUtils } from './js/mzta-utils-prompt.js'; import { mzta_specialCommand } from './js/mzta-special-commands.js'; import { getSpamFilterPrompt } from './js/mzta-prompts.js'; import { taSpamReport } from './js/mzta-spamreport.js'; +import { taWorkingStatus } from './js/mzta-working-status.js'; browser.runtime.onInstalled.addListener(({ reason, previousVersion }) => { // console.log(">>>>>>>>>>> onInstalled: " + JSON.stringify(reason) + ", previousVersion: " + previousVersion); @@ -47,6 +48,7 @@ let prefs_init = {}; await reload_pref_init(); let taLog = new taLogger("mzta-background",prefs_init.do_debug); +taWorkingStatus.taLog = taLog; let special_prompts_ids = getActiveSpecialPromptsIDs(prefs_init.add_tags, await doGetCalendarEvent(prefs_init.get_calendar_event), (prefs_init.connection_type === "chatgpt_web")); @@ -744,6 +746,7 @@ const newEmailListener = (folder, messagesList) => { } async function processEmails(messages, addTagsAuto, spamFilter) { + taWorkingStatus.startWorking(); for await (let message of messages) { let curr_fullMessage = null; let msg_text = null; @@ -824,6 +827,7 @@ async function processEmails(messages, addTagsAuto, spamFilter) { taSpamReport.saveReportData(report_data, message.headerMessageId); } } + taWorkingStatus.stopWorking(); } diff --git a/options/mzta-release-notes.html b/options/mzta-release-notes.html index 38fed925..4e4c1824 100644 --- a/options/mzta-release-notes.html +++ b/options/mzta-release-notes.html @@ -13,6 +13,7 @@
  • Added the {%mail_folder_path%} placeholder to get the mail folder path [#253].
  • Added the {%account_email_address%} placeholder to get the current account mail address [#272].
  • Added a context menu to manually add tags and run the spam filter on selected messages. [#262].
  • +
  • The button icon now shows a loading indicator when ThunderAI is performing an operation [#295].
  • Improved the handling of null or undefined placeholders [#288].
  • Czech (cs) translation added, thanks to Jaroslav Staněk and Fjuro.
  • Simplified Chinese (zh_Hans) translation added, thanks to jeklau.