Handle errors a little more gracefully

master
Frank Ploss 9 years ago
parent be8c9aa464
commit 94c0c27c25

@ -4,6 +4,7 @@
const Lang = imports.lang;
const St = imports.gi.St;
const Main = imports.ui.main;
const Notify = imports.gi.Notify;
const PanelMenu = imports.ui.panelMenu;
const Me = imports.misc.extensionUtils.getCurrentExtension();
@ -11,8 +12,8 @@ const TorControlClient = Me.imports.tor_control_client.TorControlClient;
const TorIcon = 'tor';
let torButton;
let torControlClient;
let torButton = null;
let torControlClient = null;
const TorButton = new Lang.Class({
Name: 'TorButton',
@ -43,14 +44,23 @@ function init(extensionMeta) {
}
function enable() {
try {
torControlClient = new TorControlClient();
torButton = new TorButton();
Main.panel.addToStatusArea(torButton.Name, torButton);
} catch (e) {
Main.notifyError('Error starting extension: ' + e);
disable();
}
}
function disable() {
if (torButton !== null) {
torButton.destroy();
torButton = null;
}
if (torControlClient !== null) {
torControlClient.close();
torControlClient = null;
}
}

@ -14,15 +14,17 @@ const TorControlClient = new Lang.Class({
},
close: function() {
if (this._connection.is_connected()) {
this._outputStream.close(null);
this._inputStream.close(null);
}
},
_connect: function() {
var socketClient = new Gio.SocketClient();
var connection = socketClient.connect_to_host('127.0.0.1:9051', null, null);
this._inputStream = new Gio.DataInputStream({base_stream: connection.get_input_stream()});
this._outputStream = new Gio.DataOutputStream({base_stream: connection.get_output_stream()});
this._connection = socketClient.connect_to_host('127.0.0.1:9051', null, null);
this._inputStream = new Gio.DataInputStream({base_stream: this._connection.get_input_stream()});
this._outputStream = new Gio.DataOutputStream({base_stream: this._connection.get_output_stream()});
},
_updateProtocolInfo: function() {

Loading…
Cancel
Save