summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsegfault <segfault@riseup.net>2019-03-23 20:01:35 +0100
committersegfault <segfault@riseup.net>2019-03-23 20:38:58 +0100
commit3af65b5f8482b17c2e51961f16aec1b67acb5476 (patch)
tree0175c85eaa44bc0cc8779635cdccafdbf2f58e12
parent1616d490fa2a700a029eda2946969fc3287bccc7 (diff)
status-menu-helper: Refactor (refs: #14556)
-rw-r--r--config/chroot_local-includes/usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js102
1 files changed, 47 insertions, 55 deletions
diff --git a/config/chroot_local-includes/usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js b/config/chroot_local-includes/usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js
index 7fd6ce7..ca7a809 100644
--- a/config/chroot_local-includes/usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js
+++ b/config/chroot_local-includes/usr/share/gnome-shell/extensions/status-menu-helper@tails.boum.org/extension.js
@@ -33,6 +33,15 @@ const Lib = Me.imports.lib;
const Util = imports.misc.util;
+var Action = new Lang.Class({
+ Name: 'Action',
+
+ _init: function(button, id) {
+ this.button = button;
+ this.id = id;
+ }
+});
+
const Extension = new Lang.Class({
Name: 'StatusMenuHelper.Extension',
@@ -51,8 +60,7 @@ const Extension = new Lang.Class({
return;
this._update();
});
- }
- ,
+ },
disable: function() {
// We want to keep the extention enabled on the lock screen
@@ -64,17 +72,30 @@ const Extension = new Lang.Class({
},
_createActions: function() {
- this._restartButton = this.statusMenu._createActionButton('view-refresh-symbolic', _("Restart"));
- this._restartButtonId = this._restartButton.connect('clicked', Lang.bind(this, this._onRestartClicked));
-
- this._lockScreenButton = this.statusMenu._createActionButton('changes-prevent-symbolic', _("Lock screen"));
- this._lockScreenButtonId = this._lockScreenButton.connect('clicked', Lang.bind(this, this._onLockClicked));
+ this._lockScreenAction = this._createAction(_("Lock screen"),
+ 'changes-prevent-symbolic',
+ this._onLockClicked);
+
+ this._suspendAction = this._createAction(_("Suspend"),
+ 'media-playback-pause-symbolic',
+ this._onSuspendClicked);
- this._poweroffButton = this.statusMenu._createActionButton('system-shutdown-symbolic', _("Power Off"));
- this._poweroffButtonId = this._poweroffButton.connect('clicked', Lang.bind(this, this._onPowerOffClicked));
+ this._powerOffAction = this._createAction(_("Power Off"),
+ 'system-shutdown-symbolic',
+ this._onPowerOffClicked);
- this._suspendButton = this.statusMenu._createActionButton('media-playback-pause-symbolic', _("Suspend"));
- this._suspendButtonId = this._suspendButton.connect('clicked', Lang.bind(this, this._onSuspendClicked));
+ this._restartAction = this._createAction(_("Restart"),
+ 'view-refresh-symbolic',
+ this._onRestartClicked);
+
+ this._actions = [this._lockScreenAction, this._suspendAction,
+ this._powerOffAction, this._restartAction];
+ },
+
+ _createAction: function(label, icon, onClickedFunction) {
+ let button = this.statusMenu._createActionButton(icon, label);
+ let id = button.connect('clicked', Lang.bind(this, onClickedFunction));
+ return new Action(button, id);
},
_removeAltSwitcher: function() {
@@ -86,51 +107,23 @@ const Extension = new Lang.Class({
},
_addSeparateButtons: function() {
- this.statusMenu._actionsItem.actor.add(this._lockScreenButton, { expand: true, x_fill: false });
- this.statusMenu._actionsItem.actor.add(this._suspendButton, { expand: true, x_fill: false });
- this.statusMenu._actionsItem.actor.add(this._restartButton, { expand: true, x_fill: false });
- this.statusMenu._actionsItem.actor.add(this._poweroffButton, { expand: true, x_fill: false });
+ for (let i = 0; i < this._actions.length; i++) {
+ this.statusMenu._actionsItem.actor.add(this._actions[i].button, { expand: true, x_fill: false });
+ }
},
_destroyActions: function() {
- if (this._restartButtonId) {
- this._restartButton.disconnect(this._restartButtonId);
- this._restartButtonId = 0;
- }
-
- if (this._poweroffButtonId) {
- this._poweroffButton.disconnect(this._poweroffButtonId);
- this._poweroffButtonId = 0;
- }
-
- if (this._lockScreenButtonId) {
- this._lockScreenButton.disconnect(this._lockScreenButtonId);
- this._lockScreenButtonId = 0;
- }
-
- if (this._suspendButtonId) {
- this._suspendButton.disconnect(this._suspendButtonId);
- this._suspendButtonId = 0;
- }
-
- if (this._restartButton) {
- this._restartButton.destroy();
- this._restartButton = 0;
- }
-
- if (this._poweroffButton) {
- this._poweroffButton.destroy();
- this._poweroffButton = 0;
- }
-
- if (this._lockScreenButton) {
- this._lockScreenButton.destroy();
- this._lockScreenButton = 0;
- }
-
- if (this._suspendButton) {
- this._suspendButton.destroy();
- this._suspendButton = 0;
+ for (let i = 0; i < this._actions.length; i++) {
+ let action = this._actions[i];
+ if (action.id) {
+ action.button.disconnect(action.id);
+ action.id = 0;
+ }
+
+ if (action.button) {
+ action.button.destroy();
+ action.button = 0;
+ }
}
},
@@ -156,7 +149,7 @@ const Extension = new Lang.Class({
},
_update: function() {
- this._lockScreenButton.visible = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
+ this._lockScreenAction.button.visible = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
}
});
@@ -165,4 +158,3 @@ function init(metadata) {
Lib.initTranslations(Me);
return new Extension();
}
-