Do not re-create menu if it already exists

master
Frank Ploss 8 years ago
parent 3cf6383cc8
commit 0fa48c8b78

@ -68,8 +68,11 @@ const TorControlClient = new Lang.Class({
closeConnection: function(reason) {
if (this._connection && this._connection.is_connected()) {
this._connection.close(null);
this.emit('changed-connection-state', 'closed', reason);
}
this._connection = null;
this.emit('changed-connection-state', 'closed', reason);
},
switchIdentity: function() {
@ -167,8 +170,11 @@ const TorControlClient = new Lang.Class({
do {
let line = this._readLine();
if (line === null)
return {replyLines: ['Lost connection to Tor server']};
if (line === null) {
let reason = 'Lost connection to Tor server';
this.closeConnection(reason);
return {replyLines: [reason]};
}
var reply = this._parseLine(line);
statusCode = reply.statusCode;

@ -55,7 +55,7 @@ const TorButton = new Lang.Class({
this.actor.add_child(this._icon);
this._showDisconnectedMenu();
this._showDisconnectedMenu('Havent tried to connect yet');
},
_bindEvents: function() {
@ -76,6 +76,10 @@ const TorButton = new Lang.Class({
},
_showConnectedMenu: function() {
if (this._menu instanceof TorConnectedIcon) {
return;
}
this._icon.icon_name = TorConnectedIcon;
this._menu = new TorPopupMenu(this.actor, this._torControlClient);
this.setMenu(this._menu);
@ -83,6 +87,11 @@ const TorButton = new Lang.Class({
},
_showDisconnectedMenu: function(reason) {
if (this._menu instanceof TorDisconnectedMenu) {
this._menu.setReason(reason);
return;
}
this._icon.icon_name = TorDisconnectedIcon;
this._menu = new TorDisconnectedMenu(this.actor, this._torControlClient, reason);
this.setMenu(this._menu);
@ -94,7 +103,7 @@ const TorButton = new Lang.Class({
},
_onProtocolError: function(source, message, statusCode) {
Main.notifyError('Tor: ' + message);
log('Tor control procotol error (status code ' + statusCode + '): ' + reason)
var msg = 'Tor control protocol error: ' + message + ' (status code' + statusCode + ')';
Main.notifyError(msg);
}
});

@ -29,29 +29,31 @@ const TorDisconnectedMenu = new Lang.Class({
_init: function(actor, torControlClient, reason) {
this._torControlClient = torControlClient;
this._reason = reason;
this.parent(actor, 0.25, St.Side.TOP);
this._addActions();
this.setReason(reason);
},
destroy: function() {
this.parent(arguments);
},
setReason: function(reason) {
this._msgLabel.set_text('No connection. ' + reason);
},
_addActions: function() {
var errorMessageMenuItem = new PopupMenu.PopupBaseMenuItem({reactive: false});
errorMessageMenuItem.setSensitive(false);
errorMessageMenuItem.actor.add_actor(new St.Label({
text: 'No connection. Reason: ' + this._reason
}));
this._msgLabel = new St.Label();
errorMessageMenuItem.actor.add_actor(this._msgLabel);
this.addMenuItem(errorMessageMenuItem);
this.addAction('Reconnect', Lang.bind(this, this._reconnect));
},
_reconnect: function() {
this._torControlClient.connect('changed-connection-state', function() {})
this._torControlClient.openConnection();
}
});

Loading…
Cancel
Save