Remove extra "disconnected" menu

Add a message to other menu instead.

Automatic reconnection makes it superfluous to have an extra "Reconnect"
button.
master
Frank Ploss 8 years ago
parent 94bbc987c6
commit 0d0b75cc77

@ -26,7 +26,6 @@ const PopupMenu = imports.ui.popupMenu;
const St = imports.gi.St;
const Me = imports.misc.extensionUtils.getCurrentExtension();
const TorDisconnectedMenu = Me.imports.ui.tor_disconnected_menu.TorDisconnectedMenu;
const TorPopupMenu = Me.imports.ui.tor_popup_menu.TorPopupMenu;
const TorConnectedIcon = 'tor-connected';
@ -43,8 +42,6 @@ const TorButton = new Lang.Class({
this._buildUi();
this._bindEvents();
this._currentState = null;
},
_buildUi: function() {
@ -52,10 +49,10 @@ const TorButton = new Lang.Class({
icon_name: TorDisconnectedIcon,
style_class: 'system-status-icon'
});
this.actor.add_child(this._icon);
this._showDisconnectedMenu('Havent tried to connect yet');
var menu = new TorPopupMenu(this.actor, this._torControlClient, 'disconnected');
this.setMenu(menu);
},
_bindEvents: function() {
@ -67,37 +64,16 @@ const TorButton = new Lang.Class({
_onChangedConnectionState: function(source, state, reason) {
switch (state) {
case 'ready':
this._showConnectedMenu();
this._icon.icon_name = TorConnectedIcon;
this.menu.setState('connected');
break;
case 'closed':
this._showDisconnectedMenu(reason);
this._icon.icon_name = TorDisconnectedIcon;
this.menu.setState('disconnected', reason);
break;
}
},
_showConnectedMenu: function() {
if (this._menu instanceof TorPopupMenu) {
return;
}
this._icon.icon_name = TorConnectedIcon;
this._menu = new TorPopupMenu(this.actor, this._torControlClient);
this.setMenu(this._menu);
Main.panel.menuManager.addMenu(this._menu);
},
_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);
Main.panel.menuManager.addMenu(this._menu);
},
_onSwitchedTorIdentity: function() {
Main.notify('Switched to a new Tor identity!');
},

@ -1,53 +0,0 @@
// vim: 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 PopupMenu = imports.ui.popupMenu;
const St = imports.gi.St;
const TorDisconnectedMenu = new Lang.Class({
Name: 'TorDisconnectedMenu',
Extends: PopupMenu.PopupMenu,
_init: function(actor, torControlClient, reason) {
this._torControlClient = torControlClient;
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);
this._msgLabel = new St.Label();
errorMessageMenuItem.actor.add_actor(this._msgLabel);
this.addMenuItem(errorMessageMenuItem);
},
});

@ -27,15 +27,59 @@ const TorPopupMenu = new Lang.Class({
Name: 'TorPopupMenu',
Extends: PopupMenu.PopupMenu,
_init: function(actor, torControlClient) {
_init: function(actor, torControlClient, state) {
this._torControlClient = torControlClient;
this.parent(actor, 0.25, St.Side.TOP);
this._addActions();
this.setState(state);
},
setState: function(state, reason) {
switch (state) {
case 'connected':
this._switchTorIdentityMenuItem.setSensitive(true);
this._setMessage(null);
break;
case 'disconnected':
this._switchTorIdentityMenuItem.setSensitive(false);
this._setMessage(reason);
break;
}
},
_addActions: function() {
this.addAction('Switch Tor Identity', Lang.bind(this, this._switchTorIdentity));
this._switchTorIdentityMenuItem =
this.addAction('Switch Tor Identity', Lang.bind(this, this._switchTorIdentity));
},
_setMessage: function(message) {
if (!message) {
this._removeMessageMenuItem();
return;
}
if (!this._messageMenuItem) {
this._addMessageMenuItem();
}
this._messageLabel.set_text('No connection. ' + message);
},
_addMessageMenuItem: function() {
this._messageMenuItem = new PopupMenu.PopupBaseMenuItem({reactive: false});
this._messageMenuItem.setSensitive(false);
this._messageLabel = new St.Label();
this._messageMenuItem.actor.add_actor(this._messageLabel);
this.addMenuItem(this._messageMenuItem, 0);
},
_removeMessageMenuItem: function() {
if (!this._messageMenuItem)
return;
this._messageMenuItem.destroy();
this._messageMenuItem = null;
},
_switchTorIdentity: function() {

Loading…
Cancel
Save