-
Notifications
You must be signed in to change notification settings - Fork 9
/
extension.js
174 lines (140 loc) · 4.69 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
// -*- 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 _terminal() {
Util.spawn(['xdg-terminal'])
}
function _systemPreferences() {
Util.spawn(['gnome-control-center'])
}
function _appStore() {
Util.spawn(['gnome-software'])
}
function _missionControl() {
Main.overview.toggle();
}
function _forceQuit() {
Util.spawn(['xkill'])
}
function _sleep() {
Util.spawn(['systemctl', 'suspend'])
}
function _restart() {
Util.spawn(['systemctl', 'reboot'])
}
function _shutdown() {
Util.spawn(['systemctl', 'poweroff', '-prompt'])
}
function _lockScreen() {
Util.spawn(['gnome-screensaver-command -l'])
}
function _logOut() {
Util.spawn(['gnome-session-quit'])
}
function _extensions() {
Util.spawn(['gnome-extensions-app'])
}
function _middleClick(actor, event) {
// left click === 1, middle click === 2, right click === 3
if (event.get_button() === 2) {
this.menu.close();
Main.overview.toggle();
}
}
// function _hover() {
// button.actor.remove_actor(icon)
// const icon_hover = new St.Icon({
// style_class: 'menu-button-hover'
// })
// button.actor.add_actor(icon_hover)
// }
var MenuButton = GObject.registerClass(class FedoraMenu_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.item1 = new PopupMenu.PopupMenuItem(_('About My System'))
this.item2 = new PopupMenu.PopupMenuItem(_('System Settings'))
this.item3 = new PopupMenu.PopupSeparatorMenuItem()
this.item4 = new PopupMenu.PopupMenuItem(_('Software Center'))
this.item5 = new PopupMenu.PopupMenuItem(_('Activities'))
this.item6 = new PopupMenu.PopupMenuItem(_('Force Quit App'))
this.item7 = 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', () => _appStore())
this.item5.connect('activate', () => _missionControl())
this.item6.connect('activate', () => _forceQuit())
this.item8.connect('activate', () => _terminal())
this.item9.connect('activate', () => _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)
this.menu.addMenuItem(this.item7)
this.menu.addMenuItem(this.item8)
this.menu.addMenuItem(this.item9)
//bind middle click option to toggle overview
this.connect('button-press-event', _middleClick.bind(this));
}
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() {
}
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()
}