From f3da41da01813ae4c7a809afc40de45281ad046d Mon Sep 17 00:00:00 2001 From: Butterfly Dev Date: Tue, 7 Apr 2026 04:00:30 +0000 Subject: [PATCH] fix: taskbar clock now updates every second (was computed signal that never changed) --- .../components/taskbar/taskbar.component.ts | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/desktop/src/app/components/taskbar/taskbar.component.ts b/desktop/src/app/components/taskbar/taskbar.component.ts index 348e7dd..0748a4a 100644 --- a/desktop/src/app/components/taskbar/taskbar.component.ts +++ b/desktop/src/app/components/taskbar/taskbar.component.ts @@ -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(); /** Emitted when a taskbar item requests to launch an app. */ readonly launchApp = output(); - /** 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 | 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());