From 9fd14b1276a57f5aba0a621ebadf6a61dbd72aae Mon Sep 17 00:00:00 2001 From: mic Date: Mon, 13 May 2024 20:26:58 +0200 Subject: [PATCH] correctly loading menus --- customprompts/mzta-custom-prompts.js | 7 ++++--- js/mzta-menus.js | 18 +++++++++++++----- mzta-background.js | 4 ++++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/customprompts/mzta-custom-prompts.js b/customprompts/mzta-custom-prompts.js index d03acdfc..19b0f144 100644 --- a/customprompts/mzta-custom-prompts.js +++ b/customprompts/mzta-custom-prompts.js @@ -339,7 +339,7 @@ function checkSelectedBoxes(checkboxes = null) { } //Save all prompts -function saveAll() { //TODO +async function saveAll() { somethingChanged = false; if(promptsList != null) { promptsList.reIndex(); @@ -354,8 +354,9 @@ function saveAll() { //TODO let newDefaultPrompts = newPrompts.filter(item => item.is_default == 1); console.log('>>>>>>>>>>>>> newDefaultPrompts: ' + JSON.stringify(newDefaultPrompts)); let newCustomPrompts = newPrompts.filter(item => item.is_default == 0); - setDefaultPromptsProperties(newDefaultPrompts); - setCustomPrompts(newCustomPrompts); + await setDefaultPromptsProperties(newDefaultPrompts); + await setCustomPrompts(newCustomPrompts); + browser.runtime.sendMessage({command: "reload_menus"}); } } diff --git a/js/mzta-menus.js b/js/mzta-menus.js index a227f834..2cdd2779 100644 --- a/js/mzta-menus.js +++ b/js/mzta-menus.js @@ -49,6 +49,12 @@ export class mzta_Menus { //this.addMenu(this.rootMenu); } + async reload(){ + this.rootMenu = []; + await this.initialize(); + this.loadMenus(); + } + addAction = (curr_prompt) => { let curr_menu_entry = {id: curr_prompt.id }; @@ -129,7 +135,7 @@ export class mzta_Menus { browser.menus.create({ id: id, - title: this.getCustomTextAttribute(id) + browser.i18n.getMessage(id), + title: this.getCustomTextAttribute(id) + (browser.i18n.getMessage(id) || id), contexts: this.getContexts(id), parentId: root }); @@ -146,16 +152,18 @@ export class mzta_Menus { }; getContexts(id){ + console.log(">>>>>>>>> id: " + id); const curr_prompt = this.allPrompts.find(p => p.id === id); + console.log(">>>>>>>>>> curr_prompt: " + JSON.stringify(curr_prompt)); if (!curr_prompt) { return []; } switch(curr_prompt.type){ - case 0: + case "0": console.log(">>>>>>>>>> curr_prompt.type: " + curr_prompt.type); return [this.menu_context_compose, this.menu_context_display]; - case 1: + case "1": return [this.menu_context_display]; - case 2: + case "2": return [this.menu_context_compose]; default: return []; @@ -168,7 +176,7 @@ export class mzta_Menus { if (!curr_prompt) { return ""; } - if(curr_prompt.need_custom_text === 1){ + if(curr_prompt.need_custom_text === "1"){ return "*"; }else{ return ""; diff --git a/mzta-background.js b/mzta-background.js index 71ef5ff4..01ddfc6f 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -113,6 +113,10 @@ messenger.runtime.onMessage.addListener(async (message, sender, sendResponse) => await setBody(message.tabId, original_html); await setBody(message.tabId, modified_html); break; + case 'reload_menus': + await mzta_Menus.reload(); + console.log('>>>>>>>>>>>>>>>>> Reloaded menus'); + break; default: break; }