fix: taskbar clock now updates every second (was computed signal that never changed)
This commit is contained in:
parent
5ea4cdfa0d
commit
f3da41da01
@ -1,4 +1,4 @@
|
||||
import { Component, computed, output } from '@angular/core';
|
||||
import { Component, computed, output, signal, OnDestroy } from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { WindowManagerService, type WindowState } from '../../services/window-manager.service';
|
||||
|
||||
@ -9,26 +9,35 @@ import { WindowManagerService, type WindowState } from '../../services/window-ma
|
||||
templateUrl: './taskbar.component.html',
|
||||
styleUrl: './taskbar.component.scss',
|
||||
})
|
||||
export class TaskbarComponent {
|
||||
export class TaskbarComponent implements OnDestroy {
|
||||
/** Emitted when the start button is clicked. */
|
||||
readonly startClick = output<void>();
|
||||
|
||||
/** Emitted when a taskbar item requests to launch an app. */
|
||||
readonly launchApp = output<string>();
|
||||
|
||||
/** Current time string. */
|
||||
readonly time = computed(() => {
|
||||
const now = new Date();
|
||||
return now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
|
||||
});
|
||||
|
||||
/** Current time string — updates every second via setInterval. */
|
||||
readonly time = signal('');
|
||||
/** Current date string. */
|
||||
readonly date = computed(() => {
|
||||
const now = new Date();
|
||||
return now.toLocaleDateString([], { month: 'short', day: 'numeric', year: 'numeric' });
|
||||
});
|
||||
readonly date = signal('');
|
||||
private clockTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
constructor(public wm: WindowManagerService) {}
|
||||
constructor(public wm: WindowManagerService) {
|
||||
this.updateClock();
|
||||
this.clockTimer = setInterval(() => this.updateClock(), 1000);
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
if (this.clockTimer) {
|
||||
clearInterval(this.clockTimer);
|
||||
}
|
||||
}
|
||||
|
||||
private updateClock(): void {
|
||||
const now = new Date();
|
||||
this.time.set(now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }));
|
||||
this.date.set(now.toLocaleDateString([], { month: 'short', day: 'numeric', year: 'numeric' }));
|
||||
}
|
||||
|
||||
/** All windows for the taskbar items. */
|
||||
readonly windows = computed(() => this.wm.allWindows());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user