Created
December 29, 2020 21:41
-
-
Save thatisuday/8855e13789e94523877d0f397cff7a8e to your computer and use it in GitHub Desktop.
The renderer process entrypoint for an Electron application.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const dragDrop = require( 'drag-drop' ); | |
const { ipcRenderer } = require( 'electron' ); | |
// local dependencies | |
const dom = require( './dom' ); | |
/*****************************/ | |
// get list of files from the `main` process | |
ipcRenderer.invoke( 'app:get-files' ).then( ( files = [] ) => { | |
dom.displayFiles( files ); | |
} ); | |
// handle file delete event | |
ipcRenderer.on( 'app:delete-file', ( event, filename ) => { | |
document.getElementById( filename ).remove(); | |
} ); | |
/*****************************/ | |
// add files drop listener | |
dragDrop( '#uploader', ( files ) => { | |
const _files = files.map( file => { | |
return { | |
name: file.name, | |
path: file.path, | |
}; | |
} ); | |
// send file(s) add event to the `main` process | |
ipcRenderer.invoke( 'app:on-file-add', _files ).then( () => { | |
ipcRenderer.invoke( 'app:get-files' ).then( ( files = [] ) => { | |
dom.displayFiles( files ); | |
} ); | |
} ); | |
} ); | |
// open filesystem dialog | |
window.openDialog = () => { | |
ipcRenderer.invoke( 'app:on-fs-dialog-open' ).then( () => { | |
ipcRenderer.invoke( 'app:get-files' ).then( ( files = [] ) => { | |
dom.displayFiles( files ); | |
} ); | |
} ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment