import { IService } from "../interfaces/interface.service" ; import { INotification , Notification , ENotificationType , INotificationAction , ENotificationActionType , } from "../../../common/ipc/electron.ipc.messages/index" ; import ServiceElectron from "./service.electron" ; import Logger from "../tools/env.logger" ; import { Progress } from "indexer-neon" ; export { INotification , Notification , ENotificationType , INotificationAction , ENotificationActionType , } ; class description class ServiceNotifications implements IService { private _logger : Logger = new Logger ( "ServiceNotifications" ) ; private _locked : boolean = false ; returns public init ( ) { return new Promise ( resolve => { resolve ( ) ; } ) ; } public destroy ( ) { return new Promise ( resolve => { this . _locked = true ; resolve ( ) ; } ) ; } public getName ( ) { return "ServiceNotifications" ; } param { INotification } notification param { string } session returns { Error | undefined } public notify ( notification , session ? ) { if ( this . _locked ) { return new Error ( this . _logger . warn ( `Cannot send notification "${ notification . caption }" because notification service is locked` ) ) ; } if ( typeof session === "string" && notification . session === undefined ) { notification . session = session ; } ServiceElectron . IPC . send ( new Notification ( notification ) ) . catch ( ( error ) => { this . _logger . error ( `Fail to send notification due error: ${ error . message }` ) ; } ) ; } public notifyFromNeon ( notification , category , sessionId ? , file ? ) { if ( this . _locked ) { return new Error ( this . _logger . warn ( `Cannot send notification "${ category }" because notification service is locked` ) ) ; } this . notify ( { type : this . typeFromNeonSeverity ( notification . severity ) , row : notification . line , file , message : notification . content , caption : category , } , sessionId ) ; } private typeFromNeonSeverity ( neonSeverity ) { switch ( neonSeverity ) { case Progress . Severity . ERROR : return ENotificationType . error ; case Progress . Severity . WARNING : return ENotificationType . warning ; } } } export default new ServiceNotifications ( ) ;