Skip to content

Commit

Permalink
Merge pull request #120 from jeevatkm/tb-v102-support
Browse files Browse the repository at this point in the history
  • Loading branch information
jeevatkm authored Jul 23, 2022
2 parents d5f528b + 5bbc8d7 commit aee1a41
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 49 deletions.
86 changes: 41 additions & 45 deletions experiment/api/WindowListener/implementation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This file is provided by the addon-developer-support repository at
* https://github.com/thundernest/addon-developer-support
*
* Version: 1.56
* Version: 1.57
*
* Author: John Bieling (john@thunderbird.net)
*
Expand Down Expand Up @@ -200,7 +200,7 @@ var WindowListener = class extends ExtensionCommon.ExtensionAPI {
// returns the outer browser, not the nested browser of the add-on manager
// events must be attached to the outer browser
getAddonManagerFromTab(tab) {
if (tab.browser) {
if (tab.browser && tab.mode.name == "contentTab") {
let win = tab.browser.contentWindow;
if (win && win.location.href == "about:addons") {
return win;
Expand All @@ -211,9 +211,28 @@ var WindowListener = class extends ExtensionCommon.ExtensionAPI {
getAddonManagerFromWindow(window) {
let tabMail = this.getTabMail(window);
for (let tab of tabMail.tabInfo) {
let win = this.getAddonManagerFromTab(tab);
if (win) {
return win;
let managerWindow = this.getAddonManagerFromTab(tab);
if (managerWindow) {
return managerWindow;
}
}
}

async getAddonManagerFromWindowWaitForLoad(window) {
let { setTimeout } = Services.wm.getMostRecentWindow("mail:3pane");

let tabMail = this.getTabMail(window);
for (let tab of tabMail.tabInfo) {
if (tab.browser && tab.mode.name == "contentTab") {
// Instead of registering a load observer, wait until its loaded. Not nice,
// but gets aroud a lot of edge cases.
while(!tab.pageLoaded) {
await new Promise(r => setTimeout(r, 150));
}
let managerWindow = this.getAddonManagerFromTab(tab);
if (managerWindow) {
return managerWindow;
}
}
}
}
Expand Down Expand Up @@ -329,41 +348,20 @@ var WindowListener = class extends ExtensionCommon.ExtensionAPI {

// TabMonitor to detect opening of tabs, to setup the options button in the add-on manager.
this.tabMonitor = {
onTabTitleChanged(aTab) { },
onTabClosing(aTab) { },
onTabPersist(aTab) { },
onTabRestored(aTab) { },
onTabSwitched(aNewTab, aOldTab) {
//self.setupAddonManager(self.getAddonManagerFromTab(aNewTab));
},
async onTabOpened(aTab) {
if (aTab.browser) {
if (!aTab.pageLoaded) {
// await a location change if browser is not loaded yet
await new Promise((resolve) => {
let reporterListener = {
QueryInterface: ChromeUtils.generateQI([
"nsIWebProgressListener",
"nsISupportsWeakReference",
]),
onStateChange() { },
onProgressChange() { },
onLocationChange(
/* in nsIWebProgress*/ aWebProgress,
/* in nsIRequest*/ aRequest,
/* in nsIURI*/ aLocation
) {
aTab.browser.removeProgressListener(reporterListener);
resolve();
},
onStatusChange() { },
onSecurityChange() { },
onContentBlockingEvent() { },
};
aTab.browser.addProgressListener(reporterListener);
});
onTabTitleChanged(tab) { },
onTabClosing(tab) { },
onTabPersist(tab) { },
onTabRestored(tab) { },
onTabSwitched(aNewTab, aOldTab) { },
async onTabOpened(tab) {
if (tab.browser && tab.mode.name == "contentTab") {
let { setTimeout } = Services.wm.getMostRecentWindow("mail:3pane");
// Instead of registering a load observer, wait until its loaded. Not nice,
// but gets aroud a lot of edge cases.
while(!tab.pageLoaded) {
await new Promise(r => setTimeout(r, 150));
}
self.setupAddonManager(self.getAddonManagerFromTab(aTab));
self.setupAddonManager(self.getAddonManagerFromTab(tab));
}
},
};
Expand Down Expand Up @@ -594,16 +592,14 @@ var WindowListener = class extends ExtensionCommon.ExtensionAPI {
self
);
} else {
// Setup the options button/menu in the add-on manager, if it is already open.
self.setupAddonManager(
self.getAddonManagerFromWindow(window),
true
);
// Add a tabmonitor, to be able to setup the options button/menu in the add-on manager.
self
.getTabMail(window)
.registerTabMonitor(self.tabMonitor);
window[self.uniqueRandomID].hasTabMonitor = true;
// Setup the options button/menu in the add-on manager, if it is already open.
let managerWindow = await self.getAddonManagerFromWindowWaitForLoad(window);
self.setupAddonManager(managerWindow, true);
}
}
}
Expand Down Expand Up @@ -1183,4 +1179,4 @@ var WindowListener = class extends ExtensionCommon.ExtensionAPI {
this.chromeHandle = null;
}
}
};
};
8 changes: 4 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"name": "ReplyWithHeader",
"short_name": "RWH",
"description": "Outlook style headers and few goodies for Thunderbird",
"version_name": "2.4.0",
"version": "2.4.0",
"version_name": "2.5.0",
"version": "2.5.0",
"author": "Jeevanandam M.",
"homepage_url": "https://myjeeva.com/replywithheader-mozilla",

"applications": {
"gecko": {
"id": "replywithheader@myjeeva.com",
"strict_min_version": "91.0",
"strict_max_version": "91.*"
"strict_min_version": "102.0",
"strict_max_version": "102.*"
}
},

Expand Down

0 comments on commit aee1a41

Please sign in to comment.