feat: Add time to task bar

- Add app.js to windows screen
- Add time display to task bar
- Add new TimeDisplay class to app.js
- Add play and pause buttons as example
- Fix event handlers of task bar according to bubbling and propagation
This commit is contained in:
sthag 2025-10-31 19:47:19 +01:00
parent c259ead9a0
commit bac4b73c08
4 changed files with 103 additions and 11 deletions

View file

@ -1,3 +1,53 @@
// NEWER
class TimeDisplay {
constructor(element, format = 'HH:mm:ss', interval = 1000) {
this.element = element;
this.format = format;
this.interval = interval;
this.isPaused = false;
this.locale = navigator.language || 'en-US';
this.updateTime();
}
formatTime(date) {
const options = {hour: '2-digit', minute: '2-digit', hour12: false};
switch (this.format) {
case 'HH:mm':
return date.toLocaleTimeString(this.locale, options);
case 'HH:mm:ss':
return date.toLocaleTimeString(this.locale, {...options, second: '2-digit'});
case 'hh:mm A':
return date.toLocaleTimeString(this.locale, {...options, hour12: true});
case 'hh:mm:ss A':
return date.toLocaleTimeString(this.locale, {...options, second: '2-digit', hour12: true});
}
return date.toString();
}
async updateTime() {
while (true) {
if (!this.isPaused) {
const now = new Date();
this.element.textContent = this.formatTime(now);
}
await new Promise(resolve => setTimeout(resolve, this.interval));
}
}
// Method to pause updates
pause() {
this.isPaused = true;
}
// Method to resume updates
resume() {
this.isPaused = false;
}
}
//NEW
function Clock(id) {
@ -158,3 +208,10 @@ function gigabytes(percent, total, round) {
return g;
}
function checkButtonAndTarget(event, element, button = 0) {
return (
event.button === button &&
event.target === element
);
}