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 () {
if(this._connection) {
this.stopDummyStatement();
this._connection.asyncClose();
return true;
var deferred = Q.defer();
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()
var _shutdownObserver = {observe:Zotero.shutdown};
var _shutdownObserver = {observe:function() { Zotero.shutdown() }};
Services.obs.addObserver(_shutdownObserver, "quit-application", false);
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");
try {
@ -811,10 +811,13 @@ Components.utils.import("resource://gre/modules/Services.jsm");
Components.utils.forceGC();
// unlock DB
Zotero.DB.closeDatabase();
// broadcast that DB lock has been released
Zotero.IPC.broadcast("lockReleased");
Zotero.DB.closeDatabase().then(function() {
// broadcast that DB lock has been released
Zotero.IPC.broadcast("lockReleased");
callback();
});
} else {
callback();
}
} catch(e) {
Zotero.debug(e);

View file

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