From 81739c7a664761cc31a924eb27d5f1ce4e6b2db9 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Fri, 13 Mar 2020 17:17:02 -0400 Subject: [PATCH] Add Zotero.crash() to show restart message in every window --- chrome/content/zotero/xpcom/zotero.js | 54 ++++++++++++++++++++++++++- chrome/content/zotero/zoteroPane.js | 47 ++++------------------- 2 files changed, 61 insertions(+), 40 deletions(-) diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index c98f3ca0f3..cb9b37032c 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -102,12 +102,16 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); } }); + /** + * @property {Boolean} crashed - True if the application needs to be restarted + */ + this.crashed = false; + /** * @property {Boolean} closing True if the application is closing. */ this.closing = false; - this.unlockDeferred; this.unlockPromise; this.initializationDeferred; @@ -1205,6 +1209,54 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); } + /** + * Display an error message saying that an error has occurred and Zotero needs to be restarted. + * + * If |popup| is TRUE, display in popup progress window; otherwise, display as items pane message + */ + this.crash = function (popup) { + this.crashed = true; + + var reportErrorsStr = Zotero.getString('errorReport.reportErrors'); + var reportInstructions = Zotero.getString('errorReport.reportInstructions', reportErrorsStr); + + var msg; + if (popup) { + msg = Zotero.getString('general.pleaseRestart', Zotero.appName) + ' ' + + reportInstructions; + } + else { + msg = Zotero.getString('general.errorHasOccurred') + ' ' + + Zotero.getString('general.pleaseRestart', Zotero.appName) + '\n\n' + + reportInstructions; + } + Zotero.logError(msg); + Zotero.logError(new Error().stack); + + this.startupError = msg; + this.startupErrorHandler = null; + + var enumerator = Services.wm.getEnumerator("navigator:browser"); + while (enumerator.hasMoreElements()) { + let win = enumerator.getNext(); + if (!win.ZoteroPane) continue; + + // Display as popup progress window + if (popup) { + var pw = new Zotero.ProgressWindow(); + pw.changeHeadline(Zotero.getString('general.errorHasOccurred')); + pw.addDescription(msg); + pw.show(); + pw.startCloseTimer(8000); + } + // Display as items pane message + else { + win.ZoteroPane.setItemsPaneMessage(msg, true); + } + } + }; + + this.getErrors = function (asStrings) { var errors = []; diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js index c772bde533..f48b426705 100644 --- a/chrome/content/zotero/zoteroPane.js +++ b/chrome/content/zotero/zoteroPane.js @@ -55,7 +55,6 @@ var ZoteroPane = new function() this.clearItemsPaneMessage = clearItemsPaneMessage; this.viewSelectedAttachment = viewSelectedAttachment; this.reportErrors = reportErrors; - this.displayErrorMessage = displayErrorMessage; this.document = document; @@ -154,7 +153,7 @@ var ZoteroPane = new function() ZoteroPane_Local.collectionsView = new Zotero.CollectionTreeView(); // Handle an error in setTree()/refresh() ZoteroPane_Local.collectionsView.onError = function (e) { - ZoteroPane_Local.displayErrorMessage(); + Zotero.crash(); }; var collectionsTree = document.getElementById('zotero-collections-tree'); collectionsTree.view = ZoteroPane_Local.collectionsView; @@ -387,7 +386,7 @@ var ZoteroPane = new function() } // If Zotero could not be initialized, display an error message and return - if (!Zotero || Zotero.skipLoading) { + if (!Zotero || Zotero.skipLoading || Zotero.crashed) { this.displayStartupError(); return false; } @@ -1188,7 +1187,7 @@ var ZoteroPane = new function() this.itemsView.onError = function () { // Don't reload last folder, in case that's the problem Zotero.Prefs.clear('lastViewedFolder'); - ZoteroPane_Local.displayErrorMessage(); + Zotero.crash(); }; this.itemsView.onRefresh.addListener(() => { this.setTagScope(); @@ -1506,7 +1505,7 @@ var ZoteroPane = new function() }.bind(this))() .catch(function (e) { Zotero.logError(e); - this.displayErrorMessage(); + Zotero.crash(); throw e; }.bind(this)) .finally(function () { @@ -4771,37 +4770,9 @@ var ZoteroPane = new function() "zotero-error-report", "chrome,centerscreen,modal", io); } - /* - * Display an error message saying that an error has occurred and Firefox - * needs to be restarted. - * - * If |popup| is TRUE, display in popup progress window; otherwise, display - * as items pane message - */ - function displayErrorMessage(popup) { - var reportErrorsStr = Zotero.getString('errorReport.reportErrors'); - var reportInstructions = - Zotero.getString('errorReport.reportInstructions', reportErrorsStr) - - // Display as popup progress window - if (popup) { - var pw = new Zotero.ProgressWindow(); - pw.changeHeadline(Zotero.getString('general.errorHasOccurred')); - var msg = Zotero.getString('general.pleaseRestart', Zotero.appName) + ' ' - + reportInstructions; - pw.addDescription(msg); - pw.show(); - pw.startCloseTimer(8000); - } - // Display as items pane message - else { - var msg = Zotero.getString('general.errorHasOccurred') + ' ' - + Zotero.getString('general.pleaseRestart', Zotero.appName) + '\n\n' - + reportInstructions; - self.setItemsPaneMessage(msg, true); - } - Zotero.debug(msg, 1); - Zotero.debug(new Error().stack, 1); + this.displayErrorMessage = function (popup) { + Zotero.debug("ZoteroPane.displayErrorMessage() is deprecated -- use Zotero.crash() instead"); + Zotero.crash(popup); } this.displayStartupError = function(asPaneMessage) { @@ -4830,9 +4801,7 @@ var ZoteroPane = new function() //if(asPaneMessage) { // ZoteroPane_Local.setItemsPaneMessage(errMsg, true); //} else { - var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] - .getService(Components.interfaces.nsIPromptService); - ps.alert(null, title, errMsg); + Zotero.alert(null, title, errMsg); //} } }