import { Injectable } from '@angular/core' ; import { HttpClient } from '@angular/common/http' ; import { Observable } from 'rxjs/Observable' ; import { ConfigModel } from '../../models/config.model' ; @ Injectable ( ) export class ConfigurationService { static isBackendOnline : boolean ; manifestFileName = 'manifest.json' ; configFileName = 'config.json' ; manifest : any ; config : ConfigModel ; constructor ( private http ) { ConfigurationService . isBackendOnline = true ; } getJsonFileContent ( fileName ) { return this . http . get ( chrome . extension . getURL ( fileName ) ) ; } getExtensionVersion ( ) { return Observable . create ( observer => { if ( this . manifest ) { observer . next ( this . manifest . version ) ; } else { this . getJsonFileContent ( this . manifestFileName ) . subscribe ( manifest => { this . manifest = manifest ; observer . next ( manifest . version ) ; } ) ; } } ) ; } getConfiguration ( ) { return Observable . create ( observer => { if ( this . config ) { observer . next ( this . config ) ; } else { this . getJsonFileContent ( this . configFileName ) . subscribe ( ( config ) => { this . config = config ; observer . next ( config ) ; } ) ; } } ) ; } }