correctly closing the window
This commit is contained in:
parent
687ac698a7
commit
47a4a8c5bc
3 changed files with 9 additions and 28 deletions
|
|
@ -241,20 +241,20 @@ class MessagesArea extends HTMLElement {
|
|||
case "1": // do reply
|
||||
// console.log("[ThunderAI] (do reply) fullTextHTMLAtAssignment: " + fullTextHTMLAtAssignment);
|
||||
await browser.runtime.sendMessage({command: "chatgpt_replyMessage", text: fullTextHTMLAtAssignment, tabId: promptData.tabId, mailMessageId: promptData.mailMessageId});
|
||||
browser.runtime.sendMessage({command: "chatgpt_close"});
|
||||
browser.runtime.sendMessage({command: "chatgpt_close", window_id: (await browser.windows.getCurrent()).id});
|
||||
break;
|
||||
case "2": // replace text
|
||||
// console.log("[ThunderAI] (replace text) fullTextHTMLAtAssignment: " + fullTextHTMLAtAssignment);
|
||||
await browser.runtime.sendMessage({command: "chatgpt_replaceSelectedText", text: fullTextHTMLAtAssignment, tabId: promptData.tabId, mailMessageId: promptData.mailMessageId});
|
||||
browser.runtime.sendMessage({command: "chatgpt_close"});
|
||||
browser.runtime.sendMessage({command: "chatgpt_close", window_id: (await browser.windows.getCurrent()).id});
|
||||
break;
|
||||
}
|
||||
});
|
||||
const closeButton = document.createElement('button');
|
||||
closeButton.textContent = browser.i18n.getMessage("chatgpt_win_close");
|
||||
closeButton.addEventListener('click', () => {
|
||||
closeButton.addEventListener('click', async () => {
|
||||
// console.log("[ThunderAI] (close) fullTextHTMLAtAssignment: " + fullTextHTMLAtAssignment);
|
||||
browser.runtime.sendMessage({command: "chatgpt_close"}); // close window
|
||||
browser.runtime.sendMessage({command: "chatgpt_close", window_id: (await browser.windows.getCurrent()).id}); // close window
|
||||
});
|
||||
if(promptData.action != 0) { actionButtons.appendChild(actionButton); }
|
||||
actionButtons.appendChild(closeButton);
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ function addCustomDiv(prompt_action,tabId,mailMessageId) {
|
|||
case "0": // close window
|
||||
btn_ok.textContent = browser.i18n.getMessage("chatgpt_win_close");
|
||||
btn_ok.onclick = async function() {
|
||||
browser.runtime.sendMessage({command: "chatgpt_close"});
|
||||
browser.runtime.sendMessage({command: "chatgpt_close", window_id: mztaWinId});
|
||||
};
|
||||
break;
|
||||
case "1": // do reply
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import { mzta_Menus } from './js/mzta-menus.js';
|
|||
import { taLogger } from './js/mzta-logger.js';
|
||||
import { getCurrentIdentity, getOriginalBody, replaceBody, setBody, i18nConditionalGet, generateCallID } from './js/mzta-utils.js';
|
||||
|
||||
var createdWindowID = null;
|
||||
var original_html = '';
|
||||
var modified_html = '';
|
||||
|
||||
|
|
@ -58,7 +57,7 @@ messenger.runtime.onMessage.addListener(async (message, sender, sendResponse) =>
|
|||
// openChatGPT(message.prompt,message.action,message.tabId);
|
||||
// return true;
|
||||
case 'chatgpt_close':
|
||||
browser.windows.remove(createdWindowID).then(() => {
|
||||
browser.windows.remove(message.window_id).then(() => {
|
||||
taLog.log("ChatGPT window closed successfully.");
|
||||
return true;
|
||||
}).catch((error) => {
|
||||
|
|
@ -163,29 +162,11 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
|||
});
|
||||
|
||||
taLog.log("[ThunderAI] ChatGPT web interface script started...");
|
||||
createdWindowID = newWindow.id;
|
||||
let createdTab = newWindow.tabs[0];
|
||||
let newWindowId = newWindow.id;
|
||||
|
||||
// Wait for tab loaded.
|
||||
// await new Promise(resolve => {
|
||||
// const tabIsLoaded = tab => {
|
||||
// return tab.status == "complete" && tab.url != "about:blank";
|
||||
// };
|
||||
// const listener = (tabId, changeInfo, updatedTab) => {
|
||||
// if (tabIsLoaded(updatedTab)) {
|
||||
// browser.tabs.onUpdated.removeListener(listener);
|
||||
// resolve();
|
||||
// }
|
||||
// }
|
||||
// // Early exit if loaded already
|
||||
// if (tabIsLoaded(createdTab)) {
|
||||
// resolve();
|
||||
// } else {
|
||||
// browser.tabs.onUpdated.addListener(listener);
|
||||
// }
|
||||
// });
|
||||
|
||||
let pre_script = `let mztaStatusPageDesc="`+ browser.i18n.getMessage("prefs_status_page") +`";
|
||||
let pre_script = `let mztaWinId = `+ newWindowId +`;
|
||||
let mztaStatusPageDesc="`+ browser.i18n.getMessage("prefs_status_page") +`";
|
||||
let mztaForceCompletionDesc="`+ browser.i18n.getMessage("chatgpt_force_completion") +`";
|
||||
let mztaForceCompletionTitle="`+ browser.i18n.getMessage("chatgpt_force_completion_title") +`";
|
||||
let mztaDoCustomText=`+ do_custom_text +`;
|
||||
|
|
|
|||
Loading…
Reference in a new issue