fix: taskbar clock now updates every second (was computed signal that never changed)

This commit is contained in:
Butterfly Dev 2026-04-07 04:00:30 +00:00
parent 5ea4cdfa0d
commit f3da41da01

View File

@ -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 { CommonModule } from '@angular/common';
import { WindowManagerService, type WindowState } from '../../services/window-manager.service'; 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', templateUrl: './taskbar.component.html',
styleUrl: './taskbar.component.scss', styleUrl: './taskbar.component.scss',
}) })
export class TaskbarComponent { export class TaskbarComponent implements OnDestroy {
/** Emitted when the start button is clicked. */ /** Emitted when the start button is clicked. */
readonly startClick = output<void>(); readonly startClick = output<void>();
/** Emitted when a taskbar item requests to launch an app. */ /** Emitted when a taskbar item requests to launch an app. */
readonly launchApp = output<string>(); readonly launchApp = output<string>();
/** Current time string. */ /** Current time string — updates every second via setInterval. */
readonly time = computed(() => { readonly time = signal('');
const now = new Date();
return now.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
});
/** Current date string. */ /** Current date string. */
readonly date = computed(() => { readonly date = signal('');
const now = new Date(); private clockTimer: ReturnType<typeof setInterval> | null = null;
return now.toLocaleDateString([], { month: 'short', day: 'numeric', year: 'numeric' });
});
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. */ /** All windows for the taskbar items. */
readonly windows = computed(() => this.wm.allWindows()); readonly windows = computed(() => this.wm.allWindows());