diff --git a/chrome/content/zotero/xpcom/plugins.js b/chrome/content/zotero/xpcom/plugins.js index 19553fee70..e441e344f9 100644 --- a/chrome/content/zotero/xpcom/plugins.js +++ b/chrome/content/zotero/xpcom/plugins.js @@ -92,8 +92,12 @@ Zotero.Plugins = new function () { } Object.assign(scope, { Services, Worker, ChromeWorker, Zotero }); // Add additional global functions - scope.setTimeout = Zotero.setTimeout; - scope.clearTimeout = Zotero.clearTimeout; + scope.setTimeout = setTimeout; + scope.clearTimeout = clearTimeout; + scope.setInterval = setInterval; + scope.clearInterval = clearInterval; + scope.requestIdleCallback = requestIdleCallback; + scope.cancelIdleCallback = cancelIdleCallback; scopes.set(addon.id, scope); diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index a89cfe1a61..c561673c3c 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -1427,41 +1427,6 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); return Zotero.Utilities.Internal.spawn(generator, thisObject); } - - /** - * Emulates the behavior of window.setTimeout - * - * @param {Function} func The function to be called - * @param {Integer} ms The number of milliseconds to wait before calling func - * @return {Integer} - ID of timer to be passed to clearTimeout() - */ - var _lastTimeoutID = 0; - this.setTimeout = function (func, ms) { - var id = ++_lastTimeoutID; - - var timer = Components.classes["@mozilla.org/timer;1"] - .createInstance(Components.interfaces.nsITimer); - var timerCallback = { - "notify": function () { - func(); - _runningTimers.delete(id); - } - }; - timer.initWithCallback(timerCallback, ms, Components.interfaces.nsITimer.TYPE_ONE_SHOT); - _runningTimers.set(id, timer); - return id; - }; - - - this.clearTimeout = function (id) { - var timer = _runningTimers.get(id); - if (timer) { - timer.cancel(); - _runningTimers.delete(id); - } - }; - - /** * Show Zotero pane overlay and progress bar in all windows * diff --git a/components/zotero-service.js b/components/zotero-service.js index 43585a40cf..3c061dda93 100644 --- a/components/zotero-service.js +++ b/components/zotero-service.js @@ -200,17 +200,6 @@ ZoteroContext.prototype = { "Cc":Cc, "Ci":Ci, - /** - * Convenience method to replicate window.setTimeout() - **/ - "setTimeout":function setTimeout(func, ms){ - return this.Zotero.setTimeout(func, ms); - }, - - "clearTimeout":function setTimeout(id) { - this.Zotero.clearTimeout(id); - }, - /** * Switches in or out of connector mode */ @@ -246,6 +235,18 @@ ZoteroContext.prototype = { } }; +const { XPCOMUtils } = ChromeUtils.import( + "resource://gre/modules/XPCOMUtils.jsm" +); +XPCOMUtils.defineLazyModuleGetters(ZoteroContext.prototype, { + setTimeout: "resource://gre/modules/Timer.jsm", + clearTimeout: "resource://gre/modules/Timer.jsm", + setInterval: "resource://gre/modules/Timer.jsm", + clearInterval: "resource://gre/modules/Timer.jsm", + requestIdleCallback: "resource://gre/modules/Timer.jsm", + cancelIdleCallback: "resource://gre/modules/Timer.jsm", +}); + /** * The class from which the Zotero global XPCOM context is constructed *