Return a promise from Zotero.shutdown()

This commit is contained in:
Simon Kornblith 2013-08-09 11:10:38 -04:00
parent 8a8093028d
commit a723c85999
2 changed files with 16 additions and 36 deletions

View File

@ -423,7 +423,7 @@ Components.utils.import("resource://gre/modules/Services.jsm");
} }
// Register shutdown handler to call Zotero.shutdown() // 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); Services.obs.addObserver(_shutdownObserver, "quit-application", false);
try { 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"); Zotero.debug("Shutting down Zotero");
try { try {
@ -811,20 +811,17 @@ Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.forceGC(); Components.utils.forceGC();
// unlock DB // unlock DB
Zotero.DB.closeDatabase().then(function() { return Zotero.DB.closeDatabase().then(function() {
// broadcast that DB lock has been released // broadcast that DB lock has been released
Zotero.IPC.broadcast("lockReleased"); Zotero.IPC.broadcast("lockReleased");
if(callback) callback();
}); });
} else {
if(callback) callback();
} }
return Q();
} catch(e) { } catch(e) {
Zotero.debug(e); Zotero.debug(e);
throw e; return Q.reject(e);
} }
return true;
} }

View File

@ -164,16 +164,11 @@ ZoteroContext.prototype = {
*/ */
"switchConnectorMode":function(isConnector) { "switchConnectorMode":function(isConnector) {
if(isConnector !== this.isConnector) { if(isConnector !== this.isConnector) {
zContext.Zotero.shutdown(function() { zContext.Zotero.shutdown().then(function() {
try { // create a new zContext
// create a new zContext makeZoteroContext(isConnector);
makeZoteroContext(isConnector); zContext.Zotero.init();
zContext.Zotero.init(); }).done();
} catch(e) {
dump(e.toSource());
throw e;
}
});
} }
return zContext; return zContext;
@ -297,23 +292,11 @@ function ZoteroService() {
try { try {
zContext.Zotero.init(); zContext.Zotero.init();
} catch(e) { } catch(e) {
if(e === "ZOTERO_SHOULD_START_AS_CONNECTOR") { // if Zotero should start as a connector, reload it
// if Zotero should start as a connector, reload it zContext.Zotero.shutdown().then(function() {
zContext.Zotero.shutdown(function() { makeZoteroContext(true);
try { zContext.Zotero.init();
makeZoteroContext(true); }).done();
zContext.Zotero.init();
} catch(e) {
dump(e.toSource());
Components.utils.reportError(e);
throw e;
}
});
} else {
dump(e.toSource());
Components.utils.reportError(e);
throw e;
}
} }
} }
isFirstLoadThisSession = false; // no longer first load isFirstLoadThisSession = false; // no longer first load