From edf78fffdc39c45ec26e25b091b67482d878698d Mon Sep 17 00:00:00 2001 From: mic Date: Sat, 14 Sep 2024 22:18:52 +0200 Subject: [PATCH] executing the shortcut --- mzta-background.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mzta-background.js b/mzta-background.js index 23650b38..371bdfcf 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -70,14 +70,16 @@ browser.contentScripts.register({ runAt: "document_idle" }); +let ThunderAI_Shortcut = "Ctrl+Alt+A"; + // Shortcut messenger.commands.update({ name: "_thunderai__do_action", - shortcut: "Ctrl+Alt+A" + shortcut: ThunderAI_Shortcut }).then(() => { - taLog.log('Shortcut registered successfully!'); + taLog.log('Shortcut [' + ThunderAI_Shortcut + '] registered successfully!'); }).catch((error) => { - taLog.error('Error registering shortcut: ' + error); + taLog.error('Error registering shortcut [' + ThunderAI_Shortcut + ']: ' + error); }); // Listen for shortcut command @@ -93,7 +95,7 @@ async function handleShortcut(tab) { if(!["mail", "messageCompose","messageDisplay"].includes(tab.type)){ return; } - browser.tabs.sendMessage(tab.id, { command: "searchPrompt", _prompts_data: menus.shortcutMenu, tab_type: tab.type }); + browser.tabs.sendMessage(tab.id, { command: "searchPrompt", _prompts_data: menus.shortcutMenu, tabId: tab.id, _tab_type: tab.type }); } messenger.runtime.onMessage.addListener(async (message, sender, sendResponse) => { @@ -178,6 +180,10 @@ messenger.runtime.onMessage.addListener(async (message, sender, sendResponse) => await menus.reload(); taLog.log("[ThunderAI] Reloaded menus"); break; + case 'shortcut_do_prompt': + taLog.log("Executing shortcut, promptId: " + message.promptId); + menus.executeMenuAction(message.promptId); + break; default: break; } @@ -350,7 +356,7 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_ }); const listener4 = async (message, sender, sendResponse) => { - console.log(">>>>>>>>>>>>>> message: " + JSON.stringify(message)); + //console.log(">>>>>>>>>>>>>> message: " + JSON.stringify(message)); if (message.command === "openai_comp_api_ready_"+rand_call_id4) { let newWindow4 = await browser.windows.get(message.window_id, {populate: true});