Skip to content

Commit b4b59b7

Browse files
committed
Add dynamic module loading for TB 136+ support
Detect Thunderbird version at runtime and load modules using the appropriate format (ESM for TB 136+ and JSM for older versions), ensuring compatibility across releases.
1 parent 86397b2 commit b4b59b7

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

experiments/displayReceivedHeader.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,28 @@
33

44
"use strict";
55

6-
const {ExtensionCommon} = ChromeUtils.import("resource://gre/modules/ExtensionCommon.jsm");
76
const Services = globalThis.Services || ChromeUtils.import("resource://gre/modules/Services.jsm").Services;
87
const [majorVersion] = Services.appinfo.platformVersion.split(".", 1);
98

10-
// eslint-disable-next-line no-var
9+
/**
10+
* Dynamically imports a module based on the Thunderbird version.
11+
*
12+
* For Thunderbird 136 and above, it imports the ESM version of the module.
13+
* For older versions, it imports the JSM version.
14+
*
15+
* @param {string} name - The name of the module to import.
16+
* @returns {*} The exported module object.
17+
*/
18+
function importModule(name) {
19+
const moduleSubdir = name === "ExtensionSupport" ? "" : "gre";
20+
return majorVersion >= 136
21+
? ChromeUtils.importESModule("resource://" + moduleSubdir + "/modules/" + name + ".sys.mjs")[name]
22+
: ChromeUtils.import("resource://" + moduleSubdir + "/modules/" + name + ".jsm")[name];
23+
}
24+
25+
const ExtensionCommon = importModule("ExtensionCommon");
26+
27+
// eslint-disable-next-line no-var, vars-on-top
1128
var displayReceivedHeader = class extends ExtensionCommon.ExtensionAPI {
1229
getAPI(context) {
1330
function getDocumentByTabIndex(windowId, tabIndex) {

manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
"gecko": {
55
"id": "received@alexander.moisseev",
66
"strict_min_version": "78.0",
7-
"strict_max_version": "129.*"
7+
"strict_max_version": "136.*"
88
}
99
},
1010
"name": "Received",
1111
"description": "Displays the \"Received\" header parsed with a regular expression.",
12-
"version": "2.6.0",
12+
"version": "2.6.1",
1313
"author": "Alexander Moisseev (moiseev@mezonplus.ru)",
1414
"homepage_url": "https://github.com/moisseev/received",
1515
"icons": {

0 commit comments

Comments
 (0)