Created
December 24, 2020 02:19
-
-
Save thatisuday/231f303bc2f2966903efa46bee7b9777 to your computer and use it in GitHub Desktop.
A sample Electron JavaScript entry file.
This file contains 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 { 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