Use asynchronous DB and file access for schema checks/updates

This change should improve Firefox startup time. If the Zotero pane is
opened before Zotero has initialized, the pane will be blocked with a
progress bar until it's done. Standalone currently does the same, but it
should be changed to just delay opening the window if possible.

The upgrade wizard has been disabled for schema upgrades, in the hope
that upgrades can be done in a way that won't break compatibility with
earlier versions (or that can at least be done in a way such that we can
put out point releases of the last major version that provide
compatibility during beta/post-upgrade periods).

This patch likely breaks many things, and definitely breaks connector
mode.

This change also removes upgrade steps for databases from Zotero 2.1b2
and earlier. Users with such databases will need to upgrade via Zotero
4.0.x first or delete their data directories and start anew. This should
only affect users who haven't opened Zotero since Nov. 2010.
This commit is contained in:
Dan Stillman 2013-08-11 20:51:16 -04:00
parent 2b4de89aaf
commit 5787b230f7
13 changed files with 862 additions and 2396 deletions

View File

@ -101,7 +101,7 @@ var Zotero_Browser = new function() {
* Initialize some variables and prepare event listeners for when chrome is done loading * Initialize some variables and prepare event listeners for when chrome is done loading
*/ */
function init() { function init() {
if (!Zotero || !Zotero.initialized || !window.hasOwnProperty("gBrowser")) { if (!Zotero || Zotero.skipLoading || !window.hasOwnProperty("gBrowser")) {
return; return;
} }

View File

@ -669,6 +669,6 @@ Zotero_File_Interface.Progress = new function() {
} }
function close() { function close() {
Zotero.hideZoteroPaneOverlay(); Zotero.hideZoteroPaneOverlays();
} }
} }

View File

@ -24,17 +24,16 @@
*/ */
var ZoteroItemPane = new function() { var ZoteroItemPane = new function() {
this.onLoad = onLoad;
var _lastItem, _itemBox, _notesLabel, _notesButton, _notesList, _tagsBox, _relatedBox; var _lastItem, _itemBox, _notesLabel, _notesButton, _notesList, _tagsBox, _relatedBox;
function onLoad() this.onLoad = function () {
{ if (!Zotero) {
if (!Zotero || !Zotero.initialized) {
return; return;
} }
// Not in item pane, so skip the introductions // Not in item pane, so skip the introductions
//
// DEBUG: remove?
if (!document.getElementById('zotero-view-tabbox')) { if (!document.getElementById('zotero-view-tabbox')) {
return; return;
} }

View File

@ -29,56 +29,23 @@
var ZoteroOverlay = new function() var ZoteroOverlay = new function()
{ {
const DEFAULT_ZPANE_HEIGHT = 300; const DEFAULT_ZPANE_HEIGHT = 300;
var toolbarCollapseState, showInPref; var toolbarCollapseState, showInPref;
var zoteroPane, zoteroSplitter; var zoteroPane, zoteroSplitter;
var _stateBeforeReload = false; var _stateBeforeReload = false;
var _initializationDeferred, _initializationPromise;
this.isTab = false; this.isTab = false;
this.onLoad = function() { this.onLoad = function() {
try {
zoteroPane = document.getElementById('zotero-pane-stack'); zoteroPane = document.getElementById('zotero-pane-stack');
zoteroSplitter = document.getElementById('zotero-splitter'); zoteroSplitter = document.getElementById('zotero-splitter');
ZoteroPane_Overlay = ZoteroPane;
ZoteroPane.init();
// Open Zotero app tab, if in Fx 4 and requested by pref
showInPref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch('extensions.zotero.').getIntPref('showIn');
this.isTab = showInPref !== 1;
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
var zoteroObserver = function(subject, topic, data) {
if(subject != window) return;
observerService.removeObserver(this, "browser-delayed-startup-finished");
if(showInPref === 3) {
var tabbar = document.getElementById("TabsToolbar");
if(tabbar && window.getComputedStyle(tabbar).display !== "none") {
// load Zotero as a tab, if it isn't loading by default
ZoteroOverlay.loadZoteroTab(true);
}
} else if(showInPref === 1) {
// close Zotero as a tab, in case it was pinned
var zoteroTab = ZoteroOverlay.findZoteroTab();
if(zoteroTab) gBrowser.removeTab(zoteroTab);
}
};
observerService.addObserver(zoteroObserver, "browser-delayed-startup-finished", false);
// Make Zotero icon visible, if requested // Make Zotero icon visible, if requested
var prefBranch = Components.classes["@mozilla.org/preferences-service;1"] var prefBranch = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService) .getService(Components.interfaces.nsIPrefService)
.getBranch('extensions.zotero.'); .getBranch('extensions.zotero.');
var addonBar = document.getElementById('addon-bar'); var addonBar = document.getElementById('addon-bar');
var iconPref = prefBranch.getIntPref('statusBarIcon'); var iconPref = prefBranch.getIntPref('statusBarIcon');
// If this is the first run, add icon to add-on bar if not // If this is the first run, add icon to add-on bar if not
// in the window already and not hidden by the Zotero prefs // in the window already and not hidden by the Zotero prefs
if (!document.getElementById("zotero-toolbar-button") && iconPref != 0) { if (!document.getElementById("zotero-toolbar-button") && iconPref != 0) {
@ -91,10 +58,53 @@ var ZoteroOverlay = new function()
var icon = document.getElementById('zotero-toolbar-button'); var icon = document.getElementById('zotero-toolbar-button');
// Add a listener for toolbar change events var self = this;
window.addEventListener("customizationchange", onToolbarChange, false);
if (Zotero && Zotero.initialized){ Q.fcall(function () {
if (!Zotero || Zotero.skipLoading) {
throw true;
}
return Zotero.unlockPromise;
})
.then(function () {
Zotero.debug("Initializing overlay");
if (Zotero.skipLoading) {
throw true;
}
ZoteroPane_Overlay = ZoteroPane;
ZoteroPane.init();
// Open Zotero app tab, if in Fx 4 and requested by pref
showInPref = Components.classes["@mozilla.org/preferences-service;1"]
.getService(Components.interfaces.nsIPrefService)
.getBranch('extensions.zotero.').getIntPref('showIn');
self.isTab = showInPref !== 1;
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
var zoteroObserver = function(subject, topic, data) {
if(subject != window) return;
observerService.removeObserver(this, "browser-delayed-startup-finished");
if(showInPref === 3) {
var tabbar = document.getElementById("TabsToolbar");
if(tabbar && window.getComputedStyle(tabbar).display !== "none") {
// load Zotero as a tab, if it isn't loading by default
ZoteroOverlay.loadZoteroTab(true);
}
} else if(showInPref === 1) {
// close Zotero as a tab, in case it was pinned
var zoteroTab = ZoteroOverlay.findZoteroTab();
if(zoteroTab) gBrowser.removeTab(zoteroTab);
}
};
observerService.addObserver(zoteroObserver, "browser-delayed-startup-finished", false);
// Add a listener for toolbar change events
window.addEventListener("customizationchange", onToolbarChange, false);
document.getElementById('appcontent').addEventListener('mousemove', Zotero.ProgressWindowSet.updateTimers, false); document.getElementById('appcontent').addEventListener('mousemove', Zotero.ProgressWindowSet.updateTimers, false);
if (icon) { if (icon) {
if (iconPref == 1) { if (iconPref == 1) {
@ -111,58 +121,49 @@ var ZoteroOverlay = new function()
} }
} }
} }
}
else { // Used for loading pages from upgrade wizard
if (Zotero) { if (Zotero.initialURL) {
var errMsg = Zotero.startupError; setTimeout(function () {
gBrowser.selectedTab = gBrowser.addTab(Zotero.initialURL);
Zotero.initialURL = null;
}, 1);
} }
// 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) {
// save current state
_stateBeforeReload = !zoteroPane.hidden && !zoteroPane.collapsed;
// ensure pane is closed
if(!zoteroPane.collapsed) ZoteroOverlay.toggleDisplay(false, true);
} else {
// reopen pane if it was open before
ZoteroOverlay.toggleDisplay(_stateBeforeReload, true);
}
});
})
.catch(function (e) {
var errMsg = Zotero ? Zotero.startupError : null;
// Use defaults if necessary // Use defaults if necessary
if (!errMsg) { if (!errMsg) {
// Get the stringbundle manually // Get the stringbundle manually
var src = 'chrome://zotero/locale/zotero.properties'; var src = 'chrome://zotero/locale/zotero.properties';
var localeService = Components.classes['@mozilla.org/intl/nslocaleservice;1']. var localeService = Components.classes['@mozilla.org/intl/nslocaleservice;1']
getService(Components.interfaces.nsILocaleService); .getService(Components.interfaces.nsILocaleService);
var appLocale = localeService.getApplicationLocale(); var appLocale = localeService.getApplicationLocale();
var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService); .getService(Components.interfaces.nsIStringBundleService);
var stringBundle = stringBundleService.createBundle(src, appLocale); var stringBundle = stringBundleService.createBundle(src, appLocale);
var errMsg = stringBundle.GetStringFromName('startupError'); errMsg = stringBundle.GetStringFromName('startupError');
} }
icon.setAttribute('tooltiptext', errMsg); icon.setAttribute('tooltiptext', errMsg);
icon.setAttribute('error', 'true'); icon.setAttribute('error', 'true');
}
// Used for loading pages from upgrade wizard
if (Zotero && Zotero.initialURL) {
setTimeout(function () {
gBrowser.selectedTab = gBrowser.addTab(Zotero.initialURL);
Zotero.initialURL = null;
}, 1);
}
// 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) {
// save current state
_stateBeforeReload = !zoteroPane.hidden && !zoteroPane.collapsed;
// ensure pane is closed
if(!zoteroPane.collapsed) ZoteroOverlay.toggleDisplay(false, true);
} else {
// reopen pane if it was open before
ZoteroOverlay.toggleDisplay(_stateBeforeReload, true);
}
}); });
}
catch (e) {
Zotero.debug(e);
}
} }
@ -209,7 +210,7 @@ var ZoteroOverlay = new function()
*/ */
this.toggleDisplay = function(makeVisible, dontRefocus) this.toggleDisplay = function(makeVisible, dontRefocus)
{ {
if(!Zotero || !Zotero.initialized) { if (!Zotero || Zotero.skipLoading) {
ZoteroPane.displayStartupError(); ZoteroPane.displayStartupError();
return; return;
} }
@ -236,14 +237,6 @@ var ZoteroOverlay = new function()
*/ */
if(makeVisible) { if(makeVisible) {
if (Zotero.locked) {
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var msg = Zotero.getString('general.operationInProgress') + '\n\n' + Zotero.getString('general.operationInProgress.waitUntilFinished');
ps.alert(null, "", msg);
return false;
}
zoteroSplitter.setAttribute('hidden', false); zoteroSplitter.setAttribute('hidden', false);
zoteroPane.setAttribute('hidden', false); zoteroPane.setAttribute('hidden', false);
zoteroPane.setAttribute('collapsed', false); zoteroPane.setAttribute('collapsed', false);
@ -349,6 +342,19 @@ var ZoteroOverlay = new function()
} }
} }
window.addEventListener("load", function(e) { ZoteroOverlay.onLoad(e); }, false); window.addEventListener("load", function(e) {
try {
ZoteroOverlay.onLoad(e);
}
catch (e) {
Components.utils.reportError(e);
if (Zotero) {
Zotero.debug(e, 1);
}
else {
dump(e + "\n\n");
}
}
}, false);
window.addEventListener("unload", function(e) { ZoteroOverlay.onUnload(e); }, false); window.addEventListener("unload", function(e) { ZoteroOverlay.onUnload(e); }, false);
window.addEventListener("beforeunload", function(e) { ZoteroOverlay.onBeforeUnload(e); }, false); window.addEventListener("beforeunload", function(e) { ZoteroOverlay.onBeforeUnload(e); }, false);

View File

@ -38,7 +38,6 @@
<overlay id="zotero" <overlay id="zotero"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<!-- Include the global XPCOM object -->
<script src="overlay.js"/> <script src="overlay.js"/>
<popup id="contentAreaContextMenu"/> <popup id="contentAreaContextMenu"/>

View File

@ -33,32 +33,44 @@ const ZoteroStandalone = new function() {
* Run when standalone window first opens * Run when standalone window first opens
*/ */
this.onLoad = function() { this.onLoad = function() {
if(!Zotero || !Zotero.initialized) { Q.fcall(function () {
if(!Zotero) {
throw true;
}
if(Zotero.initializationPromise.isPending()) {
Zotero.showZoteroPaneProgressMeter();
}
return Zotero.initializationPromise;
})
.then(function () {
Zotero.hideZoteroPaneOverlays();
ZoteroPane.init();
ZoteroPane.makeVisible();
// Don't ask before handing http and https URIs
var eps = Components.classes['@mozilla.org/uriloader/external-protocol-service;1']
.getService(Components.interfaces.nsIExternalProtocolService);
var hs = Components.classes["@mozilla.org/uriloader/handler-service;1"]
.getService(Components.interfaces.nsIHandlerService);
for each(var scheme in ["http", "https"]) {
var handlerInfo = eps.getProtocolHandlerInfo(scheme);
handlerInfo.preferredAction = Components.interfaces.nsIHandlerInfo.useSystemDefault;
handlerInfo.alwaysAskBeforeHandling = false;
hs.store(handlerInfo);
}
// Add add-on listeners (not yet hooked up)
Services.obs.addObserver(gXPInstallObserver, "addon-install-disabled", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-started", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-blocked", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-failed", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-complete", false);
})
.catch(function (e) {
ZoteroPane.displayStartupError(); ZoteroPane.displayStartupError();
window.close(); window.close();
return; return;
} });
ZoteroPane.init();
ZoteroPane.makeVisible();
// Don't ask before handing http and https URIs
var eps = Components.classes['@mozilla.org/uriloader/external-protocol-service;1']
.getService(Components.interfaces.nsIExternalProtocolService);
var hs = Components.classes["@mozilla.org/uriloader/handler-service;1"]
.getService(Components.interfaces.nsIHandlerService);
for each(var scheme in ["http", "https"]) {
var handlerInfo = eps.getProtocolHandlerInfo(scheme);
handlerInfo.preferredAction = Components.interfaces.nsIHandlerInfo.useSystemDefault;
handlerInfo.alwaysAskBeforeHandling = false;
hs.store(handlerInfo);
}
// Add add-on listeners (not yet hooked up)
Services.obs.addObserver(gXPInstallObserver, "addon-install-disabled", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-started", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-blocked", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-failed", false);
Services.obs.addObserver(gXPInstallObserver, "addon-install-complete", false);
} }
/** /**

View File

@ -1476,12 +1476,11 @@ Zotero.Attachments = new function(){
} }
// Since the callback can be called during an import process that uses // Since the callback can be called during an import process that uses
// Zotero.wait(), try to queue the callback to run at the end, // Zotero.wait(), wait until we're unlocked
// or run now if not queued Zotero.unlockPromise
var queued = Zotero.addUnlockCallback(writeCallback); .then(function () {
if (!queued) {
writeCallback(); writeCallback();
} });
}; };
Zotero.File.addCharsetListener(browser, callback, itemID); Zotero.File.addCharsetListener(browser, callback, itemID);

File diff suppressed because it is too large Load Diff

View File

@ -1563,7 +1563,7 @@ Zotero.Sync.Server = new function () {
Zotero.UnresponsiveScriptIndicator.enable(); Zotero.UnresponsiveScriptIndicator.enable();
if (Zotero.locked) { if (Zotero.locked) {
Zotero.hideZoteroPaneOverlay(); Zotero.hideZoteroPaneOverlays();
} }
Zotero.suppressUIUpdates = false; Zotero.suppressUIUpdates = false;
_updatesInProgress = false; _updatesInProgress = false;
@ -1585,7 +1585,7 @@ Zotero.Sync.Server = new function () {
Zotero.UnresponsiveScriptIndicator.enable(); Zotero.UnresponsiveScriptIndicator.enable();
if (Zotero.locked) { if (Zotero.locked) {
Zotero.hideZoteroPaneOverlay(); Zotero.hideZoteroPaneOverlays();
} }
Zotero.suppressUIUpdates = false; Zotero.suppressUIUpdates = false;
_updatesInProgress = false; _updatesInProgress = false;

View File

@ -156,6 +156,19 @@ Components.utils.import("resource://gre/modules/Services.jsm");
* with an overlay * with an overlay
*/ */
this.__defineGetter__('locked', function () _locked); this.__defineGetter__('locked', function () _locked);
this.__defineSetter__('locked', function (lock) {
var wasLocked = _locked;
_locked = lock;
if (!wasLocked && lock) {
this.unlockDeferred = Q.defer();
this.unlockPromise = this.unlockDeferred.promise;
}
else if (wasLocked && !lock) {
Zotero.debug("Running unlock callbacks");
this.unlockDeferred.resolve();
}
});
/** /**
* @property {Boolean} suppressUIUpdates Don't update UI on Notifier triggers * @property {Boolean} suppressUIUpdates Don't update UI on Notifier triggers
@ -167,14 +180,19 @@ Components.utils.import("resource://gre/modules/Services.jsm");
*/ */
this.closing = false; this.closing = false;
this.initializationDeferred;
this.initializationPromise;
this.unlockDeferred;
this.unlockPromise;
var _startupErrorHandler; var _startupErrorHandler;
var _zoteroDirectory = false; var _zoteroDirectory = false;
var _localizedStringBundle; var _localizedStringBundle;
var _localUserKey; var _localUserKey;
var _waiting = 0; var _waiting = 0;
var _locked; var _locked = false;
var _unlockCallbacks = [];
var _shutdownListeners = []; var _shutdownListeners = [];
var _progressMeters; var _progressMeters;
var _progressPopup; var _progressPopup;
@ -208,12 +226,18 @@ Components.utils.import("resource://gre/modules/Services.jsm");
/** /**
* Initialize the extension * Initialize the extension
*
* @return {Boolean|Promise:Boolean}
*/ */
function init() { function init() {
if (this.initialized || this.skipLoading) { if (this.initialized || this.skipLoading) {
return false; return false;
} }
this.initializationDeferred = Q.defer();
this.initializationPromise = this.initializationDeferred.promise;
this.locked = true;
// Load in the preferences branch for the extension // Load in the preferences branch for the extension
Zotero.Prefs.init(); Zotero.Prefs.init();
Zotero.Debug.init(); Zotero.Debug.init();
@ -456,9 +480,13 @@ Components.utils.import("resource://gre/modules/Services.jsm");
} }
} else { } else {
Zotero.debug("Loading in full mode"); Zotero.debug("Loading in full mode");
if(!_initFull()) return false; return Q.fcall(_initFull)
if(Zotero.isStandalone) Zotero.Standalone.init(); .then(function (success) {
Zotero.initComplete(); if(!success) return false;
if(Zotero.isStandalone) Zotero.Standalone.init();
Zotero.initComplete();
});
} }
return true; return true;
@ -469,7 +497,10 @@ Components.utils.import("resource://gre/modules/Services.jsm");
*/ */
this.initComplete = function() { this.initComplete = function() {
if(Zotero.initialized) return; if(Zotero.initialized) return;
Zotero.debug("Running initialization callbacks");
this.initialized = true; this.initialized = true;
this.initializationDeferred.resolve();
if(Zotero.isConnector) { if(Zotero.isConnector) {
Zotero.Repo.init(); Zotero.Repo.init();
@ -487,12 +518,14 @@ Components.utils.import("resource://gre/modules/Services.jsm");
/** /**
* Initialization function to be called only if Zotero is in full mode * Initialization function to be called only if Zotero is in full mode
*
* @return {Promise:Boolean}
*/ */
function _initFull() { function _initFull() {
var dataDir = Zotero.getZoteroDirectory();
Zotero.VersionHeader.init(); Zotero.VersionHeader.init();
// Check for DB restore // Check for DB restore
var dataDir = Zotero.getZoteroDirectory();
var restoreFile = dataDir.clone(); var restoreFile = dataDir.clone();
restoreFile.append('restore-from-server'); restoreFile.append('restore-from-server');
if (restoreFile.exists()) { if (restoreFile.exists()) {
@ -530,123 +563,109 @@ Components.utils.import("resource://gre/modules/Services.jsm");
Zotero.Fulltext.init(); Zotero.Fulltext.init();
// Require >=2.1b3 database to ensure proper locking return Q.fcall(function () {
if (Zotero.isStandalone && Zotero.Schema.getDBVersion('system') > 0 && Zotero.Schema.getDBVersion('system') < 31) { // Require >=2.1b3 database to ensure proper locking
var dir = Zotero.getProfileDirectory(); if (!Zotero.isStandalone) {
dir.append('zotero'); return;
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.createInstance(Components.interfaces.nsIPromptService);
var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING)
+ (ps.BUTTON_POS_2) * (ps.BUTTON_TITLE_IS_STRING)
+ ps.BUTTON_POS_2_DEFAULT;
var index = ps.confirmEx(
null,
Zotero.getString('dataDir.incompatibleDbVersion.title'),
Zotero.getString('dataDir.incompatibleDbVersion.text'),
buttonFlags,
Zotero.getString('general.useDefault'),
Zotero.getString('dataDir.standaloneMigration.selectCustom'),
Zotero.getString('general.quit'),
null,
{}
);
var quit = false;
// Default location
if (index == 0) {
Zotero.File.createDirectoryIfMissing(dir);
Zotero.Prefs.set("useDataDir", false)
Services.startup.quit(
Components.interfaces.nsIAppStartup.eAttemptQuit
| Components.interfaces.nsIAppStartup.eRestart
);
} }
// Select new data directory return Zotero.Schema.getDBVersion('system')
else if (index == 1) { .then(function (dbSystemVersion) {
var dir = Zotero.chooseZoteroDirectory(true); if (dbSystemVersion > 0 && dbSystemVersion < 31) {
if (!dir) { var dir = Zotero.getProfileDirectory();
quit = true; dir.append('zotero');
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.createInstance(Components.interfaces.nsIPromptService);
var buttonFlags = (ps.BUTTON_POS_0) * (ps.BUTTON_TITLE_IS_STRING)
+ (ps.BUTTON_POS_1) * (ps.BUTTON_TITLE_IS_STRING)
+ (ps.BUTTON_POS_2) * (ps.BUTTON_TITLE_IS_STRING)
+ ps.BUTTON_POS_2_DEFAULT;
var index = ps.confirmEx(
null,
Zotero.getString('dataDir.incompatibleDbVersion.title'),
Zotero.getString('dataDir.incompatibleDbVersion.text'),
buttonFlags,
Zotero.getString('general.useDefault'),
Zotero.getString('dataDir.standaloneMigration.selectCustom'),
Zotero.getString('general.quit'),
null,
{}
);
var quit = false;
// Default location
if (index == 0) {
Zotero.File.createDirectoryIfMissing(dir);
Zotero.Prefs.set("useDataDir", false)
Services.startup.quit(
Components.interfaces.nsIAppStartup.eAttemptQuit
| Components.interfaces.nsIAppStartup.eRestart
);
}
// Select new data directory
else if (index == 1) {
var dir = Zotero.chooseZoteroDirectory(true);
if (!dir) {
quit = true;
}
}
else {
quit = true;
}
if (quit) {
Services.startup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit);
}
throw true;
} }
} });
else { })
quit = true; .then(function () {
} return Zotero.Schema.updateSchema()
.then(function (updated) {
if (quit) { Zotero.locked = false;
Services.startup.quit(Components.interfaces.nsIAppStartup.eAttemptQuit);
} // Initialize various services
Zotero.Integration.init();
if(Zotero.Prefs.get("httpServer.enabled")) {
Zotero.Server.init();
}
Zotero.Notifier.registerObserver(Zotero.Tags, 'setting');
Zotero.Sync.init();
Zotero.Sync.Runner.init();
Zotero.MIMETypeHandler.init();
Zotero.Proxies.init();
// Initialize keyboard shortcuts
Zotero.Keys.init();
// Initialize Locate Manager
Zotero.LocateManager.init();
Zotero.Items.startEmptyTrashTimer();
})
.catch(function (e) {
Zotero.debug(e, 1);
Components.utils.reportError(e); // DEBUG: doesn't always work
Zotero.startupError = Zotero.getString('startupError.databaseUpgradeError') + "\n\n" + e;
throw true;
});
})
.then(function () {
return true;
})
.catch(function (e) {
Zotero.skipLoading = true; Zotero.skipLoading = true;
return false; return false;
} });
// Trigger updating of schema and scrapers
if (Zotero.Schema.userDataUpgradeRequired()) {
var upgraded = Zotero.Schema.showUpgradeWizard();
if (!upgraded) {
Zotero.skipLoading = true;
return false;
}
}
// If no userdata upgrade, still might need to process system
else {
try {
var updated = Zotero.Schema.updateSchema();
}
catch (e) {
if (typeof e == 'string' && e.match('newer than SQL file')) {
var kbURL = "http://zotero.org/support/kb/newer_db_version";
var msg = Zotero.localeJoin([
Zotero.getString('startupError.zoteroVersionIsOlder'),
Zotero.getString('startupError.zoteroVersionIsOlder.upgrade')
]) + "\n\n"
+ Zotero.getString('startupError.zoteroVersionIsOlder.current', Zotero.version) + "\n\n"
+ Zotero.getString('general.seeForMoreInformation', kbURL);
Zotero.startupError = msg;
}
else {
Zotero.startupError = Zotero.getString('startupError.databaseUpgradeError') + "\n\n" + e;
}
Zotero.skipLoading = true;
Components.utils.reportError(e);
return false;
}
}
// Populate combined tables for custom types and fields -- this is likely temporary
if (!upgraded && !updated) {
Zotero.Schema.updateCustomTables();
}
// Initialize various services
Zotero.Integration.init();
if(Zotero.Prefs.get("httpServer.enabled")) {
Zotero.Server.init();
}
Zotero.Notifier.registerObserver(Zotero.Tags, 'setting');
Zotero.Sync.init();
Zotero.Sync.Runner.init();
Zotero.MIMETypeHandler.init();
Zotero.Proxies.init();
// Initialize keyboard shortcuts
Zotero.Keys.init();
// Initialize Locate Manager
Zotero.LocateManager.init();
Zotero.Items.startEmptyTrashTimer();
return true;
} }
/** /**
@ -1602,6 +1621,7 @@ Components.utils.import("resource://gre/modules/Services.jsm");
* @return void * @return void
*/ */
this.showZoteroPaneProgressMeter = function (msg, determinate, icon) { this.showZoteroPaneProgressMeter = function (msg, determinate, icon) {
if (!msg) msg = "";
var currentWindow = Services.wm.getMostRecentWindow("navigator:browser"); var currentWindow = Services.wm.getMostRecentWindow("navigator:browser");
var enumerator = Services.wm.getEnumerator("navigator:browser"); var enumerator = Services.wm.getEnumerator("navigator:browser");
var progressMeters = []; var progressMeters = [];
@ -1626,7 +1646,14 @@ Components.utils.import("resource://gre/modules/Services.jsm");
continue; continue;
} }
win.ZoteroPane.document.getElementById('zotero-pane-progress-label').value = msg; var label = win.ZoteroPane.document.getElementById('zotero-pane-progress-label');
if (msg) {
label.hidden = false;
label.value = msg;
}
else {
label.hidden = true;
}
var progressMeter = win.ZoteroPane.document.getElementById('zotero-pane-progressmeter') var progressMeter = win.ZoteroPane.document.getElementById('zotero-pane-progressmeter')
if (determinate) { if (determinate) {
progressMeter.mode = 'determined'; progressMeter.mode = 'determined';
@ -1642,7 +1669,7 @@ Components.utils.import("resource://gre/modules/Services.jsm");
progressMeters.push(progressMeter); progressMeters.push(progressMeter);
} }
_locked = true; this.locked = true;
_progressMeters = progressMeters; _progressMeters = progressMeters;
} }
@ -1679,14 +1706,8 @@ Components.utils.import("resource://gre/modules/Services.jsm");
/** /**
* Hide Zotero pane overlay in all windows * Hide Zotero pane overlay in all windows
*/ */
this.hideZoteroPaneOverlay = function () { this.hideZoteroPaneOverlays = function () {
// Run any queued callbacks this.locked = false;
if (_unlockCallbacks.length) {
var func;
while (func = _unlockCallbacks.shift()) {
func();
}
}
var enumerator = Services.wm.getEnumerator("navigator:browser"); var enumerator = Services.wm.getEnumerator("navigator:browser");
while (enumerator.hasMoreElements()) { while (enumerator.hasMoreElements()) {
@ -1700,26 +1721,12 @@ Components.utils.import("resource://gre/modules/Services.jsm");
_progressPopup.close(); _progressPopup.close();
} }
_locked = false;
_progressMeters = []; _progressMeters = [];
_progressPopup = null; _progressPopup = null;
_lastPercentage = null; _lastPercentage = null;
} }
/**
* Adds a callback to be called when the Zotero pane overlay closes
*
* @param {Boolean} TRUE if added, FALSE if not locked
*/
this.addUnlockCallback = function (callback) {
if (!_locked) {
return false;
}
_unlockCallbacks.push(callback);
return true;
}
/** /**
* Adds a listener to be called when Zotero shuts down (even if Firefox is not shut down) * Adds a listener to be called when Zotero shuts down (even if Firefox is not shut down)
*/ */

View File

@ -97,6 +97,8 @@ var ZoteroPane = new function()
* Called when the window containing Zotero pane is open * Called when the window containing Zotero pane is open
*/ */
function init() { function init() {
Zotero.debug("Initializing Zotero pane");
// Set "Report Errors..." label via property rather than DTD entity, // Set "Report Errors..." label via property rather than DTD entity,
// since we need to reference it in script elsewhere // since we need to reference it in script elsewhere
document.getElementById('zotero-tb-actions-reportErrors').setAttribute('label', document.getElementById('zotero-tb-actions-reportErrors').setAttribute('label',
@ -104,9 +106,6 @@ var ZoteroPane = new function()
// Set key down handler // Set key down handler
document.getElementById('appcontent').addEventListener('keydown', ZoteroPane_Local.handleKeyDown, true); document.getElementById('appcontent').addEventListener('keydown', ZoteroPane_Local.handleKeyDown, true);
if (Zotero.locked) {
return;
}
_loaded = true; _loaded = true;
var zp = document.getElementById('zotero-pane'); var zp = document.getElementById('zotero-pane');
@ -139,8 +138,6 @@ var ZoteroPane = new function()
* mode * mode
*/ */
function _loadPane() { function _loadPane() {
if(!Zotero || !Zotero.initialized) return;
if(Zotero.isConnector) { if(Zotero.isConnector) {
ZoteroPane_Local.setItemsPaneMessage(Zotero.getString('connector.standaloneOpen')); ZoteroPane_Local.setItemsPaneMessage(Zotero.getString('connector.standaloneOpen'));
return; return;
@ -356,98 +353,100 @@ var ZoteroPane = new function()
*/ */
function makeVisible() function makeVisible()
{ {
// If pane not loaded, load it or display an error message if (Zotero.locked) {
if (!ZoteroPane_Local.loaded) { Zotero.showZoteroPaneProgressMeter();
if (Zotero.locked) { }
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"] Zotero.unlockPromise
.getService(Components.interfaces.nsIPromptService); .then(function () {
var msg = Zotero.getString('general.operationInProgress') + '\n\n' + Zotero.getString('general.operationInProgress.waitUntilFinished'); Zotero.hideZoteroPaneOverlays();
ps.alert(null, "", msg);
// If pane not loaded, load it or display an error message
if (!ZoteroPane_Local.loaded) {
ZoteroPane_Local.init();
}
// If Zotero could not be initialized, display an error message and return
if (!Zotero || Zotero.skipLoading) {
this.displayStartupError();
return false; return false;
} }
ZoteroPane_Local.init();
} if(!_madeVisible) {
this.buildItemTypeSubMenu();
// If Zotero could not be initialized, display an error message and return }
if(!Zotero || !Zotero.initialized) { _madeVisible = true;
this.displayStartupError();
return false; this.unserializePersist();
} this.updateToolbarPosition();
this.updateTagSelectorSize();
if(!_madeVisible) {
this.buildItemTypeSubMenu(); // restore saved row selection (for tab switching)
} var containerWindow = (window.ZoteroTab ? window.ZoteroTab.containerWindow : window);
_madeVisible = true; if(containerWindow.zoteroSavedCollectionSelection) {
this.collectionsView.rememberSelection(containerWindow.zoteroSavedCollectionSelection);
this.unserializePersist(); delete containerWindow.zoteroSavedCollectionSelection;
this.updateToolbarPosition(); }
this.updateTagSelectorSize();
// restore saved item selection (for tab switching)
// restore saved row selection (for tab switching) if(containerWindow.zoteroSavedItemSelection) {
var containerWindow = (window.ZoteroTab ? window.ZoteroTab.containerWindow : window); var me = this;
if(containerWindow.zoteroSavedCollectionSelection) { // hack to restore saved selection after itemTreeView finishes loading
this.collectionsView.rememberSelection(containerWindow.zoteroSavedCollectionSelection); window.setTimeout(function() {
delete containerWindow.zoteroSavedCollectionSelection; if(containerWindow.zoteroSavedItemSelection) {
} me.itemsView.rememberSelection(containerWindow.zoteroSavedItemSelection);
delete containerWindow.zoteroSavedItemSelection;
// restore saved item selection (for tab switching) }
if(containerWindow.zoteroSavedItemSelection) { }, 51);
var me = this; }
// hack to restore saved selection after itemTreeView finishes loading
window.setTimeout(function() { // Focus the quicksearch on pane open
if(containerWindow.zoteroSavedItemSelection) { var searchBar = document.getElementById('zotero-tb-search');
me.itemsView.rememberSelection(containerWindow.zoteroSavedItemSelection); setTimeout(function () {
delete containerWindow.zoteroSavedItemSelection; searchBar.inputField.select();
} }, 1);
}, 51);
} var d = new Date();
Zotero.purgeDataObjects();
// Focus the quicksearch on pane open var d2 = new Date();
var searchBar = document.getElementById('zotero-tb-search'); Zotero.debug("Purged data tables in " + (d2 - d) + " ms");
setTimeout(function () {
searchBar.inputField.select(); // Auto-sync on pane open
}, 1); if (Zotero.Prefs.get('sync.autoSync')) {
Zotero.proxyAuthComplete
var d = new Date(); .delay(1000)
Zotero.purgeDataObjects(); .then(function () {
var d2 = new Date(); if (!Zotero.Sync.Server.enabled) {
Zotero.debug("Purged data tables in " + (d2 - d) + " ms"); Zotero.debug('Sync not enabled -- skipping auto-sync', 4);
return;
// Auto-sync on pane open }
if (Zotero.Prefs.get('sync.autoSync')) {
Zotero.proxyAuthComplete if (Zotero.Sync.Server.syncInProgress || Zotero.Sync.Storage.syncInProgress) {
.delay(1000) Zotero.debug('Sync already running -- skipping auto-sync', 4);
.then(function () { return;
if (!Zotero.Sync.Server.enabled) { }
Zotero.debug('Sync not enabled -- skipping auto-sync', 4);
return; if (Zotero.Sync.Server.manualSyncRequired) {
} Zotero.debug('Manual sync required -- skipping auto-sync', 4);
return;
if (Zotero.Sync.Server.syncInProgress || Zotero.Sync.Storage.syncInProgress) { }
Zotero.debug('Sync already running -- skipping auto-sync', 4);
return; Zotero.Sync.Runner.sync({
} background: true
});
if (Zotero.Sync.Server.manualSyncRequired) { })
Zotero.debug('Manual sync required -- skipping auto-sync', 4); .done();
return; }
}
// Set sync icon to spinning or not
Zotero.Sync.Runner.sync({ //
background: true // We don't bother setting an error state at open
}); if (Zotero.Sync.Server.syncInProgress || Zotero.Sync.Storage.syncInProgress) {
}) Zotero.Sync.Runner.setSyncIcon('animate');
.done(); }
}
return true;
// Set sync icon to spinning or not }.bind(this))
// .done();
// We don't bother setting an error state at open
if (Zotero.Sync.Server.syncInProgress || Zotero.Sync.Storage.syncInProgress) {
Zotero.Sync.Runner.setSyncIcon('animate');
}
return true;
} }
/** /**
@ -3965,40 +3964,38 @@ var ZoteroPane = new function()
} }
this.displayStartupError = function(asPaneMessage) { this.displayStartupError = function(asPaneMessage) {
if(!Zotero || !Zotero.initialized) { if (Zotero) {
if (Zotero) { var errMsg = Zotero.startupError;
var errMsg = Zotero.startupError; var errFunc = Zotero.startupErrorHandler;
var errFunc = Zotero.startupErrorHandler; }
}
if (!errMsg) {
// Get the stringbundle manually
var src = 'chrome://zotero/locale/zotero.properties';
var localeService = Components.classes['@mozilla.org/intl/nslocaleservice;1'].
getService(Components.interfaces.nsILocaleService);
var appLocale = localeService.getApplicationLocale();
var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService);
var stringBundle = stringBundleService.createBundle(src, appLocale);
if (!errMsg) { var errMsg = stringBundle.GetStringFromName('startupError');
// Get the stringbundle manually }
var src = 'chrome://zotero/locale/zotero.properties';
var localeService = Components.classes['@mozilla.org/intl/nslocaleservice;1']. if (errFunc) {
getService(Components.interfaces.nsILocaleService); errFunc();
var appLocale = localeService.getApplicationLocale(); }
var stringBundleService = Components.classes["@mozilla.org/intl/stringbundle;1"] else {
.getService(Components.interfaces.nsIStringBundleService); // TODO: Add a better error page/window here with reporting
var stringBundle = stringBundleService.createBundle(src, appLocale); // instructions
// window.loadURI('chrome://zotero/content/error.xul');
var errMsg = stringBundle.GetStringFromName('startupError'); //if(asPaneMessage) {
} // ZoteroPane_Local.setItemsPaneMessage(errMsg, true);
//} else {
if (errFunc) { var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
errFunc(); .getService(Components.interfaces.nsIPromptService);
} ps.alert(null, "", errMsg);
else { //}
// TODO: Add a better error page/window here with reporting
// instructions
// window.loadURI('chrome://zotero/content/error.xul');
//if(asPaneMessage) {
// ZoteroPane_Local.setItemsPaneMessage(errMsg, true);
//} else {
var ps = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
ps.alert(null, "", errMsg);
//}
}
} }
} }

View File

@ -167,7 +167,7 @@ ZoteroContext.prototype = {
zContext.Zotero.shutdown().then(function() { zContext.Zotero.shutdown().then(function() {
// create a new zContext // create a new zContext
makeZoteroContext(isConnector); makeZoteroContext(isConnector);
zContext.Zotero.init(); return zContext.Zotero.init();
}).done(); }).done();
} }
@ -289,20 +289,30 @@ function ZoteroService() {
if(isFirstLoadThisSession) { if(isFirstLoadThisSession) {
makeZoteroContext(false); makeZoteroContext(false);
try { Q.fcall(function () {
zContext.Zotero.init(); return zContext.Zotero.init();
} catch(e) { })
.catch(function (e) {
dump(e + "\n\n");
Components.utils.reportError(e);
// if Zotero should start as a connector, reload it // if Zotero should start as a connector, reload it
zContext.Zotero.shutdown().then(function() { return zContext.Zotero.shutdown()
.then(function() {
makeZoteroContext(true); makeZoteroContext(true);
zContext.Zotero.init(); return zContext.Zotero.init();
}).done(); })
} })
.then(function () {
zContext.Zotero.debug("Initialized in "+(Date.now() - start)+" ms");
})
.done();
} }
isFirstLoadThisSession = false; // no longer first load else {
zContext.Zotero.debug("Already initialized");
}
isFirstLoadThisSession = false;
this.wrappedJSObject = zContext.Zotero; this.wrappedJSObject = zContext.Zotero;
zContext.Zotero.debug("Initialized in "+(Date.now() - start)+" ms");
} catch(e) { } catch(e) {
var msg = typeof e == 'string' ? e : e.name; var msg = typeof e == 'string' ? e : e.name;
dump(e + "\n\n"); dump(e + "\n\n");

View File

@ -1,4 +1,4 @@
-- 78 -- 79
-- Copyright (c) 2009 Center for History and New Media -- Copyright (c) 2009 Center for History and New Media
-- George Mason University, Fairfax, Virginia, USA -- George Mason University, Fairfax, Virginia, USA