mirror of
https://github.com/chuot/rdio-scanner.git
synced 2026-08-16 09:53:01 -06:00
Add visibilitychange listener
This commit is contained in:
parent
4bbff7d12c
commit
0201019ef8
|
|
@ -17,6 +17,7 @@
|
||||||
* ****************************************************************************
|
* ****************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import { DOCUMENT } from '@angular/common';
|
||||||
import {
|
import {
|
||||||
ChangeDetectionStrategy,
|
ChangeDetectionStrategy,
|
||||||
ChangeDetectorRef,
|
ChangeDetectorRef,
|
||||||
|
|
@ -24,6 +25,7 @@ import {
|
||||||
ElementRef,
|
ElementRef,
|
||||||
EventEmitter,
|
EventEmitter,
|
||||||
HostListener,
|
HostListener,
|
||||||
|
Inject,
|
||||||
OnDestroy,
|
OnDestroy,
|
||||||
OnInit,
|
OnInit,
|
||||||
Output,
|
Output,
|
||||||
|
|
@ -125,8 +127,11 @@ export class AppRdioScannerComponent implements OnDestroy, OnInit {
|
||||||
|
|
||||||
private subscriptions: Subscription[] = [];
|
private subscriptions: Subscription[] = [];
|
||||||
|
|
||||||
|
private visibilityChangeListener = () => this.ngDetectChanges();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private appRdioScannerService: AppRdioScannerService,
|
private appRdioScannerService: AppRdioScannerService,
|
||||||
|
@Inject(DOCUMENT) private document: Document,
|
||||||
private ngChangeDetectorRef: ChangeDetectorRef,
|
private ngChangeDetectorRef: ChangeDetectorRef,
|
||||||
private ngElementRef: ElementRef,
|
private ngElementRef: ElementRef,
|
||||||
private ngFormBuilder: FormBuilder,
|
private ngFormBuilder: FormBuilder,
|
||||||
|
|
@ -223,9 +228,16 @@ export class AppRdioScannerComponent implements OnDestroy, OnInit {
|
||||||
// terminate our live event emitter
|
// terminate our live event emitter
|
||||||
|
|
||||||
this.live.complete();
|
this.live.complete();
|
||||||
|
|
||||||
|
// remove visibility change listener
|
||||||
|
this.document.removeEventListener('visibilitychange', this.visibilityChangeListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
// Refresh display on visibility change
|
||||||
|
|
||||||
|
this.document.addEventListener('visibilitychange', this.visibilityChangeListener);
|
||||||
|
|
||||||
// initialize the realtime clock
|
// initialize the realtime clock
|
||||||
|
|
||||||
const setClock = () => {
|
const setClock = () => {
|
||||||
|
|
@ -554,6 +566,12 @@ export class AppRdioScannerComponent implements OnDestroy, OnInit {
|
||||||
.concat(' Hz');
|
.concat(' Hz');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ngDetectChanges(): void {
|
||||||
|
if (!this.document.hidden) {
|
||||||
|
this.ngChangeDetectorRef.detectChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private refreshSearchResults(): void {
|
private refreshSearchResults(): void {
|
||||||
const limit = this.searchResultsLimit;
|
const limit = this.searchResultsLimit;
|
||||||
const offset = this.searchResultsOffset;
|
const offset = this.searchResultsOffset;
|
||||||
|
|
@ -599,11 +617,11 @@ export class AppRdioScannerComponent implements OnDestroy, OnInit {
|
||||||
this.dimmerDelay = setTimeout(() => {
|
this.dimmerDelay = setTimeout(() => {
|
||||||
this.dimmerDelay = undefined;
|
this.dimmerDelay = undefined;
|
||||||
|
|
||||||
this.ngChangeDetectorRef.detectChanges();
|
this.ngDetectChanges();
|
||||||
}, 4000);
|
}, 4000);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ngChangeDetectorRef.detectChanges();
|
this.ngDetectChanges();
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateDisplay(time = this.callTime): void {
|
private updateDisplay(time = this.callTime): void {
|
||||||
|
|
@ -678,6 +696,6 @@ export class AppRdioScannerComponent implements OnDestroy, OnInit {
|
||||||
this.ledClass = `${this.ledClass} ${this.call.systemData.led}`;
|
this.ledClass = `${this.ledClass} ${this.call.systemData.led}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.ngChangeDetectorRef.detectChanges();
|
this.ngDetectChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue