diff --git a/js/ui/panel.js b/js/ui/panel.js index e487f4518..0700044fc 100644 --- a/js/ui/panel.js +++ b/js/ui/panel.js @@ -389,9 +389,7 @@ class AggregateMenu extends PanelMenu.Button { this._volume = new imports.ui.status.volume.Indicator(); this._brightness = new imports.ui.status.brightness.Indicator(); this._system = new imports.ui.status.system.Indicator(); - this._nightLight = new imports.ui.status.nightLight.Indicator(); - this._indicators.add_child(this._nightLight); if (this._network) this._indicators.add_child(this._network); if (this._bluetooth) @@ -413,7 +411,6 @@ class AggregateMenu extends PanelMenu.Button { this.menu.addMenuItem(this._rfkill.menu); this.menu.addMenuItem(this._power.menu); this.menu.addMenuItem(this._powerProfiles.menu); - this.menu.addMenuItem(this._nightLight.menu); this.menu.addMenuItem(new PopupMenu.PopupSeparatorMenuItem()); this.menu.addMenuItem(this._system.menu); @@ -439,16 +436,19 @@ class QuickSettings extends PanelMenu.Button { this._remoteAccess = new imports.ui.status.remoteAccess.RemoteAccessApplet(); this._location = new imports.ui.status.location.Indicator(); this._thunderbolt = new imports.ui.status.thunderbolt.Indicator(); + this._nightLight = new imports.ui.status.nightLight.Indicator(); this._unsafeMode = new UnsafeModeIndicator(); this._indicators.add_child(this._remoteAccess); this._indicators.add_child(this._thunderbolt); this._indicators.add_child(this._location); + this._indicators.add_child(this._nightLight); this._indicators.add_child(this._unsafeMode); this._addItems(this._remoteAccess.quickSettingsItems); this._addItems(this._thunderbolt.quickSettingsItems); this._addItems(this._location.quickSettingsItems); + this._addItems(this._nightLight.quickSettingsItems); this._addItems(this._unsafeMode.quickSettingsItems); } diff --git a/js/ui/status/nightLight.js b/js/ui/status/nightLight.js index 109fe6791..a7fa92a3f 100644 --- a/js/ui/status/nightLight.js +++ b/js/ui/status/nightLight.js @@ -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; } });