From 938c818b992a499b361d1dee096166dfe67c9640 Mon Sep 17 00:00:00 2001 From: Mic Date: Thu, 12 Dec 2024 00:26:00 +0100 Subject: [PATCH] correctly handling the menus loading special prompts. see #183 --- js/mzta-menus.js | 12 ++++++------ mzta-background.js | 10 +++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/js/mzta-menus.js b/js/mzta-menus.js index 0072efec..b27618d1 100644 --- a/js/mzta-menus.js +++ b/js/mzta-menus.js @@ -51,24 +51,24 @@ export class mzta_Menus { } - async initialize() { + async initialize(also_special = false) { this.allPrompts = []; this.rootMenu = []; this.shortcutMenu = []; this.menu_listeners = {}; - this.allPrompts = await getPrompts(true,true); + this.allPrompts = await getPrompts(true,also_special); this.allPrompts.sort((a, b) => a.name.localeCompare(b.name)); this.allPrompts.forEach((prompt) => { this.addAction(prompt) }); } - async reload(){ + async reload(also_special = false) { await browser.menus.removeAll().catch(error => { console.error("[ThunderAI] ERROR removing the menus: ", error); }); this.removeClickListener(); - this.loadMenus(); + this.loadMenus(also_special); } addAction = (curr_prompt) => { @@ -228,8 +228,8 @@ export class mzta_Menus { this.shortcutMenu.push(curr_menu_entry); } - async loadMenus() { - await this.initialize(); + async loadMenus(also_special = false) { + await this.initialize(also_special); await this.addMenu(this.rootMenu); this.addClickListener(); this.loadShortcutMenu(); diff --git a/mzta-background.js b/mzta-background.js index d18210b7..69814563 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -210,9 +210,13 @@ messenger.runtime.onMessage.addListener((message, sender, sendResponse) => { return _reloadBody(message.tabId); break; case 'reload_menus': - menus.reload(); - taLog.log("Reloading menus"); - return Promise.resolve(true); + async function _reload_menus() { + let prefs = await browser.storage.sync.get({add_tags: false, connection_type: 'chatgpt_web'}); + menus.reload(prefs.add_tags && (prefs.connection_type !== "chatgpt_web")); + taLog.log("Reloading menus"); + return true; + } + return _reload_menus(); break; case 'shortcut_do_prompt': taLog.log("Executing shortcut, promptId: " + message.promptId);