forked from Aryan20/Logomenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextension.js
256 lines (211 loc) · 7.98 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Me = imports.misc.extensionUtils.getCurrentExtension();
const {Gio, GLib, GObject, Shell, St} = imports.gi;
const Constants = Me.imports.constants;
const ExtensionUtils = imports.misc.extensionUtils;
const Main = imports.ui.main
const PanelMenu = imports.ui.panelMenu
const PopupMenu = imports.ui.popupMenu
const Util = imports.misc.util
const Gettext = imports.gettext.domain(Me.metadata['gettext-domain']);
const _ = Gettext.gettext;
function _aboutThisDistro() {
Util.spawn(['gnome-control-center', 'info-overview'])
}
function _systemPreferences() {
Util.spawn(['gnome-control-center'])
}
function _overviewToggle() {
Main.overview.toggle();
}
function _sleep() {
Util.spawn(['systemctl', 'suspend'])
}
function _restart() {
Util.spawn(['gnome-session-quit', '--reboot'])
}
function _shutdown() {
Util.spawn(['gnome-session-quit', '--power-off'])
}
function _lockScreen() {
Util.spawn(['loginctl', 'lock-session'])
}
function _logOut() {
Util.spawn(['gnome-session-quit', '--logout'])
}
function _appGrid() {
// Code snippet from - https://github.com/G-dH/custom-hot-corners-extended/blob/gdh/actions.js
// Pressing the apps btn before overview activation avoids icons animation in GS 3.36/3.38
Main.overview.dash.showAppsButton.checked = true;
// in 3.36 pressing the button is usualy enough to activate overview, but not always
Main.overview.show();
// pressing apps btn before overview has no effect in GS 40, so once again
Main.overview.dash.showAppsButton.checked = true;
}
function _forceQuit() {
Util.spawn(['xkill'])
}
function _extensions() {
Util.spawn(['gnome-extensions-app'])
}
function _middleClick(actor, event) {
// left click === 1, middle click === 2, right click === 3
if (event.get_button() === ExtensionUtils.getSettings(Me.metadata['settings-schema']).get_int('menu-button-icon-click-type')) {
this.menu.close();
Main.overview.toggle();
}
}
var MenuButton = GObject.registerClass(class LogoMenu_MenuButton extends PanelMenu.Button {
_init() {
super._init(0.0, "MenuButton");
this._settings = ExtensionUtils.getSettings(Me.metadata['settings-schema']);
// Icon
this.icon = new St.Icon({
style_class: 'menu-button'
})
this._settings.connect("changed::menu-button-icon-image", () => this.setIconImage())
this._settings.connect("changed::menu-button-icon-size", () => this.setIconSize())
this.setIconImage()
this.setIconSize()
this.add_actor(this.icon)
// Menu
this._settings.connect('changed::hide-softwarecentre', () => this.toggleOptions())
this._settings.connect('changed::show-power-options', () => this.toggleOptions())
this._settings.connect('changed::hide-forcequit', () => this.toggleOptions())
this._settings.connect('changed::show-lockscreen', () => this.toggleOptions())
this.toggleOptions();
//bind middle click option to toggle overview
this.connect('button-press-event', _middleClick.bind(this));
}
toggleOptions(){
let poweroption_state = this._settings.get_boolean('show-power-options')
let forcequit_state = this._settings.get_boolean('hide-forcequit')
let lockscreen_state = this._settings.get_boolean('show-lockscreen')
let softwarecenter_state = this._settings.get_boolean('hide-softwarecentre')
this.menu.removeAll()
this.item1 = new PopupMenu.PopupMenuItem(_('About My System'))
// this.item2 = new PopupMenu.PopupMenuItem(_('System Settings...'))
this.item3 = new PopupMenu.PopupSeparatorMenuItem()
this.item4 = new PopupMenu.PopupMenuItem(_('Activities'))
this.item5 = new PopupMenu.PopupMenuItem(_('App Grid'))
this.item6 = new PopupMenu.PopupSeparatorMenuItem()
this.item8 = new PopupMenu.PopupMenuItem(_('Terminal'))
this.item9 = new PopupMenu.PopupMenuItem(_('Extensions'))
this.item1.connect('activate', () => _aboutThisDistro())
// this.item2.connect('activate', () => _systemPreferences())
this.item4.connect('activate', () => _overviewToggle())
this.item5.connect('activate', () => _appGrid())
this.item8.connect('activate', () => this.terminal())
this.item9.connect('activate', () => this.extensions())
this.menu.addMenuItem(this.item1)
// this.menu.addMenuItem(this.item2)
this.menu.addMenuItem(this.item3)
this.menu.addMenuItem(this.item4)
this.menu.addMenuItem(this.item5)
this.menu.addMenuItem(this.item6)
if (!softwarecenter_state) {
this.item7 = new PopupMenu.PopupMenuItem(_('Software Center...'))
this.item7.connect('activate', () => this.softwareStore())
this.menu.addMenuItem(this.item7)
}
this.menu.addMenuItem(this.item8)
this.menu.addMenuItem(this.item9)
if(!forcequit_state) {
this.item10 = new PopupMenu.PopupSeparatorMenuItem()
this.menu.addMenuItem(this.item10)
this.item11 = new PopupMenu.PopupMenuItem(_('Force Quit App'))
this.item11.connect('activate', () => _forceQuit())
this.menu.addMenuItem(this.item11)
}
if (poweroption_state) {
this.item12 = new PopupMenu.PopupSeparatorMenuItem()
this.item13 = new PopupMenu.PopupMenuItem(_('Sleep'))
this.item14 = new PopupMenu.PopupMenuItem(_('Restart...'))
this.item15 = new PopupMenu.PopupMenuItem(_('Shut Down...'))
this.item16 = new PopupMenu.PopupSeparatorMenuItem()
if (lockscreen_state)
this.item17 = new PopupMenu.PopupMenuItem(_('Lock Screen'))
this.item18 = new PopupMenu.PopupMenuItem(_('Log Out...'))
this.menu.addMenuItem(this.item12)
this.menu.addMenuItem(this.item13)
this.menu.addMenuItem(this.item14)
this.menu.addMenuItem(this.item15)
this.menu.addMenuItem(this.item16)
if (lockscreen_state) {
this.menu.addMenuItem(this.item17)
this.item17.connect('activate', () => _lockScreen())
}
this.menu.addMenuItem(this.item18)
this.item13.connect('activate', () => _sleep())
this.item14.connect('activate', () => _restart())
this.item15.connect('activate', () => _shutdown())
this.item18.connect('activate', () => _logOut())
}
else if (!poweroption_state && lockscreen_state) {
this.item16 = new PopupMenu.PopupSeparatorMenuItem()
this.item17 = new PopupMenu.PopupMenuItem(_('Lock Screen'))
this.menu.addMenuItem(this.item16)
this.menu.addMenuItem(this.item17)
this.item17.connect('activate', () => _lockScreen())
}
}
terminal() {
Util.spawn([this._settings.get_string('menu-button-terminal')])
}
softwareStore() {
Util.spawn([this._settings.get_string('menu-button-software-center')])
}
extensions() {
const appSys = imports.gi.Shell.AppSystem.get_default();
let extensionmanager_choice = this._settings.get_string('menu-button-extensions-app');
let extensionApp = appSys.lookup_app(extensionmanager_choice)
if (extensionApp) {
try {
extensionApp.launch(
0,
-1,
Shell.AppLaunchGpu.APP_PREF,
);
} catch (e) {
log(e);
}
}
}
setIconImage(){
let iconIndex = this._settings.get_int('menu-button-icon-image');
let path = Me.path + Constants.DistroIcons[iconIndex].PATH;
if(Constants.DistroIcons[iconIndex].PATH === 'start-here-symbolic')
path = 'start-here-symbolic';
else if(!GLib.file_test(path, GLib.FileTest.IS_REGULAR))
path = 'start-here-symbolic';
this.icon.gicon = Gio.icon_new_for_string(path);
}
setIconSize(){
let iconSize = this._settings.get_int('menu-button-icon-size');
this.icon.icon_size = iconSize;
}
})
function init() {
ExtensionUtils.initTranslations(Me.metadata['gettext-domain']);
}
function enable() {
const activitiesButton = Main.panel.statusArea['activities']
if (activitiesButton) {
activitiesButton.container.hide()
}
let indicator = new MenuButton()
Main.panel.addToStatusArea('menuButton', indicator, 0, 'left')
// hide
Main.panel.statusArea['menuButton'].visible = false
// change icon
//Main.panel.statusArea['menuButton'].icon.icon_name = "appointment-soon-symbolic"
// show
Main.panel.statusArea['menuButton'].visible = true
}
function disable() {
const activitiesButton = Main.panel.statusArea['activities']
if (activitiesButton) {
activitiesButton.container.show()
}
Main.panel.statusArea['menuButton'].destroy()
}