-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
111 lines (93 loc) · 3.8 KB
/
extension.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const { GObject, Shell, St } = imports.gi;
const Lang = imports.lang;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const SystemActions = imports.misc.systemActions;
const Menu = Main.panel.statusArea.aggregateMenu._system.menu;
const ExtensionUtils = imports.misc.extensionUtils;
let separator1 = new PopupMenu.PopupSeparatorMenuItem;
let logout;
let switchUser;
let separator2 = new PopupMenu.PopupSeparatorMenuItem;
let suspend;
let restart;
let power;
let bindFlags = GObject.BindingFlags.DEFAULT | GObject.BindingFlags.SYNC_CREATE;
var _bringOut = new Lang.Class({
Name: "Bring Out Submenu Of Power Off/ Log Out",
Extends: PanelMenu.SystemIndicator,
//
_init: function() {
this._settings = ExtensionUtils.getSettings('org.gnome.shell.extensions.brngout');
this._systemActions = new SystemActions.getDefault();
this._createMenu();
this._gsettingsChanged();
this._takeAction();
},
//
_createMenu: function() {
logout = new PopupMenu.PopupImageMenuItem(_('Log Out'), 'system-log-out-symbolic');
logout.connect('activate', () => { this._systemActions.activateLogout(); });
switchUser = new PopupMenu.PopupImageMenuItem(_('Switch User…'), 'system-switch-user-symbolic.svg');
switchUser.connect('activate', () => { this._systemActions.activateSwitchUser(); });
suspend = new PopupMenu.PopupImageMenuItem(_('Suspend'), 'media-playback-pause-symbolic');
suspend.connect('activate', () => { this._systemActions.activateSuspend(); });
restart = new PopupMenu.PopupImageMenuItem(_('Restart'), 'system-reboot-symbolic');
restart.connect('activate', () => { imports.misc.gnomeSession.SessionManager().RebootRemote(); });
power = new PopupMenu.PopupImageMenuItem(_('Power Off…'), 'system-shutdown-symbolic');
power.connect('activate', () => { this._systemActions.activatePowerOff(); });
},
//
_takeAction: function() {
this.destroy();
Menu.actor.remove_child(Main.panel.statusArea.aggregateMenu._system._sessionSubMenu);
this._nextAction();
},
//
_nextAction: function() {
// Separator 1
Menu.addMenuItem(separator1);
// Logout
Menu.addMenuItem(logout); this._systemActions.bind_property('can-logout', logout, 'visible', bindFlags);
// Switch User
Menu.addMenuItem(switchUser); this._systemActions.bind_property('can-switch-user', switchUser, 'visible', bindFlags);
// Separator 2
Menu.addMenuItem(separator2);
// Suspend
this._suspend = this._settings.get_boolean('remove-suspend-button');
if (!this._suspend) { Menu.addMenuItem(suspend); };
this._systemActions.bind_property('can-suspend', suspend, 'visible', bindFlags);
//Restart
this._restart = this._settings.get_boolean('show-restart-button');
if (this._restart) { Menu.addMenuItem(restart); };
this._systemActions.bind_property('can-logout', restart, 'visible', bindFlags);
// Power
this._power = this._settings.get_boolean('remove-power-button'); if (!this._power) { Menu.addMenuItem(power); }; this._systemActions.bind_property('can-power-off', power, 'visible', bindFlags);
},
//
_gsettingsChanged: function() {
this._settings.connect("changed::remove-suspend-button", this._takeAction.bind(this));
this._settings.connect("changed::remove-power-button", this._takeAction.bind(this));
this._settings.connect("changed::show-restart-button", this._takeAction.bind(this));
},
//
destroy: function () {
Menu.box.remove_actor(separator1);
Menu.box.remove_actor(logout);
Menu.box.remove_actor(switchUser);
Menu.box.remove_actor(separator2);
Menu.box.remove_actor(suspend);
Menu.box.remove_actor(restart);
Menu.box.remove_actor(power);
Menu.box.insert_child_at_index(Main.panel.statusArea.aggregateMenu._system._sessionSubMenu, Main.panel.statusArea.aggregateMenu._system.menu.numMenuItems);
}
});
function init() {}
let modifiedMenu;
function enable() {
modifiedMenu = new _bringOut();
}
function disable() {
modifiedMenu.destroy();
}