diff --git a/src/app/services/system-config.service.ts b/src/app/services/system-config.service.ts index db715e43d..e359ca75a 100644 --- a/src/app/services/system-config.service.ts +++ b/src/app/services/system-config.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@angular/core'; -import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { HttpClient } from '@angular/common/http'; -import { Observable, Subject } from 'rxjs'; +import { Observable, ReplaySubject } from 'rxjs'; import { map } from 'rxjs/operators'; import Folder from '../folder'; @@ -16,13 +16,11 @@ import { ProgressService } from './progress.service'; export class SystemConfigService { private folders: Folder[]; private devices: Device[]; - private foldersSubject: Subject = new Subject(); - private devicesSubject: Subject = new Subject(); + private foldersSubject: ReplaySubject = new ReplaySubject(1); + private devicesSubject: ReplaySubject = new ReplaySubject(1); private systemConfigUrl = environment.production ? apiURL + 'rest/system/config' : 'api/config'; - private checkInterval: number = 100; - constructor( private http: HttpClient, private progressService: ProgressService, @@ -48,37 +46,10 @@ export class SystemConfigService { } getFolders(): Observable { - const folderObservable: Observable = new Observable((observer) => { - if (this.folders) { - observer.next(this.folders); - observer.complete(); - } else { - // create timer to keep checking for folders - let t = setInterval(() => { - if (this.folders) { - clearInterval(t); - observer.next(this.folders) - observer.complete(); - } - }, this.checkInterval); - } - }); - return folderObservable; + return this.foldersSubject.asObservable(); } getDevices(): Observable { - const deviceObserverable: Observable = new Observable((observer) => { - if (this.devices) { - observer.next(this.devices); - } else { - let t = setInterval(() => { - if (this.devices) { - clearInterval(t); - observer.next(this.devices); - } - }, this.checkInterval); - } - }); - return deviceObserverable; + return this.devicesSubject.asObservable(); } } \ No newline at end of file