From 0495b50ccb2ef97c92c606921a93b6e4c1795d68 Mon Sep 17 00:00:00 2001 From: Mic Date: Mon, 19 Aug 2024 11:48:48 +0200 Subject: [PATCH] fixed API web chat windows opnening in Thunderbird 115 --- mzta-background.js | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/mzta-background.js b/mzta-background.js index 0f6c15ac..9579d5f5 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -19,7 +19,7 @@ import { mzta_script } from './js/mzta-chatgpt.js'; import { prefs_default } from './options/mzta-options-default.js'; import { mzta_Menus } from './js/mzta-menus.js'; -import { getCurrentIdentity, getOriginalBody, replaceBody, setBody, i18nConditionalGet } from './js/mzta-utils.js'; +import { getCurrentIdentity, getOriginalBody, replaceBody, setBody, i18nConditionalGet, isThunderbird128OrGreater } from './js/mzta-utils.js'; var createdWindowID = null; var original_html = ''; @@ -223,24 +223,26 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_ createdWindowID = newWindow2.id; let createdTab2 = newWindow2.tabs[0]; - // Wait for tab loaded. - await new Promise(resolve => { - const tabIsLoaded2 = tab => { - return tab.status == "complete" && tab.url != "about:blank"; - }; - const listener2 = (tabId, changeInfo, updatedTab) => { - if (tabIsLoaded2(updatedTab)) { - browser.tabs.onUpdated.removeListener(listener2); - resolve(); + if(await isThunderbird128OrGreater()){ + // Wait for tab loaded. + await new Promise(resolve => { + const tabIsLoaded2 = tab => { + return tab.status == "complete" && tab.url != "about:blank"; + }; + const listener2 = (tabId, changeInfo, updatedTab) => { + if (tabIsLoaded2(updatedTab)) { + browser.tabs.onUpdated.removeListener(listener2); + resolve(); + } } - } - // Early exit if loaded already - if (tabIsLoaded2(createdTab2)) { - resolve(); - } else { - browser.tabs.onUpdated.addListener(listener2); - } - }); + // Early exit if loaded already + if (tabIsLoaded2(createdTab2)) { + resolve(); + } else { + browser.tabs.onUpdated.addListener(listener2); + } + }); + } let mailMessage = await browser.messageDisplay.getDisplayedMessage(curr_tabId); let mailMessageId = -1;