Skip to content

Instantly share code, notes, and snippets.

@thatisuday
Created December 24, 2020 02:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thatisuday/231f303bc2f2966903efa46bee7b9777 to your computer and use it in GitHub Desktop.
Save thatisuday/231f303bc2f2966903efa46bee7b9777 to your computer and use it in GitHub Desktop.
A sample Electron JavaScript entry file.
const { app, BrowserWindow, ipcMain } = require( 'electron' );
// open a window
const openWindow = ( type ) => {
const win = new BrowserWindow( {
width: 600,
height: 300,
} );
if( type === 'image' ) {
win.loadFile( './image.html' ); // image window
} else {
win.loadFile( './hello.html' ); // default window
}
}
// when app is ready, create a window
app.on( 'ready', () => {
openWindow(); // open default window
} );
// when all windows are closed, quit the application
app.on( 'window-all-closed', () => {
if( process.platform !== 'darwin' ) {
app.quit(); // exit
}
} );
// when application is activated, open default window
app.on( 'activate', () => {
if( BrowserWindow.getAllWindows().length === 0 ) {
openWindow(); // open default window
}
} );
// listen to application messages
ipcMain.on( 'app:display-image', () => {
console.log( '[message received]', 'app:display-image' );
openWindow( 'image' ); // open image window
} )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment