Skip to content

Commit 8c45ea2

Browse files
authored
click-clock@wernerstucky: Initial release (#6719)
1 parent 6ec4d27 commit 8c45ea2

File tree

6 files changed

+90
-0
lines changed

6 files changed

+90
-0
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- Keeping focused is important
2+
- Resist the urge to see the time constantly
3+
- You need to click to see the time
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
const Applet = imports.ui.applet;
2+
const Mainloop = imports.mainloop;
3+
4+
function MyApplet(metadata, orientation, panelHeight, instance_id) {
5+
this._init(metadata, orientation, panelHeight, instance_id);
6+
}
7+
8+
MyApplet.prototype = {
9+
__proto__: Applet.TextIconApplet.prototype,
10+
11+
_init: function (metadata, orientation, panelHeight, instance_id) {
12+
Applet.TextIconApplet.prototype._init.call(
13+
this,
14+
orientation,
15+
panelHeight,
16+
instance_id
17+
);
18+
19+
this.set_applet_icon_name("clock");
20+
this.set_applet_tooltip("Click to view the time");
21+
22+
// Debug: Log initialization
23+
// global.log("Click-Clock applet initialized successfully.");
24+
},
25+
26+
// Override the default on_applet_clicked method
27+
on_applet_clicked: function () {
28+
try {
29+
// global.log("Applet clicked!"); // Debug log
30+
31+
let now = new Date();
32+
let timeString = now.toLocaleTimeString();
33+
34+
// global.log("Current time: " + timeString); // Log the time
35+
this.set_applet_label(timeString);
36+
this.set_applet_tooltip(`Current time: ${timeString}`);
37+
38+
// Reset to icon after 20 seconds
39+
if (this._timeoutId) {
40+
Mainloop.source_remove(this._timeoutId);
41+
}
42+
43+
this._timeoutId = Mainloop.timeout_add_seconds(20, () => {
44+
this._resetToIcon();
45+
return false; // Stop the timeout
46+
});
47+
} catch (e) {
48+
global.logError("Error in on_applet_clicked: " + e);
49+
}
50+
},
51+
52+
_resetToIcon: function () {
53+
try {
54+
// global.log("Resetting to clock icon."); // Debug log
55+
this.set_applet_label("");
56+
this.set_applet_icon_name("clock");
57+
this.set_applet_tooltip("Click to view the time");
58+
} catch (e) {
59+
global.logError("Error in _resetToIcon: " + e);
60+
}
61+
},
62+
63+
on_applet_removed_from_panel: function () {
64+
try {
65+
if (this._timeoutId) {
66+
Mainloop.source_remove(this._timeoutId);
67+
}
68+
} catch (e) {
69+
global.logError("Error in on_applet_removed_from_panel: " + e);
70+
}
71+
},
72+
};
73+
74+
function main(metadata, orientation, panelHeight, instance_id) {
75+
return new MyApplet(metadata, orientation, panelHeight, instance_id);
76+
}
13.8 KB
Loading
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"uuid": "click-clock@wernerstucky",
3+
"name": "Click Clock",
4+
"description": "A simple applet that shows a clock icon by default and displays the time when clicked.",
5+
"author": "Werner Stucky",
6+
"version": "1.0",
7+
"max-instances": 1
8+
}

click-clock@wernerstucky/info.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"author": "wernerstucky"
3+
}
2.61 KB
Loading

0 commit comments

Comments
 (0)