status/nightLight: Port to quick settings
Night-light is now a simple, always visible toggle that directly controls the underlying setting. No change to the top bar icon, which is still only shown while night-light is active (read: at night). Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2392>
This commit is contained in:

committed by
Marge Bot

parent
0f1f5bb174
commit
1459173bc9
@ -3,11 +3,9 @@
|
||||
|
||||
const {Gio, GLib, GObject} = imports.gi;
|
||||
|
||||
const Main = imports.ui.main;
|
||||
const PanelMenu = imports.ui.panelMenu;
|
||||
const PopupMenu = imports.ui.popupMenu;
|
||||
const {QuickToggle, SystemIndicator} = imports.ui.quickSettings;
|
||||
|
||||
const { loadInterfaceXML } = imports.misc.fileUtils;
|
||||
const {loadInterfaceXML} = imports.misc.fileUtils;
|
||||
|
||||
const BUS_NAME = 'org.gnome.SettingsDaemon.Color';
|
||||
const OBJECT_PATH = '/org/gnome/SettingsDaemon/Color';
|
||||
@ -15,14 +13,34 @@ const OBJECT_PATH = '/org/gnome/SettingsDaemon/Color';
|
||||
const ColorInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Color');
|
||||
const colorInfo = Gio.DBusInterfaceInfo.new_for_xml(ColorInterface);
|
||||
|
||||
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);
|
||||
}
|
||||
});
|
||||
|
||||
var Indicator = GObject.registerClass(
|
||||
class Indicator extends PanelMenu.SystemIndicator {
|
||||
class Indicator extends SystemIndicator {
|
||||
_init() {
|
||||
super._init();
|
||||
|
||||
this._indicator = this._addIndicator();
|
||||
this._indicator.icon_name = 'night-light-symbolic';
|
||||
|
||||
this.quickSettingsItems.push(new NightLightToggle());
|
||||
|
||||
this._proxy = new Gio.DBusProxy({
|
||||
g_connection: Gio.DBus.session,
|
||||
g_name: BUS_NAME,
|
||||
@ -30,42 +48,17 @@ class Indicator extends PanelMenu.SystemIndicator {
|
||||
g_interface_name: colorInfo.name,
|
||||
g_interface_info: colorInfo,
|
||||
});
|
||||
this._proxy.connect('g-properties-changed', () => this._sync());
|
||||
this._proxy.connect('g-properties-changed', (p, properties) => {
|
||||
if ('NightLightActive' in properties.deep_unpack())
|
||||
this._sync();
|
||||
});
|
||||
this._proxy.init_async(GLib.PRIORITY_DEFAULT, null)
|
||||
.catch(e => console.error(e.message));
|
||||
|
||||
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', this._sessionUpdated.bind(this));
|
||||
this._sessionUpdated();
|
||||
this._sync();
|
||||
}
|
||||
|
||||
_sessionUpdated() {
|
||||
let sensitive = !Main.sessionMode.isLocked && !Main.sessionMode.isGreeter;
|
||||
this.menu.setSensitive(sensitive);
|
||||
}
|
||||
|
||||
_sync() {
|
||||
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.visible = this._indicator.visible = visible;
|
||||
this._indicator.visible = this._proxy.NightLightActive;
|
||||
}
|
||||
});
|
||||
|
Reference in New Issue
Block a user