-
Notifications
You must be signed in to change notification settings - Fork 0
/
hibernationButton.js
42 lines (34 loc) · 1.07 KB
/
hibernationButton.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
import * as PopupMenu from 'resource:///org/gnome/shell/ui/popupMenu.js';
import GLib from 'gi://GLib';
export default class HibernationButton {
constructor(systemMenu, loginManager) {
this._button = null;
this._handler = null;
this._systemMenu = systemMenu;
this._loginManager = loginManager;
}
addButton(position) {
if(this._button != null || this._button != undefined)
return;
this._button = new PopupMenu.PopupMenuItem('Hibernate');
this._handler = this._button.connect(
'activate',
() => this._execute()
);
this._systemMenu._systemItem.menu.addMenuItem(
this._button,
position
);
}
_execute() {
GLib.spawn_command_line_async('systemctl hibernate');
}
removeButton() {
if(this._button !== undefined && this._button !== null) {
this._button.disconnect(this._handler);
this._button.destroy();
}
this._button = null;
this._handler = null;
}
}