www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | Submodules | README | LICENSE

commit a723c8599949a64f6af10c81a8a652feeeaee57c
parent 8a8093028de2cf31fc90290207a76656950b9756
Author: Simon Kornblith <simon@simonster.com>
Date:   Fri,  9 Aug 2013 11:10:38 -0400

Return a promise from Zotero.shutdown()

Diffstat:
Mchrome/content/zotero/xpcom/zotero.js | 15++++++---------
Mcomponents/zotero-service.js | 37++++++++++---------------------------
2 files changed, 16 insertions(+), 36 deletions(-)

diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js @@ -423,7 +423,7 @@ Components.utils.import("resource://gre/modules/Services.jsm"); } // Register shutdown handler to call Zotero.shutdown() - var _shutdownObserver = {observe:function() { Zotero.shutdown() }}; + var _shutdownObserver = {observe:function() { Zotero.shutdown().done() }}; Services.obs.addObserver(_shutdownObserver, "quit-application", false); try { @@ -783,7 +783,7 @@ Components.utils.import("resource://gre/modules/Services.jsm"); } - this.shutdown = function(callback) { + this.shutdown = function() { Zotero.debug("Shutting down Zotero"); try { @@ -811,20 +811,17 @@ Components.utils.import("resource://gre/modules/Services.jsm"); Components.utils.forceGC(); // unlock DB - Zotero.DB.closeDatabase().then(function() { + return Zotero.DB.closeDatabase().then(function() { // broadcast that DB lock has been released Zotero.IPC.broadcast("lockReleased"); - if(callback) callback(); }); - } else { - if(callback) callback(); } + + return Q(); } catch(e) { Zotero.debug(e); - throw e; + return Q.reject(e); } - - return true; } diff --git a/components/zotero-service.js b/components/zotero-service.js @@ -164,16 +164,11 @@ ZoteroContext.prototype = { */ "switchConnectorMode":function(isConnector) { if(isConnector !== this.isConnector) { - zContext.Zotero.shutdown(function() { - try { - // create a new zContext - makeZoteroContext(isConnector); - zContext.Zotero.init(); - } catch(e) { - dump(e.toSource()); - throw e; - } - }); + zContext.Zotero.shutdown().then(function() { + // create a new zContext + makeZoteroContext(isConnector); + zContext.Zotero.init(); + }).done(); } return zContext; @@ -297,23 +292,11 @@ function ZoteroService() { try { zContext.Zotero.init(); } catch(e) { - if(e === "ZOTERO_SHOULD_START_AS_CONNECTOR") { - // if Zotero should start as a connector, reload it - zContext.Zotero.shutdown(function() { - try { - makeZoteroContext(true); - zContext.Zotero.init(); - } catch(e) { - dump(e.toSource()); - Components.utils.reportError(e); - throw e; - } - }); - } else { - dump(e.toSource()); - Components.utils.reportError(e); - throw e; - } + // if Zotero should start as a connector, reload it + zContext.Zotero.shutdown().then(function() { + makeZoteroContext(true); + zContext.Zotero.init(); + }).done(); } } isFirstLoadThisSession = false; // no longer first load