Don't load bundled files in Standalone until UI is ready

This commit is contained in:
Dan Stillman 2016-12-02 16:52:28 -05:00
parent 8c48b2f806
commit f3fd7e7a10
3 changed files with 44 additions and 11 deletions

View file

@ -88,7 +88,7 @@ Zotero.Schema = new function(){
Zotero.debug('Database does not exist -- creating\n'); Zotero.debug('Database does not exist -- creating\n');
return _initializeSchema() return _initializeSchema()
.then(function() { .then(function() {
Zotero.initializationPromise (Zotero.isStandalone ? Zotero.uiReadyPromise : Zotero.initializationPromise)
.then(1000) .then(1000)
.then(function () { .then(function () {
return Zotero.Schema.updateBundledFiles(); return Zotero.Schema.updateBundledFiles();
@ -182,7 +182,9 @@ Zotero.Schema = new function(){
// Reset sync queue tries if new version // Reset sync queue tries if new version
yield _checkClientVersion(); yield _checkClientVersion();
Zotero.initializationPromise // In Standalone, don't load bundled files until after UI is ready. In Firefox, load them as
// soon initialization is done so that translation works before the Zotero pane is opened.
(Zotero.isStandalone ? Zotero.uiReadyPromise : Zotero.initializationPromise)
.then(1000) .then(1000)
.then(function () { .then(function () {
return Zotero.Schema.updateBundledFiles(); return Zotero.Schema.updateBundledFiles();

View file

@ -93,10 +93,12 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
this.closing = false; this.closing = false;
this.initializationDeferred;
this.initializationPromise;
this.unlockDeferred; this.unlockDeferred;
this.unlockPromise; this.unlockPromise;
this.initializationDeferred;
this.initializationPromise;
this.objectInitializationDeferred;
this.objectInitializationPromise;
this.hiDPISuffix = ""; this.hiDPISuffix = "";
@ -129,6 +131,7 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
*/ */
var _runningTimers = new Map(); var _runningTimers = new Map();
var _startupTime = new Date();
// Errors that were in the console at startup // Errors that were in the console at startup
var _startupErrors = []; var _startupErrors = [];
// Number of errors to maintain in the recent errors buffer // Number of errors to maintain in the recent errors buffer
@ -146,9 +149,11 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
return false; return false;
} }
this.locked = true;
this.initializationDeferred = Zotero.Promise.defer(); this.initializationDeferred = Zotero.Promise.defer();
this.initializationPromise = this.initializationDeferred.promise; this.initializationPromise = this.initializationDeferred.promise;
this.locked = true; this.uiReadyDeferred = Zotero.Promise.defer();
this.uiReadyPromise = this.uiReadyDeferred.promise;
// Add a function to Zotero.Promise to check whether a value is still defined, and if not // Add a function to Zotero.Promise to check whether a value is still defined, and if not
// to throw a specific error that's ignored by the unhandled rejection handler in // to throw a specific error that's ignored by the unhandled rejection handler in
@ -429,6 +434,14 @@ Components.utils.import("resource://gre/modules/osfile.jsm");
} }
this.uiIsReady = function () {
if (this.uiReadyPromise.isPending()) {
Zotero.debug("User interface ready in " + (new Date() - _startupTime) + " ms");
this.uiReadyDeferred.resolve();
}
};
var _addToolbarIcon = function () { var _addToolbarIcon = function () {
if (Zotero.isStandalone) return; if (Zotero.isStandalone) return;

View file

@ -1138,17 +1138,24 @@ var ZoteroPane = new function()
}); });
this.tagSelectorShown = function () {
var collectionTreeRow = this.getCollectionTreeRow();
if (!collectionTreeRow) return;
var tagSelector = document.getElementById('zotero-tag-selector');
return !tagSelector.getAttribute('collapsed')
|| tagSelector.getAttribute('collapsed') == 'false';
};
/* /*
* Set the tags scope to the items in the current view * Set the tags scope to the items in the current view
* *
* Passed to the items tree to trigger on changes * Passed to the items tree to trigger on changes
*/ */
this.setTagScope = Zotero.Promise.coroutine(function* () { this.setTagScope = Zotero.Promise.coroutine(function* () {
var collectionTreeRow = self.getCollectionTreeRow(); var collectionTreeRow = this.getCollectionTreeRow();
if (!collectionTreeRow) return;
var tagSelector = document.getElementById('zotero-tag-selector'); var tagSelector = document.getElementById('zotero-tag-selector');
if (!tagSelector.getAttribute('collapsed') || if (this.tagSelectorShown()) {
tagSelector.getAttribute('collapsed') == 'false') {
Zotero.debug('Updating tag selector with current tags'); Zotero.debug('Updating tag selector with current tags');
if (collectionTreeRow.editable) { if (collectionTreeRow.editable) {
tagSelector.mode = 'edit'; tagSelector.mode = 'edit';
@ -1157,7 +1164,7 @@ var ZoteroPane = new function()
tagSelector.mode = 'view'; tagSelector.mode = 'view';
} }
tagSelector.collectionTreeRow = collectionTreeRow; tagSelector.collectionTreeRow = collectionTreeRow;
tagSelector.updateScope = self.setTagScope; tagSelector.updateScope = () => this.setTagScope();
tagSelector.libraryID = collectionTreeRow.ref.libraryID; tagSelector.libraryID = collectionTreeRow.ref.libraryID;
tagSelector.scope = yield collectionTreeRow.getChildTags(); tagSelector.scope = yield collectionTreeRow.getChildTags();
} }
@ -1224,7 +1231,18 @@ var ZoteroPane = new function()
Zotero.Prefs.clear('lastViewedFolder'); Zotero.Prefs.clear('lastViewedFolder');
ZoteroPane_Local.displayErrorMessage(); ZoteroPane_Local.displayErrorMessage();
}; };
this.itemsView.addEventListener('load', this.setTagScope); this.itemsView.addEventListener('load', () => this.setTagScope());
if (this.tagSelectorShown()) {
let tagSelector = document.getElementById('zotero-tag-selector')
let handler = function () {
tagSelector.removeEventListener('refresh', handler);
Zotero.uiIsReady();
};
tagSelector.addEventListener('refresh', handler);
}
else {
this.itemsView.addEventListener('load', () => Zotero.uiIsReady());
}
// If item data not yet loaded for library, load it now. // If item data not yet loaded for library, load it now.
// Other data types are loaded at startup // Other data types are loaded at startup