2017-02-10 13:14:14 +00:00
|
|
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
import Gio from 'gi://Gio';
|
|
|
|
import GLib from 'gi://GLib';
|
|
|
|
import GObject from 'gi://GObject';
|
2017-02-10 13:14:14 +00:00
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
import {QuickToggle, SystemIndicator} from '../quickSettings.js';
|
2017-02-10 13:14:14 +00:00
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
import {loadInterfaceXML} from '../../misc/fileUtils.js';
|
2018-09-06 00:55:20 +00:00
|
|
|
|
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
|
|
|
|
2022-07-24 18:18:55 +00:00
|
|
|
const NightLightToggle = GObject.registerClass(
|
|
|
|
class NightLightToggle extends QuickToggle {
|
|
|
|
_init() {
|
|
|
|
super._init({
|
2023-01-30 20:32:39 +00:00
|
|
|
title: _('Night Light'),
|
2022-07-24 18:18:55 +00:00
|
|
|
iconName: 'night-light-symbolic',
|
|
|
|
toggleMode: true,
|
|
|
|
});
|
|
|
|
|
2022-08-15 12:33:00 +00:00
|
|
|
const monitorManager = global.backend.get_monitor_manager();
|
|
|
|
monitorManager.bind_property('night-light-supported',
|
|
|
|
this, 'visible',
|
|
|
|
GObject.BindingFlags.SYNC_CREATE);
|
|
|
|
|
2022-07-24 18:18:55 +00:00
|
|
|
this._settings = new Gio.Settings({
|
|
|
|
schema_id: 'org.gnome.settings-daemon.plugins.color',
|
|
|
|
});
|
|
|
|
this._settings.bind('night-light-enabled',
|
|
|
|
this, 'checked',
|
|
|
|
Gio.SettingsBindFlags.DEFAULT);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2023-07-10 09:53:00 +00:00
|
|
|
export const Indicator = GObject.registerClass(
|
2022-07-24 18:18:55 +00:00
|
|
|
class Indicator extends 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
|
|
|
|
2022-07-24 18:18:55 +00:00
|
|
|
this.quickSettingsItems.push(new NightLightToggle());
|
|
|
|
|
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,
|
|
|
|
});
|
2022-07-24 18:18:55 +00:00
|
|
|
this._proxy.connect('g-properties-changed', (p, properties) => {
|
2022-08-10 09:44:42 +00:00
|
|
|
const nightLightActiveChanged = !!properties.lookup_value('NightLightActive', null);
|
|
|
|
if (nightLightActiveChanged)
|
2022-07-24 18:18:55 +00:00
|
|
|
this._sync();
|
|
|
|
});
|
2022-07-24 18:12:54 +00:00
|
|
|
this._proxy.init_async(GLib.PRIORITY_DEFAULT, null)
|
|
|
|
.catch(e => console.error(e.message));
|
2017-02-10 13:14:14 +00:00
|
|
|
|
|
|
|
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
|
|
|
_sync() {
|
2022-07-24 18:18:55 +00:00
|
|
|
this._indicator.visible = this._proxy.NightLightActive;
|
2017-02-10 13:14:14 +00:00
|
|
|
}
|
2019-07-16 09:24:13 +00:00
|
|
|
});
|