Move tor button into its own file

master
Frank Ploss 9 years ago
parent b02ccfe8bc
commit 28b3ad9960

@ -1,4 +1,4 @@
// ex: set sw=4 // ex: set sw=4:ts=4
/* /*
Copyright 2015 Frank Ploss <frank@fqxp.de>. Copyright 2015 Frank Ploss <frank@fqxp.de>.
@ -7,7 +7,7 @@ This file is part of gnome-shell-extension-tor.
gnome-shell-extension-tor is free software: you can redistribute it and/or modify gnome-shell-extension-tor is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
any later version. (at your option) any later version.
gnome-shell-extension-tor is distributed in the hope that it will be useful, gnome-shell-extension-tor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -19,53 +19,15 @@ along with gnome-shell-extension-tor. If not, see <http://www.gnu.org/licenses/
*/ */
'use strict'; 'use strict';
const Lang = imports.lang;
const St = imports.gi.St;
const Main = imports.ui.main; const Main = imports.ui.main;
const Notify = imports.gi.Notify;
const PanelMenu = imports.ui.panelMenu;
const Me = imports.misc.extensionUtils.getCurrentExtension(); const Me = imports.misc.extensionUtils.getCurrentExtension();
const TorButton = Me.imports.ui.tor_button.TorButton;
const TorControlClient = Me.imports.tor_control_client.TorControlClient; const TorControlClient = Me.imports.tor_control_client.TorControlClient;
const TorIcon = 'tor';
let torButton = null; let torButton = null;
let torControlClient = null; let torControlClient = null;
const TorButton = new Lang.Class({
Name: 'TorButton',
Extends: PanelMenu.Button,
_init: function(torControlClient) {
this.parent(null, this.Name);
this._torControlClient = torControlClient;
this._icon = new St.Icon({
icon_name: TorIcon,
style_class: 'system-status-icon'
});
this.actor.add_child(this._icon);
this.menu.addAction('Switch Tor Identity', Lang.bind(this, function(event) {
this._switchTorIdentity();
log('Switched to a new Tor identity!');
}));
},
_switchTorIdentity: function() {
try {
this._torControlClient.switchIdentity();
Main.notify('Switched to a new Tor identity!');
} catch (e) {
log(e);
Main.notifyError('Could not switch Tor identity: ' + e);
}
}
});
function init(extensionMeta) { function init(extensionMeta) {
let theme = imports.gi.Gtk.IconTheme.get_default(); let theme = imports.gi.Gtk.IconTheme.get_default();
theme.append_search_path(extensionMeta.path + "/icons"); theme.append_search_path(extensionMeta.path + "/icons");

@ -1,4 +1,4 @@
// ex: set sw=4 // ex: set sw=4:ts=4
/* /*
Copyright 2015 Frank Ploss <frank@fqxp.de>. Copyright 2015 Frank Ploss <frank@fqxp.de>.
@ -7,7 +7,7 @@ This file is part of gnome-shell-extension-tor.
gnome-shell-extension-tor is free software: you can redistribute it and/or modify gnome-shell-extension-tor is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or the Free Software Foundation, either version 3 of the License, or
any later version. (at your option) any later version.
gnome-shell-extension-tor is distributed in the hope that it will be useful, gnome-shell-extension-tor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of but WITHOUT ANY WARRANTY; without even the implied warranty of

@ -0,0 +1,60 @@
// ex: set sw=4:ts=4
/*
Copyright 2015 Frank Ploss <frank@fqxp.de>.
This file is part of gnome-shell-extension-tor.
gnome-shell-extension-tor is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
gnome-shell-extension-tor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with gnome-shell-extension-tor. If not, see <http://www.gnu.org/licenses/>./
*/
'use strict';
const Lang = imports.lang;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const St = imports.gi.St;
const TorIcon = 'tor';
const TorButton = new Lang.Class({
Name: 'TorButton',
Extends: PanelMenu.Button,
_init: function(torControlClient) {
this.parent(null, this.Name);
this._torControlClient = torControlClient;
this._icon = new St.Icon({
icon_name: TorIcon,
style_class: 'system-status-icon'
});
this.actor.add_child(this._icon);
this.menu.addAction('Switch Tor Identity', Lang.bind(this, function(event) {
this._switchTorIdentity();
log('Switched to a new Tor identity!');
}));
},
_switchTorIdentity: function() {
try {
this._torControlClient.switchIdentity();
Main.notify('Switched to a new Tor identity! EEEEE');
} catch (e) {
log(e);
Main.notifyError('Could not switch Tor identity: ' + e);
}
}
});
Loading…
Cancel
Save