correctly handling the menus loading special prompts. see #183

This commit is contained in:
Mic 2024-12-12 00:26:00 +01:00
parent 501fdf2fc1
commit 938c818b99
2 changed files with 13 additions and 9 deletions

View file

@ -51,24 +51,24 @@ export class mzta_Menus {
} }
async initialize() { async initialize(also_special = false) {
this.allPrompts = []; this.allPrompts = [];
this.rootMenu = []; this.rootMenu = [];
this.shortcutMenu = []; this.shortcutMenu = [];
this.menu_listeners = {}; 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.sort((a, b) => a.name.localeCompare(b.name));
this.allPrompts.forEach((prompt) => { this.allPrompts.forEach((prompt) => {
this.addAction(prompt) this.addAction(prompt)
}); });
} }
async reload(){ async reload(also_special = false) {
await browser.menus.removeAll().catch(error => { await browser.menus.removeAll().catch(error => {
console.error("[ThunderAI] ERROR removing the menus: ", error); console.error("[ThunderAI] ERROR removing the menus: ", error);
}); });
this.removeClickListener(); this.removeClickListener();
this.loadMenus(); this.loadMenus(also_special);
} }
addAction = (curr_prompt) => { addAction = (curr_prompt) => {
@ -228,8 +228,8 @@ export class mzta_Menus {
this.shortcutMenu.push(curr_menu_entry); this.shortcutMenu.push(curr_menu_entry);
} }
async loadMenus() { async loadMenus(also_special = false) {
await this.initialize(); await this.initialize(also_special);
await this.addMenu(this.rootMenu); await this.addMenu(this.rootMenu);
this.addClickListener(); this.addClickListener();
this.loadShortcutMenu(); this.loadShortcutMenu();

View file

@ -210,9 +210,13 @@ messenger.runtime.onMessage.addListener((message, sender, sendResponse) => {
return _reloadBody(message.tabId); return _reloadBody(message.tabId);
break; break;
case 'reload_menus': case 'reload_menus':
menus.reload(); async function _reload_menus() {
taLog.log("Reloading menus"); let prefs = await browser.storage.sync.get({add_tags: false, connection_type: 'chatgpt_web'});
return Promise.resolve(true); menus.reload(prefs.add_tags && (prefs.connection_type !== "chatgpt_web"));
taLog.log("Reloading menus");
return true;
}
return _reload_menus();
break; break;
case 'shortcut_do_prompt': case 'shortcut_do_prompt':
taLog.log("Executing shortcut, promptId: " + message.promptId); taLog.log("Executing shortcut, promptId: " + message.promptId);