-
Notifications
You must be signed in to change notification settings - Fork 179
/
nightLight.js
74 lines (61 loc) · 2.94 KB
/
nightLight.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
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
const Gio = imports.gi.Gio;
const Lang = imports.lang;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const BUS_NAME = 'org.gnome.SettingsDaemon.Color';
const OBJECT_PATH = '/org/gnome/SettingsDaemon/Color';
const ColorInterface = '<node> \
<interface name="org.gnome.SettingsDaemon.Color"> \
<property name="DisabledUntilTomorrow" type="b" access="readwrite"/> \
<property name="NightLightActive" type="b" access="read"/> \
</interface> \
</node>';
const ColorProxy = Gio.DBusProxy.makeProxyWrapper(ColorInterface);
var Indicator = new Lang.Class({
Name: 'NightLightIndicator',
Extends: PanelMenu.SystemIndicator,
_init: function() {
this.parent();
this._indicator = this._addIndicator();
this._indicator.icon_name = 'night-light-symbolic';
this._proxy = new ColorProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
(proxy, error) => {
if (error) {
log(error.message);
return;
}
this._proxy.connect('g-properties-changed',
Lang.bind(this, this._sync));
this._sync();
});
this._item = new PopupMenu.PopupSubMenuMenuItem("", true);
this._item.icon.icon_name = 'night-light-symbolic';
this._disableItem = this._item.menu.addAction('', () => {
this._proxy.DisabledUntilTomorrow = !this._proxy.DisabledUntilTomorrow;
});
this._item.menu.addAction(_("Turn Off"), () => {
let settings = new Gio.Settings({ schema_id: 'org.gnome.settings-daemon.plugins.color' });
settings.set_boolean('night-light-enabled', false);
});
this._item.menu.addSettingsAction(_("Display Settings"), 'gnome-display-panel.desktop');
this.menu.addMenuItem(this._item);
Main.sessionMode.connect('updated', Lang.bind(this, this._sessionUpdated));
this._sessionUpdated();
this._sync();
},
_sessionUpdated: function() {
let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
this.menu.setSensitive(sensitive);
},
_sync: function() {
let visible = this._proxy.NightLightActive;
let disabled = this._proxy.DisabledUntilTomorrow;
this._item.label.text = disabled ? _("Night Light Disabled")
: _("Night Light On");
this._disableItem.label.text = disabled ? _("Resume")
: _("Disable Until Tomorrow");
this._item.actor.visible = this._indicator.visible = visible;
}
});