import ComponentStore from '../store/componentStore' ; import { ElectronApi , ElectronFFmpeg , ElectronFileApi , TransitImage } from '../types/electronApi' ; import { FFmpegDataType } from '../types/ffmpegType' ; const { ProgressStore } = ComponentStore ; const { updateProgress } = ProgressStore ; class Electron { _isElectron = false ; _electronApi : ElectronApi ; _ffmpegApi : ElectronFFmpeg | undefined ; _fileApi : ElectronFileApi | undefined ; constructor ( ) { if ( typeof window !== 'undefined' ) { this . _isElectron = window . isElectron || false ; this . _electronApi = window . electronApi || undefined ; } if ( this . isElectron && this . _electronApi ) { const { ffmpeg , fileApi } = this . _electronApi ; this . _ffmpegApi = ffmpeg ; this . _fileApi = fileApi ; } } get isElectron ( ) : boolean { return this . _isElectron ; } get tempDir ( ) : string | undefined { if ( this . isElectron ) { return this . _fileApi ?. tempDir ; } return undefined ; } param inputFilePaths param ffmpegData Object of type  FFmpegDataType param inputOptions runFFmpeg = ( inputFilePaths , ffmpegData , inputOptions ? ) => { if ( this . isElectron && this . _ffmpegApi ) { const { run } = this . _ffmpegApi ; console . info ( 'Within Electron Bridge Running FFmpeg' ) ; return run ( inputFilePaths , { ... ffmpegData , ffmpegCommands : ffmpegData . ffmpegCommands } , updateProgress , inputOptions ) ; } } ; param fileName readFile = ( fileName ) => { if ( this . _fileApi ) { return this . _fileApi . readOutputFile ( fileName ) ; } } ; param fileName param fileText writeText = ( fileName , fileText ) => { if ( this . _fileApi ) { return this . _fileApi . writeText ( fileName , fileText ) ; } return new Promise < string > ( resolve => resolve ( 'Undefined file api' ) ) ; } ; param images Array of type  TransitImage saveImages = ( images ) => { if ( this . _fileApi ) { return this . _fileApi . saveImages ( images ) ; } throw new Error ( 'Using electron api without electron' ) ; } ; param oldPath param ext saveFile = ( oldPath , ext ) => { if ( this . isElectron && this . _fileApi ) { const { saveFile } = this . _fileApi ; saveFile ( oldPath , ext ) ; } } ; } const electron = new Electron ( ) ; export default electron ; export const isElectron = electron . isElectron ; export const tempDir = electron . tempDir ; /**
 * Hook that wraps functions to use electron or web versions
 */ export const electronWrapper = ( func , electronFunc ? , ... args ) => { if ( isElectron ) { if ( electronFunc ) return electronFunc ( ... args ) ; } else { return func ( ... args ) ; } } ;