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,154 @@
const Desklet = imports.ui.desklet;
const St = imports.gi.St;
const Settings = imports.ui.settings;
const Mainloop = imports.mainloop;
const GLib = imports.gi.GLib;
const Gettext = imports.gettext;
const Gio = imports.gi.Gio;

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.setHeader(_("Day Percentage"));

this._deskletHeight = 100;
this._deskletWidth = 300;
this._isReloading = true;
this._iconSize = 45;

// Default settings
this.scaleSize = 1;
this.decoration = true;
this.showSunAndMoon = true;

this.settings = new Settings.DeskletSettings(this, metadata["uuid"], deskletId);
this.settings.bindProperty(Settings.BindingDirection.IN, "decoration", "decoration", this._onSettingsChanged.bind(this));
this.settings.bindProperty(Settings.BindingDirection.IN, "scale-size", "scaleSize", this._onSettingsChanged.bind(this));
this.settings.bindProperty(Settings.BindingDirection.IN, "show-sun-and-moon", "showSunAndMoon", this._onSettingsChanged.bind(this));
}

on_desklet_added_to_desktop() {
this._initUI();
this.timeout = Mainloop.timeout_add_seconds(1, this._update.bind(this));
}

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

if (this.settings && !this._isReloading) {
this.settings.finalize();
}
}

on_desklet_reloaded() {
this._isReloading = true;
}

_initUI() {
this.container = new St.BoxLayout({ vertical: true });
this.iconContainer = new St.Widget({ x_expand: true, y_expand: true });
this.text = new St.Label();
this.text.style = `font-size: ${16 * this.scaleSize}px; text-align: center;`;

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

this._createIcons();

this.container.add_child(this.iconContainer);
this.container.add_child(this.text);
this._updateWindowSize();
this._updateContent();
this.setContent(this.container);
}

_updateWindowSize() {
if (this.showSunAndMoon) {
this.iconContainer.show();
this.container.set_size(this._deskletWidth * this.scaleSize, this._deskletHeight * this.scaleSize);
} else {
this.iconContainer.hide();
// Set the container size to auto when sun and moon icons are hidden
this.container.set_width(-1);
this.container.set_height(-1);
}
}

// update every second
_update() {
this._updateContent();
return true;
}

_onSettingsChanged() {
this.iconContainer.destroy_all_children();

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

this._createIcons();
this._updateWindowSize();
this._updateContent();
}

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

this.sunIcon = new St.Icon({ gicon: Gio.icon_new_for_string(`${deskletPath}/images/sun.svg`), icon_size: iconSize });
this.moonIcon = new St.Icon({ gicon: Gio.icon_new_for_string(`${deskletPath}/images/moon.svg`), icon_size: iconSize });
this.iconContainer.add_child(this.sunIcon);
this.iconContainer.add_child(this.moonIcon);
}

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

if (!this.showSunAndMoon) return;

const iconSize = this._iconSize * this.scaleSize;
const textHeight = this.text.get_height();

const radiusY = this._deskletHeight * this.scaleSize - iconSize - textHeight;
const radiusX = (this._deskletWidth * this.scaleSize) / 2 - iconSize / 2;

const centerX = (this._deskletWidth * this.scaleSize) / 2;
const centerY = this._deskletHeight * this.scaleSize - textHeight - iconSize / 2;

const angle = Math.PI + (dayPercent / 100.0) * Math.PI;
const iconX = centerX - iconSize / 2 + radiusX * Math.cos(angle);
const iconY = centerY - iconSize / 2 + radiusY * Math.sin(angle);

// Set sun or moon icon based on the time of day
const hour = new Date().getHours();
const isDay = hour >= 6 && hour < 18;
this.sunIcon.visible = isDay;
this.moonIcon.visible = !isDay;
const currentIcon = isDay ? this.sunIcon : this.moonIcon;

currentIcon.set_position(iconX, iconY);
}

_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;
}
}

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,47 @@
# 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: 2026-02-07 11:42+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->scale-size->description
msgid "Desklet size"
msgstr ""

#. settings-schema.json->decoration->description
msgid "Show decoration"
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 ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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: 2026-02-07 11:42+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->scale-size->description
msgid "Desklet size"
msgstr "Desklet Größe"

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

#. 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."
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"head0": {
"type": "header",
"description": "General"
},
"scale-size": {
"type": "scale",
"default": 1,
"min": 0.4,
"max": 3,
"step": 0.05,
"description": "Desklet size"
},
"decoration": {
"type": "checkbox",
"default": true,
"description": "Show decoration"
},
"head1": {
"type": "header",
"description": "Icon"
},
"show-sun-and-moon": {
"type": "checkbox",
"default": true,
"description": "Show the rising and setting sun and the 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.
Loading