diff --git a/files/usr/share/cinnamon/applets/nightlight@cinnamon.org/applet.js b/files/usr/share/cinnamon/applets/nightlight@cinnamon.org/applet.js new file mode 100644 index 0000000000..0f2b2e2383 --- /dev/null +++ b/files/usr/share/cinnamon/applets/nightlight@cinnamon.org/applet.js @@ -0,0 +1,51 @@ +const Applet = imports.ui.applet; +const Gio = imports.gi.Gio; +const PopupMenu = imports.ui.popupMenu; +const Util = imports.misc.util; +const St = imports.gi.St; + +class NightLightSwitch extends Applet.IconApplet { + constructor(metadata, orientation, panelHeight, instance_id) { + super(orientation, panelHeight, instance_id); + + this.gsettings = Gio.Settings.new("org.cinnamon.settings-daemon.plugins.color"); + this.nightLightEnabled = this.gsettings.get_boolean("night-light-enabled"); + this.connectColorID = this.gsettings.connect("changed", () => this.set_icon()); + this.set_icon(); + + let items = this._applet_context_menu._getMenuItems(); + if (this.context_menu_item_configure == null) { + this.context_menu_item_configure = new PopupMenu.PopupIconMenuItem(_("Configure..."), + "system-run", + St.IconType.SYMBOLIC); + this.context_menu_item_configure.connect('activate', + () => { Util.spawnCommandLineAsync("cinnamon-settings nightlight"); } + ); + } + if (items.indexOf(this.context_menu_item_configure) == -1) { + this._applet_context_menu.addMenuItem(this.context_menu_item_configure); + } + } + + on_applet_clicked() { + this.gsettings.set_boolean("night-light-enabled", !this.nightLightEnabled); + this.set_icon(); + } + + set_icon() { + this.nightLightEnabled = this.gsettings.get_boolean("night-light-enabled"); + if (this.nightLightEnabled) { + this.set_applet_icon_symbolic_name("night-light-2"); + } else { + this.set_applet_icon_symbolic_name("night-light-disabled-2"); + } + } + + on_applet_removed_from_panel() { + this.gsettings.disconnect(this.connectColorID); + } +} + +function main(metadata, orientation, panel_height, instance_id) { + return new NightLightSwitch(metadata, orientation, panel_height, instance_id); +} diff --git a/files/usr/share/cinnamon/applets/nightlight@cinnamon.org/icons/night-light-2-symbolic.svg b/files/usr/share/cinnamon/applets/nightlight@cinnamon.org/icons/night-light-2-symbolic.svg new file mode 100644 index 0000000000..4cd3b351b3 --- /dev/null +++ b/files/usr/share/cinnamon/applets/nightlight@cinnamon.org/icons/night-light-2-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/files/usr/share/cinnamon/applets/nightlight@cinnamon.org/icons/night-light-disabled-2-symbolic.svg b/files/usr/share/cinnamon/applets/nightlight@cinnamon.org/icons/night-light-disabled-2-symbolic.svg new file mode 100644 index 0000000000..f44544983e --- /dev/null +++ b/files/usr/share/cinnamon/applets/nightlight@cinnamon.org/icons/night-light-disabled-2-symbolic.svg @@ -0,0 +1,3 @@ + + + diff --git a/files/usr/share/cinnamon/applets/nightlight@cinnamon.org/metadata.json b/files/usr/share/cinnamon/applets/nightlight@cinnamon.org/metadata.json new file mode 100644 index 0000000000..13ebaf9bae --- /dev/null +++ b/files/usr/share/cinnamon/applets/nightlight@cinnamon.org/metadata.json @@ -0,0 +1,8 @@ +{ + "description": "Activate/deactivate Night Light mode.", + "icon": "cs-nightlight", + "max-instances": "1", + "hide-configuration": true, + "uuid": "nightlight@cinnamon.org", + "name": "Night Light" +}