From 95d8b37f0a633ea913da7669f4645c5bb90b1185 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Tue, 22 Mar 2022 12:55:47 -0700 Subject: [PATCH] Potentially fix ProgressWindow crash The call to _window.addEventListener() might have been causing an error when _window was null or undefined (no main Zotero window could be found), which would prevent _windowLoading from being set to true and the window from being added to the ProgressWindowSet, which might have caused unpredictable behavior when positioning windows later on. I could only briefly reproduce the issue, so this is just one idea. The call to addEventListener on a potentially null _window was definitely a bug but I don't know if it caused the crash. --- chrome/content/zotero/xpcom/progressWindow.js | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/chrome/content/zotero/xpcom/progressWindow.js b/chrome/content/zotero/xpcom/progressWindow.js index 5797725948..c212c92acd 100644 --- a/chrome/content/zotero/xpcom/progressWindow.js +++ b/chrome/content/zotero/xpcom/progressWindow.js @@ -115,24 +115,24 @@ Zotero.ProgressWindow = function(options = {}) { * Shows the progress window */ this.show = function show() { - if(_windowLoading || _windowLoaded) { // already loading or loaded + if (_windowLoading || _windowLoaded) { // already loading or loaded return false; } - var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]. - getService(Components.interfaces.nsIWindowWatcher); - - if (!_window){ - _window = Components.classes["@mozilla.org/appshell/window-mediator;1"] - .getService(Components.interfaces.nsIWindowMediator) - .getMostRecentWindow("navigator:browser"); + if (!_window) { + _window = Zotero.getMainWindow(); } if (_window) { _progressWindow = _window.openDialog("chrome://zotero/content/progressWindow.xul", "", "chrome,dialog=no,titlebar=no,popup=yes"); + _window.addEventListener('close', () => { + this.close(); + }); } else { + let ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] + .getService(Components.interfaces.nsIWindowWatcher); _progressWindow = ww.openWindow(null, "chrome://zotero/content/progressWindow.xul", "", "chrome,dialog=no,titlebar=no,popup=yes", null); } @@ -140,9 +140,6 @@ Zotero.ProgressWindow = function(options = {}) { _progressWindow.addEventListener("mouseover", _onMouseOver, false); _progressWindow.addEventListener("mouseout", _onMouseOut, false); _progressWindow.addEventListener("mouseup", _onMouseUp, false); - _window.addEventListener('close', () => { - this.close(); - }); _windowLoading = true;