This repository has been archived by the owner on Dec 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
87 lines (72 loc) · 2.12 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
/*
Credits:
https://github.com/laserb/gnome-shell-extension-suspend-button
https://github.com/arelange/gnome-shell-extension-hibernate-status
*/
const Gio = imports.gi.Gio;
const Main = imports.ui.main;
const Util = imports.misc.util;
const BoxPointer = imports.ui.boxpointer;
let systemMenu, _cancellable, _proxy, _lockAction, _lockActionId;
function init() {
}
function _onProxyCallFailure(o, res)
{
try {
o.call_finish(res);
} catch(e) {
// Make one last-ditch attempt by having the D-Bus call done externally
Util.spawn(['gnome-screensaver-command', '-l']);
}
}
function _onLockClicked()
{
systemMenu.menu.itemActivated(BoxPointer.PopupAnimation.NONE);
_proxy.call("Lock", null, Gio.DBusCallFlags.NONE, -1, null, _onProxyCallFailure);
}
function _onProxyReady(o, res) {
try {
_cancellable = null;
_proxy = Gio.DBusProxy.new_finish(res);
_lockAction = systemMenu._createActionButton('system-lock-screen-symbolic', C_("search-result", "Lock Screen"));
_lockActionId = _lockAction.connect('clicked', _onLockClicked);
systemMenu._actionsItem.actor.insert_child_at_index(_lockAction, 2);
_lockAction.visible = true;
} catch(e) {
return;
}
}
function enable() {
systemMenu = Main.panel.statusArea['aggregateMenu']._system;
_cancellable = new Gio.Cancellable();
Gio.DBusProxy.new(Gio.DBus.session,
Gio.DBusProxyFlags.DO_NOT_LOAD_PROPERTIES | Gio.DBusProxyFlags.DO_NOT_CONNECT_SIGNALS | Gio.DBusProxyFlags.DO_NOT_AUTO_START,
null,
"org.gnome.ScreenSaver",
"/org/gnome/ScreenSaver",
"org.gnome.ScreenSaver",
_cancellable,
_onProxyReady);
}
function disable() {
if (_cancellable) {
_cancellable.cancel();
_cancellable = null;
}
if (_lockActionId) {
_lockAction.disconnect(_lockActionId);
_lockActionId = 0;
}
if (_proxy) {
_proxy = null;
}
if (_lockAction) {
_lockAction.visible = false;
if (systemMenu)
systemMenu._actionsItem.actor.remove_child(_lockAction);
_lockAction.destroy();
_lockAction = null;
}
if (systemMenu)
systemMenu = null;
}