2017-02-10 13:14:14 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 14:07:06 +00:00
|
|
|
/* exported Indicator */
|
2017-02-10 13:14:14 +00:00
|
|
|
|
2022-07-24 18:12:54 +00:00
|
|
|
const {Gio, GLib, GObject} = imports.gi;
|
2017-02-10 13:14:14 +00:00
|
|
|
|
|
|
|
const Main = imports.ui.main;
|
|
|
|
const PanelMenu = imports.ui.panelMenu;
|
|
|
|
const PopupMenu = imports.ui.popupMenu;
|
|
|
|
|
2018-09-06 00:55:20 +00:00
|
|
|
const { loadInterfaceXML } = imports.misc.fileUtils;
|
|
|
|
|
2017-02-10 13:14:14 +00:00
|
|
|
const BUS_NAME = 'org.gnome.SettingsDaemon.Color';
|
|
|
|
const OBJECT_PATH = '/org/gnome/SettingsDaemon/Color';
|
|
|
|
|
2018-09-06 00:55:20 +00:00
|
|
|
const ColorInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Color');
|
2022-07-24 18:12:54 +00:00
|
|
|
const colorInfo = Gio.DBusInterfaceInfo.new_for_xml(ColorInterface);
|
2017-02-10 13:14:14 +00:00
|
|
|
|
2019-10-28 18:35:33 +00:00
|
|
|
var Indicator = GObject.registerClass(
|
|
|
|
class Indicator extends PanelMenu.SystemIndicator {
|
2019-07-16 09:24:13 +00:00
|
|
|
_init() {
|
|
|
|
super._init();
|
2017-02-10 13:14:14 +00:00
|
|
|
|
|
|
|
this._indicator = this._addIndicator();
|
|
|
|
this._indicator.icon_name = 'night-light-symbolic';
|
2022-07-24 18:12:54 +00:00
|
|
|
|
|
|
|
this._proxy = new Gio.DBusProxy({
|
|
|
|
g_connection: Gio.DBus.session,
|
|
|
|
g_name: BUS_NAME,
|
|
|
|
g_object_path: OBJECT_PATH,
|
|
|
|
g_interface_name: colorInfo.name,
|
|
|
|
g_interface_info: colorInfo,
|
|
|
|
});
|
|
|
|
this._proxy.connect('g-properties-changed', () => this._sync());
|
|
|
|
this._proxy.init_async(GLib.PRIORITY_DEFAULT, null)
|
|
|
|
.catch(e => console.error(e.message));
|
2017-02-10 13:14:14 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2017-12-02 00:27:35 +00:00
|
|
|
Main.sessionMode.connect('updated', this._sessionUpdated.bind(this));
|
2017-02-10 13:14:14 +00:00
|
|
|
this._sessionUpdated();
|
|
|
|
this._sync();
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-02-10 13:14:14 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sessionUpdated() {
|
2017-02-10 13:14:14 +00:00
|
|
|
let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
|
|
|
this.menu.setSensitive(sensitive);
|
2017-10-31 01:19:44 +00:00
|
|
|
}
|
2017-02-10 13:14:14 +00:00
|
|
|
|
2017-10-31 00:03:21 +00:00
|
|
|
_sync() {
|
2017-02-10 13:14:14 +00:00
|
|
|
let visible = this._proxy.NightLightActive;
|
|
|
|
let disabled = this._proxy.DisabledUntilTomorrow;
|
|
|
|
|
2019-08-19 19:33:15 +00:00
|
|
|
this._item.label.text = disabled
|
|
|
|
? _("Night Light Disabled")
|
|
|
|
: _("Night Light On");
|
|
|
|
this._disableItem.label.text = disabled
|
|
|
|
? _("Resume")
|
|
|
|
: _("Disable Until Tomorrow");
|
2019-04-12 21:00:49 +00:00
|
|
|
this._item.visible = this._indicator.visible = visible;
|
2017-02-10 13:14:14 +00:00
|
|
|
}
|
2019-07-16 09:24:13 +00:00
|
|
|
});
|