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:
parent
0f1f5bb174
commit
1459173bc9
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user