Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions daypercentagebot@FlyingSaturn/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## Icons

- [Sun Icon](https://iconscout.com/free-icon/free-sun-icon_1798521) by [Delesign Graphics](https://iconscout.com/contributors/delesign) [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) (Percent sign added for desklet icon)
- [Moon Icon](https://iconscout.com/free-icon/free-moon-icon_1798529) by [Delesign Graphics](https://iconscout.com/contributors/delesign) [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
const Desklet = imports.ui.desklet;
const St = imports.gi.St;
const Settings = imports.ui.settings;
const Mainloop = imports.mainloop;
const Lang = imports.lang;
const GLib = imports.gi.GLib;
const Gettext = imports.gettext;
const GdkPixbuf = imports.gi.GdkPixbuf;
const Clutter = imports.gi.Clutter;
const Cogl = imports.gi.Cogl;

const UUID = "daypercentagebot@FlyingSaturn";

Gettext.bindtextdomain(UUID, GLib.get_home_dir() + "/.local/share/locale");

function _(str) {
return Gettext.dgettext(UUID, str);
}

class MyDesklet extends Desklet.Desklet {
constructor(metadata, deskletId) {
super(metadata, deskletId);
this.metadata = metadata;

const settings = new Settings.DeskletSettings(this, metadata["uuid"], deskletId);
settings.bindProperty(Settings.BindingDirection.IN, "icon-size", "iconSize", this._onSettingsChanged.bind(this));
settings.bindProperty(Settings.BindingDirection.IN, "decoration", "decoration", this._onSettingsChanged.bind(this));
settings.bindProperty(Settings.BindingDirection.IN, "font-size-label", "fontSizeLabel", this._onSettingsChanged.bind(this));
settings.bindProperty(Settings.BindingDirection.IN, "show-sun-and-moon", "showSunAndMoon", this._onSettingsChanged.bind(this));

this.setHeader(_("Day Percentage"));
this._initUI();
this._update();
}

_initUI() {
this.window = new St.Bin();
this.container = new Clutter.Actor();
this.text = new St.Label();
this.text.set_text("... %");
this.text.style = `font-size: ${this.fontSizeLabel}px; text-align: center;`;

this.metadata["prevent-decorations"] = !this.decoration;
this._updateDecoration();

this._createIcons();

this.container.add_actor(this.text);
this.container.add_actor(this.sunIcon);
this.container.add_actor(this.moonIcon);
this.window.add_actor(this.container);
this.setContent(this.window);
}

_update() {
if (this.timeout) {
Mainloop.source_remove(this.timeout);
}

this._updateContent();

// update every second
this.timeout = Mainloop.timeout_add_seconds(1, Lang.bind(this, this._update));
}

_onSettingsChanged() {
this.sunIcon.destroy();
this.moonIcon.destroy();

this.metadata["prevent-decorations"] = !this.decoration;
this._updateDecoration();
this.text.set_style(`font-size: ${this.fontSizeLabel}px; text-align: center;`);

this._createIcons();

this.container.add_actor(this.sunIcon);
this.container.add_actor(this.moonIcon);

this._updateContent();
}

_createIcons() {
const iconSize = this.iconSize;
const deskletPath = this.metadata.path;

try {
this.sunIcon = this._getImageAtScale(`${deskletPath}/images/sun.svg`, iconSize, iconSize);
this.moonIcon = this._getImageAtScale(`${deskletPath}/images/moon.svg`, iconSize, iconSize);
} catch (e) {
global.logError(`[${UUID}] Error loading icons: ${e}`);
this.sunIcon = new St.Label({ text: "S" });
this.moonIcon = new St.Label({ text: "M" });
}

this.sunIcon.set_pivot_point(0.5, 0.5);
this.moonIcon.set_pivot_point(0.5, 0.5);
}

_updateContent() {
const dayPercent = this._calcPercent();
this.text.set_text(dayPercent.toFixed(1) + " %");

if (!this.showSunAndMoon) {
this.sunIcon.visible = false;
this.moonIcon.visible = false;
const containerHeight = this.text.get_height();
const containerWidth = this.text.get_width();
this.window.set_size(containerWidth, containerHeight);
this.container.set_size(containerWidth, containerHeight);
this.text.set_position(0, 0);
return;
}

const now = new Date();
const hour = now.getHours();

const iconSize = this.iconSize;
const radius = this.iconSize * 1.5;
const containerWidth = radius * 2 + iconSize;
const containerHeight = radius + iconSize * 1.5;

this.window.set_size(containerWidth, containerHeight);
this.container.set_size(containerWidth, containerHeight);

const centerX = this.window.get_width() / 2;
const centerY = this.window.get_height() - this.text.get_height() - iconSize / 2;

const angle = Math.PI * (dayPercent / 100.0);
const iconX = centerX - radius * Math.cos(angle);
const iconY = centerY - radius * Math.sin(angle);

const isDay = hour >= 6 && hour < 18;
this.sunIcon.visible = isDay;
this.moonIcon.visible = !isDay;
const currentIcon = isDay ? this.sunIcon : this.moonIcon;

const iconWidth = currentIcon.get_width();
const iconHeight = currentIcon.get_height();
const textWidth = this.text.get_width();
currentIcon.set_position(iconX - iconWidth / 2, iconY - iconHeight / 2);
this.text.set_position(centerX - textWidth / 2, this.window.get_height() - this.text.get_height() - iconSize / 2);
}

_calcPercent() {
const now = new Date();
const startOfDay = new Date(now.getFullYear(), now.getMonth(), now.getDate());
const secondsPassed = (now.getTime() - startOfDay.getTime()) / 1000;
const totalSecondsInDay = 24 * 60 * 60;
return (secondsPassed / totalSecondsInDay) * 100;
}

_createActorFromPixbuf(pixBuf) {
const pixelFormat = pixBuf.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGB_888;
const image = new Clutter.Image();
image.set_data(pixBuf.get_pixels(), pixelFormat, pixBuf.get_width(), pixBuf.get_height(), pixBuf.get_rowstride());

return new Clutter.Actor({
content: image,
width: pixBuf.get_width(),
height: pixBuf.get_height(),
});
}

_getImageAtScale(imageFilePath, requestedWidth, requestedHeight) {
const pixBuf = GdkPixbuf.Pixbuf.new_from_file_at_size(imageFilePath, requestedWidth, requestedHeight);
return this._createActorFromPixbuf(pixBuf);
}

on_desklet_removed() {
if (this.timeout) {
Mainloop.source_remove(this.timeout);
}
this.container.destroy();
}
}

function main(metadata, deskletId) {
return new MyDesklet(metadata, deskletId);
}
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,7 @@
{
"uuid": "daypercentagebot@FlyingSaturn",
"name": "Day Percentage",
"description": "Uses percentage to show how much of the day has passed.",
"max-instances": "50",
"version": "1.0"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# DAY PERCENTAGE
# This file is put in the public domain.
# FlyingSaturn, 2025
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: daypercentagebot@FlyingSaturn 1.0\n"
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-desklets/"
"issues\n"
"POT-Creation-Date: 2025-10-31 19:30+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#. metadata.json->name
#. desklet.js:31
msgid "Day Percentage"
msgstr ""

#. metadata.json->description
msgid "Uses percentage to show how much of the day has passed."
msgstr ""

#. settings-schema.json->head0->description
msgid "General"
msgstr ""

#. settings-schema.json->decoration->description
msgid "Show decoration"
msgstr ""

#. settings-schema.json->font-size-label->description
msgid "Font size for the percent label."
msgstr ""

#. settings-schema.json->head1->description
msgid "Icon"
msgstr ""

#. settings-schema.json->show-sun-and-moon->description
msgid "Show the rising and setting sun and the moon."
msgstr ""

#. settings-schema.json->icon-size->description
msgid "Icon size of the sun and moon."
msgstr ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# DAY PERCENTAGE
# This file is put in the public domain.
# FlyingSaturn, 2025
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: daypercentagebot@FlyingSaturn 1.0\n"
"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-desklets/"
"issues\n"
"POT-Creation-Date: 2025-10-31 19:30+0100\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: de\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 3.4.2\n"

#. metadata.json->name
#. desklet.js:31
msgid "Day Percentage"
msgstr "Tagesprozentsatz"

#. metadata.json->description
msgid "Uses percentage to show how much of the day has passed."
msgstr ""
"Verwendet Prozentangaben, um anzuzeigen, wie viel Prozent des Tages "
"vergangen sind."

#. settings-schema.json->head0->description
msgid "General"
msgstr "Allgemein"

#. settings-schema.json->decoration->description
msgid "Show decoration"
msgstr "Dekoration zeigen"

#. settings-schema.json->font-size-label->description
msgid "Font size for the percent label."
msgstr "Schriftgröße für die Prozentangabe."

#. settings-schema.json->head1->description
msgid "Icon"
msgstr "Icon"

#. settings-schema.json->show-sun-and-moon->description
msgid "Show the rising and setting sun and the moon."
msgstr "Sonnenaufgang und -untergang sowie den Mond anzeigen."

#. settings-schema.json->icon-size->description
msgid "Icon size of the sun and moon."
msgstr "Symbolgröße von Sonne und Mond."
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"head0": {
"type": "header",
"description": "General"
},
"decoration": {
"type": "checkbox",
"default": true,
"description": "Show decoration"
},
"font-size-label": {
"type": "scale",
"default": 24,
"min": 8,
"max": 100,
"step": 1,
"description": "Font size for the percent label."
},
"head1": {
"type": "header",
"description": "Icon"
},
"show-sun-and-moon": {
"type": "checkbox",
"default": true,
"description": "Show the rising and setting sun and the moon."
},
"icon-size": {
"type": "scale",
"default": 32,
"min": 30,
"max": 150,
"step": 1,
"description": "Icon size of the sun and moon.",
"dependency": "show-sun-and-moon"
}
}
3 changes: 3 additions & 0 deletions daypercentagebot@FlyingSaturn/info.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"author": "FlyingSaturn"
}
Binary file added daypercentagebot@FlyingSaturn/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.