Bug 1028378 - Changing runtime should disconnect the current one. r=jryans

This commit is contained in:
Paul Rouget 2014-08-01 14:47:37 +02:00
Родитель b63dd7beb8
Коммит 6b99371a4c
2 изменённых файлов: 28 добавлений и 20 удалений

Просмотреть файл

@ -297,31 +297,38 @@ exports.AppManager = AppManager = {
},
connectToRuntime: function(runtime) {
if (this.connection.status == Connection.Status.CONNECTED) {
return promise.reject("Already connected");
if (this.connection.status == Connection.Status.CONNECTED &&
this.selectedRuntime === runtime) {
// Already connected
return promise.resolve();
}
this.selectedRuntime = runtime;
let deferred = promise.defer();
let onConnectedOrDisconnected = () => {
this.connection.off(Connection.Events.CONNECTED, onConnectedOrDisconnected);
this.connection.off(Connection.Events.DISCONNECTED, onConnectedOrDisconnected);
if (this.connection.status == Connection.Status.CONNECTED) {
deferred.resolve();
} else {
this.disconnectRuntime().then(() => {
this.selectedRuntime = runtime;
let onConnectedOrDisconnected = () => {
this.connection.off(Connection.Events.CONNECTED, onConnectedOrDisconnected);
this.connection.off(Connection.Events.DISCONNECTED, onConnectedOrDisconnected);
if (this.connection.status == Connection.Status.CONNECTED) {
deferred.resolve();
} else {
deferred.reject();
}
}
this.connection.on(Connection.Events.CONNECTED, onConnectedOrDisconnected);
this.connection.on(Connection.Events.DISCONNECTED, onConnectedOrDisconnected);
try {
this.selectedRuntime.connect(this.connection).then(
() => {},
() => {deferred.reject()});
} catch(e) {
console.error(e);
deferred.reject();
}
}
this.connection.on(Connection.Events.CONNECTED, onConnectedOrDisconnected);
this.connection.on(Connection.Events.DISCONNECTED, onConnectedOrDisconnected);
try {
this.selectedRuntime.connect(this.connection).then(
() => {},
() => {deferred.reject()});
} catch(e) {
console.error(e);
deferred.reject();
}
}, deferred.reject);
return deferred.promise;
},

Просмотреть файл

@ -91,6 +91,7 @@ SimulatorRuntime.prototype = {
return simulator.launch({port: port}).then(() => {
connection.port = port;
connection.keepConnecting = true;
connection.once(Connection.Events.DISCONNECTED, simulator.close);
connection.connect();
});
},