gnome-shell/js/ui/status/nightLight.js
Florian Müllner af87bd8c87 cleanup: Use consistent style for ternary operator
We are currently inconsistent whether to put the operators in front
of the corresponding line or at the end of the preceding one. The
most dominant style for now is to put condition and first branch on
the same line, and then align the second branch:

  let foo = condition ? fooValue
                      : notFooValue;

Unfortunately that's a style that eslint doesn't support, so to account
for it, our legacy configuration currently plainly ignores all indentation
in conditionals.

In order to drop that exception and not let messed up indentation slip
through, change all ternary operators to the non-legacy style.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/725
2019-09-15 13:30:19 +00:00

70 lines
2.7 KiB
JavaScript

// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
/* exported Indicator */
const Gio = imports.gi.Gio;
const Main = imports.ui.main;
const PanelMenu = imports.ui.panelMenu;
const PopupMenu = imports.ui.popupMenu;
const { loadInterfaceXML } = imports.misc.fileUtils;
const BUS_NAME = 'org.gnome.SettingsDaemon.Color';
const OBJECT_PATH = '/org/gnome/SettingsDaemon/Color';
const ColorInterface = loadInterfaceXML('org.gnome.SettingsDaemon.Color');
const ColorProxy = Gio.DBusProxy.makeProxyWrapper(ColorInterface);
var Indicator = class extends PanelMenu.SystemIndicator {
constructor() {
super();
this._indicator = this._addIndicator();
this._indicator.icon_name = 'night-light-symbolic';
this._proxy = new ColorProxy(Gio.DBus.session, BUS_NAME, OBJECT_PATH,
(proxy, error) => {
if (error) {
log(error.message);
return;
}
this._proxy.connect('g-properties-changed',
this._sync.bind(this));
this._sync();
});
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;
}
};