Fix switching in and out of connector mode

Broken by 9d3f55be51
This commit is contained in:
Simon Kornblith 2013-08-09 10:55:29 -04:00
parent 8f0dac0eb4
commit 2069b5b396
3 changed files with 34 additions and 16 deletions

View file

@ -794,8 +794,11 @@ Zotero.DBConnection.prototype.checkException = function (e) {
Zotero.DBConnection.prototype.closeDatabase = function () { Zotero.DBConnection.prototype.closeDatabase = function () {
if(this._connection) { if(this._connection) {
this.stopDummyStatement(); this.stopDummyStatement();
this._connection.asyncClose(); var deferred = Q.defer();
return true; this._connection.asyncClose(deferred.resolve);
return deferred.promise;
} else {
return Q();
} }
} }

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:Zotero.shutdown}; var _shutdownObserver = {observe:function() { Zotero.shutdown() }};
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 (subject, topic, data) { this.shutdown = function(callback) {
Zotero.debug("Shutting down Zotero"); Zotero.debug("Shutting down Zotero");
try { try {
@ -811,10 +811,13 @@ Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.forceGC(); Components.utils.forceGC();
// unlock DB // unlock DB
Zotero.DB.closeDatabase(); 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"); callback();
});
} else {
callback();
} }
} catch(e) { } catch(e) {
Zotero.debug(e); Zotero.debug(e);

View file

@ -164,11 +164,16 @@ ZoteroContext.prototype = {
*/ */
"switchConnectorMode":function(isConnector) { "switchConnectorMode":function(isConnector) {
if(isConnector !== this.isConnector) { if(isConnector !== this.isConnector) {
zContext.Zotero.shutdown(); zContext.Zotero.shutdown(function() {
try {
// create a new zContext // create a new zContext
makeZoteroContext(isConnector); makeZoteroContext(isConnector);
zContext.Zotero.init(); zContext.Zotero.init();
} catch(e) {
dump(e.toSource());
throw e;
}
});
} }
return zContext; return zContext;
@ -294,9 +299,16 @@ function ZoteroService() {
} catch(e) { } catch(e) {
if(e === "ZOTERO_SHOULD_START_AS_CONNECTOR") { 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(); zContext.Zotero.shutdown(function() {
makeZoteroContext(true); try {
zContext.Zotero.init(); makeZoteroContext(true);
zContext.Zotero.init();
} catch(e) {
dump(e.toSource());
Components.utils.reportError(e);
throw e;
}
});
} else { } else {
dump(e.toSource()); dump(e.toSource());
Components.utils.reportError(e); Components.utils.reportError(e);