Skip to content

Instantly share code, notes, and snippets.

@thatisuday
Created December 29, 2020 21:41
Show Gist options
  • Save thatisuday/8855e13789e94523877d0f397cff7a8e to your computer and use it in GitHub Desktop.
Save thatisuday/8855e13789e94523877d0f397cff7a8e to your computer and use it in GitHub Desktop.
The renderer process entrypoint for an Electron application.
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