import { injectable } from "inversify" ; import { lazyInject } from "../inversify.config" ; import ComponentStatusStore from "../stores/ComponentStatusStore" ; import SonarQubeComponentInfoService from "./sonarqube/SonarQubeComponentInfoService" ; @ injectable ( ) export default class AutoReloadService { public static RELOAD_INTERVAL_MS = 5 * 60 * 1000 ; @ lazyInject ( "ComponentStatusStore" ) private readonly componentStatusStore ! : ComponentStatusStore ; @ lazyInject ( "SonarQubeComponentInfoService" ) private readonly componentInfoService ! : SonarQubeComponentInfoService ; private timer ? : number ; public startAutoReload ( ) { if ( this . timer ) { window . clearInterval ( this . timer ) ; } if ( this . componentStatusStore . lastAnalysisDate !== undefined ) { this . timer = window . setInterval ( this . updateAnalysisDate . bind ( this ) , AutoReloadService . RELOAD_INTERVAL_MS ) ; } } public updateAnalysisDate ( ) { this . componentInfoService . loadComponentInfo ( ) ; } public isActive ( ) { return this . timer !== undefined ; } }