-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
systemUptime@KopfDesDaemons: Initial release (#1334)
- Loading branch information
1 parent
2444433
commit daea30b
Showing
10 changed files
with
293 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# System Uptime Desklet | ||
|
||
Displays the current system uptime and system start time. |
1 change: 1 addition & 0 deletions
1
systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/clock.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
141 changes: 141 additions & 0 deletions
141
systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/desklet.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
Binary file added
BIN
+15.8 KB
systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions
7
systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"uuid": "systemUptime@KopfDesDaemons", | ||
"name": "System Uptime", | ||
"description": "Displays the current system uptime.", | ||
"version": "1.0", | ||
"max-instances": "50" | ||
} |
60 changes: 60 additions & 0 deletions
60
systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/po/de.po
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |
59 changes: 59 additions & 0 deletions
59
...ptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/po/[email protected]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 "" |
19 changes: 19 additions & 0 deletions
19
systemUptime@KopfDesDaemons/files/systemUptime@KopfDesDaemons/settings-schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"author": "KopfDesDaemons" | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.