Wait for schema update before updating save icon

Technically rather than waiting for the schema update we should wait for
translator initialization, which should wait for the schema update
itself, but the schema update also needs to initialize the translators,
so avoiding a hang is tricky, particularly with the use of Zotero.lazy()
for Zotero.Translators.init(). For now, just wait for the schema update.
This commit is contained in:
Dan Stillman 2015-07-07 16:36:00 -04:00
parent c590aa0eb4
commit 2a5b026f65
3 changed files with 27 additions and 16 deletions

View file

@ -44,12 +44,9 @@ var Zotero_Browser = new function() {
this.toggleMode = toggleMode;
this.toggleCollapsed = toggleCollapsed;
this.chromeLoad = chromeLoad;
this.contentLoad = contentLoad;
this.itemUpdated = itemUpdated;
this.contentHide = contentHide;
this.tabClose = tabClose;
this.resize = resize;
this.updateStatus = updateStatus;
this.tabbrowser = null;
this.appcontent = null;
@ -243,6 +240,7 @@ var Zotero_Browser = new function() {
gBrowser.tabContainer.addEventListener("TabSelect",
function(e) {
//Zotero.debug("TabSelect");
// Note: async
Zotero_Browser.updateStatus();
}, false);
// this is for pageshow, for updating the status of the book icon
@ -284,7 +282,11 @@ var Zotero_Browser = new function() {
* An event handler called when a new document is loaded. Creates a new document
* object, and updates the status of the capture icon
*/
function contentLoad(event) {
var contentLoad = Zotero.Promise.coroutine(function* (event) {
if (Zotero.Schema.schemaUpdatePromise.isPending()) {
yield Zotero.Schema.schemaUpdatePromise;
}
var doc = event.originalTarget;
var isHTML = doc instanceof HTMLDocument;
var rootDoc = (doc instanceof HTMLDocument ? doc.defaultView.top.document : doc);
@ -352,12 +354,12 @@ var Zotero_Browser = new function() {
contentWin.haveZoteroEventListener = true;
}
}
}
});
/*
* called to unregister Zotero icon, etc.
*/
function contentHide(event) {
this.contentHide = function (event) {
var doc = event.originalTarget;
if(!(doc instanceof HTMLDocument)) return;
@ -377,7 +379,8 @@ var Zotero_Browser = new function() {
// update status
if(Zotero_Browser.tabbrowser.selectedBrowser == browser) {
updateStatus();
// Note: async
this.updateStatus();
}
}
@ -425,7 +428,11 @@ var Zotero_Browser = new function() {
* Updates the status of the capture icon to reflect the scrapability or lack
* thereof of the current page
*/
function updateStatus() {
this.updateStatus = Zotero.Promise.coroutine(function* () {
if (Zotero.Schema.schemaUpdatePromise.isPending()) {
yield Zotero.Schema.schemaUpdatePromise;
}
if (!Zotero_Browser.tabbrowser) return;
var tab = _getTabObject(Zotero_Browser.tabbrowser.selectedBrowser);
@ -455,7 +462,7 @@ var Zotero_Browser = new function() {
} else {
document.getElementById('zotero-annotate-tb').hidden = true;
}
}
});
function getSaveButtons() {
Components.utils.import("resource:///modules/CustomizableUI.jsm");
@ -1011,6 +1018,7 @@ Zotero_Browser.Tab.prototype._translatorsAvailable = function(translate, transla
if(!translators || !translators.length) Zotero.debug("Translate: No translators found");
// Note: async
Zotero_Browser.updateStatus();
}

View file

@ -958,7 +958,9 @@ Zotero.Schema = new function(){
}
});
yield Zotero[Mode].reinit(cache);
yield Zotero[Mode].reinit({
metadataCache: cache
});
return true;
});

View file

@ -39,13 +39,12 @@ Zotero.Translators = new function() {
/**
* Initializes translator cache, loading all translator metadata into memory
*
* @param {Object} [memCache] - Translator metadata keyed by filename, if already available
* (e.g., in updateBundledFiles()), to avoid unnecesary file reads
* @param {Object} [options.metadataCache] - Translator metadata keyed by filename, if already
* available (e.g., in updateBundledFiles()), to avoid unnecesary file reads
*/
this.reinit = Zotero.Promise.coroutine(function* (memCache) {
this.reinit = Zotero.Promise.coroutine(function* (options = {}) {
Zotero.debug("Initializing translators");
var start = new Date;
_initialized = true;
_cache = {"import":[], "export":[], "web":[], "search":[]};
_translators = {};
@ -83,8 +82,8 @@ Zotero.Translators = new function() {
// Check passed cache for metadata
let memCacheJSON = false;
if (memCache && memCache[fileName]) {
memCacheJSON = memCache[fileName];
if (options.metadataCache && options.metadataCache[fileName]) {
memCacheJSON = options.metadataCache[fileName];
}
// Check DB cache
@ -183,6 +182,8 @@ Zotero.Translators = new function() {
_cache[type].sort(cmp);
}
_initialized = true;
Zotero.debug("Cached " + numCached + " translators in " + ((new Date) - start) + " ms");
});
this.init = Zotero.lazy(this.reinit);