Skip to content

Commit

Permalink
Add [email protected] applet
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiux committed Dec 11, 2024
1 parent 5174d3c commit 5eeb328
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
51 changes: 51 additions & 0 deletions files/usr/share/cinnamon/applets/[email protected]/applet.js
Original file line number Diff line number Diff line change
@@ -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");
} else {
this.set_applet_icon_symbolic_name("night-light-disabled");
}
}

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);
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"description": "Activate/deactivate Night Light mode.",
"icon": "cs-nightlight",
"max-instances": "1",
"hide-configuration": true,
"uuid": "[email protected]",
"name": "Night Light"
}

0 comments on commit 5eeb328

Please sign in to comment.