2017-02-10 08:14:14 -05:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
2019-01-31 09:07:06 -05:00
|
|
|
/* exported Indicator */
|
2017-02-10 08:14:14 -05:00
|
|
|
|
2022-07-24 14:12:54 -04:00
|
|
|
const {Gio, GLib, GObject} = imports.gi;
|
2017-02-10 08:14:14 -05:00
|
|
|
|
2022-07-24 14:18:55 -04:00
|
|
|
const {QuickToggle, SystemIndicator} = imports.ui.quickSettings;
|
2017-02-10 08:14:14 -05:00
|
|
|
|
2022-07-24 14:18:55 -04:00
|
|
|
const {loadInterfaceXML} = imports.misc.fileUtils;
|
2018-09-05 20:55:20 -04:00
|
|
|
|
2017-02-10 08:14:14 -05:00
|
|
|
const BUS_NAME = 'org.gnome.SettingsDaemon.Color';
|
|
|
|
const OBJECT_PATH = '/org/gnome/SettingsDaemon/Color';
|
|
|
|
|
2018-09-05 20:55:20 -04:00
|
|
|
const ColorInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Color');
|
2022-07-24 14:12:54 -04:00
|
|
|
const colorInfo = Gio.DBusInterfaceInfo.new_for_xml(ColorInterface);
|
2017-02-10 08:14:14 -05:00
|
|
|
|
2022-07-24 14:18:55 -04:00
|
|
|
const NightLightToggle = GObject.registerClass(
|
|
|
|
class NightLightToggle extends QuickToggle {
|
|
|
|
_init() {
|
|
|
|
super._init({
|
|
|
|
label: _('Night Light'),
|
|
|
|
iconName: 'night-light-symbolic',
|
|
|
|
toggleMode: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
this._settings = new Gio.Settings({
|
|
|
|
schema_id: 'org.gnome.settings-daemon.plugins.color',
|
|
|
|
});
|
|
|
|
this._settings.bind('night-light-enabled',
|
|
|
|
this, 'checked',
|
|
|
|
Gio.SettingsBindFlags.DEFAULT);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-10-28 14:35:33 -04:00
|
|
|
var Indicator = GObject.registerClass(
|
2022-07-24 14:18:55 -04:00
|
|
|
class Indicator extends SystemIndicator {
|
2019-07-16 05:24:13 -04:00
|
|
|
_init() {
|
|
|
|
super._init();
|
2017-02-10 08:14:14 -05:00
|
|
|
|
|
|
|
this._indicator = this._addIndicator();
|
|
|
|
this._indicator.icon_name = 'night-light-symbolic';
|
2022-07-24 14:12:54 -04:00
|
|
|
|
2022-07-24 14:18:55 -04:00
|
|
|
this.quickSettingsItems.push(new NightLightToggle());
|
|
|
|
|
2022-07-24 14:12:54 -04: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,
|
|
|
|
});
|
2022-07-24 14:18:55 -04:00
|
|
|
this._proxy.connect('g-properties-changed', (p, properties) => {
|
|
|
|
if ('NightLightActive' in properties.deep_unpack())
|
|
|
|
this._sync();
|
|
|
|
});
|
2022-07-24 14:12:54 -04:00
|
|
|
this._proxy.init_async(GLib.PRIORITY_DEFAULT, null)
|
|
|
|
.catch(e => console.error(e.message));
|
2017-02-10 08:14:14 -05:00
|
|
|
|
|
|
|
this._sync();
|
2017-10-30 21:19:44 -04:00
|
|
|
}
|
2017-02-10 08:14:14 -05:00
|
|
|
|
2017-10-30 20:03:21 -04:00
|
|
|
_sync() {
|
2022-07-24 14:18:55 -04:00
|
|
|
this._indicator.visible = this._proxy.NightLightActive;
|
2017-02-10 08:14:14 -05:00
|
|
|
}
|
2019-07-16 05:24:13 -04:00
|
|
|
});
|