This repository has been archived by the owner on Dec 1, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
extension.js
113 lines (93 loc) · 3.72 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
/* -*- mode: js2 - indent-tabs-mode: nil - js2-basic-offset: 4 -*- */
const Lang = imports.lang;
const St = imports.gi.St;
const Gio = imports.gi.Gio;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const Gettext = imports.gettext.domain('gnome-shell-extension-inhibitapplet');
const _ = Gettext.gettext;
const POWER_SCHEMA = 'org.gnome.settings-daemon.plugins.power';
const POWER_KEY = 'active';
const SCREEN_SCHEMA = 'org.gnome.desktop.screensaver';
const SCREEN_KEY = 'idle-activation-enabled';
let indicationbutton;
//Icon variables for easy editing/customization:
let DisabledIcon = 'preferences-desktop-screensaver-symbolic';
let EnabledIcon = 'system-run-symbolic';
////An alternative icon could be 'action-unavailable-symbolic'
const TOOLTIPON = _("Suspend Inhibited");
const TOOLTIPOFF = _("Suspend Enabled");
const ROLE = 'inhibitbutton';
function InhibitButton() {
this._init.apply(this, arguments);
}
InhibitButton.prototype = {
__proto__: PanelMenu.ButtonBox.prototype,
__proto__: PanelMenu.ButtonBox.prototype,
_init: function(metadata, params)
{
PanelMenu.ButtonBox.prototype._init.call(this, {
reactive: true,
can_focus: true,
track_hover: true
});
this.temp = new St.Icon({
icon_name: DisabledIcon,
icon_type: St.IconType.SYMBOLIC,
style_class: 'system-status-icon'
});
this.actor.add_actor(this.temp);
this.actor.add_style_class_name('panel-status-button');
this.actor.has_tooltip = true;
this.actor.tooltip_text = TOOLTIPOFF;
///Power Setting
this._powerSettings = new Gio.Settings({ schema: POWER_SCHEMA });
var powerManagementFlag = this._powerSettings.get_boolean(POWER_KEY);
///ScreenSaver Setting
this._screenSettings = new Gio.Settings({ schema: SCREEN_SCHEMA });
//Make sure the screensaver enable is synchronized
this._screenSettings.set_boolean(SCREEN_KEY, powerManagementFlag);
//Change Icon if necessary
if(!powerManagementFlag) {
this.actor.tooltip_text = TOOLTIPON;
this.temp.icon_name = EnabledIcon;
}
this.actor.connect('button-press-event', Lang.bind(this, function () {
var powerManagementFlag = this._powerSettings.get_boolean(POWER_KEY);
this._powerSettings.set_boolean(POWER_KEY, !powerManagementFlag);
this._screenSettings.set_boolean(SCREEN_KEY, !powerManagementFlag);
if(powerManagementFlag) {
this.actor.tooltip_text = TOOLTIPON;
this.temp.icon_name = EnabledIcon;
} else {
this.actor.tooltip_text = TOOLTIPOFF;
this.temp.icon_name = DisabledIcon;
}
}));
Main.panel._insertStatusItem(this.actor, 0);
Main.panel._statusArea[ROLE] = this;
},
destroy: function() {
if (this._powerSettings) {
this._powerSettings.set_boolean(POWER_KEY, true);
}
if (this._screenSettings) {
this._screenSettings.set_boolean(SCREEN_KEY, true);
}
Main.panel._statusArea[ROLE] = null;
this.actor._delegate = null;
this.actor.destroy();
this.actor.emit('destroy');
}
};
function init(extensionMeta) {
imports.gettext.bindtextdomain("gnome-shell-extension-inhibitapplet",
extensionMeta.path + "/locale");
}
function enable() {
indicationbutton = new InhibitButton();
}
function disable() {
indicationbutton.destroy();
}