Update clock on tab focus

This commit is contained in:
Chrystian Huot 2020-07-13 08:25:38 -04:00
parent 79bdf7b3e7
commit ca410ce742

View file

@ -129,7 +129,7 @@ export class AppRdioScannerComponent implements AfterViewInit, OnDestroy {
private subscriptions: Subscription[] = [];
private visibilityChangeListener = () => this.ngDetectChanges();
private visibilityChangeListener = () => this.syncClock();
constructor(
private appRdioScannerService: AppRdioScannerService,
@ -224,15 +224,7 @@ export class AppRdioScannerComponent implements AfterViewInit, OnDestroy {
// initialize the realtime clock
const setClock = () => {
this.clock = new Date();
this.clockRefresh = setTimeout(() => setClock(), (60 - this.clock.getSeconds()) * 1000);
this.ngDetectChanges();
};
setClock();
this.syncClock();
// subscribe to events
@ -783,6 +775,18 @@ export class AppRdioScannerComponent implements AfterViewInit, OnDestroy {
}
}
private syncClock(): void {
this.clock = new Date();
if (this.clockRefresh) {
clearTimeout(this.clockRefresh);
}
this.clockRefresh = setTimeout(() => this.syncClock(), (60 - this.clock.getSeconds()) * 1000);
this.ngDetectChanges();
};
private transformCall(call: RdioScannerCall): RdioScannerCall {
if (call && Array.isArray(this.config && this.config.systems)) {
call.systemData = this.config?.systems.find((sys) => sys.id === call.system);