From d0db9cbadfe1a14e8927f5aaf471967d6a52b940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adomas=20Ven=C4=8Dkauskas?= Date: Fri, 15 May 2020 10:30:40 +0300 Subject: [PATCH] Attempt to catch/log initialization errors for the citation dialog --- .../content/zotero/integration/quickFormat.js | 71 ++++++++++--------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/chrome/content/zotero/integration/quickFormat.js b/chrome/content/zotero/integration/quickFormat.js index debfa2fe30..ac5d366cb8 100644 --- a/chrome/content/zotero/integration/quickFormat.js +++ b/chrome/content/zotero/integration/quickFormat.js @@ -143,43 +143,48 @@ var Zotero_QuickFormat = new function () { /** * Initialize add citation dialog */ - this.onLoad = function(event) { - if (event.target !== document) return; - // make sure we are visible - window.setTimeout(function() { - window.resizeTo(window.outerWidth, qfb.clientHeight); - var screenX = window.screenX; - var screenY = window.screenY; - var xRange = [window.screen.availLeft, window.screen.width-window.outerWidth]; - var yRange = [window.screen.availTop, window.screen.height-window.outerHeight]; - if(screenX < xRange[0] || screenX > xRange[1] || screenY < yRange[0] || screenY > yRange[1]) { - var targetX = Math.max(Math.min(screenX, xRange[1]), xRange[0]); - var targetY = Math.max(Math.min(screenY, yRange[1]), yRange[0]); - Zotero.debug("Moving window to "+targetX+", "+targetY); - window.moveTo(targetX, targetY); - } - qfGuidance = document.getElementById('quick-format-guidance'); - qfGuidance.show(); - _refocusQfe(); - }, 0); - - window.focus(); - qfe.focus(); - - // load citation data - if(io.citation.citationItems.length) { - // hack to get spacing right - var evt = qfiDocument.createEvent("KeyboardEvent"); - evt.initKeyEvent("keypress", true, true, qfiWindow, - 0, 0, 0, 0, - 0, " ".charCodeAt(0)) - qfe.dispatchEvent(evt); - window.setTimeout(function() { + this.onLoad = async function (event) { + try { + if (event.target !== document) return; + // make sure we are visible + let resizePromise = (async function () { + await Zotero.Promise.delay(); + window.resizeTo(window.outerWidth, qfb.clientHeight); + var screenX = window.screenX; + var screenY = window.screenY; + var xRange = [window.screen.availLeft, window.screen.width - window.outerWidth]; + var yRange = [window.screen.availTop, window.screen.height - window.outerHeight]; + if (screenX < xRange[0] || screenX > xRange[1] || screenY < yRange[0] || screenY > yRange[1]) { + var targetX = Math.max(Math.min(screenX, xRange[1]), xRange[0]); + var targetY = Math.max(Math.min(screenY, yRange[1]), yRange[0]); + Zotero.debug(`Moving window to ${targetX}, ${targetY}`); + window.moveTo(targetX, targetY); + } + qfGuidance = document.getElementById('quick-format-guidance'); + qfGuidance.show(); + _refocusQfe(); + })(); + + window.focus(); + qfe.focus(); + + // load citation data + if (io.citation.citationItems.length) { + // hack to get spacing right + var evt = qfiDocument.createEvent("KeyboardEvent"); + evt.initKeyEvent("keypress", true, true, qfiWindow, + 0, 0, 0, 0, + 0, " ".charCodeAt(0)); + qfe.dispatchEvent(evt); + await resizePromise; var node = qfe.firstChild; node.nodeValue = ""; _showCitation(node); _resize(); - }, 1); + } + } + catch (e) { + Zotero.logError(e); } };