From 5a08d22dbf03452468b499b2ffbb9e7d48ef2765 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 30 Mar 2018 01:47:54 -0400 Subject: [PATCH] Fix attachment save failure on macOS with window closed Use hiddenDOMWindow if no other window --- chrome/content/zotero/xpcom/zotero.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 84cc45d74..149fe935d 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -2730,14 +2730,17 @@ Zotero.DragDrop = { Zotero.Browser = new function() { var nBrowsers = 0; - this.createHiddenBrowser = createHiddenBrowser; - this.deleteHiddenBrowser = deleteHiddenBrowser; - - function createHiddenBrowser(win) { - if (!win) { - var win = Services.wm.getMostRecentWindow("navigator:browser"); - if(!win) { - var win = Services.ww.activeWindow; + this.createHiddenBrowser = function (win) { + if (!win) { + win = Services.wm.getMostRecentWindow("navigator:browser"); + if (!win) { + win = Services.ww.activeWindow; + } + // Use the hidden DOM window on macOS with the main window closed + if (!win) { + let appShellService = Components.classes["@mozilla.org/appshell/appShellService;1"] + .getService(Components.interfaces.nsIAppShellService); + win = appShellService.hiddenDOMWindow; } if (!win) { throw new Error("Parent window not available for hidden browser"); @@ -2760,7 +2763,7 @@ Zotero.Browser = new function() { return hiddenBrowser; } - function deleteHiddenBrowser(myBrowsers) { + this.deleteHiddenBrowser = function (myBrowsers) { if(!(myBrowsers instanceof Array)) myBrowsers = [myBrowsers]; for(var i=0; i