Modify behavior on Zotero Standalone launch to account for failure

- Close Zotero pane before database is closed prior to reload, instead
  of waiting until reload is complete
- Show an error message if Zotero Standalone is not accessible when it
  should be
This commit is contained in:
Simon Kornblith 2013-11-05 15:52:40 -05:00
parent dd8c0ecf37
commit 0b92ad0037
5 changed files with 41 additions and 12 deletions

View file

@ -146,14 +146,19 @@ var ZoteroOverlay = new function()
// Hide browser chrome on Zotero tab
XULBrowserWindow.inContentWhitelist.push("chrome://zotero/content/tab.xul");
// Close pane if connector is enabled
ZoteroPane_Local.addReloadListener(function() {
if(Zotero.isConnector) {
// Close pane before reload
ZoteroPane_Local.addBeforeReloadListener(function(newMode) {
if(newMode == "connector") {
// save current state
_stateBeforeReload = !zoteroPane.hidden && !zoteroPane.collapsed;
// ensure pane is closed
if(!zoteroPane.collapsed) ZoteroOverlay.toggleDisplay(false, true);
} else {
}
});
// Close pane if connector is enabled
ZoteroPane_Local.addReloadListener(function() {
if(!Zotero.isConnector) {
// reopen pane if it was open before
ZoteroOverlay.toggleDisplay(_stateBeforeReload, true);
}

View file

@ -472,6 +472,9 @@ Components.utils.import("resource://gre/modules/Services.jsm");
if(Zotero.isConnector) {
Zotero.debug("Loading in connector mode");
Zotero.Connector_Types.init();
// Store a startupError until we get information from Zotero Standalone
Zotero.startupError = Zotero.getString("connector.loadInProgress")
if(!Zotero.isFirstLoadThisSession) {
// We want to get a checkInitComplete message before initializing if we switched to
@ -496,6 +499,7 @@ Components.utils.import("resource://gre/modules/Services.jsm");
this.initComplete = function() {
if(Zotero.initialized) return;
this.initialized = true;
delete this.startupError;
if(Zotero.isConnector) {
Zotero.Repo.init();

View file

@ -91,7 +91,7 @@ var ZoteroPane = new function()
var self = this,
_loaded = false, _madeVisible = false,
titlebarcolorState, titleState, observerService,
_reloadFunctions = [];
_reloadFunctions = [], _beforeReloadFunctions = [];
/**
* Called when the window containing Zotero pane is open
@ -128,6 +128,13 @@ var ZoteroPane = new function()
observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(_reloadObserver, "zotero-reloaded", false);
observerService.addObserver(_reloadObserver, "zotero-before-reload", false);
this.addBeforeReloadListener(function(newMode) {
if(newMode == "connector") {
ZoteroPane_Local.setItemsPaneMessage(Zotero.getString('connector.standaloneOpen'));
}
return;
});
this.addReloadListener(_loadPane);
// continue loading pane
@ -141,10 +148,7 @@ var ZoteroPane = new function()
function _loadPane() {
if(!Zotero || !Zotero.initialized) return;
if(Zotero.isConnector) {
ZoteroPane_Local.setItemsPaneMessage(Zotero.getString('connector.standaloneOpen'));
return;
} else {
if(!Zotero.isConnector) {
ZoteroPane_Local.clearItemsPaneMessage();
}
@ -4106,6 +4110,14 @@ var ZoteroPane = new function()
if(_reloadFunctions.indexOf(func) === -1) _reloadFunctions.push(func);
}
/**
* Adds or removes a function to be called just before Zotero is reloaded by switching into or
* out of the connector
*/
this.addBeforeReloadListener = function(/** @param {Function} **/func) {
if(_beforeReloadFunctions.indexOf(func) === -1) _beforeReloadFunctions.push(func);
}
/**
* Implements nsIObserver for Zotero reload
*/
@ -4113,9 +4125,14 @@ var ZoteroPane = new function()
/**
* Called when Zotero is reloaded (i.e., if it is switched into or out of connector mode)
*/
"observe":function() {
Zotero.debug("Reloading Zotero pane");
for each(var func in _reloadFunctions) func();
"observe":function(aSubject, aTopic, aData) {
if(aTopic == "zotero-reloaded") {
Zotero.debug("Reloading Zotero pane");
for each(var func in _reloadFunctions) func(aData);
} else if(aTopic == "zotero-before-reload") {
Zotero.debug("Zotero pane caught before-reload event");
for each(var func in _beforeReloadFunctions) func(aData);
}
}
};
}

View file

@ -944,6 +944,7 @@ standalone.updateMessage = A recommended update is available, but you do not h
connector.error.title = Zotero Connector Error
connector.standaloneOpen = Your database cannot be accessed because Zotero Standalone is currently open. Please view your items in Zotero Standalone.
connector.loadInProgress = Zotero Standalone was launched but is not accessible. If you experienced an error opening Zotero Standalone, restart Firefox.
firstRunGuidance.saveIcon = Zotero has found a reference on this page. Click this icon in the address bar to save the reference to your Zotero library.
firstRunGuidance.authorMenu = Zotero lets you specify editors and translators, too. You can turn an author into an editor or translator by selecting from this menu.

View file

@ -120,6 +120,7 @@ const xpcomFilesConnector = [
];
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
Components.utils.import("resource://gre/modules/Services.jsm");
var instanceID = (new Date()).getTime();
var isFirstLoadThisSession = true;
@ -164,6 +165,7 @@ ZoteroContext.prototype = {
*/
"switchConnectorMode":function(isConnector) {
if(isConnector !== this.isConnector) {
Services.obs.notifyObservers(zContext.Zotero, "zotero-before-reload", isConnector ? "connector" : "full");
zContext.Zotero.shutdown().then(function() {
// create a new zContext
makeZoteroContext(isConnector);