diff --git a/systemUptime@KopfDesDaemons/README.md b/systemUptime@KopfDesDaemons/README.md new file mode 100644 index 000000000..ecc24a456 --- /dev/null +++ b/systemUptime@KopfDesDaemons/README.md @@ -0,0 +1,3 @@ +# System Uptime Desklet + +Displays the current system uptime and system start time. diff --git a/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/clock.svg b/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/clock.svg new file mode 100644 index 000000000..9265bd0fc --- /dev/null +++ b/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/clock.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/desklet.js b/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/desklet.js new file mode 100644 index 000000000..a698815b4 --- /dev/null +++ b/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/desklet.js @@ -0,0 +1,141 @@ +const Desklet = imports.ui.desklet; +const Lang = imports.lang; +const St = imports.gi.St; +const Mainloop = imports.mainloop; +const GLib = imports.gi.GLib; +const Settings = imports.ui.settings; +const Gettext = imports.gettext; +const Clutter = imports.gi.Clutter; +const GdkPixbuf = imports.gi.GdkPixbuf; +const Cogl = imports.gi.Cogl; + +const UUID = "systemUptime@KopfDesDaemons"; + +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.settings = new Settings.DeskletSettings(this, metadata["uuid"], deskletId); + + // Bind settings properties + this.settings.bindProperty(Settings.BindingDirection.IN, "fontSize", "fontSize", this.onSettingsChanged.bind(this)); + this.settings.bindProperty(Settings.BindingDirection.IN, "colorLabel", "colorLabel", this.onSettingsChanged.bind(this)); + + this.fontSize = this.settings.getValue("fontSize") || 20; + this.colorLabel = this.settings.getValue("colorLabel") || "rgb(51, 209, 122)"; + this._timeout = null; + + this.setHeader(_("System Uptime")); + this.setupLayout(); + this.getStartupTime(); + this.updateUptime(); + } + + setupLayout() { + // Create labels for uptime + this.uptimeLabel = this.createLabel(_("Uptime:") + " ", this.colorLabel); + this.uptimeValue = this.createLabel(_("Loading...")); + + const uptimeRow = this.createRow([this.uptimeLabel, this.uptimeValue]); + + // Create labels for startup time + this.startTimeLabel = this.createLabel(_("System start time:") + " ", this.colorLabel); + this.startupValue = this.createLabel(_("Loading...")); + + const startupRow = this.createRow([this.startTimeLabel, this.startupValue]); + + // Combine all into the main container + const contentBox = new St.BoxLayout({ vertical: true }); + contentBox.set_style("margin-left: 0.5em;"); + contentBox.add_child(startupRow); + contentBox.add_child(uptimeRow); + + const clockIcon = this.getImageAtScale(`${this.metadata.path}/clock.svg`, (this.fontSize * 2), (this.fontSize * 2),); + + this.container = new St.BoxLayout(); + this.container.add_child(clockIcon); + this.container.add_child(contentBox); + + this.setContent(this.container); + } + + createLabel(text, color = "inherit") { + return new St.Label({ + text, + y_align: St.Align.START, + style: `font-size: ${this.fontSize}px; color: ${color};` + }); + } + + createRow(children) { + const row = new St.BoxLayout(); + children.forEach(child => row.add_child(child)); + return row; + } + + updateUptime() { + try { + const [result, out] = GLib.spawn_command_line_sync("awk '{print $1}' /proc/uptime"); + if (!result || !out) throw new Error("Could not get system uptime."); + + const uptimeInSeconds = parseFloat(out.toString().trim()); + const hours = Math.floor(uptimeInSeconds / 3600); + const minutes = Math.floor((uptimeInSeconds % 3600) / 60); + + this.uptimeValue.set_text(`${hours} ${_("hours")} ${minutes} ${_("minutes")}`); + } catch (error) { + this.uptimeValue.set_text("Error"); + global.logError(`${UUID}: ${error.message}`); + } + + if (this._timeout) Mainloop.source_remove(this._timeout); + this._timeout = Mainloop.timeout_add_seconds(60, () => this.updateUptime()); + } + + getStartupTime() { + try { + const [result, out] = GLib.spawn_command_line_sync("uptime -s"); + if (!result || !out) throw new Error("Could not get system startup time."); + + this.startupValue.set_text(out.toString().split(" ")[1].trim()); + } catch (error) { + this.startupValue.set_text("Error"); + global.logError(`${UUID}: ${error.message}`); + } + } + + onSettingsChanged() { + this.setupLayout(); + this.updateUptime(); + this.getStartupTime(); + } + + on_desklet_removed() { + if (this._timeout) Mainloop.source_remove(this._timeout); + } + + getImageAtScale(imageFileName, width, height) { + const pixBuf = GdkPixbuf.Pixbuf.new_from_file_at_size(imageFileName, width, height); + const image = new Clutter.Image(); + image.set_data( + pixBuf.get_pixels(), + pixBuf.get_has_alpha() ? Cogl.PixelFormat.RGBA_8888 : Cogl.PixelFormat.RGBA_888, + width, height, + pixBuf.get_rowstride() + ); + + const actor = new Clutter.Actor({ width, height }); + actor.set_content(image); + return actor; + } +} + +function main(metadata, deskletId) { + return new MyDesklet(metadata, deskletId); +} diff --git a/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/icon.png b/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/icon.png new file mode 100644 index 000000000..5c6c1cc49 Binary files /dev/null and b/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/icon.png differ diff --git a/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/metadata.json b/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/metadata.json new file mode 100644 index 000000000..bce6f3e02 --- /dev/null +++ b/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/metadata.json @@ -0,0 +1,7 @@ +{ + "uuid": "systemUptime@KopfDesDaemons", + "name": "System Uptime", + "description": "Displays the current system uptime.", + "version": "1.0", + "max-instances": "50" +} \ No newline at end of file diff --git a/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/po/de.po b/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/po/de.po new file mode 100644 index 000000000..01813b7dd --- /dev/null +++ b/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/po/de.po @@ -0,0 +1,60 @@ +# SYSTEM UPTIME +# This file is put in the public domain. +# KopfDesDaemons, 2024 +# +msgid "" +msgstr "" +"Project-Id-Version: systemUptime@KopfDesDaemons 1.0\n" +"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-desklets/" +"issues\n" +"POT-Creation-Date: 2024-11-26 19:00+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" +"Plural-Forms: nplurals=2; plural=(n != 1);\n" +"X-Generator: Poedit 3.0.1\n" + +#. metadata.json->name +#. desklet.js:34 +msgid "System Uptime" +msgstr "Systembetriebszeit" + +#. desklet.js:42 +msgid "Uptime:" +msgstr "Betriebszeit:" + +#. desklet.js:43 desklet.js:49 +msgid "Loading..." +msgstr "Lade..." + +#. desklet.js:48 +msgid "System start time:" +msgstr "Systemstartzeitpunkt:" + +#. desklet.js:91 +msgid "hours" +msgstr "Stunden" + +#. desklet.js:91 +msgid "minutes" +msgstr "Minuten" + +#. metadata.json->description +msgid "Displays the current system uptime." +msgstr "Zeigt die aktuelle Systembetriebszeit." + +#. settings-schema.json->head0->description +msgid "Style" +msgstr "Stil" + +#. settings-schema.json->fontSize->description +msgid "Font size" +msgstr "Schriftgröße" + +#. settings-schema.json->colorLabel->description +msgid "Label color" +msgstr "Labelfarbe" diff --git a/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/po/systemUptime@KopfDesDaemons.pot b/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/po/systemUptime@KopfDesDaemons.pot new file mode 100644 index 000000000..1a6b17045 --- /dev/null +++ b/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/po/systemUptime@KopfDesDaemons.pot @@ -0,0 +1,59 @@ +# SYSTEM UPTIME +# This file is put in the public domain. +# KopfDesDaemons, 2024 +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: systemUptime@KopfDesDaemons 1.0\n" +"Report-Msgid-Bugs-To: https://github.com/linuxmint/cinnamon-spices-desklets/" +"issues\n" +"POT-Creation-Date: 2024-11-26 19:00+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:34 +msgid "System Uptime" +msgstr "" + +#. desklet.js:42 +msgid "Uptime:" +msgstr "" + +#. desklet.js:43 desklet.js:49 +msgid "Loading..." +msgstr "" + +#. desklet.js:48 +msgid "System start time:" +msgstr "" + +#. desklet.js:91 +msgid "hours" +msgstr "" + +#. desklet.js:91 +msgid "minutes" +msgstr "" + +#. metadata.json->description +msgid "Displays the current system uptime." +msgstr "" + +#. settings-schema.json->head0->description +msgid "Style" +msgstr "" + +#. settings-schema.json->fontSize->description +msgid "Font size" +msgstr "" + +#. settings-schema.json->colorLabel->description +msgid "Label color" +msgstr "" diff --git a/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/settings-schema.json b/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/settings-schema.json new file mode 100644 index 000000000..fa68b1be1 --- /dev/null +++ b/systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/settings-schema.json @@ -0,0 +1,19 @@ +{ + "head0": { + "type": "header", + "description": "Style" + }, + "fontSize": { + "type": "scale", + "default": 20, + "min": 12, + "max": 60, + "step": 1, + "description": "Font size" + }, + "colorLabel": { + "type": "colorchooser", + "default": "rgb(51, 209, 122)", + "description": "Label color" + } +} \ No newline at end of file diff --git a/systemUptime@KopfDesDaemons/info.json b/systemUptime@KopfDesDaemons/info.json new file mode 100644 index 000000000..abdd76797 --- /dev/null +++ b/systemUptime@KopfDesDaemons/info.json @@ -0,0 +1,3 @@ +{ + "author": "KopfDesDaemons" +} \ No newline at end of file diff --git a/systemUptime@KopfDesDaemons/screenshot.png b/systemUptime@KopfDesDaemons/screenshot.png new file mode 100644 index 000000000..c055d7c06 Binary files /dev/null and b/systemUptime@KopfDesDaemons/screenshot.png differ