From 159ed6ba68d428d02c26475803bdcf2fef71201a Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Mon, 30 Jun 2025 18:36:51 -0400 Subject: [PATCH] More progress toward startup --- chrome/content/scaffold/scaffold.js | 2 +- ...ckingObserver.jsm => BlockingObserver.mjs} | 8 +- .../{HiddenBrowser.jsm => HiddenBrowser.mjs} | 24 +- chrome/content/zotero/RemoteTranslate.jsm | 2 +- ...lHandler.jsm => ZoteroProtocolHandler.mjs} | 34 ++- .../{ActorManager.jsm => ActorManager.mjs} | 4 +- .../zotero/actors/ZoteroPrintParent.jsm | 2 +- .../containers/tagSelectorContainer.jsx | 1 - chrome/content/zotero/debugViewer.js | 4 +- .../content/zotero/elements/editableText.js | 2 +- chrome/content/zotero/elements/itemBox.js | 2 +- chrome/content/zotero/fileInterface.js | 61 +++-- .../zotero/import/mendeley/authViewer.js | 2 +- .../import/mendeley/mendeleyAPIUtils.js | 2 +- .../zotero/import/mendeley/mendeleyImport.js | 11 +- chrome/content/zotero/include.js | 2 +- chrome/content/zotero/itemTree.jsx | 1 - chrome/content/zotero/locateMenu.js | 72 +++--- chrome/content/zotero/osfile.mjs | 7 +- .../preferences/preferences_advanced.js | 2 +- .../content/zotero/standalone/standalone.js | 26 +- chrome/content/zotero/update/updates.js | 54 ++-- chrome/content/zotero/xpcom/attachments.js | 2 +- chrome/content/zotero/xpcom/bluebirdShim.mjs | 10 +- .../content/zotero/xpcom/browserDownload.js | 2 +- chrome/content/zotero/xpcom/data/feedItem.js | 2 +- chrome/content/zotero/xpcom/db.js | 4 +- chrome/content/zotero/xpcom/editorInstance.js | 2 +- chrome/content/zotero/xpcom/file.js | 4 +- chrome/content/zotero/xpcom/fulltext.js | 6 +- chrome/content/zotero/xpcom/http.js | 2 +- chrome/content/zotero/xpcom/integration.js | 2 +- chrome/content/zotero/xpcom/intl.js | 2 +- chrome/content/zotero/xpcom/ipc.js | 2 +- chrome/content/zotero/xpcom/plugins.js | 7 +- chrome/content/zotero/xpcom/reader.js | 4 +- chrome/content/zotero/xpcom/schema.js | 7 +- chrome/content/zotero/xpcom/server/server.js | 2 +- chrome/content/zotero/xpcom/storage/webdav.js | 2 +- chrome/content/zotero/xpcom/style.js | 2 +- .../content/zotero/xpcom/sync/syncRunner.js | 5 +- .../xpcom/translation/translate_firefox.js | 2 +- .../zotero/xpcom/utilities_internal.js | 18 +- chrome/content/zotero/xpcom/zotero.js | 27 +- ...utocomplete.js => zotero-autocomplete.mjs} | 15 +- chrome/content/zotero/zotero.mjs | 12 +- chrome/content/zotero/zoteroPane.js | 244 +++++++++--------- resource/{PluralForm.jsm => PluralForm.mjs} | 5 +- resource/concurrentCaller.mjs | 5 +- resource/config.mjs | 4 +- resource/require.js | 8 + test/tests/HiddenBrowserTest.js | 4 +- test/tests/RemoteTranslateTest.js | 2 +- test/tests/attachmentsTest.js | 2 +- test/tests/concurrentCallerTest.js | 2 +- test/tests/fileTest.js | 3 +- test/tests/syncAPIClientTest.js | 2 +- test/tests/syncEngineTest.js | 2 +- test/tests/syncFullTextEngineTest.js | 2 +- test/tests/syncRunnerTest.js | 2 +- test/tests/translateTest.js | 2 +- test/tests/zfsTest.js | 2 +- 62 files changed, 381 insertions(+), 378 deletions(-) rename chrome/content/zotero/{BlockingObserver.jsm => BlockingObserver.mjs} (92%) rename chrome/content/zotero/{HiddenBrowser.jsm => HiddenBrowser.mjs} (93%) rename chrome/content/zotero/{ZoteroProtocolHandler.jsm => ZoteroProtocolHandler.mjs} (97%) rename chrome/content/zotero/actors/{ActorManager.jsm => ActorManager.mjs} (95%) rename chrome/content/zotero/{zotero-autocomplete.js => zotero-autocomplete.mjs} (95%) rename resource/{PluralForm.jsm => PluralForm.mjs} (99%) diff --git a/chrome/content/scaffold/scaffold.js b/chrome/content/scaffold/scaffold.js index 7bc48f3ff7..9202589da4 100644 --- a/chrome/content/scaffold/scaffold.js +++ b/chrome/content/scaffold/scaffold.js @@ -1980,7 +1980,7 @@ var Scaffold = new function () { if (test.type == 'web') { _logOutput("Loading web page from " + test.url); - const { HiddenBrowser } = ChromeUtils.import("chrome://zotero/content/HiddenBrowser.jsm"); + const { HiddenBrowser } = ChromeUtils.importESModule("chrome://zotero/content/HiddenBrowser.mjs"); let browser = new HiddenBrowser({ docShell: { allowMetaRedirects: true } }); diff --git a/chrome/content/zotero/BlockingObserver.jsm b/chrome/content/zotero/BlockingObserver.mjs similarity index 92% rename from chrome/content/zotero/BlockingObserver.jsm rename to chrome/content/zotero/BlockingObserver.mjs index a5c38c9fb1..532fcc38ec 100644 --- a/chrome/content/zotero/BlockingObserver.jsm +++ b/chrome/content/zotero/BlockingObserver.mjs @@ -23,15 +23,11 @@ ***** END LICENSE BLOCK ***** */ -const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); - -ChromeUtils.defineESModuleGetters(this, { +ChromeUtils.defineESModuleGetters(globalThis, { Zotero: "chrome://zotero/content/zotero.mjs", }); -var EXPORTED_SYMBOLS = ["BlockingObserver"]; - -class BlockingObserver { +export class BlockingObserver { shouldBlock; _observerAdded = false; diff --git a/chrome/content/zotero/HiddenBrowser.jsm b/chrome/content/zotero/HiddenBrowser.mjs similarity index 93% rename from chrome/content/zotero/HiddenBrowser.jsm rename to chrome/content/zotero/HiddenBrowser.mjs index 7af27d7271..9f96af103c 100644 --- a/chrome/content/zotero/HiddenBrowser.jsm +++ b/chrome/content/zotero/HiddenBrowser.mjs @@ -24,21 +24,17 @@ */ -var EXPORTED_SYMBOLS = ["HiddenBrowser"]; +const { BlockingObserver } = ChromeUtils.importESModule("chrome://zotero/content/BlockingObserver.mjs"); -const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); -const { BlockingObserver } = ChromeUtils.import("chrome://zotero/content/BlockingObserver.jsm"); +// TODO: Fx140: Migrate actors and re-enable +// ChromeUtils.importESModule("chrome://zotero/content/actors/ActorManager.mjs"); -ChromeUtils.import("chrome://zotero/content/actors/ActorManager.jsm"); - -/* global HiddenFrame, E10SUtils, this */ -XPCOMUtils.defineLazyModuleGetters(this, { - E10SUtils: "resource://gre/modules/E10SUtils.jsm", - HiddenFrame: "resource://gre/modules/HiddenFrame.jsm", - setTimeout: "resource://gre/modules/Timer.jsm", -}); -ChromeUtils.defineESModuleGetters(this, { - Zotero: "chrome://zotero/content/zotero.mjs" +/* global HiddenFrame, E10SUtils */ +ChromeUtils.defineESModuleGetters(globalThis, { + E10SUtils: "resource://gre/modules/E10SUtils.sys.mjs", + HiddenFrame: "resource://gre/modules/HiddenFrame.sys.mjs", + Zotero: "chrome://zotero/content/zotero.mjs", + setTimeout: "resource://gre/modules/Timer.sys.mjs" }); const progressListeners = new Set(); @@ -46,7 +42,7 @@ const progressListeners = new Set(); /** * Functions for creating and destroying hidden browser objects **/ -class HiddenBrowser { +export class HiddenBrowser { /** * @param {Object} options * @param {Boolean} [options.allowJavaScript] diff --git a/chrome/content/zotero/RemoteTranslate.jsm b/chrome/content/zotero/RemoteTranslate.jsm index 4430f42fbf..b6bd1bc88a 100644 --- a/chrome/content/zotero/RemoteTranslate.jsm +++ b/chrome/content/zotero/RemoteTranslate.jsm @@ -30,7 +30,7 @@ ChromeUtils.defineESModuleGetters(this, { Zotero: "chrome://zotero/content/zotero.mjs", }); -const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); +const { XPCOMUtils } = ChromeUtils.importESModule("resource://gre/modules/XPCOMUtils.sys.mjs"); XPCOMUtils.defineLazyModuleGetters(this, { TranslationManager: "chrome://zotero/content/actors/TranslationParent.jsm", ZOTERO_CONFIG: "resource://zotero/config.js", diff --git a/chrome/content/zotero/ZoteroProtocolHandler.jsm b/chrome/content/zotero/ZoteroProtocolHandler.mjs similarity index 97% rename from chrome/content/zotero/ZoteroProtocolHandler.jsm rename to chrome/content/zotero/ZoteroProtocolHandler.mjs index 5b653bcd5d..77a5f3c7a7 100644 --- a/chrome/content/zotero/ZoteroProtocolHandler.jsm +++ b/chrome/content/zotero/ZoteroProtocolHandler.mjs @@ -27,15 +27,13 @@ ***** END LICENSE BLOCK ***** */ -const EXPORTED_SYMBOLS = ['ZoteroProtocolHandler']; - const ZOTERO_SCHEME = "zotero"; const ZOTERO_PROTOCOL_CID = Components.ID("{9BC3D762-9038-486A-9D70-C997AF848A7C}"); const ZOTERO_PROTOCOL_CONTRACTID = "@mozilla.org/network/protocol;1?name=" + ZOTERO_SCHEME; const ZOTERO_PROTOCOL_NAME = "Zotero Chrome Extension Protocol"; -Components.utils.import("resource://gre/modules/ComponentUtils.jsm"); -const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); +ChromeUtils.importESModule("resource://gre/modules/ComponentUtils.sys.mjs"); +import { NetUtil } from "resource://gre/modules/NetUtil.sys.mjs"; const Cc = Components.classes; const Ci = Components.interfaces; @@ -45,9 +43,9 @@ const ios = Services.io; // Dummy chrome URL used to obtain a valid chrome channel const DUMMY_CHROME_URL = "chrome://zotero/content/zoteroPane.xul"; -var { Zotero } = ChromeUtils.importESModule("chrome://zotero/content/zotero.mjs"); +import { Zotero } from "chrome://zotero/content/zotero.mjs"; -function ZoteroProtocolHandler() { +export function ZoteroProtocolHandler() { this.wrappedJSObject = this; this._principal = null; this._extensions = {}; @@ -422,7 +420,7 @@ function ZoteroProtocolHandler() { var collation = Zotero.getLocaleCollation(); - var compareFunction = function(a, b) { + var compareFunction = function (a, b) { var index = 0; // Multidimensional sort @@ -819,7 +817,7 @@ function ZoteroProtocolHandler() { var SelectExtension = { noContent: true, - doAction: Zotero.Promise.coroutine(function* (uri) { + doAction: async function (uri) { var userLibraryID = Zotero.Libraries.userLibraryID; var path = uri.pathQueryRef; @@ -885,7 +883,7 @@ function ZoteroProtocolHandler() { return; } - var results = yield Zotero.API.getResultsFromParams(params); + var results = await Zotero.API.getResultsFromParams(params); if (!results.length) { var msg = "Objects not found"; @@ -920,7 +918,7 @@ function ZoteroProtocolHandler() { else { col = Zotero.Collections.get(params.scopeObjectID); } - yield zp.collectionsView.selectCollection(col.id); + await zp.collectionsView.selectCollection(col.id); } else if (params.scopeObject == 'searches') { let s; @@ -932,15 +930,15 @@ function ZoteroProtocolHandler() { else { s = Zotero.Searches.get(params.scopeObjectID); } - yield zp.collectionsView.selectSearch(s.id); + await zp.collectionsView.selectSearch(s.id); } // If collection not specified, select library root else { - yield zp.collectionsView.selectLibrary(params.libraryID); + await zp.collectionsView.selectLibrary(params.libraryID); } return zp.selectItems(results.map(x => x.id)); } - }), + }, newChannel: function (uri) { this.doAction(uri); @@ -1316,7 +1314,7 @@ function AsyncChannel(uri, loadInfo, gen) { } AsyncChannel.prototype = { - asyncOpen: Zotero.Promise.coroutine(function* (streamListener) { + asyncOpen: async function (streamListener) { if (this.loadGroup) this.loadGroup.addRequest(this, null); var channel = this; @@ -1361,7 +1359,7 @@ AsyncChannel.prototype = { var data; try { if (!data) { - data = yield Zotero.spawn(channel._generator, channel) + data = await Zotero.spawn(channel._generator, channel) } if (typeof data == 'string') { //Zotero.debug("AsyncChannel: Got string from generator"); @@ -1402,11 +1400,11 @@ AsyncChannel.prototype = { uri.QueryInterface(Ci.nsIURL); this.contentType = Zotero.MIME.getMIMETypeFromExtension(uri.fileExtension); if (!this.contentType) { - let sample = yield Zotero.File.getSample(uri.spec); + let sample = await Zotero.File.getSample(uri.spec); this.contentType = Zotero.MIME.getMIMETypeFromData(sample); } - Components.utils.import("resource://gre/modules/NetUtil.jsm"); + ChromeUtils.importESModule("resource://gre/modules/NetUtil.sys.mjs"); NetUtil.asyncFetch({ uri: data, loadUsingSystemPrincipal: true }, function (inputStream, status) { if (!Components.isSuccessCode(status)) { reject(); @@ -1449,7 +1447,7 @@ AsyncChannel.prototype = { } catch (e) {} } - }), + }, // nsIRequest isPending: function () { diff --git a/chrome/content/zotero/actors/ActorManager.jsm b/chrome/content/zotero/actors/ActorManager.mjs similarity index 95% rename from chrome/content/zotero/actors/ActorManager.jsm rename to chrome/content/zotero/actors/ActorManager.mjs index 76f1cb01ea..05696789a2 100644 --- a/chrome/content/zotero/actors/ActorManager.jsm +++ b/chrome/content/zotero/actors/ActorManager.mjs @@ -1,7 +1,5 @@ -var EXPORTED_SYMBOLS = []; - // Register Mozilla actors -ChromeUtils.importESModule("resource://gre/modules/ActorManagerParent.sys.mjs"); +import "resource://gre/modules/ActorManagerParent.sys.mjs"; ChromeUtils.registerWindowActor("PageData", { child: { diff --git a/chrome/content/zotero/actors/ZoteroPrintParent.jsm b/chrome/content/zotero/actors/ZoteroPrintParent.jsm index 7de688ecc8..608155fa04 100644 --- a/chrome/content/zotero/actors/ZoteroPrintParent.jsm +++ b/chrome/content/zotero/actors/ZoteroPrintParent.jsm @@ -1,6 +1,6 @@ var EXPORTED_SYMBOLS = ["ZoteroPrintParent"]; -const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); +const { XPCOMUtils } = ChromeUtils.importESModule("resource://gre/modules/XPCOMUtils.sys.mjs"); XPCOMUtils.defineLazyModuleGetters(this, { }); diff --git a/chrome/content/zotero/containers/tagSelectorContainer.jsx b/chrome/content/zotero/containers/tagSelectorContainer.jsx index 039595b93b..6416e24372 100644 --- a/chrome/content/zotero/containers/tagSelectorContainer.jsx +++ b/chrome/content/zotero/containers/tagSelectorContainer.jsx @@ -40,7 +40,6 @@ const defaults = { searchString: '', loaded: false }; -const { Cc, Ci } = require('chrome'); // first n tags will be measured using DOM method for more accurate measurment (at the cost of performance) const FORCE_DOM_TAGS_FOR_COUNT = 200; diff --git a/chrome/content/zotero/debugViewer.js b/chrome/content/zotero/debugViewer.js index 1130336959..d83be71c09 100644 --- a/chrome/content/zotero/debugViewer.js +++ b/chrome/content/zotero/debugViewer.js @@ -82,7 +82,7 @@ function submit(button) { button.setAttribute('disabled', ''); clearSubmitStatus(); - Components.utils.import("resource://zotero/config.js"); + Cu.import("resource://zotero/config.js"); var url = ZOTERO_CONFIG.REPOSITORY_URL + "report?debug=1"; var output = document.getElementById('errors').textContent + "\n\n" + "=========================================================\n\n" @@ -120,7 +120,7 @@ function submit(button) { } }, - QueryInterface: function(iid) { + QueryInterface: function (iid) { if (iid.equals(Components.interfaces.nsISupports) || iid.equals(Components.interfaces.nsIInterfaceRequestor) || iid.equals(Components.interfaces.nsIProgressEventSink)) { diff --git a/chrome/content/zotero/elements/editableText.js b/chrome/content/zotero/elements/editableText.js index d34d58b9e4..fc5c032734 100644 --- a/chrome/content/zotero/elements/editableText.js +++ b/chrome/content/zotero/elements/editableText.js @@ -26,7 +26,7 @@ "use strict"; { - const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); + const { XPCOMUtils } = ChromeUtils.importESModule("resource://gre/modules/XPCOMUtils.sys.mjs"); const lazy = {}; XPCOMUtils.defineLazyPreferenceGetter( diff --git a/chrome/content/zotero/elements/itemBox.js b/chrome/content/zotero/elements/itemBox.js index ac68be23a7..5cba4ad3c1 100644 --- a/chrome/content/zotero/elements/itemBox.js +++ b/chrome/content/zotero/elements/itemBox.js @@ -26,7 +26,7 @@ "use strict"; { - const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); + const { XPCOMUtils } = ChromeUtils.importESModule("resource://gre/modules/XPCOMUtils.sys.mjs"); const lazy = {}; XPCOMUtils.defineLazyPreferenceGetter( diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js index cbd6a11e0b..bc6c059f39 100644 --- a/chrome/content/zotero/fileInterface.js +++ b/chrome/content/zotero/fileInterface.js @@ -26,9 +26,8 @@ var { FilePicker } = ChromeUtils.importESModule('chrome://zotero/content/modules/filePicker.mjs'); import { ImportCitaviAnnotatons } from 'zotero/import/citavi'; -var { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); -XPCOMUtils.defineLazyModuleGetters(globalThis, { - HiddenBrowser: 'chrome://zotero/content/HiddenBrowser.jsm', +ChromeUtils.defineESModuleGetters(globalThis, { + HiddenBrowser: 'chrome://zotero/content/HiddenBrowser.mjs', }); /****Zotero_File_Exporter**** @@ -39,7 +38,7 @@ XPCOMUtils.defineLazyModuleGetters(globalThis, { /** * Constructs a new Zotero_File_Exporter with defaults **/ -var Zotero_File_Exporter = function() { +var Zotero_File_Exporter = function () { this.name = Zotero.getString("fileInterface.exportedItems"); this.collection = false; this.items = false; @@ -176,7 +175,7 @@ Zotero_File_Exporter.prototype.save = async function () { * A singleton to interface with ZoteroPane to provide export/bibliography * capabilities **/ -var Zotero_File_Interface = new function() { +var Zotero_File_Interface = new function () { var _unlock; this.exportCollection = exportCollection; @@ -342,7 +341,7 @@ var Zotero_File_Interface = new function() { var dbs = []; try { var dir = this.getMendeleyDirectory(); - if (!await OS.File.exists(dir)) { + if (!(await OS.File.exists(dir))) { Zotero.debug(`${dir} does not exist`); return dbs; } @@ -407,7 +406,7 @@ var Zotero_File_Interface = new function() { * for displaying progress in a different way. This also causes an error to be throw * instead of shown in the main window. */ - this.importFile = Zotero.Promise.coroutine(function* (options = {}) { + this.importFile = async function (options = {}) { if (!options) { options = {}; } @@ -432,7 +431,7 @@ var Zotero_File_Interface = new function() { try { let zp = Zotero.getActiveZoteroPane(); if (!zp.canEdit()) { - yield zp.collectionsView.selectLibrary(Zotero.Libraries.userLibraryID); + await zp.collectionsView.selectLibrary(Zotero.Libraries.userLibraryID); } } catch (e) { @@ -445,7 +444,7 @@ var Zotero_File_Interface = new function() { var translation; if (options.mendeleyAuth || options.mendeleyCode) { - translation = yield _getMendeleyTranslation(); + translation = await _getMendeleyTranslation(); translation.createNewCollection = createNewCollection; translation.mendeleyAuth = options.mendeleyAuth; translation.mendeleyCode = options.mendeleyCode; @@ -453,7 +452,7 @@ var Zotero_File_Interface = new function() { translation.relinkOnly = options.relinkOnly; } else if (options.folder) { - Components.utils.import("chrome://zotero/content/import/folderImport.js"); + Cu.import("chrome://zotero/content/import/folderImport.js"); translation = new Zotero_Import_Folder({ folder: options.folder, recreateStructure: options.recreateStructure, @@ -463,14 +462,14 @@ var Zotero_File_Interface = new function() { } else { // Check if the file is an SQLite database - var sample = yield Zotero.File.getSample(file.path); + var sample = await Zotero.File.getSample(file.path); if (file.path == Zotero.DataDirectory.getDatabase()) { // Blacklist the current Zotero database, which would cause a hang } else if (Zotero.MIME.sniffForMIMEType(sample) == 'application/x-sqlite3') { // Mendeley import doesn't use the real translation architecture, but we create a // translation object with the same interface - translation = yield _getMendeleyTranslation(); + translation = await _getMendeleyTranslation(); translation.createNewCollection = createNewCollection; defaultNewCollectionPrefix = Zotero.getString( 'fileInterface.appImportCollection', 'Mendeley' @@ -496,13 +495,13 @@ var Zotero_File_Interface = new function() { defaultNewCollectionPrefix, onBeforeImport }); - }); + }; /** * Imports from clipboard */ - this.importFromClipboard = Zotero.Promise.coroutine(function* () { + this.importFromClipboard = async function () { var str = Zotero.Utilities.Internal.getClipboard("text/plain"); if(!str) { var ps = Services.prompt; @@ -518,11 +517,11 @@ var Zotero_File_Interface = new function() { try { if (!ZoteroPane.collectionsView.editable) { - yield ZoteroPane.collectionsView.selectLibrary(); + await ZoteroPane.collectionsView.selectLibrary(); } } catch(e) {} - yield _finishImport({ + await _finishImport({ translation, createNewCollection: false }); @@ -536,10 +535,10 @@ var Zotero_File_Interface = new function() { catch (e) { Zotero.logError(e, 2); } - }); + }; - var _finishImport = Zotero.Promise.coroutine(function* (options) { + var _finishImport = async function (options) { var t = performance.now(); var translation = options.translation; @@ -555,12 +554,12 @@ var Zotero_File_Interface = new function() { var showProgressWindow = !onBeforeImport; - let translators = yield translation.getTranslators(); + let translators = await translation.getTranslators(); // Unrecognized file if (!translators.length) { if (onBeforeImport) { - yield onBeforeImport(false); + await onBeforeImport(false); } let ps = Services.prompt; @@ -587,7 +586,7 @@ var Zotero_File_Interface = new function() { let zp = Zotero.getActiveZoteroPane(); libraryID = zp.getSelectedLibraryID(); if (addToLibraryRoot) { - yield zp.collectionsView.selectLibrary(libraryID); + await zp.collectionsView.selectLibrary(libraryID); } else if (!createNewCollection) { importCollection = zp.getSelectedCollection(); @@ -618,7 +617,7 @@ var Zotero_File_Interface = new function() { importCollection = new Zotero.Collection; importCollection.libraryID = libraryID; importCollection.name = collectionName; - yield importCollection.saveTx(); + await importCollection.saveTx(); } translation.setTranslator(translators[0]); @@ -641,15 +640,15 @@ var Zotero_File_Interface = new function() { progress.setProgress(translation.getProgress()); }); - yield Zotero.Promise.delay(0); + await Zotero.Promise.delay(0); } else { - yield onBeforeImport(translation); + await onBeforeImport(translation); } var notifierQueue = new Zotero.Notifier.Queue; try { - yield translation.translate({ + await translation.translate({ libraryID, collections: importCollection ? [importCollection.id] : null, linkFiles, @@ -672,11 +671,11 @@ var Zotero_File_Interface = new function() { return false; } finally { - yield Zotero.Notifier.commit(notifierQueue); + await Zotero.Notifier.commit(notifierQueue); } if (translators[0].label.match(/^Citavi (?:[56]) XML/i)) { - yield ImportCitaviAnnotatons(translation); + await ImportCitaviAnnotatons(translation); } var numItems = translation.newItems.length; @@ -700,16 +699,16 @@ var Zotero_File_Interface = new function() { Zotero.debug(`Imported ${numItems} item(s) in ${performance.now() - t} ms`); return true; - }); + }; var _getMendeleyTranslation = async function () { if (true) { - Components.utils.import("chrome://zotero/content/import/mendeley/mendeleyImport.js"); + Cu.import("chrome://zotero/content/import/mendeley/mendeleyImport.js"); } // TEMP: Load uncached from ~/zotero-client for development else { - Components.utils.import("resource://gre/modules/FileUtils.jsm"); + ChromeUtils.importESModule("resource://gre/modules/FileUtils.sys.mjs"); let file = FileUtils.getDir("Home", []); file = OS.Path.join( file.path, @@ -984,7 +983,7 @@ var Zotero_File_Interface = new function() { }; // Handles the display of a progress indicator -Zotero_File_Interface.Progress = new function() { +Zotero_File_Interface.Progress = new function () { this.show = show; this.close = close; diff --git a/chrome/content/zotero/import/mendeley/authViewer.js b/chrome/content/zotero/import/mendeley/authViewer.js index 1279f7aaff..e5babdfb36 100644 --- a/chrome/content/zotero/import/mendeley/authViewer.js +++ b/chrome/content/zotero/import/mendeley/authViewer.js @@ -2,7 +2,7 @@ /* global Zotero_File_Interface: false */ Services.scriptloader.loadSubScript("chrome://zotero/content/fileInterface.js", window); -const { E10SUtils } = ChromeUtils.import("resource://gre/modules/E10SUtils.jsm"); +const { E10SUtils } = ChromeUtils.importESModule("resource://gre/modules/E10SUtils.sys.mjs"); const URI = `https://api.mendeley.com/oauth/authorize?client_id=5907&redirect_uri=https%3A%2F%2Fzotero-static.s3.amazonaws.com%2Fmendeley_oauth_redirect.html&response_type=code&state=&scope=all`; var startTime; diff --git a/chrome/content/zotero/import/mendeley/mendeleyAPIUtils.js b/chrome/content/zotero/import/mendeley/mendeleyAPIUtils.js index d86ef0d1a4..08b52378b9 100644 --- a/chrome/content/zotero/import/mendeley/mendeleyAPIUtils.js +++ b/chrome/content/zotero/import/mendeley/mendeleyAPIUtils.js @@ -157,7 +157,7 @@ const getAll = async (tokens, endPoint, params = {}, headers = {}, options = {}, * @throws {Error} - Throws an error if login fails, or if the access token cannot be obtained. */ const obtainReferenceManagerToken = async (login, password) => { - let { HiddenBrowser } = ChromeUtils.import("chrome://zotero/content/HiddenBrowser.jsm"); + let { HiddenBrowser } = ChromeUtils.importESModule("chrome://zotero/content/HiddenBrowser.mjs"); let cookieSandbox = new Zotero.CookieSandbox({}); let browser = new HiddenBrowser({ cookieSandbox, diff --git a/chrome/content/zotero/import/mendeley/mendeleyImport.js b/chrome/content/zotero/import/mendeley/mendeleyImport.js index 7fae113ceb..7e0bc60075 100644 --- a/chrome/content/zotero/import/mendeley/mendeleyImport.js +++ b/chrome/content/zotero/import/mendeley/mendeleyImport.js @@ -1,6 +1,6 @@ -/* eslint-disable no-await-in-loop, camelcase */ + /* global mendeleyDBMaps:false, mendeleyOnlineMappings:false, mendeleyAPIUtils:false, PathUtils: false */ -var EXPORTED_SYMBOLS = ["Zotero_Import_Mendeley"]; //eslint-disable-line no-unused-vars +var EXPORTED_SYMBOLS = ["Zotero_Import_Mendeley"]; var { OS } = ChromeUtils.importESModule("chrome://zotero/content/osfile.mjs"); Services.scriptloader.loadSubScript("chrome://zotero/content/include.js"); @@ -120,7 +120,7 @@ Zotero_Import_Mendeley.prototype.translate = async function (options = {}) { } try { - if (this._file && !await this._isValidDatabase()) { + if (this._file && !(await this._isValidDatabase())) { throw new Error("Not a valid Mendeley database"); } @@ -838,12 +838,11 @@ Zotero_Import_Mendeley.prototype._getDocumentFilesAPI = async function (document this._totalSize = 0; - Components.utils.import("resource://zotero/concurrentCaller.js"); + const { ConcurrentCaller } = ChromeUtils.importESModule("resource://zotero/concurrentCaller.mjs"); this._caller = new ConcurrentCaller({ numConcurrent: 6, onError: e => Zotero.logError(e), - logger: Zotero.debug, - Promise: Zotero.Promise + logger: Zotero.debug }); for (let doc of documents) { diff --git a/chrome/content/zotero/include.js b/chrome/content/zotero/include.js index 8fb85a11ae..b0106e9823 100644 --- a/chrome/content/zotero/include.js +++ b/chrome/content/zotero/include.js @@ -1,6 +1,6 @@ var { Zotero } = ChromeUtils.importESModule("chrome://zotero/content/zotero.mjs"); -// Components.utils.import('resource://zotero/require.js'); +// Cu.import('resource://zotero/require.js'); // Not using Cu.import here since we don't want the require module to be cached // for includes within ZoteroPane or other code, where we want the window // instance available to modules. diff --git a/chrome/content/zotero/itemTree.jsx b/chrome/content/zotero/itemTree.jsx index 35e8b6d31e..e918e98d10 100644 --- a/chrome/content/zotero/itemTree.jsx +++ b/chrome/content/zotero/itemTree.jsx @@ -33,7 +33,6 @@ const { renderCell, formatColumnName } = VirtualizedTable; const Icons = require('components/icons'); const { getCSSIcon, getCSSItemTypeIcon } = Icons; const { COLUMNS } = require("zotero/itemTreeColumns"); -const { Cc, Ci, Cu, ChromeUtils } = require('chrome'); const { OS } = ChromeUtils.importESModule("chrome://zotero/content/osfile.mjs"); const { XPCOMUtils } = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm"); diff --git a/chrome/content/zotero/locateMenu.js b/chrome/content/zotero/locateMenu.js index e8ab8b6dcf..0a488ddd23 100644 --- a/chrome/content/zotero/locateMenu.js +++ b/chrome/content/zotero/locateMenu.js @@ -23,12 +23,12 @@ ***** END LICENSE BLOCK ***** */ -Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); +ChromeUtils.importESModule("resource://gre/modules/XPCOMUtils.sys.mjs"); /* * This object contains the various functions for the interface */ -var Zotero_LocateMenu = new function() { +var Zotero_LocateMenu = new function () { XPCOMUtils.defineLazyServiceGetter(this, "ios", "@mozilla.org/network/io-service;1", "nsIIOService"); /** @@ -97,15 +97,15 @@ var Zotero_LocateMenu = new function() { * @param {Boolean} showIcons Whether menu items should have associated icons * @return {Promise} */ - this.buildContextMenu = Zotero.Promise.coroutine(function* (menu, showIcons) { + this.buildContextMenu = async function (menu, showIcons) { // get selected items - var selectedItems = yield _getSelectedItems(); + var selectedItems = await _getSelectedItems(); // if no items selected or >20 items selected, stop now if(!selectedItems.length || selectedItems.length > 20) return; // add view options - yield _addViewOptions(menu, selectedItems, showIcons); + await _addViewOptions(menu, selectedItems, showIcons); /*// look for locate engines var availableEngines = _getAvailableLocateEngines(selectedItems); @@ -122,8 +122,8 @@ var Zotero_LocateMenu = new function() { menu.appendChild(submenu); }*/ - yield document.l10n.translateFragment(menu); - }); + await document.l10n.translateFragment(menu); + }; function _addViewOption(selectedItems, optionName, optionObject, showIcons) { var menuitem; @@ -234,7 +234,7 @@ var Zotero_LocateMenu = new function() { * @param {Function|null} items Function to call to locate items * @param {Boolean} showIcons Whether menu items should have associated icons */ - this.addLocateEngines = function(menu, engines, locateFn, showIcons) { + this.addLocateEngines = function (menu, engines, locateFn, showIcons) { if(!locateFn) { locateFn = this.locateItem; } @@ -298,7 +298,7 @@ var Zotero_LocateMenu = new function() { /** * Locate selected items */ - this.locateItem = async function(event, selectedItems) { + this.locateItem = async function (event, selectedItems) { if(!selectedItems) { selectedItems = await _getSelectedItems(); } @@ -351,7 +351,7 @@ var Zotero_LocateMenu = new function() { var item = allSelectedItems.shift(); if (item.isAnnotation()) { let attachment = item.parentItem; - if (attachment.parentItem && attachment === await attachment.parentItem.getBestAttachment()) { + if (attachment.parentItem && attachment === (await attachment.parentItem.getBestAttachment())) { selectedItems.push(attachment.parentItem); } else { @@ -452,19 +452,19 @@ var Zotero_LocateMenu = new function() { this._numAttachments = numAttachments; }; - this.handleItems = Zotero.Promise.coroutine(function* (items, event) { + this.handleItems = async function (items, event) { var attachments = []; for (let item of items) { - var attachment = yield _getFirstUsableAttachment(item); + var attachment = await _getFirstUsableAttachment(item); if (attachment) attachments.push(attachment.id); } ZoteroPane_Local.viewAttachment(attachments, event, false, { forceAlternateWindowBehavior: alternateWindowBehavior }); - }); + }; - var _getFirstUsableAttachment = Zotero.Promise.coroutine(function* (item) { - var attachments = item.isAttachment() ? [item] : (yield item.getBestAttachments()); + var _getFirstUsableAttachment = async function (item) { + var attachments = item.isAttachment() ? [item] : ((await item.getBestAttachments())); for (let i = 0; i < attachments.length; i++) { let attachment = attachments[i]; if (attachment.attachmentReaderType @@ -473,7 +473,7 @@ var Zotero_LocateMenu = new function() { } } return null; - }); + }; } ViewOptions.viewAttachmentInTab = new ViewAttachment(false); @@ -484,18 +484,18 @@ var Zotero_LocateMenu = new function() { * * Should appear only when an item or an attachment has a URL */ - ViewOptions.online = new function() { + ViewOptions.online = new function () { this.className = "zotero-menuitem-view-online"; this.canHandleItem = function (item) { return _getURL(item).then((val) => val !== false); } - this.handleItems = Zotero.Promise.coroutine(function* (items, event) { - var urls = yield Zotero.Promise.all(items.map(item => _getURL(item))); + this.handleItems = async function (items, event) { + var urls = await Promise.all(items.map(item => _getURL(item))); ZoteroPane_Local.loadURI(urls.filter(url => !!url), event); - }); + }; - var _getURL = Zotero.Promise.coroutine(function* (item) { + var _getURL = async function (item) { // try url field for item and for attachments var itemURL = item.getField('url'); if (itemURL) { @@ -530,7 +530,7 @@ var Zotero_LocateMenu = new function() { } return false; - }); + }; }; /** @@ -539,32 +539,32 @@ var Zotero_LocateMenu = new function() { * Should appear only when an item or a linked or attached file or web attachment can be * viewed by an internal non-native handler and "launchNonNativeFiles" pref is disabled */ - ViewOptions.externalViewer = new function() { + ViewOptions.externalViewer = new function () { this.className = "zotero-menuitem-view-external"; this.useExternalViewer = true; - this.canHandleItem = Zotero.Promise.coroutine(function* (item) { + this.canHandleItem = async function (item) { //return (this.useExternalViewer ^ Zotero.Prefs.get('launchNonNativeFiles')) // && (yield _getBestNonNativeAttachment(item)); return false; - }); + }; - this.handleItems = Zotero.Promise.coroutine(function* (items, event) { + this.handleItems = async function (items, event) { var attachments = []; for (let item of items) { - var attachment = yield _getBestNonNativeAttachment(item); + var attachment = await _getBestNonNativeAttachment(item); if(attachment) attachments.push(attachment.id); } ZoteroPane_Local.viewAttachment(attachments, event, false, this.useExternalViewer); - }); + }; - var _getBestNonNativeAttachment = Zotero.Promise.coroutine(function* (item) { - var attachments = item.isAttachment() ? [item] : (yield item.getBestAttachments()); + var _getBestNonNativeAttachment = async function (item) { + var attachments = item.isAttachment() ? [item] : ((await item.getBestAttachments())); for (let i = 0; i < attachments.length; i++) { let attachment = attachments[i]; if(attachment.attachmentLinkMode !== Zotero.Attachments.LINK_MODE_LINKED_URL) { - var path = yield attachment.getFilePathAsync(); + var path = await attachment.getFilePathAsync(); if (path) { try { var ext = Zotero.File.getExtension(Zotero.File.pathToFile(path)); @@ -582,7 +582,7 @@ var Zotero_LocateMenu = new function() { } } return false; - }); + }; }; /** @@ -591,7 +591,7 @@ var Zotero_LocateMenu = new function() { * Should appear only when an item or a linked or attached file or web attachment can be * viewed by an internal non-native handler and "launchNonNativeFiles" pref is enabled */ - ViewOptions.internalViewer = new function() { + ViewOptions.internalViewer = new function () { this.icon = "chrome://zotero/skin/locate-internal-viewer.png"; this.useExternalViewer = false; this.canHandleItem = ViewOptions.externalViewer.canHandleItem; @@ -604,7 +604,7 @@ var Zotero_LocateMenu = new function() { * Should appear only when an item is a file or web attachment, or has a linked or attached * file or web attachment */ - ViewOptions.showFile = new function() { + ViewOptions.showFile = new function () { this.className = "zotero-menuitem-show-file"; this.hideInToolbar = true; @@ -633,9 +633,9 @@ var Zotero_LocateMenu = new function() { * * Should appear only for regular items */ - ViewOptions._libraryLookup = new function() { + ViewOptions._libraryLookup = new function () { this.className = "zotero-menuitem-library-lookup"; - this.canHandleItem = function (item) { return Zotero.Promise.resolve(item.isRegularItem()); }; + this.canHandleItem = function (item) { return Promise.resolve(item.isRegularItem()); }; this.handleItems = async function (items, event) { // If no resolver configured, show error if (!Zotero.Prefs.get('openURL.resolver')) { diff --git a/chrome/content/zotero/osfile.mjs b/chrome/content/zotero/osfile.mjs index afca9247ad..830cb28311 100644 --- a/chrome/content/zotero/osfile.mjs +++ b/chrome/content/zotero/osfile.mjs @@ -1,6 +1,11 @@ // // Compatibility shims from the Mozilla codebase // + +ChromeUtils.defineESModuleGetters(globalThis, { + FileUtils: "resource://gre/modules/FileUtils.sys.mjs", +}); + const isWin = Services.appinfo.OS == 'WINNT'; export let OS = { @@ -495,4 +500,4 @@ function wrapWrite(func) { throw e; } }; -} \ No newline at end of file +} diff --git a/chrome/content/zotero/preferences/preferences_advanced.js b/chrome/content/zotero/preferences/preferences_advanced.js index 2e083ef438..bd4f903097 100644 --- a/chrome/content/zotero/preferences/preferences_advanced.js +++ b/chrome/content/zotero/preferences/preferences_advanced.js @@ -96,7 +96,7 @@ Zotero_Preferences.Advanced = { return; } - Components.utils.import("resource://zotero/config.js") + Cu.import("resource://zotero/config.js") var ps = Services.prompt; // If there's a migration marker, point data directory back to the current location and remove diff --git a/chrome/content/zotero/standalone/standalone.js b/chrome/content/zotero/standalone/standalone.js index 8edbd6d72e..65e739a599 100644 --- a/chrome/content/zotero/standalone/standalone.js +++ b/chrome/content/zotero/standalone/standalone.js @@ -27,7 +27,7 @@ /** * This object contains the various functions for the interface */ -const ZoteroStandalone = new function() { +const ZoteroStandalone = new function () { const FONT_SIZES = [ "0.77", // 10 "0.85", // 11 @@ -232,7 +232,7 @@ const ZoteroStandalone = new function() { /** * Builds new item menu */ - this.buildNewItemMenu = function() { + this.buildNewItemMenu = function () { var addMenu = document.getElementById('menu_NewItemPopup'); // Remove all nodes so we can regenerate @@ -252,7 +252,7 @@ const ZoteroStandalone = new function() { }); } var collation = Zotero.getLocaleCollation(); - itemTypes.sort(function(a, b) { + itemTypes.sort(function (a, b) { return collation.compareString(1, a.localized, b.localized); }); @@ -261,7 +261,7 @@ const ZoteroStandalone = new function() { menuitem.setAttribute("label", itemTypes[i].localized); menuitem.setAttribute("tooltiptext", ""); let type = itemTypes[i].id; - menuitem.addEventListener("command", function() { + menuitem.addEventListener("command", function () { ZoteroPane_Local.newItem(type, null, null, true); }, false); menuitem.className = "zotero-tb-add"; @@ -739,8 +739,8 @@ const ZoteroStandalone = new function() { /** * Handles help menu requests */ - this.openHelp = function(type) { - Components.utils.import("resource://zotero/config.js"); + this.openHelp = function (type) { + Cu.import("resource://zotero/config.js"); switch (type) { case "troubleshooting": @@ -763,7 +763,7 @@ const ZoteroStandalone = new function() { /** * Checks for updates */ - this.checkForUpdates = function() { + this.checkForUpdates = function () { Zotero.debug('ZoteroStandalone.checkForUpdates is deprecated -- use Zotero.openCheckForUpdatesWindow() instead'); Zotero.openCheckForUpdatesWindow(); } @@ -771,7 +771,7 @@ const ZoteroStandalone = new function() { /** * Called before standalone window is closed */ - this.onUnload = function() { + this.onUnload = function () { Zotero.Notifier.unregisterObserver(this._notifierID); ZoteroPane.destroy(); } @@ -821,7 +821,7 @@ ZoteroStandalone.DebugOutput = { return Zotero.Promise.coroutine(function* () { Zotero.debug("Submitting debug output"); - Components.utils.import("resource://zotero/config.js"); + Cu.import("resource://zotero/config.js"); var url = ZOTERO_CONFIG.REPOSITORY_URL + "report?debug=1"; var output = yield Zotero.Debug.get( @@ -858,7 +858,7 @@ ZoteroStandalone.DebugOutput = { } }, - QueryInterface: function(iid) { + QueryInterface: function (iid) { if (iid.equals(Components.interfaces.nsISupports) || iid.equals(Components.interfaces.nsIInterfaceRequestor) || iid.equals(Components.interfaces.nsIProgressEventSink)) { @@ -985,7 +985,7 @@ ZoteroStandalone.DebugOutput = { async function toJavaScriptConsole() { // We need the DevTools' built-in require() for this - const { require } = ChromeUtils.import("resource://devtools/shared/loader/Loader.jsm"); + const { require } = ChromeUtils.importESModule("resource://devtools/shared/loader/Loader.sys.mjs"); const { BrowserConsoleManager } = require("resource://devtools/client/webconsole/browser-console-manager.js"); await BrowserConsoleManager.openBrowserConsoleOrFocus(); // Add missing aria labels for the the VPAT review @@ -1057,5 +1057,5 @@ function openUILinkIn(url) { ZoteroPane.loadURI(url); } -window.addEventListener("load", function(e) { ZoteroStandalone.onLoad(e); }, false); -window.addEventListener("unload", function(e) { ZoteroStandalone.onUnload(e); }, false); +window.addEventListener("load", function (e) { ZoteroStandalone.onLoad(e); }, false); +window.addEventListener("unload", function (e) { ZoteroStandalone.onUnload(e); }, false); diff --git a/chrome/content/zotero/update/updates.js b/chrome/content/zotero/update/updates.js index f3c0784ac5..be5dff3a03 100644 --- a/chrome/content/zotero/update/updates.js +++ b/chrome/content/zotero/update/updates.js @@ -9,10 +9,10 @@ /* globals DownloadUtils, Services, AUSTLMY */ var { Zotero } = ChromeUtils.importESModule("chrome://zotero/content/zotero.mjs"); -const { DownloadUtils } = ChromeUtils.import( - "resource://gre/modules/DownloadUtils.jsm" +const { DownloadUtils } = ChromeUtils.importESModule( + "resource://gre/modules/DownloadUtils.sys.mjs" ); -const { UpdateUtils } = ChromeUtils.import("resource://gre/modules/UpdateUtils.jsm"); +const { UpdateUtils } = ChromeUtils.importESModule("resource://gre/modules/UpdateUtils.sys.mjs"); const gAUS = Cc["@mozilla.org/updates/update-service;1"].getService(Ci.nsIApplicationUpdateService); @@ -378,7 +378,7 @@ var gUpdates = { for (var i = 0; i < pages.length; ++i) { var page = pages[i]; if (page.localName == "wizardpage") { - // eslint-disable-next-line no-eval + this._pages[page.pageid] = eval(page.getAttribute("object")); } } @@ -389,97 +389,97 @@ var gUpdates = { this._cacheButtonStrings("extra1"); this._cacheButtonStrings("extra2"); - document.addEventListener("wizardfinish", function() { + document.addEventListener("wizardfinish", function () { gUpdates.onWizardFinish(); }); - document.addEventListener("wizardcancel", function() { + document.addEventListener("wizardcancel", function () { gUpdates.onWizardCancel(); }); - document.addEventListener("wizardnext", function() { + document.addEventListener("wizardnext", function () { gUpdates.onWizardNext(); }); document .getElementById("checking") - .addEventListener("pageshow", function() { + .addEventListener("pageshow", function () { gCheckingPage.onPageShow(); }); document .getElementById("noupdatesfound") - .addEventListener("pageshow", function() { + .addEventListener("pageshow", function () { gNoUpdatesPage.onPageShow(); }); document .getElementById("manualUpdate") - .addEventListener("pageshow", function() { + .addEventListener("pageshow", function () { gManualUpdatePage.onPageShow(); }); document .getElementById("unsupported") - .addEventListener("pageshow", function() { + .addEventListener("pageshow", function () { gUnsupportedPage.onPageShow(); }); document .getElementById("updatesfoundbasic") - .addEventListener("pageshow", function() { + .addEventListener("pageshow", function () { gUpdatesFoundBasicPage.onPageShow(); }); document .getElementById("downloading") - .addEventListener("pageshow", function() { + .addEventListener("pageshow", function () { gDownloadingPage.onPageShow(); }); - document.getElementById("errors").addEventListener("pageshow", function() { + document.getElementById("errors").addEventListener("pageshow", function () { gErrorsPage.onPageShow(); }); document .getElementById("errorextra") - .addEventListener("pageshow", function() { + .addEventListener("pageshow", function () { gErrorExtraPage.onPageShow(); }); document .getElementById("errorpatching") - .addEventListener("pageshow", function() { + .addEventListener("pageshow", function () { gErrorPatchingPage.onPageShow(); }); document .getElementById("finished") - .addEventListener("pageshow", function() { + .addEventListener("pageshow", function () { gFinishedPage.onPageShow(); }); document .getElementById("finishedBackground") - .addEventListener("pageshow", function() { + .addEventListener("pageshow", function () { gFinishedPage.onPageShowBackground(); }); document .getElementById("updatesfoundbasic") - .addEventListener("extra1", function() { + .addEventListener("extra1", function () { gUpdatesFoundBasicPage.onExtra1(); }); document .getElementById("downloading") - .addEventListener("extra1", function() { + .addEventListener("extra1", function () { gDownloadingPage.onHide(); }); - document.getElementById("finished").addEventListener("extra1", function() { + document.getElementById("finished").addEventListener("extra1", function () { gFinishedPage.onExtra1(); }); document .getElementById("finishedBackground") - .addEventListener("extra1", function() { + .addEventListener("extra1", function () { gFinishedPage.onExtra1(); }); document .getElementById("updatesfoundbasic") - .addEventListener("extra2", function() { + .addEventListener("extra2", function () { gUpdatesFoundBasicPage.onExtra2(); }); document .getElementById("finishedBackground") - .addEventListener("extra2", function() { + .addEventListener("extra2", function () { gFinishedPage.onExtra2(); }); @@ -487,7 +487,7 @@ var gUpdates = { gUpdates.wiz.shadowRoot.querySelector('.wizard-header').hidden = true; // Advance to the Start page. - this.getStartPageID(function(startPageID) { + this.getStartPageID(function (startPageID) { LOG( "gUpdates", "onLoad - setting current page to startpage " + startPageID @@ -600,7 +600,7 @@ var gUpdates = { var um = Cc["@mozilla.org/updates/update-manager;1"].getService( Ci.nsIUpdateManager ); - let activeUpdate = await um.getDownloadingUpdate() || await um.getReadyUpdate(); + let activeUpdate = (await um.getDownloadingUpdate()) || (await um.getReadyUpdate()); if (activeUpdate) { this.setUpdate(activeUpdate); aCallback("downloading"); @@ -931,7 +931,7 @@ var gDownloadingPage = { var um = Cc["@mozilla.org/updates/update-manager;1"].getService( Ci.nsIUpdateManager ); - var activeUpdate = await um.getDownloadingUpdate() || await um.getReadyUpdate(); + var activeUpdate = (await um.getDownloadingUpdate()) || (await um.getReadyUpdate()); if (activeUpdate) { gUpdates.setUpdate(activeUpdate); diff --git a/chrome/content/zotero/xpcom/attachments.js b/chrome/content/zotero/xpcom/attachments.js index d8a42cf098..fb469f0ddd 100644 --- a/chrome/content/zotero/xpcom/attachments.js +++ b/chrome/content/zotero/xpcom/attachments.js @@ -24,7 +24,7 @@ */ Zotero.Attachments = new function () { - const { HiddenBrowser } = ChromeUtils.import("chrome://zotero/content/HiddenBrowser.jsm"); + const { HiddenBrowser } = ChromeUtils.importESModule("chrome://zotero/content/HiddenBrowser.mjs"); // Keep in sync with Zotero.Schema.integrityCheck() and this.linkModeToName() this.LINK_MODE_IMPORTED_FILE = 0; diff --git a/chrome/content/zotero/xpcom/bluebirdShim.mjs b/chrome/content/zotero/xpcom/bluebirdShim.mjs index 3a4a3932ae..88a82c2b26 100644 --- a/chrome/content/zotero/xpcom/bluebirdShim.mjs +++ b/chrome/content/zotero/xpcom/bluebirdShim.mjs @@ -1,4 +1,4 @@ -export default class BluebirdShimPromise extends Promise { +export class BluebirdShimPromise extends Promise { static delay(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } @@ -11,4 +11,12 @@ export default class BluebirdShimPromise extends Promise { }); return deferred; } + + static method(fn) { + // TEMP: "Implement" this with a stub until we update zotero/translate + // Don't bother with synchronous resolution - this is just enough to get the client to load + return function (...args) { + return Promise.resolve(fn.apply(this, args)); + }; + } } diff --git a/chrome/content/zotero/xpcom/browserDownload.js b/chrome/content/zotero/xpcom/browserDownload.js index e5927b5db0..6d98d82eb3 100644 --- a/chrome/content/zotero/xpcom/browserDownload.js +++ b/chrome/content/zotero/xpcom/browserDownload.js @@ -23,7 +23,7 @@ ***** END LICENSE BLOCK ***** */ -const { HiddenBrowser } = ChromeUtils.import("chrome://zotero/content/HiddenBrowser.jsm"); +const { HiddenBrowser } = ChromeUtils.importESModule("chrome://zotero/content/HiddenBrowser.mjs"); Zotero.BrowserDownload = { HANDLED_URLS: { diff --git a/chrome/content/zotero/xpcom/data/feedItem.js b/chrome/content/zotero/xpcom/data/feedItem.js index fdd8c2546d..b7b4dc9eac 100644 --- a/chrome/content/zotero/xpcom/data/feedItem.js +++ b/chrome/content/zotero/xpcom/data/feedItem.js @@ -209,7 +209,7 @@ Zotero.FeedItem.prototype.toggleRead = async function (state) { */ Zotero.FeedItem.prototype.translate = async function (libraryID, collectionID) { const { RemoteTranslate } = ChromeUtils.import("chrome://zotero/content/RemoteTranslate.jsm"); - const { HiddenBrowser } = ChromeUtils.import("chrome://zotero/content/HiddenBrowser.jsm"); + const { HiddenBrowser } = ChromeUtils.importESModule("chrome://zotero/content/HiddenBrowser.mjs"); Zotero.debug("Translating feed item " + this.id + " with URL " + this.getField('url'), 2); if (Zotero.locked) { diff --git a/chrome/content/zotero/xpcom/db.js b/chrome/content/zotero/xpcom/db.js index f226631b9b..7dbd7e6813 100644 --- a/chrome/content/zotero/xpcom/db.js +++ b/chrome/content/zotero/xpcom/db.js @@ -42,7 +42,9 @@ Zotero.DBConnection = function (dbNameOrPath) { "2152857611" ]; - Components.utils.import("resource://gre/modules/Sqlite.jsm", this); + ChromeUtils.defineESModuleGetters(this, { + Sqlite: "resource://gre/modules/Sqlite.sys.mjs", + }); this.closed = false; this.skipBackup = false; diff --git a/chrome/content/zotero/xpcom/editorInstance.js b/chrome/content/zotero/xpcom/editorInstance.js index 05fe1f02db..1a81e05645 100644 --- a/chrome/content/zotero/xpcom/editorInstance.js +++ b/chrome/content/zotero/xpcom/editorInstance.js @@ -23,7 +23,7 @@ ***** END LICENSE BLOCK ***** */ -Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm"); +ChromeUtils.importESModule("resource://gre/modules/InlineSpellChecker.sys.mjs"); var { FilePicker } = ChromeUtils.importESModule('chrome://zotero/content/modules/filePicker.mjs'); diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 418e77a221..c018489473 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -28,8 +28,8 @@ * @namespace */ Zotero.File = new function () { - Components.utils.import("resource://gre/modules/NetUtil.jsm"); - Components.utils.import("resource://gre/modules/FileUtils.jsm"); + ChromeUtils.importESModule("resource://gre/modules/NetUtil.sys.mjs"); + ChromeUtils.importESModule("resource://gre/modules/FileUtils.sys.mjs"); this.getExtension = getExtension; this.getContentsFromURL = getContentsFromURL; diff --git a/chrome/content/zotero/xpcom/fulltext.js b/chrome/content/zotero/xpcom/fulltext.js index c882e26e40..b593af610d 100644 --- a/chrome/content/zotero/xpcom/fulltext.js +++ b/chrome/content/zotero/xpcom/fulltext.js @@ -93,7 +93,9 @@ Zotero.Fulltext = Zotero.FullText = new function () { _pdfConverter.append(pdfConverterFileName); _pdfInfo.append(pdfInfoFileName); - Zotero.uiReadyPromise.delay(30000).then(() => { + Zotero.uiReadyPromise.then(async () => { + await Zotero.Promise.delay(30000); + this.registerContentProcessor(); Zotero.addShutdownListener(this.unregisterContentProcessor.bind(this)); @@ -1604,7 +1606,7 @@ Zotero.Fulltext = Zotero.FullText = new function () { async function getPageData(path, contentType) { - const { HiddenBrowser } = ChromeUtils.import("chrome://zotero/content/HiddenBrowser.jsm"); + const { HiddenBrowser } = ChromeUtils.importESModule("chrome://zotero/content/HiddenBrowser.mjs"); var blobURL; var browser; var pageData; diff --git a/chrome/content/zotero/xpcom/http.js b/chrome/content/zotero/xpcom/http.js index 5f367513b4..7bd1d57e08 100644 --- a/chrome/content/zotero/xpcom/http.js +++ b/chrome/content/zotero/xpcom/http.js @@ -1183,7 +1183,7 @@ Zotero.HTTP = new function () { _proxyAsyncResolve = function (uri) { - Components.utils.import("resource://gre/modules/NetUtil.jsm"); + ChromeUtils.importESModule("resource://gre/modules/NetUtil.sys.mjs"); var pps = Components.classes["@mozilla.org/network/protocol-proxy-service;1"] .getService(Components.interfaces.nsIProtocolProxyService); var deferred = Zotero.Promise.defer(); diff --git a/chrome/content/zotero/xpcom/integration.js b/chrome/content/zotero/xpcom/integration.js index ea7c813377..5ace303671 100644 --- a/chrome/content/zotero/xpcom/integration.js +++ b/chrome/content/zotero/xpcom/integration.js @@ -79,7 +79,7 @@ const PLUGIN_PATHS = { Zotero.Integration = new function () { - Components.utils.import("resource://gre/modules/AddonManager.jsm"); + ChromeUtils.importESModule("resource://gre/modules/AddonManager.sys.mjs"); this.currentWindow = false; this.currentCommandPromise = Promise.resolve(); diff --git a/chrome/content/zotero/xpcom/intl.js b/chrome/content/zotero/xpcom/intl.js index 1aef2b3d83..486e43e9c5 100644 --- a/chrome/content/zotero/xpcom/intl.js +++ b/chrome/content/zotero/xpcom/intl.js @@ -54,7 +54,7 @@ Zotero.Intl = new function () { } } - Components.utils.import("resource://zotero/PluralForm.jsm"); + const { PluralForm } = ChromeUtils.importESModule("resource://zotero/PluralForm.mjs"); // Exposed for tests this._bundle = bundle = Services.strings.createBundle('chrome://zotero/locale/zotero.properties'); diff --git a/chrome/content/zotero/xpcom/ipc.js b/chrome/content/zotero/xpcom/ipc.js index c2f5e476f1..a52015d8fd 100755 --- a/chrome/content/zotero/xpcom/ipc.js +++ b/chrome/content/zotero/xpcom/ipc.js @@ -68,7 +68,7 @@ Zotero.IPC = new function () { this.getLibcPath = function () { if(_libcPath) return _libcPath; - Components.utils.import("resource://gre/modules/ctypes.jsm"); + ChromeUtils.importESModule("resource://gre/modules/ctypes.sys.mjs"); // get possible names for libc if(Zotero.isMac) { diff --git a/chrome/content/zotero/xpcom/plugins.js b/chrome/content/zotero/xpcom/plugins.js index 4175f7eee2..4c83198380 100644 --- a/chrome/content/zotero/xpcom/plugins.js +++ b/chrome/content/zotero/xpcom/plugins.js @@ -25,11 +25,12 @@ Zotero.Plugins = new function () { - var { AddonManager } = ChromeUtils.import("resource://gre/modules/AddonManager.jsm"); + var { AddonManager } = ChromeUtils.importESModule("resource://gre/modules/AddonManager.sys.mjs"); var lazy = {}; - XPCOMUtils.defineLazyModuleGetters(lazy, { - XPIDatabase: "resource://gre/modules/addons/XPIDatabase.jsm", + ChromeUtils.defineESModuleGetters(lazy, { + XPIDatabase: "resource://gre/modules/addons/XPIDatabase.sys.mjs", }); + const { XPCOMUtils } = ChromeUtils.importESModule("resource://gre/modules/XPCOMUtils.sys.mjs"); XPCOMUtils.defineLazyServiceGetters(lazy, { aomStartup: [ "@mozilla.org/addons/addon-manager-startup;1", diff --git a/chrome/content/zotero/xpcom/reader.js b/chrome/content/zotero/xpcom/reader.js index e9ea194fef..5f55f99f5d 100644 --- a/chrome/content/zotero/xpcom/reader.js +++ b/chrome/content/zotero/xpcom/reader.js @@ -25,7 +25,7 @@ var { FilePicker } = ChromeUtils.importESModule('chrome://zotero/content/modules/filePicker.mjs'); -const { BlockingObserver } = ChromeUtils.importESModule("chrome://zotero/content/BlockingObserver.sys.mjs"); +const { BlockingObserver } = ChromeUtils.importESModule("chrome://zotero/content/BlockingObserver.mjs"); const ZipReader = Components.Constructor( "@mozilla.org/libjar/zip-reader;1", @@ -33,7 +33,7 @@ const ZipReader = Components.Constructor( "open" ); -Components.utils.import("resource://gre/modules/InlineSpellChecker.jsm"); +ChromeUtils.importESModule("resource://gre/modules/InlineSpellChecker.sys.mjs"); // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Invalid_array_length const ARRAYBUFFER_MAX_LENGTH = Services.appinfo.is64Bit diff --git a/chrome/content/zotero/xpcom/schema.js b/chrome/content/zotero/xpcom/schema.js index 3de83d1017..ef0a7f62bc 100644 --- a/chrome/content/zotero/xpcom/schema.js +++ b/chrome/content/zotero/xpcom/schema.js @@ -108,8 +108,9 @@ Zotero.Schema = new function () { // Don't load bundled files until after UI is ready, unless this is a test run, // in which case tests can run without a window open (!Zotero.test ? Zotero.uiReadyPromise : Zotero.initializationPromise) - .delay(1000) .then(async function () { + await Zotero.Promise.delay(1000); + await this.updateBundledFiles(); if (Zotero.Prefs.get('automaticScraperUpdates')) { try { @@ -988,7 +989,7 @@ Zotero.Schema = new function () { * @param {Boolean} [skipVersionUpdates=false] */ var _updateBundledFilesAtLocation = async function (installLocation, mode, skipVersionUpdates) { - Components.utils.import("resource://gre/modules/FileUtils.jsm"); + ChromeUtils.importESModule("resource://gre/modules/FileUtils.sys.mjs"); var isUnpacked = (await OS.File.stat(installLocation)).isDir; if(!isUnpacked) { @@ -3299,7 +3300,7 @@ Zotero.Schema = new function () { } else if (i == 101) { - Components.utils.import("chrome://zotero/content/import/mendeley/mendeleyImport.js"); + Cu.import("chrome://zotero/content/import/mendeley/mendeleyImport.js"); let importer = new Zotero_Import_Mendeley(); if (await importer.hasImportedFiles()) { await importer.queueFileCleanup(); diff --git a/chrome/content/zotero/xpcom/server/server.js b/chrome/content/zotero/xpcom/server/server.js index ba39fe89d8..b08422e840 100755 --- a/chrome/content/zotero/xpcom/server/server.js +++ b/chrome/content/zotero/xpcom/server/server.js @@ -24,7 +24,7 @@ */ var { HttpServer } = ChromeUtils.importESModule("chrome://remote/content/server/httpd.sys.mjs"); -Components.utils.import("resource://gre/modules/NetUtil.jsm"); +ChromeUtils.importESModule("resource://gre/modules/NetUtil.sys.mjs"); Zotero.Server = new function () { var _onlineObserverRegistered, serv; diff --git a/chrome/content/zotero/xpcom/storage/webdav.js b/chrome/content/zotero/xpcom/storage/webdav.js index cb42125fa3..bb7ae78190 100644 --- a/chrome/content/zotero/xpcom/storage/webdav.js +++ b/chrome/content/zotero/xpcom/storage/webdav.js @@ -1492,7 +1492,7 @@ Zotero.Sync.Storage.Mode.WebDAV.prototype = { }.bind(this)); } - Components.utils.import("resource://zotero/concurrentCaller.js"); + const { ConcurrentCaller } = ChromeUtils.importESModule("resource://zotero/concurrentCaller.mjs"); var caller = new ConcurrentCaller({ numConcurrent: 4, stopOnError: true, diff --git a/chrome/content/zotero/xpcom/style.js b/chrome/content/zotero/xpcom/style.js index 352928d342..ac4688922a 100644 --- a/chrome/content/zotero/xpcom/style.js +++ b/chrome/content/zotero/xpcom/style.js @@ -30,7 +30,7 @@ Zotero.Styles = new function () { var _renamedStyles = null; - Components.utils.import("resource://gre/modules/FileUtils.jsm"); + ChromeUtils.importESModule("resource://gre/modules/FileUtils.sys.mjs"); this.xsltProcessor = null; this.ns = { diff --git a/chrome/content/zotero/xpcom/sync/syncRunner.js b/chrome/content/zotero/xpcom/sync/syncRunner.js index 5900186feb..15888559e9 100644 --- a/chrome/content/zotero/xpcom/sync/syncRunner.js +++ b/chrome/content/zotero/xpcom/sync/syncRunner.js @@ -59,13 +59,12 @@ Zotero.Sync.Runner_Module = function (options = {}) { var _apiKey = options.apiKey; Zotero.defineProperty(this, 'apiKey', { set: val => _apiKey = val }); - Components.utils.import("resource://zotero/concurrentCaller.js"); + const { ConcurrentCaller } = ChromeUtils.importESModule("resource://zotero/concurrentCaller.mjs"); this.caller = new ConcurrentCaller({ numConcurrent: 4, stopOnError, logger: msg => Zotero.debug(msg), - onError: e => Zotero.logError(e), - Promise: Zotero.Promise + onError: e => Zotero.logError(e) }); var _enabled = false; diff --git a/chrome/content/zotero/xpcom/translation/translate_firefox.js b/chrome/content/zotero/xpcom/translation/translate_firefox.js index bdd641e4f3..7e08e5065d 100644 --- a/chrome/content/zotero/xpcom/translation/translate_firefox.js +++ b/chrome/content/zotero/xpcom/translation/translate_firefox.js @@ -34,7 +34,7 @@ const BOMs = { "UTF-32LE":"\xFF\xFE\x00\x00" } -Components.utils.import("resource://gre/modules/NetUtil.jsm"); +ChromeUtils.importESModule("resource://gre/modules/NetUtil.sys.mjs"); Zotero.Translate.DOMWrapper = new function () { var Cu = Components.utils; diff --git a/chrome/content/zotero/xpcom/utilities_internal.js b/chrome/content/zotero/xpcom/utilities_internal.js index ce83e8e2fb..0dbdc42d70 100644 --- a/chrome/content/zotero/xpcom/utilities_internal.js +++ b/chrome/content/zotero/xpcom/utilities_internal.js @@ -26,8 +26,8 @@ ***** END LICENSE BLOCK ***** */ -XPCOMUtils.defineLazyModuleGetters(globalThis, { - Subprocess: "resource://gre/modules/Subprocess.jsm", +ChromeUtils.defineESModuleGetters(globalThis, { + Subprocess: "resource://gre/modules/Subprocess.sys.mjs", }); /** @@ -280,7 +280,7 @@ Zotero.Utilities.Internal = { gunzip: async function (data) { var deferred = Zotero.Promise.defer(); - Components.utils.import("resource://gre/modules/NetUtil.jsm"); + ChromeUtils.importESModule("resource://gre/modules/NetUtil.sys.mjs"); var is = Components.classes["@mozilla.org/io/string-input-stream;1"] .createInstance(Ci.nsIStringInputStream); @@ -581,7 +581,7 @@ Zotero.Utilities.Internal = { */ exec: function (cmd, args) { if (typeof cmd == 'string') { - Components.utils.import("resource://gre/modules/FileUtils.jsm"); + ChromeUtils.importESModule("resource://gre/modules/FileUtils.sys.mjs"); cmd = new FileUtils.File(cmd); } @@ -2651,7 +2651,7 @@ Zotero.Utilities.Internal.activate = new function () { * Find an X11 window given a name */ function _X11FindWindow(w, searchName) { - Components.utils.import("resource://gre/modules/ctypes.jsm"); + ChromeUtils.importESModule("resource://gre/modules/ctypes.sys.mjs"); var res = _X11GetProperty(w, "_NET_CLIENT_LIST", 33 /** XA_WINDOW **/) || _X11GetProperty(w, "_WIN_CLIENT_LIST", 6 /** XA_CARDINAL **/); @@ -2681,7 +2681,7 @@ Zotero.Utilities.Internal.activate = new function () { * Get a property from an X11 window */ function _X11GetProperty(win, propertyName, propertyType) { - Components.utils.import("resource://gre/modules/ctypes.jsm"); + ChromeUtils.importESModule("resource://gre/modules/ctypes.sys.mjs"); var returnType = new X11Atom(), returnFormat = new ctypes.int(), @@ -2708,7 +2708,7 @@ Zotero.Utilities.Internal.activate = new function () { } if (Zotero.isMac) { if (win) { - Components.utils.import("resource://gre/modules/ctypes.jsm"); + ChromeUtils.importESModule("resource://gre/modules/ctypes.sys.mjs"); win.focus(); if (!_carbon) { @@ -2756,7 +2756,7 @@ Zotero.Utilities.Internal.activate = new function () { } } else if (Zotero.isLinux && !isWayland && win) { - Components.utils.import("resource://gre/modules/ctypes.jsm"); + ChromeUtils.importESModule("resource://gre/modules/ctypes.sys.mjs"); if (_x11 === false) return; if (!_x11) { @@ -3006,7 +3006,7 @@ Zotero.Utilities.Internal.Environment = { * Since nsIEnvironment doesn't have an unset method */ unset: function (varName) { - Components.utils.import("resource://gre/modules/ctypes.jsm"); + ChromeUtils.importESModule("resource://gre/modules/ctypes.sys.mjs"); let lib; let result; diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 818d423db9..55c8aa7fc3 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -23,8 +23,8 @@ ***** END LICENSE BLOCK ***** */ -const BluebirdShimPromise = ChromeUtils.importESModule('chrome://zotero/content/xpcom/bluebirdShim.mjs'); -const ZOTERO_CONFIG = ChromeUtils.importESModule('resource://zotero/config.mjs'); +const { BluebirdShimPromise } = ChromeUtils.importESModule('chrome://zotero/content/xpcom/bluebirdShim.mjs'); +const { ZOTERO_CONFIG } = ChromeUtils.importESModule('resource://zotero/config.mjs'); // Commonly used imports accessible anywhere Components.utils.importGlobalProperties(["XMLHttpRequest"]); @@ -39,7 +39,7 @@ const { CommandLineOptions } = ChromeUtils.importESModule("chrome://zotero/conte /* * Core functions */ - (function () { +(function () { // Privileged (public) methods this.getStorageDirectory = getStorageDirectory; this.debug = debug; @@ -56,15 +56,15 @@ const { CommandLineOptions } = ChromeUtils.importESModule("chrome://zotero/conte get: () => _startupErrorHandler, enumerable: true, configurable: true - }); - Object.defineProperty(this, 'resourcesDir', { + }); + Object.defineProperty(this, 'resourcesDir', { get: () => { // AChrome is app/chrome return FileUtils.getDir('AChrom', []).parent.parent.path; }, enumerable: true, configurable: true - }); + }); this.version; this.platform; this.locale; @@ -231,9 +231,6 @@ const { CommandLineOptions } = ChromeUtils.importESModule("chrome://zotero/conte this.isSourceBuild = Zotero.version.includes('SOURCE'); // OS platform - var win = Components.classes["@mozilla.org/appshell/appShellService;1"] - .getService(Components.interfaces.nsIAppShellService) - .hiddenDOMWindow; var os = Services.appinfo.OS; this.isMac = os == 'Darwin'; this.isWin = os == 'WINNT'; @@ -669,13 +666,13 @@ const { CommandLineOptions } = ChromeUtils.importESModule("chrome://zotero/conte throw e; } - const { ZoteroProtocolHandler } = ChromeUtils.import( - `chrome://zotero/content/ZoteroProtocolHandler.jsm` + const { ZoteroProtocolHandler } = ChromeUtils.importESModule( + `chrome://zotero/content/ZoteroProtocolHandler.mjs` ); ZoteroProtocolHandler.init(); - const { ZoteroAutoComplete } = ChromeUtils.import( - `chrome://zotero/content/zotero-autocomplete.js` + const { ZoteroAutoComplete } = ChromeUtils.importESModule( + `chrome://zotero/content/zotero-autocomplete.mjs` ); ZoteroAutoComplete.init(); @@ -1511,7 +1508,7 @@ const { CommandLineOptions } = ChromeUtils.importESModule("chrome://zotero/conte * @return {Promise} - Promise for an array of extension names and versions */ this.getInstalledExtensions = async function () { - var { AddonManager } = ChromeUtils.import("resource://gre/modules/AddonManager.jsm"); + var { AddonManager } = ChromeUtils.importESModule("resource://gre/modules/AddonManager.sys.mjs"); var installed = await AddonManager.getAllAddons(); installed.sort(function (a, b) { @@ -1857,7 +1854,7 @@ const { CommandLineOptions } = ChromeUtils.importESModule("chrome://zotero/conte Zotero.getString("standalone.rootWarning.exit"), Zotero.getString("standalone.rootWarning.continue"), null, null, {}) == 0) { - Components.utils.import("resource://gre/modules/ctypes.jsm"); + ChromeUtils.importESModule("resource://gre/modules/ctypes.sys.mjs"); var exit = Zotero.IPC.getLibc().declare("exit", ctypes.default_abi, ctypes.void_t, ctypes.int); // Zap cache files diff --git a/chrome/content/zotero/zotero-autocomplete.js b/chrome/content/zotero/zotero-autocomplete.mjs similarity index 95% rename from chrome/content/zotero/zotero-autocomplete.js rename to chrome/content/zotero/zotero-autocomplete.mjs index d556fa57c9..005065f105 100644 --- a/chrome/content/zotero/zotero-autocomplete.js +++ b/chrome/content/zotero/zotero-autocomplete.mjs @@ -25,22 +25,21 @@ const ZOTERO_AC_CLASS_ID = Components.ID('{06a2ed11-d0a4-4ff0-a56f-a44545eee6ea}'); const ZOTERO_AC_CONTRACT_ID = "@mozilla.org/autocomplete/search;1?name=zotero"; -const EXPORTED_SYMBOLS = ['ZoteroAutoComplete']; const Cc = Components.classes; const Ci = Components.interfaces; const Cr = Components.results; -Components.utils.import("resource://gre/modules/ComponentUtils.jsm"); +ChromeUtils.importESModule("resource://gre/modules/ComponentUtils.sys.mjs"); -var { Zotero } = ChromeUtils.importESModule("chrome://zotero/content/zotero.mjs"); +import { Zotero } from "chrome://zotero/content/zotero.mjs"; /* * Implements nsIAutoCompleteSearch */ -function ZoteroAutoComplete() {} +export function ZoteroAutoComplete() {} -ZoteroAutoComplete.prototype.startSearch = Zotero.Promise.coroutine(function* (searchString, searchParams, previousResult, listener) { +ZoteroAutoComplete.prototype.startSearch = async function (searchString, searchParams, previousResult, listener) { // FIXME //this.stopSearch(); @@ -259,7 +258,7 @@ ZoteroAutoComplete.prototype.startSearch = Zotero.Promise.coroutine(function* (s } var resultCode; try { - let results = yield Zotero.DB.queryAsync(sql, sqlParams, { onRow: onRow }); + let results = await Zotero.DB.queryAsync(sql, sqlParams, { onRow: onRow }); // Post-process the results if (resultsCallback) { resultsCallback(results); @@ -280,7 +279,7 @@ ZoteroAutoComplete.prototype.startSearch = Zotero.Promise.coroutine(function* (s finally { this.updateResults(null, null, false, resultCode); }; -}); +}; ZoteroAutoComplete.prototype.updateResult = function (value, id) { @@ -345,7 +344,7 @@ ZoteroAutoComplete.prototype.createInstance = function (iid) { }; // FIXME -ZoteroAutoComplete.prototype.stopSearch = function(){ +ZoteroAutoComplete.prototype.stopSearch = function (){ Zotero.debug('Stopping autocomplete search'); this._cancelled = true; } diff --git a/chrome/content/zotero/zotero.mjs b/chrome/content/zotero/zotero.mjs index 405be58eca..fa0c17d23b 100644 --- a/chrome/content/zotero/zotero.mjs +++ b/chrome/content/zotero/zotero.mjs @@ -166,14 +166,14 @@ var isFirstLoadThisSession = true; var zContext = null; var initCallbacks = []; -// Components.utils.import('resource://zotero/require.js'); +// Cu.import('resource://zotero/require.js'); // Not using Cu.import here since we don't want the require module to be cached // for includes within ZoteroPane or other code, where we want the window instance available to modules. Components.classes["@mozilla.org/moz/jssubscript-loader;1"] .getService(Components.interfaces.mozIJSSubScriptLoader) .loadSubScript('resource://zotero/require.js'); -var ZoteroContext = function() {} +var ZoteroContext = function () {} ZoteroContext.prototype = { /** * Shuts down Zotero, calls a callback (that may return a promise), @@ -182,12 +182,12 @@ ZoteroContext.prototype = { */ reinit: function (cb, options = {}) { Services.obs.notifyObservers(zContext.Zotero, "zotero-before-reload"); - return zContext.Zotero.shutdown().then(function() { + return zContext.Zotero.shutdown().then(function () { // Unregister custom protocol handler Services.io.unregisterProtocolHandler('zotero'); return cb ? cb() : false; - }).finally(function() { + }).finally(function () { makeZoteroContext(); var o = {}; Object.assign(o, CommandLineOptions); @@ -227,7 +227,7 @@ function makeZoteroContext() { for(var key in zContext.Zotero) delete zContext.Zotero[key]; } else { zContext = new ZoteroContext(); - zContext.Zotero = function() {}; + zContext.Zotero = function () {}; // Override Date prototype to follow Zotero configured locale #3880 subscriptLoader.loadSubScript("chrome://zotero/content/dateOverrides.js"); @@ -293,7 +293,7 @@ function makeZoteroContext() { // add connector-related properties zContext.Zotero.instanceID = instanceID; - zContext.Zotero.__defineGetter__("isFirstLoadThisSession", function() { return isFirstLoadThisSession; }); + zContext.Zotero.__defineGetter__("isFirstLoadThisSession", function () { return isFirstLoadThisSession; }); }; /** diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index c3fc74eae4..ac54929f0a 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -28,8 +28,7 @@ var { FilePicker } = ChromeUtils.importESModule('chrome://zotero/content/modules /* * This object contains the various functions for the interface */ -var ZoteroPane = new function() -{ +var ZoteroPane = new function () { var _unserialized = false; this.collectionsView = false; this.itemsView = false; @@ -136,7 +135,7 @@ var ZoteroPane = new function() } // Set the sync tooltip label - Components.utils.import("resource://zotero/config.js"); + Cu.import("resource://zotero/config.js"); let syncLabel = document.getElementById('zotero-tb-sync-label'); syncLabel.value = Zotero.getString('sync.syncWith', ZOTERO_CONFIG.DOMAIN_NAME); let syncButton = document.querySelector("#zotero-tb-sync"); @@ -649,7 +648,7 @@ var ZoteroPane = new function() ) if (!needsCleanup) return; - Components.utils.import("chrome://zotero/content/import/mendeley/mendeleyImport.js"); + Cu.import("chrome://zotero/content/import/mendeley/mendeleyImport.js"); var importer = new Zotero_Import_Mendeley(); importer.deleteNonPrimaryFiles(); }, 10000) @@ -772,12 +771,12 @@ var ZoteroPane = new function() * @return {Boolean} True if Zotero pane should be loaded, false otherwise (if an error * occurred) */ - this.makeVisible = Zotero.Promise.coroutine(function* () { + this.makeVisible = async function () { if (Zotero.locked) { Zotero.showZoteroPaneProgressMeter(); } - yield Zotero.unlockPromise; + await Zotero.unlockPromise; // The items pane is hidden initially to avoid showing column lines Zotero.hideZoteroPaneOverlays(); @@ -814,10 +813,12 @@ var ZoteroPane = new function() showFxProfileWarning = true; } else if (!Zotero.Prefs.get(pref)) { - showFxProfileWarning = !(yield Zotero.Profile.checkFirefoxProfileAccess()); + showFxProfileWarning = !await Zotero.Profile.checkFirefoxProfileAccess(); } if (showFxProfileWarning) { - Zotero.uiReadyPromise.delay(2000).then(function () { + Zotero.uiReadyPromise.then(async function () { + await Zotero.Promise.delay(2000); + var ps = Services.prompt; var buttonFlags = ps.BUTTON_POS_0 * ps.BUTTON_TITLE_IS_STRING + ps.BUTTON_POS_1 * ps.BUTTON_TITLE_IS_STRING; @@ -863,8 +864,8 @@ var ZoteroPane = new function() // Auto-sync on pane open or if new account if (Zotero.Prefs.get('sync.autoSync') || Zotero.initAutoSync) { - yield Zotero.proxyAuthComplete; - yield Zotero.uiReadyPromise; + await Zotero.proxyAuthComplete; + await Zotero.uiReadyPromise; if (!Zotero.Sync.Runner.enabled) { Zotero.debug('Sync not enabled -- skipping auto-sync', 4); @@ -893,7 +894,7 @@ var ZoteroPane = new function() } return true; - }); + }; function isFullScreen() { @@ -1258,10 +1259,10 @@ var ZoteroPane = new function() } } // Get collections containing items - toHighlight.push(...await Zotero.Collections.getCollectionsContainingItems( + toHighlight.push(...(await Zotero.Collections.getCollectionsContainingItems( items.map(x => x.id), true - )); + ))); var treeViewIDs = toHighlight.map(id => 'C' + id); var userLibraryID = Zotero.Libraries.userLibraryID; // If no collections selected and every item is in My Publications, highlight that @@ -1394,6 +1395,7 @@ var ZoteroPane = new function() if (!row || !row.isFeedsOrFeed()) return; this.toggleSelectedItemsRead(); if (itemReadPromise) { + // FIXME: fx140: replace call to Zotero.Promise instance method 'cancel()' itemReadPromise.cancel(); itemReadPromise = null; } @@ -1424,8 +1426,7 @@ var ZoteroPane = new function() * * _data_ is an optional object with field:value for itemData */ - this.newItem = Zotero.Promise.coroutine(function* (typeID, data, row, manual) - { + this.newItem = async function (typeID, data, row, manual) { if ((row === undefined || row === null) && this.getCollectionTreeRow()) { row = this.collectionsView.selection.focused; @@ -1436,7 +1437,7 @@ var ZoteroPane = new function() } } - yield this.itemPane.handleBlur(); + await this.itemPane.handleBlur(); if (row !== undefined && row !== null) { var collectionTreeRow = this.collectionsView.getRow(row); @@ -1448,7 +1449,7 @@ var ZoteroPane = new function() } let itemID; - yield Zotero.DB.executeTransaction(async function () { + await Zotero.DB.executeTransaction(async function () { var item = new Zotero.Item(typeID); item.libraryID = libraryID; for (var i in data) { @@ -1470,7 +1471,7 @@ var ZoteroPane = new function() document.getElementById('zotero-view-item').selectedIndex = 0; // Ensure item is visible - yield this.selectItem(itemID); + await this.selectItem(itemID); if (manual) { // Update most-recently-used list for New Item menu @@ -1483,7 +1484,7 @@ var ZoteroPane = new function() } return Zotero.Items.getAsync(itemID); - }); + }; this.addItemTypeToNewItemTypeMRU = function (itemType) { @@ -1556,7 +1557,7 @@ var ZoteroPane = new function() fp.init(window, Zotero.getString('fileInterface.importOPML'), fp.modeOpen); fp.appendFilter(Zotero.getString('fileInterface.OPMLFeedFilter'), '*.opml; *.xml'); fp.appendFilters(fp.filterAll); - if (await fp.show() == fp.returnOK) { + if ((await fp.show()) == fp.returnOK) { var contents = await Zotero.File.getContentsAsync(fp.file); var success = await Zotero.Feeds.importFromOPML(contents); if (success) { @@ -1571,7 +1572,7 @@ var ZoteroPane = new function() }; - this.newFeedFromURL = Zotero.Promise.coroutine(function* () { + this.newFeedFromURL = async function () { let data = {}; window.openDialog('chrome://zotero/content/feedSettings.xhtml', null, 'centerscreen, modal', data); @@ -1582,19 +1583,19 @@ var ZoteroPane = new function() feed.refreshInterval = data.ttl; feed.cleanupReadAfter = data.cleanupReadAfter; feed.cleanupUnreadAfter = data.cleanupUnreadAfter; - yield feed.saveTx(); - yield feed.updateFeed(); + await feed.saveTx(); + await feed.updateFeed(); } - }); + }; this.newGroup = function () { this.loadURI(Zotero.Groups.addGroupURL); } - this.newSearch = Zotero.Promise.coroutine(function* () { + this.newSearch = async function () { if (Zotero.DB.inTransaction()) { - yield Zotero.DB.waitForTransaction(); + await Zotero.DB.waitForTransaction(); } var libraryID = this.getSelectedLibraryID(); @@ -1603,7 +1604,7 @@ var ZoteroPane = new function() s.libraryID = libraryID; s.addCondition('title', 'contains', ''); - var searches = yield Zotero.Searches.getAll(libraryID) + var searches = await Zotero.Searches.getAll(libraryID) var prefix = Zotero.getString('pane.collections.untitled'); var name = Zotero.Utilities.Internal.getNextName( prefix, @@ -1616,11 +1617,11 @@ var ZoteroPane = new function() return false; } s.fromJSON(io.dataOut.json); - yield s.saveTx(); + await s.saveTx(); return s.id; - }); + }; - this.setVirtual = function(libraryID, type, show, select) { + this.setVirtual = function (libraryID, type, show, select) { return this.collectionsView.toggleVirtualCollection(libraryID, type, show, select); }; @@ -1713,7 +1714,7 @@ var ZoteroPane = new function() }; - this.handleTagSelectorResize = Zotero.Utilities.debounce(function() { + this.handleTagSelectorResize = Zotero.Utilities.debounce(function () { if (this.tagSelectorShown()) { // Initialize if dragging open after startup if (!this.tagSelector) { @@ -1731,11 +1732,11 @@ var ZoteroPane = new function() /* * Sets the tag filter on the items view */ - this.updateTagFilter = Zotero.Promise.coroutine(function* () { + this.updateTagFilter = async function () { if (this.itemsView) { - yield this.itemsView.setFilter('tags', ZoteroPane_Local.tagSelector.getTagSelection()); + await this.itemsView.setFilter('tags', ZoteroPane_Local.tagSelector.getTagSelection()); } - }); + }; // Keep in sync with ZoteroStandalone.updateViewOption() @@ -1919,7 +1920,7 @@ var ZoteroPane = new function() * be a better test for whether the item pane changed) */ this.itemSelected = function () { - return Zotero.Promise.coroutine(function* () { + return async function () { if (!this.itemsView || !this.itemsView.selection) { Zotero.debug("Items view not available in itemSelected", 2); return false; @@ -1957,7 +1958,7 @@ var ZoteroPane = new function() _lastSelectedItems = ids; return this.itemPane.render(); - }.bind(this))() + }.bind(this)() .catch((e) => { Zotero.logError(e); Zotero.crash(); @@ -2033,7 +2034,7 @@ var ZoteroPane = new function() /** * @return {Promise} */ - this.reindexItem = Zotero.Promise.coroutine(function* () { + this.reindexItem = async function () { var items = this.getSelectedItems(); if (!items) { return; @@ -2045,15 +2046,15 @@ var ZoteroPane = new function() itemIDs.push(items[i].id); } - yield Zotero.FullText.indexItems(itemIDs, { complete: true }); - yield document.getElementById('zotero-attachment-box').updateItemIndexedState(); - }); + await Zotero.FullText.indexItems(itemIDs, { complete: true }); + await document.getElementById('zotero-attachment-box').updateItemIndexedState(); + }; /** * @return {Promise} - The new Zotero.Item */ - this.duplicateSelectedItem = Zotero.Promise.coroutine(function* () { + this.duplicateSelectedItem = async function () { var self = this; if (!self.canEdit()) { self.displayCannotEditLibraryMessage(); @@ -2062,14 +2063,14 @@ var ZoteroPane = new function() var item = self.getSelectedItems()[0]; if (item.isNote() - && !(yield Zotero.Notes.ensureEmbeddedImagesAreAvailable(item)) + && !((await Zotero.Notes.ensureEmbeddedImagesAreAvailable(item))) && !Zotero.Notes.promptToIgnoreMissingImage()) { return; } var newItem; - yield Zotero.DB.executeTransaction(async function () { + await Zotero.DB.executeTransaction(async function () { newItem = item.clone(); // If in a collection, add new item to it if (self.getCollectionTreeRow().isCollection() && newItem.isTopLevelItem()) { @@ -2094,10 +2095,10 @@ var ZoteroPane = new function() } }); - yield self.selectItem(newItem.id); + await self.selectItem(newItem.id); return newItem; - }); + }; this.duplicateAndConvertSelectedItem = async function () { @@ -2477,7 +2478,7 @@ var ZoteroPane = new function() /** * @return {Promise} */ - this.emptyTrash = Zotero.Promise.coroutine(function* () { + this.emptyTrash = async function () { var libraryID = this.getSelectedLibraryID(); var result = Services.prompt.confirm( @@ -2489,11 +2490,11 @@ var ZoteroPane = new function() if (result) { Zotero.showZoteroPaneProgressMeter(null, true); try { - let deletedSearches = yield Zotero.Searches.getDeleted(libraryID, true); - yield Zotero.Searches.erase(deletedSearches); - let deletedCollections = yield Zotero.Collections.getDeleted(libraryID, true); - yield Zotero.Collections.erase(deletedCollections); - let deleted = yield Zotero.Items.emptyTrash( + let deletedSearches = await Zotero.Searches.getDeleted(libraryID, true); + await Zotero.Searches.erase(deletedSearches); + let deletedCollections = await Zotero.Collections.getDeleted(libraryID, true); + await Zotero.Collections.erase(deletedCollections); + let deleted = await Zotero.Items.emptyTrash( libraryID, { onProgress: (progress, progressMax) => { @@ -2506,9 +2507,9 @@ var ZoteroPane = new function() finally { Zotero.hideZoteroPaneOverlays(); } - yield Zotero.purgeDataObjects(); + await Zotero.purgeDataObjects(); } - }); + }; // Currently only works on searches @@ -2529,7 +2530,7 @@ var ZoteroPane = new function() }; - this.editSelectedCollection = Zotero.Promise.coroutine(function* () { + this.editSelectedCollection = async function () { if (!this.canEdit()) { this.displayCannotEditLibraryMessage(); return; @@ -2560,12 +2561,12 @@ var ZoteroPane = new function() window.openDialog('chrome://zotero/content/searchDialog.xhtml','','chrome,modal,centerscreen',io); if (io.dataOut) { row.ref.fromJSON(io.dataOut.json); - yield row.ref.saveTx(); + await row.ref.saveTx(); Zotero_Tabs.rename("zotero-pane", row.ref.name); } } } - }); + }; // Move selected collection to specified target collection or library. // Target has to be in the same library as the currently selected collection. @@ -2616,23 +2617,23 @@ var ZoteroPane = new function() }); }; - this.toggleSelectedItemsRead = Zotero.Promise.coroutine(function* () { - yield Zotero.FeedItems.toggleReadByID(this.getSelectedItems(true)); - }); + this.toggleSelectedItemsRead = async function () { + await Zotero.FeedItems.toggleReadByID(this.getSelectedItems(true)); + }; - this.markFeedRead = Zotero.Promise.coroutine(function* () { + this.markFeedRead = async function () { var row = this.getCollectionTreeRow(); if (!row) return; let feeds = row.isFeeds() ? Zotero.Feeds.getAll() : [row.ref]; for (let feed of feeds) { - let feedItemIDs = yield Zotero.FeedItems.getAll(feed.libraryID, true, false, true); - yield Zotero.FeedItems.toggleReadByID(feedItemIDs, true); + let feedItemIDs = await Zotero.FeedItems.getAll(feed.libraryID, true, false, true); + await Zotero.FeedItems.toggleReadByID(feedItemIDs, true); } - }); + }; - this.editSelectedFeed = Zotero.Promise.coroutine(function* () { + this.editSelectedFeed = async function () { var row = this.getCollectionTreeRow(); if (!row) return; @@ -2653,11 +2654,11 @@ var ZoteroPane = new function() feed.refreshInterval = data.ttl; feed.cleanupReadAfter = data.cleanupReadAfter; feed.cleanupUnreadAfter = data.cleanupUnreadAfter; - yield feed.saveTx(); + await feed.saveTx(); Zotero_Tabs.rename("zotero-pane", feed.name); - }); + }; - this.refreshFeed = function() { + this.refreshFeed = function () { var row = this.getCollectionTreeRow(); if (!row) return; @@ -2728,15 +2729,15 @@ var ZoteroPane = new function() } - this.clearQuicksearch = Zotero.Promise.coroutine(function* () { + this.clearQuicksearch = async function () { var search = document.getElementById('zotero-tb-search'); if (search.searchTextbox.value !== '') { search.searchTextbox.value = ''; - yield this.search(); + await this.search(); return true; } return false; - }); + }; /** @@ -2780,7 +2781,7 @@ var ZoteroPane = new function() /** * @return {Promise} */ - this.search = Zotero.Promise.coroutine(function* (runAdvanced) { + this.search = async function (runAdvanced) { if (!this.itemsView) { return; } @@ -2792,13 +2793,13 @@ var ZoteroPane = new function() var spinner = document.getElementById('zotero-tb-search-spinner'); spinner.setAttribute("status", "animate"); spinner.style.visibility = 'visible'; - yield this.itemsView.setFilter('search', searchVal); + await this.itemsView.setFilter('search', searchVal); spinner.style.removeProperty("visibility"); spinner.removeAttribute("status"); if (runAdvanced) { this.clearItemsPaneMessage(); } - }); + }; this.sync = function () { @@ -3577,7 +3578,7 @@ var ZoteroPane = new function() }; - this.buildItemContextMenu = Zotero.Promise.coroutine(function* () { + this.buildItemContextMenu = async function () { var options = [ 'showInLibrary', 'sep1', @@ -3672,7 +3673,7 @@ var ZoteroPane = new function() canMerge = false; } - if (canIndex && !(yield Zotero.Fulltext.canReindex(item))) { + if (canIndex && !((await Zotero.Fulltext.canReindex(item)))) { canIndex = false; } @@ -3869,7 +3870,7 @@ var ZoteroPane = new function() } // If not linked URL, show reindex line - if (yield Zotero.Fulltext.canReindex(item)) { + if (await Zotero.Fulltext.canReindex(item)) { show.add(m.reindexItem); showSep5 = true; } @@ -4078,8 +4079,8 @@ var ZoteroPane = new function() if (annotationsSelected) return; // add locate menu options - yield Zotero_LocateMenu.buildContextMenu(menu, true); - }); + await Zotero_LocateMenu.buildContextMenu(menu, true); + }; // Build a menu to move or copy a collection into another collection and library. @@ -4283,7 +4284,7 @@ var ZoteroPane = new function() }; - this.onItemTreeActivate = function(event, items) { + this.onItemTreeActivate = function (event, items) { var viewOnDoubleClick = Zotero.Prefs.get('viewOnDoubleClick'); // Mouse event if (event.button && items.length == 1 && viewOnDoubleClick) { @@ -4399,7 +4400,7 @@ var ZoteroPane = new function() * @return {Promise} - The id of the new note in non-popup mode, null in * popup mode (where a note isn't created immediately), or false if library isn't editable */ - this.newNote = Zotero.Promise.coroutine(function* (popup, parentKey, text, citeURI) { + this.newNote = async function (popup, parentKey, text, citeURI) { if (!this.canEdit()) { this.displayCannotEditLibraryMessage(); return false; @@ -4437,18 +4438,18 @@ var ZoteroPane = new function() else if (this.getCollectionTreeRow().isCollection()) { item.addToCollection(this.getCollectionTreeRow().ref.id); } - var itemID = yield item.saveTx({ + var itemID = await item.saveTx({ notifierData: { autoSyncDelay: Zotero.Notes.AUTO_SYNC_DELAY } }); - yield this.selectItem(itemID); + await this.selectItem(itemID); document.getElementById('zotero-note-editor').focus(); return itemID; - }); + }; /** @@ -4465,7 +4466,7 @@ var ZoteroPane = new function() // TODO: Move to server_connector - this.addSelectedTextToCurrentNote = Zotero.Promise.coroutine(function* () { + this.addSelectedTextToCurrentNote = async function () { if (!this.canEdit()) { this.displayCannotEditLibraryMessage(); return; @@ -4493,7 +4494,7 @@ var ZoteroPane = new function() var note = items[0].note; items[0].setNote(note + text); - yield items[0].saveTx(); + await items[0].saveTx(); var noteElem = document.getElementById('zotero-note-editor') noteElem.focus(); @@ -4501,7 +4502,7 @@ var ZoteroPane = new function() } return false; - }); + }; this.openNoteWindow = function (itemID, col, parentKey) { @@ -4607,7 +4608,7 @@ var ZoteroPane = new function() fp.init(window, Zotero.getString('pane.item.attachments.select'), fp.modeOpenMultiple); fp.appendFilters(fp.filterAll); - if (await fp.show() != fp.returnOK) { + if ((await fp.show()) != fp.returnOK) { return null; } @@ -4723,7 +4724,7 @@ var ZoteroPane = new function() * regardless of automaticSnapshots pref * @return {Promise|false} */ - this.addItemFromDocument = Zotero.Promise.coroutine(function* (doc, itemType, saveSnapshot, row) { + this.addItemFromDocument = async function (doc, itemType, saveSnapshot, row) { _showPageSaveStatus(doc.title); // Save snapshot if explicitly enabled or automatically pref is set and not explicitly disabled @@ -4757,7 +4758,7 @@ var ZoteroPane = new function() // Duplicate newItem() checks here // if (Zotero.DB.inTransaction()) { - yield Zotero.DB.waitForTransaction(); + await Zotero.DB.waitForTransaction(); } // Currently selected row @@ -4794,13 +4795,13 @@ var ZoteroPane = new function() var collectionID = false; } - let item = yield Zotero.Attachments.importFromDocument({ + let item = await Zotero.Attachments.importFromDocument({ libraryID: libraryID, document: doc, collections: collectionID ? [collectionID] : [] }); - yield this.selectItem(item.id); + await this.selectItem(item.id); return false; } } @@ -4815,20 +4816,20 @@ var ZoteroPane = new function() accessDate: "CURRENT_TIMESTAMP" } itemType = Zotero.ItemTypes.getID(itemType); - var item = yield this.newItem(itemType, data, row); + var item = await this.newItem(itemType, data, row); var filesEditable = Zotero.Libraries.get(item.libraryID).filesEditable; if (saveSnapshot) { var link = false; if (link) { - yield Zotero.Attachments.linkFromDocument({ + await Zotero.Attachments.linkFromDocument({ document: doc, parentItemID: item.id }); } else if (filesEditable) { - yield Zotero.Attachments.importFromDocument({ + await Zotero.Attachments.importFromDocument({ document: doc, parentItemID: item.id }); @@ -4836,16 +4837,16 @@ var ZoteroPane = new function() } return item; - }); + }; /** * @return {Zotero.Item|false} - The saved item, or false if item can't be saved */ - this.addItemFromURL = Zotero.Promise.coroutine(function* (url, itemType, saveSnapshot, row) { + this.addItemFromURL = async function (url, itemType, saveSnapshot, row) { url = Zotero.Utilities.Internal.resolveIntermediateURL(url); - let [mimeType, hasNativeHandler] = yield Zotero.MIME.getMIMETypeFromURL(url); + let [mimeType, hasNativeHandler] = await Zotero.MIME.getMIMETypeFromURL(url); // If native type, save using a hidden browser if (hasNativeHandler) { @@ -4858,7 +4859,7 @@ var ZoteroPane = new function() }); }; try { - yield Zotero.HTTP.processDocuments([url], processor); + await Zotero.HTTP.processDocuments([url], processor); } catch (e) { Zotero.debug(e, 1); deferred.reject(e); @@ -4877,7 +4878,7 @@ var ZoteroPane = new function() // Duplicate newItem() checks here // if (Zotero.DB.inTransaction()) { - yield Zotero.DB.waitForTransaction(); + await Zotero.DB.waitForTransaction(); } // Currently selected row @@ -4914,7 +4915,7 @@ var ZoteroPane = new function() var collectionID = false; } - let attachmentItem = yield Zotero.Attachments.importFromURL({ + let attachmentItem = await Zotero.Attachments.importFromURL({ libraryID, url, collections: collectionID ? [collectionID] : undefined, @@ -4929,7 +4930,7 @@ var ZoteroPane = new function() itemType = 'webpage'; } - var item = yield ZoteroPane_Local.newItem(itemType, {}, row) + var item = await ZoteroPane_Local.newItem(itemType, {}, row) var filesEditable = Zotero.Libraries.get(item.libraryID).filesEditable; // Save snapshot if explicitly enabled or automatically pref is set and not explicitly disabled @@ -4940,7 +4941,7 @@ var ZoteroPane = new function() //Zotero.Attachments.linkFromURL(doc, item.id); } else if (filesEditable) { - var attachmentItem = yield Zotero.Attachments.importFromURL({ + var attachmentItem = await Zotero.Attachments.importFromURL({ url, parentItemID: item.id, contentType: mimeType @@ -4949,24 +4950,24 @@ var ZoteroPane = new function() item.setField('title', attachmentItem.getField('title')); item.setField('url', attachmentItem.getField('url')); item.setField('accessDate', attachmentItem.getField('accessDate')); - yield item.saveTx(); + await item.saveTx(); } } } return item; } - }); + }; - this.viewItems = Zotero.Promise.coroutine(function* (items, event) { + this.viewItems = async function (items, event) { for (let i = 0; i < items.length; i++) { let item = items[i]; if (item.isRegularItem()) { // Prefer local file attachments - let attachment = yield item.getBestAttachment(); + let attachment = await item.getBestAttachment(); if (attachment) { - yield this.viewAttachment(attachment.id, event); + await this.viewAttachment(attachment.id, event); continue; } @@ -4987,7 +4988,7 @@ var ZoteroPane = new function() if (!uri) { let attachmentID = item.getAttachments()[0]; if (attachmentID) { - let attachment = yield Zotero.Items.getAsync(attachmentID); + let attachment = await Zotero.Items.getAsync(attachmentID); if (attachment) uri = attachment.getField('url'); } } @@ -5003,13 +5004,13 @@ var ZoteroPane = new function() ZoteroPane.openNoteWindow(item.id); } else if (item.isAttachment()) { - yield this.viewAttachment(item.id, event); + await this.viewAttachment(item.id, event); } else if (item.isAnnotation()) { this.viewAttachment(item.parentItemID, event, false, { location: { annotationID: item.key } }); } } - }); + }; this.viewAttachment = Zotero.serial(async function (itemIDs, event, noLocateOnMissing, extraData) { @@ -5034,7 +5035,7 @@ var ZoteroPane = new function() contentType = sniffedType; } } - else if (contentType === 'application/epub' && await sniffType() === 'application/epub+zip') { + else if (contentType === 'application/epub' && (await sniffType()) === 'application/epub+zip') { contentType = 'application/epub+zip'; } if (item.attachmentContentType !== contentType) { @@ -5194,7 +5195,7 @@ var ZoteroPane = new function() return; } - if (!await item.getFilePathAsync()) { + if (!(await item.getFilePathAsync())) { ZoteroPane_Local.showAttachmentNotFoundDialog( item, path, @@ -5535,7 +5536,7 @@ var ZoteroPane = new function() this.showAttachmentNotFoundDialog = async function (item, path, options = {}) { var { noLocate, notOnServer, linkedFile } = options; - if (item.isLinkedFileAttachment() && await this.checkForLinkedFilesToRelink(item)) { + if (item.isLinkedFileAttachment() && (await this.checkForLinkedFilesToRelink(item))) { return; } @@ -5663,7 +5664,7 @@ var ZoteroPane = new function() }; - this.recognizeSelected = function() { + this.recognizeSelected = function () { Zotero.RecognizeDocument.recognizeItems(ZoteroPane.getSelectedItems()); Zotero.ProgressQueues.get('recognize').getDialog().open(); }; @@ -6324,7 +6325,7 @@ var ZoteroPane = new function() fp.appendFilters(fp.filterAll); - if (await fp.show() == fp.returnOK) { + if ((await fp.show()) == fp.returnOK) { let file = Zotero.File.pathToFile(fp.file); // Disallow hidden files @@ -6350,6 +6351,7 @@ var ZoteroPane = new function() var itemReadPromise; this.startItemReadTimeout = function (feedItemID) { if (itemReadPromise) { + // FIXME: fx140: replace call to Zotero.Promise instance method 'cancel()' itemReadPromise.cancel(); } @@ -6403,7 +6405,7 @@ var ZoteroPane = new function() Zotero.crash(popup); } - this.displayStartupError = function(asPaneMessage) { + this.displayStartupError = function (asPaneMessage) { if (Zotero) { var errMsg = Zotero.startupError; var errFunc = Zotero.startupErrorHandler; @@ -6645,7 +6647,7 @@ var ZoteroPane = new function() /** * Sets the layout to either a three-vertical-pane layout and a layout where itemsPane is above itemPane */ - this.updateLayout = function() { + this.updateLayout = function () { var layoutSwitcher = document.getElementById("zotero-layout-switcher"); var itemsSplitter = document.getElementById("zotero-items-splitter"); var sidenav = document.getElementById("zotero-view-item-sidenav"); @@ -6739,7 +6741,7 @@ var ZoteroPane = new function() /** * Serializes zotero-persist attributes to preferences */ - this.serializePersist = function() { + this.serializePersist = function () { if (!_unserialized) return; try { var serializedValues = JSON.parse(Zotero.Prefs.get('pane.persist')); @@ -6892,7 +6894,7 @@ var ZoteroPane = new function() /** * Opens the about dialog */ - this.openAboutDialog = function() { + this.openAboutDialog = function () { window.openDialog('chrome://zotero/content/about.xhtml', 'about', 'chrome,centerscreen'); } @@ -6900,7 +6902,7 @@ var ZoteroPane = new function() * Adds or removes a function to be called when Zotero is reloaded by switching into or out of * the connector */ - this.addReloadListener = function(/** @param {Function} **/func) { + this.addReloadListener = function (/** @param {Function} **/func) { if(_reloadFunctions.indexOf(func) === -1) _reloadFunctions.push(func); } @@ -6908,7 +6910,7 @@ var ZoteroPane = new function() * Adds or removes a function to be called just before Zotero is reloaded by switching into or * out of the connector */ - this.addBeforeReloadListener = function(/** @param {Function} **/func) { + this.addBeforeReloadListener = function (/** @param {Function} **/func) { if(_beforeReloadFunctions.indexOf(func) === -1) _beforeReloadFunctions.push(func); } diff --git a/resource/PluralForm.jsm b/resource/PluralForm.mjs similarity index 99% rename from resource/PluralForm.jsm rename to resource/PluralForm.mjs index 46aca2c5d0..1ef34dacfb 100644 --- a/resource/PluralForm.jsm +++ b/resource/PluralForm.mjs @@ -2,9 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -var EXPORTED_SYMBOLS = ["PluralForm"]; - - /** * This module provides the PluralForm object which contains a method to figure * out which plural form of a word to use for a given number based on the @@ -188,7 +185,7 @@ var gFunctions = [ ]; /* eslint-enable no-nested-ternary */ -var PluralForm = { +export var PluralForm = { /** * Get the correct plural form of a word based on the number * diff --git a/resource/concurrentCaller.mjs b/resource/concurrentCaller.mjs index f1fe90a1d1..3d4a11cb70 100644 --- a/resource/concurrentCaller.mjs +++ b/resource/concurrentCaller.mjs @@ -23,6 +23,8 @@ ***** END LICENSE BLOCK ***** */ +import { BluebirdShimPromise as Promise } from 'chrome://zotero/content/xpcom/bluebirdShim.mjs'; + /** * Call a fixed number of functions at once, queueing the rest until slots * open and returning a promise for the final completion. The functions do @@ -64,8 +66,7 @@ export var ConcurrentCaller = function (options = {}) { } if (!options.numConcurrent) throw new Error("numConcurrent must be provided"); - - if (options.Promise) Promise = options.Promise; + if (options.Promise) throw new Error("promise option is no longer supported"); this.stopOnError = options.stopOnError || false; this.onError = options.onError || null; diff --git a/resource/config.mjs b/resource/config.mjs index 78378c864a..90ac775289 100644 --- a/resource/config.mjs +++ b/resource/config.mjs @@ -1,4 +1,4 @@ -var ZOTERO_CONFIG = { +export var ZOTERO_CONFIG = { GUID: 'zotero@zotero.org', ID: 'zotero', // used for db filename, etc. CLIENT_NAME: 'Zotero', @@ -33,5 +33,3 @@ var ZOTERO_CONFIG = { PLUGINS_URL: 'https://www.zotero.org/support/plugins', NEW_FEATURES_URL: 'https://www.zotero.org/blog/zotero-7/' }; - -export default ZOTERO_CONFIG; diff --git a/resource/require.js b/resource/require.js index e3840022eb..164ca6cef8 100644 --- a/resource/require.js +++ b/resource/require.js @@ -122,6 +122,14 @@ function ZoteroLoader({ for (const name in injectedGlobals) { this.loader.globals[name] = injectedGlobals[name]; } + + Object.defineProperty(this.loader.globals, "Zotero", { + get: () => { + const { Zotero } = ChromeUtils.importESModule("chrome://zotero/content/zotero.mjs"); + // TODO: Cache + return Zotero; + } + }) // Fetch custom pseudo modules and globals const { modules, globals } = { diff --git a/test/tests/HiddenBrowserTest.js b/test/tests/HiddenBrowserTest.js index 68fe6641fe..58b5240716 100644 --- a/test/tests/HiddenBrowserTest.js +++ b/test/tests/HiddenBrowserTest.js @@ -1,7 +1,7 @@ describe("HiddenBrowser", function() { var { HttpServer } = ChromeUtils.importESModule("chrome://remote/content/server/httpd.sys.mjs");; - const { HiddenBrowser } = ChromeUtils.import( - "chrome://zotero/content/HiddenBrowser.jsm" + const { HiddenBrowser } = ChromeUtils.importESModule( + "chrome://zotero/content/HiddenBrowser.mjs" ); describe("#create()", function () { diff --git a/test/tests/RemoteTranslateTest.js b/test/tests/RemoteTranslateTest.js index c9bffe0011..3b999eafde 100644 --- a/test/tests/RemoteTranslateTest.js +++ b/test/tests/RemoteTranslateTest.js @@ -1,6 +1,6 @@ "use strict"; -const { HiddenBrowser } = ChromeUtils.import("chrome://zotero/content/HiddenBrowser.jsm"); +const { HiddenBrowser } = ChromeUtils.importESModule("chrome://zotero/content/HiddenBrowser.mjs"); const { RemoteTranslate } = ChromeUtils.import("chrome://zotero/content/RemoteTranslate.jsm"); describe("RemoteTranslate", function () { diff --git a/test/tests/attachmentsTest.js b/test/tests/attachmentsTest.js index b100b7e7e8..d2caaf3c84 100644 --- a/test/tests/attachmentsTest.js +++ b/test/tests/attachmentsTest.js @@ -3,7 +3,7 @@ describe("Zotero.Attachments", function() { var browser; before(function () { - HiddenBrowser = ChromeUtils.import("chrome://zotero/content/HiddenBrowser.jsm").HiddenBrowser; + HiddenBrowser = ChromeUtils.importESModule("chrome://zotero/content/HiddenBrowser.mjs").HiddenBrowser; }); afterEach(function () { diff --git a/test/tests/concurrentCallerTest.js b/test/tests/concurrentCallerTest.js index 7883400110..48c66aa6b6 100644 --- a/test/tests/concurrentCallerTest.js +++ b/test/tests/concurrentCallerTest.js @@ -1,7 +1,7 @@ "use strict"; describe("ConcurrentCaller", function () { - Components.utils.import("resource://zotero/concurrentCaller.js"); + const { ConcurrentCaller } = ChromeUtils.importESModule("resource://zotero/concurrentCaller.mjs"); var logger = null; // Uncomment to get debug output //logger = Zotero.debug; diff --git a/test/tests/fileTest.js b/test/tests/fileTest.js index ce749cf9f7..7dc0d529e0 100644 --- a/test/tests/fileTest.js +++ b/test/tests/fileTest.js @@ -505,10 +505,9 @@ describe("Zotero.File", function () { it("should concurrently download three large files", async function () { const url = `${baseURL}/file1.txt`; - var { ConcurrentCaller } = ChromeUtils.import("resource://zotero/concurrentCaller.js"); + const { ConcurrentCaller } = ChromeUtils.importESModule("resource://zotero/concurrentCaller.mjs"); var caller = new ConcurrentCaller({ numConcurrent: 3, - Promise: Zotero.Promise, }); let failed = false; diff --git a/test/tests/syncAPIClientTest.js b/test/tests/syncAPIClientTest.js index 481a5d9951..c12f87742c 100644 --- a/test/tests/syncAPIClientTest.js +++ b/test/tests/syncAPIClientTest.js @@ -16,7 +16,7 @@ describe("Zotero.Sync.APIClient", function () { }); beforeEach(function () { - Components.utils.import("resource://zotero/concurrentCaller.js"); + const { ConcurrentCaller } = ChromeUtils.importESModule("resource://zotero/concurrentCaller.mjs"); var caller = new ConcurrentCaller(1); caller.setLogger(msg => Zotero.debug(msg)); caller.stopOnError = true; diff --git a/test/tests/syncEngineTest.js b/test/tests/syncEngineTest.js index e7750d0c60..47d1dd529f 100644 --- a/test/tests/syncEngineTest.js +++ b/test/tests/syncEngineTest.js @@ -16,7 +16,7 @@ describe("Zotero.Sync.Data.Engine", function () { var background = options.background === undefined ? true : options.background; var stopOnError = options.stopOnError === undefined ? true : options.stopOnError; - Components.utils.import("resource://zotero/concurrentCaller.js"); + const { ConcurrentCaller } = ChromeUtils.importESModule("resource://zotero/concurrentCaller.mjs"); var caller = new ConcurrentCaller(1); caller.setLogger(msg => Zotero.debug(msg)); caller.stopOnError = stopOnError; diff --git a/test/tests/syncFullTextEngineTest.js b/test/tests/syncFullTextEngineTest.js index e76ff66c97..58c73f228c 100644 --- a/test/tests/syncFullTextEngineTest.js +++ b/test/tests/syncFullTextEngineTest.js @@ -13,7 +13,7 @@ describe("Zotero.Sync.Data.FullTextEngine", function () { server = sinon.fakeServer.create(); server.autoRespond = true; - Components.utils.import("resource://zotero/concurrentCaller.js"); + const { ConcurrentCaller } = ChromeUtils.importESModule("resource://zotero/concurrentCaller.mjs"); var caller = new ConcurrentCaller(1); caller.setLogger(msg => Zotero.debug(msg)); caller.stopOnError = true; diff --git a/test/tests/syncRunnerTest.js b/test/tests/syncRunnerTest.js index 86f24cf0bc..49550dd2e6 100644 --- a/test/tests/syncRunnerTest.js +++ b/test/tests/syncRunnerTest.js @@ -184,7 +184,7 @@ describe("Zotero.Sync.Runner", function () { runner = new Zotero.Sync.Runner_Module({ baseURL, apiKey }); - Components.utils.import("resource://zotero/concurrentCaller.js"); + const { ConcurrentCaller } = ChromeUtils.importESModule("resource://zotero/concurrentCaller.mjs"); caller = new ConcurrentCaller(1); caller.setLogger(msg => Zotero.debug(msg)); caller.stopOnError = true; diff --git a/test/tests/translateTest.js b/test/tests/translateTest.js index fd76d78207..9a4b36cc8e 100644 --- a/test/tests/translateTest.js +++ b/test/tests/translateTest.js @@ -1,7 +1,7 @@ new function() { var { HttpServer } = ChromeUtils.importESModule("chrome://remote/content/server/httpd.sys.mjs");; -const { HiddenBrowser } = ChromeUtils.import('chrome://zotero/content/HiddenBrowser.jsm'); +const { HiddenBrowser } = ChromeUtils.importESModule('chrome://zotero/content/HiddenBrowser.mjs'); /** * Create a new translator that saves the specified items diff --git a/test/tests/zfsTest.js b/test/tests/zfsTest.js index 178fe06721..d69fa961a2 100644 --- a/test/tests/zfsTest.js +++ b/test/tests/zfsTest.js @@ -70,7 +70,7 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () { }) var setup = Zotero.Promise.coroutine(function* (options = {}) { - Components.utils.import("resource://zotero/concurrentCaller.js"); + const { ConcurrentCaller } = ChromeUtils.importESModule("resource://zotero/concurrentCaller.mjs"); var stopOnError = options.stopOnError !== undefined ? options.stopOnError : true; var caller = new ConcurrentCaller(1); caller.setLogger(msg => Zotero.debug(msg));