commit 0b92ad0037a14631c5f48832623cb58619e13f4a
parent dd8c0ecf37bc9141779c61b0b801215a1a6ee94e
Author: Simon Kornblith <simon@simonster.com>
Date: Tue, 5 Nov 2013 15:52:40 -0500
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
Diffstat:
5 files changed, 41 insertions(+), 12 deletions(-)
diff --git a/chrome/content/zotero/overlay.js b/chrome/content/zotero/overlay.js
@@ -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);
}
diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js
@@ -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();
diff --git a/chrome/content/zotero/zoteroPane.js b/chrome/content/zotero/zoteroPane.js
@@ -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();
}
@@ -4107,15 +4111,28 @@ var ZoteroPane = new function()
}
/**
+ * 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
*/
var _reloadObserver = {
/**
* 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);
+ }
}
};
}
diff --git a/chrome/locale/en-US/zotero/zotero.properties b/chrome/locale/en-US/zotero/zotero.properties
@@ -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.
diff --git a/components/zotero-service.js b/components/zotero-service.js
@@ -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);