import { ipcRenderer } from "electron" ; import { ProgressMessage } from "./ProgressMessage" ; import { ProgressMessages } from "./ProgressMessages" ; import { DeterminateProgressBar } from './DeterminateProgressBar' ; import { Logger } from 'polar-shared/src/logger/Logger' ; import { TypedMessage } from '../../util/TypedMessage' ; const log = Logger . create ( ) ; export class ProgressService { public start ( ) { if ( ipcRenderer ) { ipcRenderer . on ( ProgressMessages . CHANNEL , ( event , progressMessage ) => { this . onProgressMessage ( progressMessage ) ; } ) ; } window . addEventListener ( "message" , event => this . onMessageReceived ( event ) , false ) ; } private onMessageReceived ( event ) { switch ( event . data . type ) { case ProgressMessages . CHANNEL : const typedMessage = < TypedMessage < ProgressMessage > > event . data ; this . onProgressMessage ( typedMessage . value ) ; break ; } } private onProgressMessage ( progressMessage ) { DeterminateProgressBar . update ( progressMessage ) ; } }