Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 9 additions & 33 deletions src/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { version } from "../package.json";
import ToolkitGlobal from "./managers/toolkitGlobal.js";

/**
* Basic APIs with Zotero 6 & newer (7) compatibility.
* Basic APIs for Zotero 7+.
* See also https://www.zotero.org/support/dev/zotero_7_for_developers
*/
export class BasicTool {
Expand Down Expand Up @@ -63,17 +63,12 @@ export class BasicTool {
},
};
try {
if (
typeof globalThis.ChromeUtils?.importESModule !== "undefined" ||
typeof globalThis.ChromeUtils?.import !== "undefined"
) {
const { ConsoleAPI } = _importESModule(
"resource://gre/modules/Console.sys.mjs",
);
this._console = new ConsoleAPI({
consoleID: `${this._basicOptions.api.pluginID}-${Date.now()}`,
});
}
const { ConsoleAPI } = ChromeUtils.importESModule(
"resource://gre/modules/Console.sys.mjs",
);
this._console = new ConsoleAPI({
consoleID: `${this._basicOptions.api.pluginID}-${Date.now()}`,
});
} catch {}

this.updateOptions(data);
Expand Down Expand Up @@ -188,12 +183,8 @@ export class BasicTool {

/**
* Create an XUL element
*
* For Zotero 6, use `createElementNS`;
*
* For Zotero 7+, use `createXULElement`.
* @param doc
* @param type
* @param doc Document
* @param type Element type
* @example
* Create a `<menuitem>`:
* ```ts
Expand Down Expand Up @@ -506,21 +497,6 @@ export function makeHelperTool(cls: any, options: BasicTool | BasicOptions) {
});
}

// Make compatible import between fx128 (import jsm) and fx140 (importESModule mjs)
export function _importESModule(path: string): any {
// Since the `Zotero` or `Services` might not be available,
// we directly check `ChromeUtils` for import.
if (typeof ChromeUtils.import === "undefined") {
return ChromeUtils.importESModule(path, { global: "contextual" });
}

// If matching *.sys.mjs, convert to *.jsm
if (path.endsWith(".sys.mjs")) {
path = path.replace(/\.sys\.mjs$/, ".jsm");
}
return ChromeUtils.import(path);
}

declare interface ListenerCallbackMap {
onMainWindowLoad: (win: Window) => void;
onMainWindowUnload: (win: Window) => void;
Expand Down
4 changes: 1 addition & 3 deletions src/tools/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,7 @@ export class UITool extends BasicTool {
}

/**
* Parse XHTML to XUL fragment. For Zotero 6.
*
* To load preferences from a Zotero 7's `.xhtml`, use this method to parse it.
* Parse XHTML to XUL fragment.
* @param str xhtml raw text
* @param entities dtd file list ("chrome://xxx.dtd")
* @param defaultXUL true for default XUL namespace
Expand Down
4 changes: 2 additions & 2 deletions src/utils/pluginBridge.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type ToolkitGlobal from "../managers/toolkitGlobal.js";
import { _importESModule, BasicTool } from "../basic.js";
import { BasicTool } from "../basic.js";

/**
* Plugin bridge. Install plugin from zotero://plugin
Expand Down Expand Up @@ -33,7 +33,7 @@ export class PluginBridge {
}

private initializePluginBridge() {
const { AddonManager } = _importESModule(
const { AddonManager } = ChromeUtils.importESModule(
"resource://gre/modules/AddonManager.sys.mjs",
);
const Zotero = BasicTool.getZotero();
Expand Down
4 changes: 0 additions & 4 deletions src/version.ts

This file was deleted.