Add Zotero.crash() to show restart message in every window

This commit is contained in:
Dan Stillman 2020-03-13 17:17:02 -04:00
parent 9175f9ade8
commit 81739c7a66
2 changed files with 61 additions and 40 deletions

View file

@ -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. * @property {Boolean} closing True if the application is closing.
*/ */
this.closing = false; this.closing = false;
this.unlockDeferred; this.unlockDeferred;
this.unlockPromise; this.unlockPromise;
this.initializationDeferred; 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) { this.getErrors = function (asStrings) {
var errors = []; var errors = [];

View file

@ -55,7 +55,6 @@ var ZoteroPane = new function()
this.clearItemsPaneMessage = clearItemsPaneMessage; this.clearItemsPaneMessage = clearItemsPaneMessage;
this.viewSelectedAttachment = viewSelectedAttachment; this.viewSelectedAttachment = viewSelectedAttachment;
this.reportErrors = reportErrors; this.reportErrors = reportErrors;
this.displayErrorMessage = displayErrorMessage;
this.document = document; this.document = document;
@ -154,7 +153,7 @@ var ZoteroPane = new function()
ZoteroPane_Local.collectionsView = new Zotero.CollectionTreeView(); ZoteroPane_Local.collectionsView = new Zotero.CollectionTreeView();
// Handle an error in setTree()/refresh() // Handle an error in setTree()/refresh()
ZoteroPane_Local.collectionsView.onError = function (e) { ZoteroPane_Local.collectionsView.onError = function (e) {
ZoteroPane_Local.displayErrorMessage(); Zotero.crash();
}; };
var collectionsTree = document.getElementById('zotero-collections-tree'); var collectionsTree = document.getElementById('zotero-collections-tree');
collectionsTree.view = ZoteroPane_Local.collectionsView; 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 could not be initialized, display an error message and return
if (!Zotero || Zotero.skipLoading) { if (!Zotero || Zotero.skipLoading || Zotero.crashed) {
this.displayStartupError(); this.displayStartupError();
return false; return false;
} }
@ -1188,7 +1187,7 @@ var ZoteroPane = new function()
this.itemsView.onError = function () { this.itemsView.onError = function () {
// Don't reload last folder, in case that's the problem // Don't reload last folder, in case that's the problem
Zotero.Prefs.clear('lastViewedFolder'); Zotero.Prefs.clear('lastViewedFolder');
ZoteroPane_Local.displayErrorMessage(); Zotero.crash();
}; };
this.itemsView.onRefresh.addListener(() => { this.itemsView.onRefresh.addListener(() => {
this.setTagScope(); this.setTagScope();
@ -1506,7 +1505,7 @@ var ZoteroPane = new function()
}.bind(this))() }.bind(this))()
.catch(function (e) { .catch(function (e) {
Zotero.logError(e); Zotero.logError(e);
this.displayErrorMessage(); Zotero.crash();
throw e; throw e;
}.bind(this)) }.bind(this))
.finally(function () { .finally(function () {
@ -4771,37 +4770,9 @@ var ZoteroPane = new function()
"zotero-error-report", "chrome,centerscreen,modal", io); "zotero-error-report", "chrome,centerscreen,modal", io);
} }
/* this.displayErrorMessage = function (popup) {
* Display an error message saying that an error has occurred and Firefox Zotero.debug("ZoteroPane.displayErrorMessage() is deprecated -- use Zotero.crash() instead");
* needs to be restarted. Zotero.crash(popup);
*
* 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.displayStartupError = function(asPaneMessage) { this.displayStartupError = function(asPaneMessage) {
@ -4830,9 +4801,7 @@ var ZoteroPane = new function()
//if(asPaneMessage) { //if(asPaneMessage) {
// ZoteroPane_Local.setItemsPaneMessage(errMsg, true); // ZoteroPane_Local.setItemsPaneMessage(errMsg, true);
//} else { //} else {
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] Zotero.alert(null, title, errMsg);
.getService(Components.interfaces.nsIPromptService);
ps.alert(null, title, errMsg);
//} //}
} }
} }